Skip to content

Commit

Permalink
feat: Segmentation architecture improvements (#330)
Browse files Browse the repository at this point in the history
* renamed labelmap to segmentation

* wip

* fix toolGroup viewports and toolOptions in enabled and disabled

* fix ItoolGroup location

* wip for new states

* fix rename

* minor work

* more work

* add removeViewports from toolGroup

* feat getSegmentations for toolGroup

* wip

* inactive segmentations

* active segmentation controller

* fix naming

* add remove viewport for toolGroup

* wip

* wip for using toolGroups

* change gettoolGroups to toolGroup

* fix active segmentation for toolGroup

* feat add segmentation visibility

* add enable disable callback

* fixed rectangle scissor

* fix trigger segmentation modified

* fix create new segmentation

* fix test

* renamed global segmentation methods

* wip

* change state to toolGroup based

* wip

* first render with the new state manager

add toolGroupUID to toolInstances

toolGroupId to toolGroupUID rename

rename bunch of methods

rename id to uid

fix remove segmentation from toolGroup

working new rectangle scissor with new state

modifiy hide segmentation controller

finished all controllers

add segmentation config controller

toolGroup specific configuration

initial toolGroup segmentation config

address review comments

fix build issues

address more comments

address more comments

add remove segmentations after toolgroup destroy

chore: add .yarn to gitignore

fix: setSegmentIndexLockedStatus for tool group and a bunch of typos

wip for tests

* add initial rendering tests for segmentation

* add segmentation state tests

* fix seg state test

* initial seg tool tests

* add documentation to segmentation functions

* fix draw test for scissor

* fix bug for rectangle scissor test

* fix tool name typo

* refactored various testutils

* add custom colorLUT test for segmentation

* visibility controller

* segmentation config controller tests

* fix test errors

* address some comments

* address some comments and add docs to tools
  • Loading branch information
sedghi authored and swederik committed Mar 22, 2022
1 parent cfff4e3 commit c603906
Show file tree
Hide file tree
Showing 179 changed files with 7,594 additions and 2,958 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ build
.env.development.local
.env.test.local
.env.production.local
.yarn

npm-debug.log*
yarn-debug.log*
Expand Down
13 changes: 13 additions & 0 deletions packages/cornerstone-render/src/RenderingEngine/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class Viewport {
public getRenderer() {
const renderingEngine = this.getRenderingEngine()

if (!renderingEngine || renderingEngine.hasBeenDestroyed) {
throw new Error('Rendering engine has been destroyed')
}

return renderingEngine.offscreenMultiRenderWindow.getRenderer(this.uid)
}

Expand Down Expand Up @@ -318,6 +322,15 @@ class Viewport {

public addActor(actorEntry: ActorEntry): void {
const { uid: actorUID, volumeActor } = actorEntry
const renderingEngine = this.getRenderingEngine()

if (!renderingEngine || renderingEngine.hasBeenDestroyed) {
console.warn(
`Cannot add actor UID of ${actorUID} Rendering Engine has been destroyed`
)
return
}

if (!actorUID || !volumeActor) {
throw new Error('Actors should have uid and vtk volumeActor properties')
}
Expand Down
18 changes: 13 additions & 5 deletions packages/cornerstone-render/src/RenderingEngine/VolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,20 @@ class VolumeViewport extends Viewport {

// One actor per volume
for (let i = 0; i < volumeInputArray.length; i++) {
const { volumeUID, visibility } = volumeInputArray[i]
const { volumeUID, visibility, actorUID } = volumeInputArray[i]
const volumeActor = await createVolumeActor(volumeInputArray[i])

if (visibility === false) {
volumeActor.setVisibility(false)
}

volumeActors.push({ uid: volumeUID, volumeActor })
// We cannot use only volumeUID since then we cannot have for instance more
// than one representation of the same volume (since actors would have the
// same name, and we don't allow that) AND We cannot use only any uid, since
// we rely on the volume in the cache for mapper. So we prefer actorUID if
// it is defined, otherwise we use volumeUID for the actor name.
const uid = actorUID || volumeUID
volumeActors.push({ uid, volumeActor })
}

this.addActors(volumeActors)
Expand All @@ -168,11 +174,13 @@ class VolumeViewport extends Viewport {
/**
* It removes the volume actor from the Viewport. If the volume actor is not in
* the viewport, it does nothing.
* @param volumeUIDs Array of volume UIDs to remove
* @param actorUIDs Array of actor UIDs to remove. In case of simple volume it will
* be the volume UID, but in caase of Segmentation it will be `{volumeUID}-{representationType}`
* since the same volume can be rendered in multiple representations.
* @param immediate If true, the Viewport will be rendered immediately
*/
public removeVolumes(volumeUIDs: Array<string>, immediate = false): void {
this.removeActors(volumeUIDs)
public removeVolumeActors(actorUIDs: Array<string>, immediate = false): void {
this.removeActors(actorUIDs)

if (immediate) {
this.render()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import renderingEngineCache from './renderingEngineCache'
import RenderingEngine from './RenderingEngine'
import { IViewport } from '../types'

/**
* Method to retrieve a RenderingEngine by its unique identifier.
Expand All @@ -20,10 +21,6 @@ import RenderingEngine from './RenderingEngine'
* @public
*/
export function getRenderingEngine(uid: string): RenderingEngine | undefined {
// if (!uid) {
// return renderingEngineCache.getAll()
// }

return renderingEngineCache.get(uid)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import vtkVolumeMapper from 'vtk.js/Sources/Rendering/Core/VolumeMapper'

import { vtkSharedVolumeMapper } from '../vtkClasses'

export default function createVolumeMapper(
Expand Down
10 changes: 8 additions & 2 deletions packages/cornerstone-render/src/getEnabledElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ export default function getEnabledElement(
return
}

const { viewportUid: viewportUID, renderingEngineUid: renderingEngineUID } =
element.dataset
const { viewportUid, renderingEngineUid } = element.dataset

return getEnabledElementByUIDs(renderingEngineUid, viewportUid)
}

export function getEnabledElementByUIDs(
renderingEngineUID: string,
viewportUID: string
): IEnabledElement {
if (!renderingEngineUID || !viewportUID) {
return
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cornerstone-render/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
registerVolumeLoader,
registerUnknownVolumeLoader,
} from './volumeLoader'
import getEnabledElement from './getEnabledElement'
import getEnabledElement, { getEnabledElementByUIDs } from './getEnabledElement'
import configuration from './configuration'
import metaData from './metaData'
import {
Expand Down Expand Up @@ -114,6 +114,7 @@ export {
cache,
Cache,
getEnabledElement,
getEnabledElementByUIDs,
renderToCanvas,
//
eventTarget,
Expand Down
14 changes: 14 additions & 0 deletions packages/cornerstone-render/src/types/CustomEventType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface CustomEvent<T = any> extends Event {
/**
* Returns any custom data event was created with. Typically used for synthetic events.
*/
readonly detail: T
initCustomEvent(
typeArg: string,
canBubbleArg: boolean,
cancelableArg: boolean,
detailArg: T
): void
}

export default CustomEvent
1 change: 1 addition & 0 deletions packages/cornerstone-render/src/types/IViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IViewport {
renderingEngineUID: string
type: string
canvas: HTMLCanvasElement
element: HTMLElement
sx: number
sy: number
sWidth: number
Expand Down
3 changes: 3 additions & 0 deletions packages/cornerstone-render/src/types/IVolumeInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ type VolumeInputCallback = (params: {

type IVolumeInput = {
volumeUID: string
// actorUID for segmentations, since two segmentations with the same volumeUID
// can have different represetnations
actorUID?: string
visibility?: boolean
callback?: VolumeInputCallback
blendMode?: string
Expand Down
3 changes: 3 additions & 0 deletions packages/cornerstone-render/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type IImageVolume from './IImageVolume'
import type VolumeLoaderFn from './VolumeLoaderFn'
import type IRegisterImageLoader from './IRegisterImageLoader'
import type IStreamingVolume from './IStreamingVolume'
import type CustomEventType from './CustomEventType'
import type {
IViewport,
ViewportInput,
Expand Down Expand Up @@ -106,4 +107,6 @@ export type {
CPUFallbackLookupTable,
CPUFallbackLUT,
CPUFallbackRenderingTools,
//
CustomEventType,
}
Loading

0 comments on commit c603906

Please sign in to comment.