@cornerstonejs/tools 2.0.0-beta.23 → 2.0.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/esm/enums/SegmentationRepresentations.d.ts +3 -3
  2. package/dist/esm/enums/SegmentationRepresentations.js +3 -3
  3. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseMove.js +4 -0
  4. package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +27 -23
  5. package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js +2 -2
  6. package/dist/esm/stateManagement/index.d.ts +3 -2
  7. package/dist/esm/stateManagement/index.js +2 -2
  8. package/dist/esm/stateManagement/segmentation/SegmentationRenderingEngine.d.ts +1 -2
  9. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.d.ts +9 -6
  10. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +72 -24
  11. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.d.ts +8 -3
  12. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.js +14 -4
  13. package/dist/esm/stateManagement/segmentation/config/segmentationConfig.d.ts +8 -7
  14. package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js +1 -1
  15. package/dist/esm/stateManagement/segmentation/getGlobalConfig.d.ts +2 -2
  16. package/dist/esm/stateManagement/segmentation/getPerSegmentConfig.d.ts +2 -2
  17. package/dist/esm/stateManagement/segmentation/getStackSegmentationImageIdsForViewport.d.ts +1 -0
  18. package/dist/esm/stateManagement/segmentation/getStackSegmentationImageIdsForViewport.js +5 -0
  19. package/dist/esm/stateManagement/segmentation/helpers/updateStackSegmentationState.js +5 -5
  20. package/dist/esm/stateManagement/segmentation/index.d.ts +2 -2
  21. package/dist/esm/stateManagement/segmentation/index.js +2 -2
  22. package/dist/esm/stateManagement/segmentation/internalAddSegmentationRepresentation.d.ts +3 -0
  23. package/dist/esm/stateManagement/segmentation/{addSegmentationRepresentation.js → internalAddSegmentationRepresentation.js} +4 -3
  24. package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +4 -4
  25. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js +4 -4
  26. package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.js +1 -1
  27. package/dist/esm/stateManagement/segmentation/polySeg/Surface/surfaceComputationStrategies.js +6 -6
  28. package/dist/esm/stateManagement/segmentation/polySeg/Surface/updateSurfaceData.js +2 -2
  29. package/dist/esm/stateManagement/segmentation/segmentationState.d.ts +2 -2
  30. package/dist/esm/stateManagement/segmentation/segmentationState.js +2 -2
  31. package/dist/esm/stateManagement/segmentation/setGlobalConfig.d.ts +2 -2
  32. package/dist/esm/stateManagement/segmentation/setPerSegmentConfig.d.ts +2 -2
  33. package/dist/esm/store/ToolGroupManager/ToolGroup.d.ts +1 -1
  34. package/dist/esm/tools/AdvancedMagnifyTool.js +2 -2
  35. package/dist/esm/tools/ScaleOverlayTool.js +23 -20
  36. package/dist/esm/tools/annotation/LivewireContourTool.d.ts +5 -0
  37. package/dist/esm/tools/annotation/LivewireContourTool.js +156 -8
  38. package/dist/esm/tools/base/BaseTool.d.ts +1 -13
  39. package/dist/esm/tools/base/ContourSegmentationBaseTool.js +1 -1
  40. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +4 -4
  41. package/dist/esm/tools/displayTools/Contour/contourHandler/utils.js +1 -1
  42. package/dist/esm/tools/displayTools/Contour/removeContourFromElement.js +1 -1
  43. package/dist/esm/tools/segmentation/BrushTool.d.ts +38 -0
  44. package/dist/esm/tools/segmentation/BrushTool.js +40 -7
  45. package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js +23 -15
  46. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +6 -0
  47. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +10 -5
  48. package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
  49. package/dist/esm/tools/segmentation/strategies/compositions/preview.js +2 -2
  50. package/dist/esm/tools/segmentation/strategies/compositions/setValue.js +6 -4
  51. package/dist/esm/tools/segmentation/strategies/fillSphere.js +5 -14
  52. package/dist/esm/types/EventTypes.d.ts +1 -2
  53. package/dist/esm/types/IBaseTool.d.ts +2 -0
  54. package/dist/esm/types/IBaseTool.js +1 -0
  55. package/dist/esm/types/IToolGroup.d.ts +3 -63
  56. package/dist/esm/types/LabelmapToolOperationData.d.ts +5 -0
  57. package/dist/esm/types/SegmentationStateTypes.d.ts +22 -22
  58. package/dist/esm/types/index.d.ts +3 -2
  59. package/dist/esm/utilities/contourSegmentation/addContourSegmentationAnnotation.js +3 -3
  60. package/dist/esm/utilities/contourSegmentation/removeContourSegmentationAnnotation.js +1 -1
  61. package/dist/esm/utilities/contours/generateContourSetsFromLabelmap.js +7 -7
  62. package/dist/esm/utilities/segmentation/getHoveredContourSegmentationAnnotation.js +1 -1
  63. package/dist/esm/utilities/segmentation/getSegmentIndexAtLabelmapBorder.js +8 -4
  64. package/dist/esm/utilities/segmentation/getSegmentIndexAtWorldPoint.js +2 -2
  65. package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js +2 -2
  66. package/dist/esm/utilities/segmentation/isLineInSegment.js +3 -3
  67. package/dist/umd/index.js +1 -1
  68. package/dist/umd/index.js.map +1 -1
  69. package/package.json +16 -7
  70. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentation.d.ts +0 -3
