Skip to content

Commit

Permalink
feat: Add initial segmentation demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi authored and swederik committed Mar 21, 2022
1 parent 9ed4425 commit 0b9b2b3
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 2 deletions.
42 changes: 42 additions & 0 deletions packages/cornerstone-render/src/RenderingEngine/Scene.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { vtkImageData } from 'vtk.js/Sources/Common/DataModel/ImageData'
import renderingEngineCache from './renderingEngineCache'
import RenderingEngine from './RenderingEngine'
import { createVolumeActor } from './helpers'
import { loadVolume } from '../volumeLoader'
import { uuidv4 } from '../utilities'
import VolumeViewport from './VolumeViewport'
import { VolumeActor, ActorEntry } from '../types'
import vtkVolumeMapper from 'vtk.js/Sources/Rendering/Core/VolumeMapper'
import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume'

type VolumeInput = {
volumeUID: string
Expand Down Expand Up @@ -158,6 +161,45 @@ class Scene {
}
}

// todo: should add segmentationUID similar to volumeUID
public async setSegmentations(
labelMap: any,
immediate = false
): Promise<void> {
debugger
const volumeActors = []

// todo: use shared volume mapper for seg too
const { imageData: vtkImageData, actor, mapper } = labelMap
// const volumeMapper = vtkVolumeMapper.newInstance()
// volumeMapper.setInputData(vtkImageData)

// const spacing = vtkImageData.getSpacing()
// // Set the sample distance to half the mean length of one side. This is where the divide by 6 comes from.
// // https://github.com/Kitware/VTK/blob/6b559c65bb90614fb02eb6d1b9e3f0fca3fe4b0b/Rendering/VolumeOpenGL2/vtkSmartVolumeMapper.cxx#L344
// const sampleDistance = (spacing[0] + spacing[1] + spacing[2]) / 6

// // This is to allow for good pixel level image quality.
// volumeMapper.setMaximumSamplesPerRay(4000)

// volumeMapper.setSampleDistance(sampleDistance)

// const volumeActor = vtkVolume.newInstance()
// // volumeActor.getProperty().setInterpolationTypeToNearest()
// volumeActor.setMapper(volumeMapper)

volumeActors.push({ uid: 'Seg', volumeActor: actor })

this._sceneViewports.forEach((uid) => {
const viewport = this.getViewport(uid)
viewport.addActors(volumeActors)
})

if (immediate) {
this.render()
}
}

/**
* @method render Renders all `Viewport`s in the `Scene` using the `Scene`'s `RenderingEngine`.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import createVolumeActor from './createVolumeActor'
import createVolumeMapper from './createVolumeMapper'

export { createVolumeActor }
export { createVolumeActor, createVolumeMapper }
8 changes: 7 additions & 1 deletion packages/cornerstone-render/src/RenderingEngine/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import RenderingEngine from './RenderingEngine'
import getRenderingEngine from './getRenderingEngine'
import { createVolumeActor, createVolumeMapper } from './helpers'

export { getRenderingEngine, RenderingEngine }
export {
getRenderingEngine,
RenderingEngine,
createVolumeActor,
createVolumeMapper,
}

export default RenderingEngine
3 changes: 3 additions & 0 deletions packages/cornerstone-render/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ORIENTATION from './constants/orientation'
import VIEWPORT_TYPE from './constants/viewportType'
import INTERPOLATION_TYPE from './constants/interpolationType'
//
import { createVolumeActor, createVolumeMapper } from './RenderingEngine'
import RenderingEngine from './RenderingEngine'
import VolumeViewport from './RenderingEngine/VolumeViewport'
import StackViewport from './RenderingEngine/StackViewport'
Expand Down Expand Up @@ -81,6 +82,8 @@ export {
RenderingEngine,
getRenderingEngine,
getRenderingEngines,
createVolumeActor,
createVolumeMapper,
//
cache,
Cache,
Expand Down
12 changes: 12 additions & 0 deletions packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import TestUtils from './ExampleTestUtils'
import TestUtilsVolume from './ExampleTestUtilsVolume'
import CalibrationExample from './ExampleCalibration'
import { resetCPURenderingOnlyForDebugOrTests } from '@ohif/cornerstone-render'
import SegmentationRender from './ExampleSegmentationRender'

function LinkOut({ href, text }) {
return (
Expand Down Expand Up @@ -77,6 +78,11 @@ function Index() {
url: '/oneStackCPU',
text: 'Example one Stack with CPU fallback (even if your environment supports GPU)',
},
{
title: 'Segmentation Render',
url: '/segmentationRender',
text: 'Example for demonstrating the rendering of Segmentation',
},
{
title: 'Canvas Resize',
url: '/canvasResize',
Expand Down Expand Up @@ -231,6 +237,11 @@ function AppRouter() {
children: <CalibrationExample />,
})

const segmentationRender = () =>
Example({
children: <SegmentationRender />,
})

const stackViewport = () =>
Example({
children: <StackViewportExample />,
Expand Down Expand Up @@ -323,6 +334,7 @@ function AppRouter() {
<Route exact path="/testUtils/" render={Test} />
<Route exact path="/testUtilsVolume/" render={TestVolume} />
<Route exact path="/calibratedImages/" render={calibratedImages} />
<Route exact path="/segmentationRender/" render={segmentationRender} />
<Route
exact
path="/toolDisplayConfiguration/"
Expand Down
Loading

0 comments on commit 0b9b2b3

Please sign in to comment.