@@ -1,6 +1,6 @@
1
1
  declare enum SegmentationRepresentations {
2
- Labelmap = "LABELMAP",
3
- Contour = "CONTOUR",
4
- Surface = "SURFACE"
2
+ Labelmap = "Labelmap",
3
+ Contour = "Contour",
4
+ Surface = "Surface"
5
5
  }
6
6
  export default SegmentationRepresentations;
@@ -1,7 +1,7 @@
1
1
  var SegmentationRepresentations;
2
2
  (function (SegmentationRepresentations) {
3
- SegmentationRepresentations["Labelmap"] = "LABELMAP";
4
- SegmentationRepresentations["Contour"] = "CONTOUR";
5
- SegmentationRepresentations["Surface"] = "SURFACE";
3
+ SegmentationRepresentations["Labelmap"] = "Labelmap";
4
+ SegmentationRepresentations["Contour"] = "Contour";
5
+ SegmentationRepresentations["Surface"] = "Surface";
6
6
  })(SegmentationRepresentations || (SegmentationRepresentations = {}));
7
7
  export default SegmentationRepresentations;
@@ -3,6 +3,7 @@ import { ToolModes } from '../../enums';
3
3
  import filterToolsWithAnnotationsForElement from '../../store/filterToolsWithAnnotationsForElement';
4
4
  import getToolsWithModesForMouseEvent from '../shared/getToolsWithModesForMouseEvent';
5
5
  import triggerAnnotationRender from '../../utilities/triggerAnnotationRender';
6
+ import { initElementCursor } from '../../cursors/elementCursor';
6
7
  const { Active, Passive } = ToolModes;
7
8
  export default function mouseMove(evt) {
8
9
  if (state.isInteractingWithTool || state.isMultiPartToolActive) {
@@ -34,4 +35,7 @@ export default function mouseMove(evt) {
34
35
  if (annotationsNeedToBeRedrawn === true) {
35
36
  triggerAnnotationRender(element);
36
37
  }
38
+ if (!state.isInteractingWithTool) {
39
+ initElementCursor(element, null);
40
+ }
37
41
  }
@@ -1,30 +1,34 @@
1
- import { cache, utilities as csUtils, VolumeViewport, getEnabledElementByViewportId, } from '@cornerstonejs/core';
1
+ import { cache, utilities as csUtils, VolumeViewport, getEnabledElementByViewportId, StackViewport, } from '@cornerstonejs/core';
2
2
  import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
3
3
  const onLabelmapSegmentationDataModified = function (evt) {
4
4
  const { segmentationId, modifiedSlicesToUse } = evt.detail;
5
- let modifiedSlices = modifiedSlicesToUse;
6
5
  const { representationData, type } = SegmentationState.getSegmentation(segmentationId);
7
- const labelmapRepresentationData = representationData[type];
8
- if ('stack' in labelmapRepresentationData &&
9
- 'volumeId' in labelmapRepresentationData) {
10
- modifiedSlices = [];
11
- }
12
- if ('volumeId' in labelmapRepresentationData) {
13
- performVolumeLabelmapUpdate({
14
- modifiedSlicesToUse: modifiedSlices,
15
- representationData,
16
- type,
17
- });
18
- }
19
6
  const viewportIds = SegmentationState.getViewportIdsWithSegmentation(segmentationId);
20
- if ('imageIds' in labelmapRepresentationData) {
21
- performStackLabelmapUpdate({
22
- viewportIds,
23
- segmentationId,
24
- representationData,
25
- type,
26
- });
27
- }
7
+ const hasVolumeViewport = viewportIds.some((viewportId) => {
8
+ const { viewport } = getEnabledElementByViewportId(viewportId);
9
+ return viewport instanceof VolumeViewport;
10
+ });
11
+ const hasStackViewport = viewportIds.some((viewportId) => {
12
+ const { viewport } = getEnabledElementByViewportId(viewportId);
13
+ return viewport instanceof StackViewport;
14
+ });
15
+ const hasBothStackAndVolume = hasVolumeViewport && hasStackViewport;
16
+ viewportIds.forEach((viewportId) => {
17
+ const { viewport } = getEnabledElementByViewportId(viewportId);
18
+ if (viewport instanceof VolumeViewport) {
19
+ performVolumeLabelmapUpdate({
20
+ modifiedSlicesToUse: hasBothStackAndVolume ? [] : modifiedSlicesToUse,
21
+ representationData,
22
+ type,
23
+ });
24
+ }
25
+ if (viewport instanceof StackViewport) {
26
+ performStackLabelmapUpdate({
27
+ viewportIds,
28
+ segmentationId,
29
+ });
30
+ }
31
+ });
28
32
  };
29
33
  function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData, type, }) {
30
34
  const segmentationVolume = cache.getVolume(representationData[type].volumeId);
@@ -46,7 +50,7 @@ function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData,
46
50
  });
47
51
  imageData.modified();
48
52
  }
49
- function performStackLabelmapUpdate({ viewportIds, segmentationId, representationData, type, }) {
53
+ function performStackLabelmapUpdate({ viewportIds, segmentationId }) {
50
54
  viewportIds.forEach((viewportId) => {
51
55
  const viewportSegReps = SegmentationState.getSegmentationRepresentations(viewportId);
52
56
  viewportSegReps.forEach((representation) => {
@@ -1,10 +1,10 @@
1
1
  import SegmentationRepresentations from '../../enums/SegmentationRepresentations';
2
- import * as SegmentationState from '../../stateManagement/segmentation/segmentationState';
3
2
  import { triggerSegmentationRenderBySegmentationId } from '../../stateManagement/segmentation/SegmentationRenderingEngine';
4
3
  import onLabelmapSegmentationDataModified from './labelmap/onLabelmapSegmentationDataModified';
4
+ import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
5
5
  const onSegmentationDataModified = function (evt) {
6
6
  const { segmentationId } = evt.detail;
7
- const { type } = SegmentationState.getSegmentation(segmentationId);
7
+ const { type } = getSegmentation(segmentationId);
8
8
  if (type === SegmentationRepresentations.Labelmap) {
9
9
  onLabelmapSegmentationDataModified(evt);
10
10
  }
@@ -15,6 +15,7 @@ import { setAnnotationManager } from './annotation/annotationState';
15
15
  import { getAnnotationManager } from './annotation/annotationState';
16
16
  import { resetAnnotationManager } from './annotation/annotationState';
17
17
  import { invalidateAnnotation } from './annotation/annotationState';
18
- import addSegmentationRepresentations from './segmentation/addSegmentationRepresentations';
18
+ import { addSegmentationRepresentations } from './segmentation/addSegmentationRepresentations';
19
+ import { addMultiViewportSegmentationRepresentations } from './segmentation/addSegmentationRepresentations';
19
20
  import removeSegmentationRepresentations from './segmentation/removeSegmentationRepresentations';
20
- export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, removeSegmentationRepresentations };
21
+ export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, removeSegmentationRepresentations };
@@ -2,6 +2,6 @@ import FrameOfReferenceSpecificAnnotationManager, { defaultFrameOfReferenceSpeci
2
2
  import * as annotationLocking from './annotation/annotationLocking';
3
3
  import * as annotationSelection from './annotation/annotationSelection';
4
4
  import { getAnnotations, addAnnotation, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, getNumberOfAnnotations, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, } from './annotation/annotationState';
5
- import addSegmentationRepresentations from './segmentation/addSegmentationRepresentations';
5
+ import { addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, } from './segmentation/addSegmentationRepresentations';
6
6
  import removeSegmentationRepresentations from './segmentation/removeSegmentationRepresentations';
7
- export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, removeSegmentationRepresentations, };
7
+ export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, removeSegmentationRepresentations, };
@@ -1,4 +1,3 @@
1
- import type { Types } from '@cornerstonejs/core';
2
1
  declare class SegmentationRenderingEngine {
3
2
  private _needsRender;
4
3
  private _animationFrameSet;
@@ -6,7 +5,7 @@ declare class SegmentationRenderingEngine {
6
5
  hasBeenDestroyed: boolean;
7
6
  renderSegmentationsForViewport(viewportId?: string): void;
8
7
  renderSegmentation(segmentationId: string): void;
9
- _getAllViewports: () => Types.IViewport[];
8
+ _getAllViewports: () => import("@cornerstonejs/core").Viewport[];
10
9
  _getViewportIdsForSegmentation(segmentationId?: string): string[];
11
10
  private _throwIfDestroyed;
12
11
  private _setViewportsToBeRenderedNextFrame;
@@ -1,5 +1,5 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
- import type { RepresentationConfig, SegmentRepresentationConfig, Segmentation, SegmentationRepresentation, SegmentationRepresentationConfig, SegmentationState } from '../../types/SegmentationStateTypes';
2
+ import type { GlobalConfig, RepresentationConfig, Segmentation, SegmentationRepresentation, SegmentationState } from '../../types/SegmentationStateTypes';
3
3
  export default class SegmentationStateManager {
4
4
  private state;
5
5
  readonly uid: string;
@@ -15,23 +15,26 @@ export default class SegmentationStateManager {
15
15
  getSegmentationRepresentation(segmentationRepresentationUID: string): SegmentationRepresentation | undefined;
16
16
  addSegmentationRepresentationState(segmentationRepresentation: SegmentationRepresentation): void;
17
17
  addSegmentationRepresentationToViewport(viewportId: string, segmentationRepresentationUID: string): void;
18
+ _updateLabelmapSegmentationReferences(segmentationId: any, stackViewport: any, labelmapImageIds: any, updateCallback: any): string;
18
19
  updateLabelmapSegmentationImageReferences(viewportId: any, segmentationId: any): string;
20
+ _updateAllLabelmapSegmentationImageReferences(viewportId: any, segmentationId: any): void;
19
21
  private getLabelmapImageIds;
20
22
  getCurrentLabelmapImageIdForViewport(viewportId: string, segmentationId: string): string | undefined;
23
+ getStackSegmentationImageIdsForViewport(viewportId: string, segmentationId: string): string[];
21
24
  getSegmentationRepresentations(viewportId: string): SegmentationRepresentation[];
22
25
  removeRepresentation(segmentationRepresentationUID: string): void;
23
26
  setActiveSegmentationRepresentation(viewportId: string, segmentationRepresentationUID: string): void;
24
27
  getActiveSegmentationRepresentation(viewportId: string): SegmentationRepresentation | undefined;
25
- getGlobalConfig(): SegmentationRepresentationConfig;
26
- setGlobalConfig(config: SegmentationRepresentationConfig): void;
28
+ getGlobalConfig(): GlobalConfig;
29
+ setGlobalConfig(config: GlobalConfig): void;
27
30
  _getRepresentationConfig(segmentationRepresentationUID: string): {
28
31
  allSegments?: RepresentationConfig;
29
- perSegment?: SegmentRepresentationConfig;
32
+ perSegment?: RepresentationConfig;
30
33
  };
31
34
  getSegmentationRepresentationConfig(segmentationRepresentationUID: string): RepresentationConfig;
32
- getPerSegmentConfig(segmentationRepresentationUID: string): SegmentRepresentationConfig;
35
+ getPerSegmentConfig(segmentationRepresentationUID: string): RepresentationConfig;
33
36
  setSegmentationRepresentationConfig(segmentationRepresentationUID: string, config: RepresentationConfig): void;
34
- setPerSegmentConfig(segmentationRepresentationUID: string, config: SegmentRepresentationConfig): void;
37
+ setPerSegmentConfig(segmentationRepresentationUID: string, config: RepresentationConfig): void;
35
38
  getSegmentationRepresentationVisibility(viewportId: string, segmentationRepresentationUID: string): boolean;
36
39
  setSegmentationRepresentationVisibility(viewportId: string, segmentationRepresentationUID: string, visible: boolean): void;
37
40
  addColorLUT(colorLUT: Types.ColorLUT, lutIndex: number): void;
@@ -47,12 +47,12 @@ export default class SegmentationStateManager {
47
47
  if (this.getSegmentation(segmentation.segmentationId)) {
48
48
  throw new Error(`Segmentation with id ${segmentation.segmentationId} already exists`);
49
49
  }
50
- if (segmentation.representationData.LABELMAP &&
51
- 'volumeId' in segmentation.representationData.LABELMAP &&
52
- !('imageIds' in segmentation.representationData.LABELMAP)) {
50
+ if (segmentation.representationData.Labelmap &&
51
+ 'volumeId' in segmentation.representationData.Labelmap &&
52
+ !('imageIds' in segmentation.representationData.Labelmap)) {
53
53
  const imageIds = this.getLabelmapImageIds(segmentation.representationData);
54
54
  segmentation.representationData
55
- .LABELMAP.imageIds = imageIds;
55
+ .Labelmap.imageIds = imageIds;
56
56
  }
57
57
  this.state.segmentations.push(segmentation);
58
58
  }
@@ -83,12 +83,12 @@ export default class SegmentationStateManager {
83
83
  const volumeViewport = enabledElement.viewport instanceof BaseVolumeViewport;
84
84
  const segmentation = this.getSegmentation(representation.segmentationId);
85
85
  const { representationData } = segmentation;
86
- const isLabelmap = representationData.LABELMAP;
86
+ const isLabelmap = representationData.Labelmap;
87
87
  if (!isLabelmap) {
88
88
  this.setActiveSegmentationRepresentation(viewportId, segmentationRepresentationUID);
89
89
  return;
90
90
  }
91
- const isBaseVolumeSegmentation = 'volumeId' in representationData.LABELMAP;
91
+ const isBaseVolumeSegmentation = 'volumeId' in representationData.Labelmap;
92
92
  if (!volumeViewport) {
93
93
  if (isBaseVolumeSegmentation) {
94
94
  }
@@ -111,6 +111,23 @@ export default class SegmentationStateManager {
111
111
  }
112
112
  this.setActiveSegmentationRepresentation(viewportId, segmentationRepresentationUID);
113
113
  }
114
+ _updateLabelmapSegmentationReferences(segmentationId, stackViewport, labelmapImageIds, updateCallback) {
115
+ const currentImageId = stackViewport.getCurrentImageId();
116
+ for (const labelmapImageId of labelmapImageIds) {
117
+ const viewableImageId = stackViewport.isReferenceViewable({ referencedImageId: labelmapImageId }, { asOverlay: true });
118
+ if (viewableImageId) {
119
+ this._stackLabelmapImageIdReferenceMap
120
+ .get(segmentationId)
121
+ .set(currentImageId, labelmapImageId);
122
+ }
123
+ }
124
+ if (updateCallback) {
125
+ updateCallback(stackViewport, segmentationId, labelmapImageIds);
126
+ }
127
+ return this._stackLabelmapImageIdReferenceMap
128
+ .get(segmentationId)
129
+ .get(currentImageId);
130
+ }
114
131
  updateLabelmapSegmentationImageReferences(viewportId, segmentationId) {
115
132
  const segmentation = this.getSegmentation(segmentationId);
116
133
  if (!segmentation) {
@@ -120,27 +137,45 @@ export default class SegmentationStateManager {
120
137
  this._stackLabelmapImageIdReferenceMap.set(segmentationId, new Map());
121
138
  }
122
139
  const { representationData } = segmentation;
123
- if (!representationData.LABELMAP) {
140
+ if (!representationData.Labelmap) {
124
141
  return;
125
142
  }
126
143
  const labelmapImageIds = this.getLabelmapImageIds(representationData);
127
144
  const enabledElement = getEnabledElementByViewportId(viewportId);
128
145
  const stackViewport = enabledElement.viewport;
129
- const currentImageId = stackViewport.getCurrentImageId();
130
- for (const labelmapImageId of labelmapImageIds) {
131
- const viewableImageId = stackViewport.isReferenceViewable({ referencedImageId: labelmapImageId }, { asOverlay: true });
132
- if (viewableImageId) {
133
- this._stackLabelmapImageIdReferenceMap
134
- .get(segmentationId)
135
- .set(currentImageId, labelmapImageId);
136
- }
146
+ return this._updateLabelmapSegmentationReferences(segmentationId, stackViewport, labelmapImageIds, null);
147
+ }
148
+ _updateAllLabelmapSegmentationImageReferences(viewportId, segmentationId) {
149
+ const segmentation = this.getSegmentation(segmentationId);
150
+ if (!segmentation) {
151
+ return;
137
152
  }
138
- return this._stackLabelmapImageIdReferenceMap
139
- .get(segmentationId)
140
- .get(currentImageId);
153
+ if (!this._stackLabelmapImageIdReferenceMap.has(segmentationId)) {
154
+ this._stackLabelmapImageIdReferenceMap.set(segmentationId, new Map());
155
+ }
156
+ const { representationData } = segmentation;
157
+ if (!representationData.Labelmap) {
158
+ return;
159
+ }
160
+ const labelmapImageIds = this.getLabelmapImageIds(representationData);
161
+ const enabledElement = getEnabledElementByViewportId(viewportId);
162
+ const stackViewport = enabledElement.viewport;
163
+ this._updateLabelmapSegmentationReferences(segmentationId, stackViewport, labelmapImageIds, (stackViewport, segmentationId, labelmapImageIds) => {
164
+ const imageIds = stackViewport.getImageIds();
165
+ imageIds.forEach((imageId, index) => {
166
+ for (const labelmapImageId of labelmapImageIds) {
167
+ const viewableImageId = stackViewport.isReferenceViewable({ referencedImageId: labelmapImageId, sliceIndex: index }, { asOverlay: true, withNavigation: true });
168
+ if (viewableImageId) {
169
+ this._stackLabelmapImageIdReferenceMap
170
+ .get(segmentationId)
171
+ .set(imageId, labelmapImageId);
172
+ }
173
+ }
174
+ });
175
+ });
141
176
  }
142
177
  getLabelmapImageIds(representationData) {
143
- const labelmapData = representationData.LABELMAP;
178
+ const labelmapData = representationData.Labelmap;
144
179
  let labelmapImageIds;
145
180
  if (labelmapData.imageIds) {
146
181
  labelmapImageIds = labelmapData
@@ -168,6 +203,19 @@ export default class SegmentationStateManager {
168
203
  const imageIdReferenceMap = this._stackLabelmapImageIdReferenceMap.get(segmentationId);
169
204
  return imageIdReferenceMap.get(currentImageId);
170
205
  }
206
+ getStackSegmentationImageIdsForViewport(viewportId, segmentationId) {
207
+ const segmentation = this.getSegmentation(segmentationId);
208
+ if (!segmentation) {
209
+ return [];
210
+ }
211
+ this._updateAllLabelmapSegmentationImageReferences(viewportId, segmentationId);
212
+ const { viewport } = getEnabledElementByViewportId(viewportId);
213
+ const imageIds = viewport.getImageIds();
214
+ const associatedReferenceImageAndLabelmapImageIds = this._stackLabelmapImageIdReferenceMap.get(segmentationId);
215
+ return imageIds.map((imageId) => {
216
+ return associatedReferenceImageAndLabelmapImageIds.get(imageId);
217
+ });
218
+ }
171
219
  getSegmentationRepresentations(viewportId) {
172
220
  const viewport = this.state.viewports[viewportId];
173
221
  if (!viewport) {
@@ -286,7 +334,7 @@ async function computeVolumeSegmentationFromStack({ imageIds, options, }) {
286
334
  async function convertStackToVolumeSegmentation({ segmentationId, options, }) {
287
335
  const segmentation = defaultSegmentationStateManager.getSegmentation(segmentationId);
288
336
  const data = segmentation.representationData
289
- .LABELMAP;
337
+ .Labelmap;
290
338
  const { volumeId } = await computeVolumeSegmentationFromStack({
291
339
  imageIds: data.imageIds,
292
340
  options,
@@ -302,18 +350,18 @@ async function updateSegmentationState({ segmentationId, viewportId, volumeId, o
302
350
  const segmentation = defaultSegmentationStateManager.getSegmentation(segmentationId);
303
351
  if (options?.removeOriginal) {
304
352
  const data = segmentation.representationData
305
- .LABELMAP;
353
+ .Labelmap;
306
354
  const { imageIds } = data;
307
355
  imageIds.forEach((imageId) => {
308
356
  cache.removeImageLoadObject(imageId);
309
357
  });
310
- segmentation.representationData.LABELMAP = {
358
+ segmentation.representationData.Labelmap = {
311
359
  volumeId,
312
360
  };
313
361
  }
314
362
  else {
315
- segmentation.representationData.LABELMAP = {
316
- ...segmentation.representationData.LABELMAP,
363
+ segmentation.representationData.Labelmap = {
364
+ ...segmentation.representationData.Labelmap,
317
365
  volumeId,
318
366
  };
319
367
  }
@@ -1,3 +1,8 @@
1
- import type { SegmentationRepresentationConfig, RepresentationPublicInput } from '../../types/SegmentationStateTypes';
2
- declare function addSegmentationRepresentations(viewportId: string, representationInputArray: RepresentationPublicInput[], segmentationRepresentationConfig?: SegmentationRepresentationConfig): Promise<string[]>;
3
- export default addSegmentationRepresentations;
1
+ import type { RepresentationPublicInput } from '../../types/SegmentationStateTypes';
2
+ declare function addSegmentationRepresentations(viewportId: string, representationInputArray: RepresentationPublicInput[]): Promise<string[]>;
3
+ declare function addMultiViewportSegmentationRepresentations(viewportInputMap: {
4
+ [viewportId: string]: RepresentationPublicInput[];
5
+ }): Promise<{
6
+ [viewportId: string]: string[];
7
+ }>;
8
+ export { addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, };
@@ -1,9 +1,19 @@
1
- import { addSegmentationRepresentation } from './addSegmentationRepresentation';
2
- async function addSegmentationRepresentations(viewportId, representationInputArray, segmentationRepresentationConfig) {
1
+ import { internalAddSegmentationRepresentation } from './internalAddSegmentationRepresentation';
2
+ async function addSegmentationRepresentations(viewportId, representationInputArray) {
3
3
  const promises = representationInputArray.map((representationInput) => {
4
- return addSegmentationRepresentation(viewportId, representationInput, segmentationRepresentationConfig);
4
+ return internalAddSegmentationRepresentation(viewportId, representationInput);
5
5
  });
6
6
  const segmentationRepresentationUIDs = await Promise.all(promises);
7
7
  return segmentationRepresentationUIDs;
8
8
  }
9
- export default addSegmentationRepresentations;
9
+ async function addMultiViewportSegmentationRepresentations(viewportInputMap) {
10
+ const results = {};
11
+ for (const [viewportId, inputArray] of Object.entries(viewportInputMap)) {
12
+ const promises = inputArray.map((representationInput) => {
13
+ return internalAddSegmentationRepresentation(viewportId, representationInput);
14
+ });
15
+ results[viewportId] = await Promise.all(promises);
16
+ }
17
+ return results;
18
+ }
19
+ export { addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, };
@@ -1,13 +1,14 @@
1
1
  import type SegmentationRepresentations from '../../../enums/SegmentationRepresentations';
2
- import type { RepresentationConfig, SegmentationRepresentationConfig, SegmentRepresentationConfig } from '../../../types/SegmentationStateTypes';
3
- declare function getGlobalConfig(): SegmentationRepresentationConfig;
4
- declare function setGlobalConfig(segmentationConfig: SegmentationRepresentationConfig): void;
5
- declare function getGlobalRepresentationConfig(representationType: SegmentationRepresentations): RepresentationConfig['LABELMAP'];
6
- declare function setGlobalRepresentationConfig(representationType: SegmentationRepresentations, config: RepresentationConfig['LABELMAP']): void;
2
+ import type { GlobalConfig, RepresentationConfig } from '../../../types/SegmentationStateTypes';
3
+ import type { LabelmapConfig } from '../../../types/LabelmapTypes';
4
+ declare function getGlobalConfig(): GlobalConfig;
5
+ declare function setGlobalConfig(segmentationConfig: GlobalConfig): void;
6
+ declare function getGlobalRepresentationConfig(representationType: SegmentationRepresentations): LabelmapConfig;
7
+ declare function setGlobalRepresentationConfig(representationType: SegmentationRepresentations, config: LabelmapConfig): void;
7
8
  declare function getSegmentationRepresentationConfig(segmentationRepresentationUID: string): RepresentationConfig;
8
9
  declare function setSegmentationRepresentationConfig(segmentationRepresentationUID: string, config: RepresentationConfig): void;
9
- declare function setPerSegmentConfig(segmentationRepresentationUID: string, config: SegmentRepresentationConfig): void;
10
- declare function getPerSegmentConfig(segmentationRepresentationUID: string): SegmentRepresentationConfig;
10
+ declare function setPerSegmentConfig(segmentationRepresentationUID: string, config: RepresentationConfig): void;
11
+ declare function getPerSegmentConfig(segmentationRepresentationUID: string): RepresentationConfig;
11
12
  declare function setSegmentIndexConfig(segmentationRepresentationUID: string, segmentIndex: number, config: RepresentationConfig, suppressEvent?: boolean): void;
12
13
  declare function getSegmentIndexConfig(segmentationRepresentationUID: string, segmentIndex: number): RepresentationConfig;
13
14
  export { getGlobalConfig, setGlobalConfig, getGlobalRepresentationConfig, setGlobalRepresentationConfig, getSegmentationRepresentationConfig, setSegmentationRepresentationConfig, setPerSegmentConfig, getPerSegmentConfig, setSegmentIndexConfig, getSegmentIndexConfig, };
@@ -8,7 +8,7 @@ export async function computeStackSegmentationFromVolume({ volumeId, }) {
8
8
  export async function convertVolumeToStackSegmentation({ segmentationId, options, }) {
9
9
  const segmentation = getSegmentation(segmentationId);
10
10
  const { volumeId } = segmentation.representationData
11
- .LABELMAP;
11
+ .Labelmap;
12
12
  const segmentationVolume = cache.getVolume(volumeId);
13
13
  await updateStackSegmentationState({
14
14
  segmentationId,
@@ -1,2 +1,2 @@
1
- import type { SegmentationRepresentationConfig } from '../../types';
2
- export declare function getGlobalConfig(): SegmentationRepresentationConfig;
1
+ import type { GlobalConfig } from '../../types';
2
+ export declare function getGlobalConfig(): GlobalConfig;
@@ -1,2 +1,2 @@
1
- import type { SegmentRepresentationConfig } from '../../types/SegmentationStateTypes';
2
- export declare function getPerSegmentConfig(segmentationRepresentationUID: string): SegmentRepresentationConfig;
1
+ import type { RepresentationConfig } from '../../types/SegmentationStateTypes';
2
+ export declare function getPerSegmentConfig(segmentationRepresentationUID: string): RepresentationConfig;
@@ -0,0 +1 @@
1
+ export declare function getStackSegmentationImageIdsForViewport(viewportId: string, segmentationId: string): string[];
@@ -0,0 +1,5 @@
1
+ import { defaultSegmentationStateManager } from './SegmentationStateManager';
2
+ export function getStackSegmentationImageIdsForViewport(viewportId, segmentationId) {
3
+ const segmentationStateManager = defaultSegmentationStateManager;
4
+ return segmentationStateManager.getStackSegmentationImageIdsForViewport(viewportId, segmentationId);
5
+ }
@@ -2,22 +2,22 @@ import { cache, eventTarget } from '@cornerstonejs/core';
2
2
  import { Events, SegmentationRepresentations } from '../../../enums';
3
3
  import { getSegmentation } from '../getSegmentation';
4
4
  import { triggerSegmentationDataModified } from '../triggerSegmentationEvents';
5
- import addSegmentationRepresentations from '../addSegmentationRepresentations';
5
+ import { addSegmentationRepresentations } from '../addSegmentationRepresentations';
6
6
  export async function updateStackSegmentationState({ segmentationId, viewportId, imageIds, options, }) {
7
7
  const segmentation = getSegmentation(segmentationId);
8
8
  if (options?.removeOriginal) {
9
9
  const data = segmentation.representationData
10
- .LABELMAP;
10
+ .Labelmap;
11
11
  if (cache.getVolume(data.volumeId)) {
12
12
  cache.removeVolumeLoadObject(data.volumeId);
13
13
  }
14
- segmentation.representationData.LABELMAP = {
14
+ segmentation.representationData.Labelmap = {
15
15
  imageIds,
16
16
  };
17
17
  }
18
18
  else {
19
- segmentation.representationData.LABELMAP = {
20
- ...segmentation.representationData.LABELMAP,
19
+ segmentation.representationData.Labelmap = {
20
+ ...segmentation.representationData.Labelmap,
21
21
  imageIds,
22
22
  };
23
23
  }
@@ -1,6 +1,6 @@
1
1
  import removeSegmentationRepresentations from './removeSegmentationRepresentations';
2
2
  import addSegmentations from './addSegmentations';
3
- import addSegmentationRepresentations from './addSegmentationRepresentations';
3
+ import { addSegmentationRepresentations, addMultiViewportSegmentationRepresentations } from './addSegmentationRepresentations';
4
4
  import addRepresentationData from './addRepresentationData';
5
5
  import { convertVolumeToStackSegmentation } from './convertVolumeToStackSegmentation';
6
6
  import * as activeSegmentation from './activeSegmentation';
@@ -11,4 +11,4 @@ import * as segmentIndex from './segmentIndex';
11
11
  import * as triggerSegmentationEvents from './triggerSegmentationEvents';
12
12
  import { convertStackToVolumeSegmentation } from './SegmentationStateManager';
13
13
  import * as polySegManager from './polySeg';
14
- export { addSegmentations, addSegmentationRepresentations, removeSegmentationRepresentations, addRepresentationData, state, activeSegmentation, segmentLocking, config, segmentIndex, triggerSegmentationEvents, convertStackToVolumeSegmentation, convertVolumeToStackSegmentation, polySegManager as polySeg, };
14
+ export { addSegmentations, addSegmentationRepresentations, removeSegmentationRepresentations, addRepresentationData, addMultiViewportSegmentationRepresentations, state, activeSegmentation, segmentLocking, config, segmentIndex, triggerSegmentationEvents, convertStackToVolumeSegmentation, convertVolumeToStackSegmentation, polySegManager as polySeg, };
@@ -1,6 +1,6 @@
1
1
  import removeSegmentationRepresentations from './removeSegmentationRepresentations';
2
2
  import addSegmentations from './addSegmentations';
3
- import addSegmentationRepresentations from './addSegmentationRepresentations';
3
+ import { addSegmentationRepresentations, addMultiViewportSegmentationRepresentations, } from './addSegmentationRepresentations';
4
4
  import addRepresentationData from './addRepresentationData';
5
5
  import { convertVolumeToStackSegmentation } from './convertVolumeToStackSegmentation';
6
6
  import * as activeSegmentation from './activeSegmentation';
@@ -11,4 +11,4 @@ import * as segmentIndex from './segmentIndex';
11
11
  import * as triggerSegmentationEvents from './triggerSegmentationEvents';
12
12
  import { convertStackToVolumeSegmentation } from './SegmentationStateManager';
13
13
  import * as polySegManager from './polySeg';
14
- export { addSegmentations, addSegmentationRepresentations, removeSegmentationRepresentations, addRepresentationData, state, activeSegmentation, segmentLocking, config, segmentIndex, triggerSegmentationEvents, convertStackToVolumeSegmentation, convertVolumeToStackSegmentation, polySegManager as polySeg, };
14
+ export { addSegmentations, addSegmentationRepresentations, removeSegmentationRepresentations, addRepresentationData, addMultiViewportSegmentationRepresentations, state, activeSegmentation, segmentLocking, config, segmentIndex, triggerSegmentationEvents, convertStackToVolumeSegmentation, convertVolumeToStackSegmentation, polySegManager as polySeg, };
@@ -0,0 +1,3 @@
1
+ import type { RepresentationPublicInput } from '../../types/SegmentationStateTypes';
2
+ declare function internalAddSegmentationRepresentation(viewportId: string, representationInput: RepresentationPublicInput): Promise<string>;
3
+ export { internalAddSegmentationRepresentation };
@@ -18,7 +18,7 @@ function getLabelmapSegmentationRepresentationRenderingConfig() {
18
18
  cfun,
19
19
  };
20
20
  }
21
- async function addSegmentationRepresentation(viewportId, representationInput, initialConfig) {
21
+ async function internalAddSegmentationRepresentation(viewportId, representationInput) {
22
22
  const { segmentationId, options = {} } = representationInput;
23
23
  const segmentationRepresentationUID = representationInput.options?.segmentationRepresentationUID ||
24
24
  utilities.uuidv4();
@@ -44,8 +44,9 @@ async function addSegmentationRepresentation(viewportId, representationInput, in
44
44
  },
45
45
  };
46
46
  addSegmentationRepresentationState(viewportId, representation);
47
+ const initialConfig = representationInput.config;
47
48
  if (initialConfig) {
48
- setSegmentationRepresentationConfig(segmentationRepresentationUID, initialConfig.representations);
49
+ setSegmentationRepresentationConfig(segmentationRepresentationUID, initialConfig);
49
50
  }
50
51
  if (representationInput.type === SegmentationRepresentations.Contour) {
51
52
  triggerAnnotationRenderForViewportIds([viewportId]);
@@ -69,4 +70,4 @@ function getColorLUTIndex(options = {}) {
69
70
  }
70
71
  return colorLUTIndexToUse;
71
72
  }
72
- export { addSegmentationRepresentation };
73
+ export { internalAddSegmentationRepresentation };
@@ -14,13 +14,13 @@ export async function computeContourData(segmentationId, options = {}) {
14
14
  const segmentation = getSegmentation(segmentationId);
15
15
  const representationData = segmentation.representationData;
16
16
  try {
17
- if (representationData.SURFACE) {
17
+ if (representationData.Surface) {
18
18
  rawContourData = await computeContourFromSurfaceSegmentation(segmentationId, {
19
19
  segmentIndices,
20
20
  ...options,
21
21
  });
22
22
  }
23
- else if (representationData.LABELMAP) {
23
+ else if (representationData.Labelmap) {
24
24
  rawContourData = await computeContourFromLabelmapSegmentation(segmentationId, {
25
25
  segmentIndices,
26
26
  ...options,
@@ -37,7 +37,7 @@ export async function computeContourData(segmentationId, options = {}) {
37
37
  const { viewport, segmentationRepresentationUID } = options;
38
38
  const annotationUIDsMap = createAndAddContourSegmentationsFromClippedSurfaces(rawContourData, viewport, segmentationId);
39
39
  setSegmentationRepresentationConfig(segmentationRepresentationUID, {
40
- CONTOUR: {
40
+ Contour: {
41
41
  fillAlpha: 0,
42
42
  },
43
43
  });
@@ -78,7 +78,7 @@ async function computeContourFromSurfaceSegmentation(segmentationId, options = {
78
78
  const segmentIndexToSurfaceId = new Map();
79
79
  const surfaceIdToSegmentIndex = new Map();
80
80
  const segmentation = getSegmentation(segmentationId);
81
- const representationData = segmentation.representationData.SURFACE;
81
+ const representationData = segmentation.representationData.Surface;
82
82
  const surfacesInfo = [];
83
83
  representationData.geometryIds.forEach((geometryId, segmentIndex) => {
84
84
  if (segmentIndices.includes(segmentIndex)) {
@@ -12,13 +12,13 @@ export async function computeLabelmapData(segmentationId, options = {}) {
12
12
  const segmentation = getSegmentation(segmentationId);
13
13
  const representationData = segmentation.representationData;
14
14
  try {
15
- if (representationData.CONTOUR) {
15
+ if (representationData.Contour) {
16
16
  rawLabelmapData = await computeLabelmapFromContourSegmentation(segmentationId, {
17
17
  segmentIndices,
18
18
  ...options,
19
19
  });
20
20
  }
21
- else if (representationData.SURFACE) {
21
+ else if (representationData.Surface) {
22
22
  rawLabelmapData = await computeLabelmapFromSurfaceSegmentation(segmentation.segmentationId, {
23
23
  segmentIndices,
24
24
  ...options,
@@ -43,7 +43,7 @@ async function computeLabelmapFromContourSegmentation(segmentationId, options =
43
43
  ? options.segmentIndices
44
44
  : getUniqueSegmentIndices(segmentationId);
45
45
  const segmentation = getSegmentation(segmentationId);
46
- const representationData = segmentation.representationData.CONTOUR;
46
+ const representationData = segmentation.representationData.Contour;
47
47
  const convertFunction = isVolume
48
48
  ? convertContourToVolumeLabelmap
49
49
  : convertContourToStackLabelmap;
@@ -62,7 +62,7 @@ async function computeLabelmapFromSurfaceSegmentation(segmentationId, options =
62
62
  : getUniqueSegmentIndices(segmentationId);
63
63
  const segmentation = getSegmentation(segmentationId);
64
64
  const segmentsGeometryIds = new Map();
65
- const representationData = segmentation.representationData.SURFACE;
65
+ const representationData = segmentation.representationData.Surface;
66
66
  representationData.geometryIds.forEach((geometryId, segmentIndex) => {
67
67
  if (segmentIndices.includes(segmentIndex)) {
68
68
  segmentsGeometryIds.set(segmentIndex, geometryId);