@cornerstonejs/tools 2.0.0-beta.17 → 2.0.0-beta.19

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 (118) hide show
  1. package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +11 -14
  2. package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +26 -27
  3. package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js +1 -4
  4. package/dist/esm/eventListeners/segmentation/segmentationModifiedEventListener.js +2 -11
  5. package/dist/esm/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.js +10 -2
  6. package/dist/esm/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.js +2 -2
  7. package/dist/esm/index.d.ts +2 -2
  8. package/dist/esm/index.js +2 -2
  9. package/dist/esm/stateManagement/index.d.ts +3 -3
  10. package/dist/esm/stateManagement/index.js +2 -2
  11. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.d.ts +19 -18
  12. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +87 -130
  13. package/dist/esm/stateManagement/segmentation/activeSegmentation.d.ts +4 -5
  14. package/dist/esm/stateManagement/segmentation/activeSegmentation.js +6 -23
  15. package/dist/esm/stateManagement/segmentation/addRepresentation.d.ts +3 -0
  16. package/dist/esm/stateManagement/segmentation/addRepresentation.js +51 -0
  17. package/dist/esm/stateManagement/segmentation/addRepresentations.d.ts +3 -0
  18. package/dist/esm/stateManagement/segmentation/addRepresentations.js +9 -0
  19. package/dist/esm/stateManagement/segmentation/config/index.d.ts +2 -2
  20. package/dist/esm/stateManagement/segmentation/config/index.js +2 -2
  21. package/dist/esm/stateManagement/segmentation/config/segmentationColor.d.ts +4 -4
  22. package/dist/esm/stateManagement/segmentation/config/segmentationColor.js +10 -10
  23. package/dist/esm/stateManagement/segmentation/config/segmentationConfig.d.ts +8 -8
  24. package/dist/esm/stateManagement/segmentation/config/segmentationConfig.js +19 -13
  25. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.d.ts +7 -6
  26. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.js +29 -54
  27. package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts +1 -1
  28. package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.js +5 -5
  29. package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts +3 -3
  30. package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js +5 -5
  31. package/dist/esm/stateManagement/segmentation/helpers/getRepresentationRenderingConfig.d.ts +2 -0
  32. package/dist/esm/stateManagement/segmentation/helpers/{getRepresentationSpecificConfig.js → getRepresentationRenderingConfig.js} +1 -1
  33. package/dist/esm/stateManagement/segmentation/index.d.ts +3 -3
  34. package/dist/esm/stateManagement/segmentation/index.js +3 -3
  35. package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +2 -4
  36. package/dist/esm/stateManagement/segmentation/polySeg/Surface/createAndCacheSurfacesFromRaw.js +5 -6
  37. package/dist/esm/stateManagement/segmentation/polySeg/Surface/updateSurfaceData.js +4 -4
  38. package/dist/esm/stateManagement/segmentation/polySeg/canComputeRequestedRepresentation.js +2 -6
  39. package/dist/esm/stateManagement/segmentation/removeRepresentationsFromViewport.d.ts +2 -0
  40. package/dist/esm/stateManagement/segmentation/removeRepresentationsFromViewport.js +23 -0
  41. package/dist/esm/stateManagement/segmentation/segmentIndex.js +6 -4
  42. package/dist/esm/stateManagement/segmentation/segmentationState.d.ts +23 -20
  43. package/dist/esm/stateManagement/segmentation/segmentationState.js +68 -95
  44. package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.d.ts +2 -2
  45. package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js +4 -18
  46. package/dist/esm/store/ToolGroupManager/destroyToolGroup.js +0 -4
  47. package/dist/esm/tools/AdvancedMagnifyViewport.js +3 -3
  48. package/dist/esm/tools/ScaleOverlayTool.d.ts +1 -1
  49. package/dist/esm/tools/annotation/BidirectionalTool.js +6 -7
  50. package/dist/esm/tools/annotation/CircleROITool.js +14 -14
  51. package/dist/esm/tools/annotation/DragProbeTool.js +3 -3
  52. package/dist/esm/tools/annotation/EllipticalROITool.js +12 -12
  53. package/dist/esm/tools/annotation/LengthTool.js +2 -2
  54. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +13 -15
  55. package/dist/esm/tools/annotation/ProbeTool.js +10 -10
  56. package/dist/esm/tools/annotation/RectangleROITool.js +12 -12
  57. package/dist/esm/tools/annotation/SplineROITool.js +5 -5
  58. package/dist/esm/tools/base/ContourSegmentationBaseTool.d.ts +0 -1
  59. package/dist/esm/tools/base/ContourSegmentationBaseTool.js +42 -33
  60. package/dist/esm/tools/displayTools/Contour/contourDisplay.d.ts +4 -4
  61. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +17 -30
  62. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.d.ts +4 -4
  63. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +20 -11
  64. package/dist/esm/tools/displayTools/Contour/contourHandler/utils.d.ts +0 -2
  65. package/dist/esm/tools/displayTools/Contour/contourHandler/utils.js +0 -11
  66. package/dist/esm/tools/displayTools/Contour/removeContourFromElement.d.ts +1 -1
  67. package/dist/esm/tools/displayTools/Contour/removeContourFromElement.js +3 -3
  68. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.d.ts +5 -5
  69. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +51 -54
  70. package/dist/esm/tools/displayTools/SegmentationRenderingEngine.d.ts +19 -0
  71. package/dist/esm/tools/displayTools/SegmentationRenderingEngine.js +136 -0
  72. package/dist/esm/tools/displayTools/Surface/surfaceDisplay.d.ts +5 -5
  73. package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +14 -25
  74. package/dist/esm/tools/index.d.ts +1 -2
  75. package/dist/esm/tools/index.js +1 -2
  76. package/dist/esm/tools/segmentation/BrushTool.d.ts +15 -2
  77. package/dist/esm/tools/segmentation/BrushTool.js +13 -14
  78. package/dist/esm/tools/segmentation/CircleScissorsTool.js +3 -4
  79. package/dist/esm/tools/segmentation/PaintFillTool.js +1 -2
  80. package/dist/esm/tools/segmentation/RectangleScissorsTool.js +3 -4
  81. package/dist/esm/tools/segmentation/SegmentSelectTool.d.ts +3 -2
  82. package/dist/esm/tools/segmentation/SegmentSelectTool.js +5 -5
  83. package/dist/esm/tools/segmentation/SphereScissorsTool.js +4 -5
  84. package/dist/esm/tools/segmentation/strategies/compositions/preview.js +2 -2
  85. package/dist/esm/types/EventTypes.d.ts +0 -3
  86. package/dist/esm/types/SegmentationStateTypes.d.ts +24 -23
  87. package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +2 -2
  88. package/dist/esm/types/index.d.ts +2 -2
  89. package/dist/esm/utilities/getCalibratedUnits.d.ts +6 -0
  90. package/dist/esm/utilities/getCalibratedUnits.js +16 -8
  91. package/dist/esm/utilities/getPixelValueUnits.d.ts +6 -0
  92. package/dist/esm/utilities/{getModalityUnit.js → getPixelValueUnits.js} +2 -2
  93. package/dist/esm/utilities/segmentation/getSegmentIndexAtLabelmapBorder.d.ts +7 -0
  94. package/dist/esm/utilities/segmentation/{getSegmentAtLabelmapBorder.js → getSegmentIndexAtLabelmapBorder.js} +3 -3
  95. package/dist/esm/utilities/segmentation/getSegmentIndexAtWorldPoint.d.ts +11 -0
  96. package/dist/esm/utilities/segmentation/{getSegmentAtWorldPoint.js → getSegmentIndexAtWorldPoint.js} +7 -7
  97. package/dist/esm/utilities/segmentation/index.d.ts +3 -3
  98. package/dist/esm/utilities/segmentation/index.js +3 -3
  99. package/dist/esm/utilities/segmentation/triggerSegmentationRender.d.ts +2 -17
  100. package/dist/esm/utilities/segmentation/triggerSegmentationRender.js +4 -106
  101. package/dist/esm/utilities/segmentation/triggerSegmentationRenderForViewports.d.ts +3 -0
  102. package/dist/esm/utilities/segmentation/triggerSegmentationRenderForViewports.js +6 -0
  103. package/dist/esm/utilities/triggerAnnotationRenderForViewportIds.js +7 -2
  104. package/dist/umd/index.js +1 -1
  105. package/dist/umd/index.js.map +1 -1
  106. package/package.json +3 -4
  107. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentation.d.ts +0 -3
  108. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentation.js +0 -63
  109. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.d.ts +0 -3
  110. package/dist/esm/stateManagement/segmentation/addSegmentationRepresentations.js +0 -14
  111. package/dist/esm/stateManagement/segmentation/helpers/getRepresentationSpecificConfig.d.ts +0 -2
  112. package/dist/esm/stateManagement/segmentation/removeSegmentationsFromToolGroup.d.ts +0 -2
  113. package/dist/esm/stateManagement/segmentation/removeSegmentationsFromToolGroup.js +0 -39
  114. package/dist/esm/tools/displayTools/SegmentationDisplayTool.d.ts +0 -13
  115. package/dist/esm/tools/displayTools/SegmentationDisplayTool.js +0 -101
  116. package/dist/esm/utilities/getModalityUnit.d.ts +0 -6
  117. package/dist/esm/utilities/segmentation/getSegmentAtLabelmapBorder.d.ts +0 -7
  118. package/dist/esm/utilities/segmentation/getSegmentAtWorldPoint.d.ts +0 -11
@@ -1,11 +1,11 @@
1
1
  import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
2
2
  import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
3
3
  import { BaseVolumeViewport, getEnabledElement, Enums, getEnabledElementByIds, cache, utilities, } from '@cornerstonejs/core';
4
- import { getToolGroupForViewport } from '../../store/ToolGroupManager';
5
4
  import Representations from '../../enums/SegmentationRepresentations';
6
5
  import * as SegmentationState from '../../stateManagement/segmentation/segmentationState';
7
6
  import { isVolumeSegmentation } from '../../tools/segmentation/strategies/utils/stackVolumeCheck';
8
7
  import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
8
+ import triggerSegmentationRenderForViewports from '../../utilities/segmentation/triggerSegmentationRenderForViewports';
9
9
  const enable = function (element) {
10
10
  const { viewport } = getEnabledElement(element);
11
11
  if (viewport instanceof BaseVolumeViewport) {
@@ -18,23 +18,20 @@ const disable = function (element) {
18
18
  element.removeEventListener(Enums.Events.STACK_NEW_IMAGE, _imageChangeEventListener);
19
19
  element.removeEventListener(Enums.Events.IMAGE_RENDERED, _imageChangeEventListener);
20
20
  };
21
- const perToolGroupManualTriggers = new Map();
21
+ const perViewportManualTriggers = new Map();
22
22
  function _imageChangeEventListener(evt) {
23
23
  const eventData = evt.detail;
24
24
  const { viewportId, renderingEngineId } = eventData;
25
25
  const { viewport } = getEnabledElementByIds(viewportId, renderingEngineId);
26
- const toolGroup = getToolGroupForViewport(viewportId, renderingEngineId);
27
- if (!toolGroup) {
26
+ const segmentationRepresentations = SegmentationState.getRepresentationsForViewport(viewportId);
27
+ if (!segmentationRepresentations?.length) {
28
28
  return;
29
29
  }
30
- let toolGroupSegmentationRepresentations = SegmentationState.getSegmentationRepresentations(toolGroup.id) || [];
31
- toolGroupSegmentationRepresentations =
32
- toolGroupSegmentationRepresentations.filter((representation) => representation.type === Representations.Labelmap);
33
- if (!toolGroupSegmentationRepresentations?.length) {
30
+ const labelmapRepresentations = segmentationRepresentations.filter((representation) => representation.type === Representations.Labelmap);
31
+ if (!labelmapRepresentations.length) {
34
32
  return;
35
33
  }
36
- const segmentationRepresentations = {};
37
- toolGroupSegmentationRepresentations.forEach((representation) => {
34
+ labelmapRepresentations.forEach((representation) => {
38
35
  const segmentation = SegmentationState.getSegmentation(representation.segmentationId);
39
36
  if (!segmentation || !segmentation.representationData?.LABELMAP) {
40
37
  return;
@@ -59,9 +56,9 @@ function _imageChangeEventListener(evt) {
59
56
  return true;
60
57
  });
61
58
  if (!segmentationFound) {
62
- if (!perToolGroupManualTriggers.has(toolGroup.id)) {
63
- perToolGroupManualTriggers.set(toolGroup.id, true);
64
- triggerSegmentationRender(toolGroup.id);
59
+ if (!perViewportManualTriggers.has(viewportId)) {
60
+ perViewportManualTriggers.set(viewportId, true);
61
+ triggerSegmentationRenderForViewports([viewportId]);
65
62
  }
66
63
  return;
67
64
  }
@@ -121,7 +118,7 @@ function _imageChangeEventListener(evt) {
121
118
  },
122
119
  },
123
120
  ]);
124
- triggerSegmentationRender(toolGroup.id);
121
+ triggerSegmentationRender();
125
122
  return;
126
123
  }
127
124
  if (segmentationImageData.setDerivedImage) {
@@ -1,10 +1,8 @@
1
- import { cache, getEnabledElementByIds, utilities as csUtils, VolumeViewport, } from '@cornerstonejs/core';
1
+ import { cache, utilities as csUtils, VolumeViewport, getEnabledElementByViewportId, } from '@cornerstonejs/core';
2
2
  import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
3
- import { getToolGroup } from '../../../store/ToolGroupManager';
4
3
  const onLabelmapSegmentationDataModified = function (evt) {
5
4
  const { segmentationId, modifiedSlicesToUse } = evt.detail;
6
5
  const { representationData, type } = SegmentationState.getSegmentation(segmentationId);
7
- const toolGroupIds = SegmentationState.getToolGroupIdsWithSegmentation(segmentationId);
8
6
  const labelmapRepresentationData = representationData[type];
9
7
  if ('volumeId' in labelmapRepresentationData) {
10
8
  performVolumeLabelmapUpdate({
@@ -13,9 +11,10 @@ const onLabelmapSegmentationDataModified = function (evt) {
13
11
  type,
14
12
  });
15
13
  }
14
+ const viewportIds = SegmentationState.getViewportIdsWithSegmentationId(segmentationId);
16
15
  if ('imageIdReferenceMap' in labelmapRepresentationData) {
17
16
  performStackLabelmapUpdate({
18
- toolGroupIds,
17
+ viewportIds,
19
18
  segmentationId,
20
19
  representationData,
21
20
  type,
@@ -42,32 +41,32 @@ function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData,
42
41
  });
43
42
  imageData.modified();
44
43
  }
45
- function performStackLabelmapUpdate({ toolGroupIds, segmentationId, representationData, type, }) {
46
- toolGroupIds.forEach((toolGroupId) => {
47
- const toolGroupSegmentationRepresentations = SegmentationState.getSegmentationRepresentations(toolGroupId);
48
- const toolGroup = getToolGroup(toolGroupId);
49
- const viewportsInfo = toolGroup.getViewportsInfo();
50
- toolGroupSegmentationRepresentations.forEach((representation) => {
44
+ function performStackLabelmapUpdate({ viewportIds, segmentationId, representationData, type, }) {
45
+ viewportIds.forEach((viewportId) => {
46
+ const viewportSegReps = SegmentationState.getRepresentationsForViewport(viewportId);
47
+ viewportSegReps.forEach((representation) => {
51
48
  if (representation.segmentationId !== segmentationId) {
52
49
  return;
53
50
  }
54
- viewportsInfo.forEach(({ viewportId, renderingEngineId }) => {
55
- const viewport = getEnabledElementByIds(viewportId, renderingEngineId).viewport;
56
- if (viewport instanceof VolumeViewport) {
57
- return;
58
- }
59
- const actorEntry = viewport.getActor(representation.segmentationRepresentationUID);
60
- if (!actorEntry) {
61
- return;
62
- }
63
- const currentImageId = viewport.getCurrentImageId();
64
- const segImageData = actorEntry.actor.getMapper().getInputData();
65
- const { imageIdReferenceMap } = representationData[type];
66
- const currentSegmentationImageId = imageIdReferenceMap.get(currentImageId);
67
- const segmentationImage = cache.getImage(currentSegmentationImageId);
68
- segImageData.modified();
69
- csUtils.updateVTKImageDataWithCornerstoneImage(segImageData, segmentationImage);
70
- });
51
+ const enabledElement = getEnabledElementByViewportId(viewportId);
52
+ if (!enabledElement) {
53
+ return;
54
+ }
55
+ const { viewport } = enabledElement;
56
+ if (viewport instanceof VolumeViewport) {
57
+ return;
58
+ }
59
+ const actorEntry = viewport.getActor(representation.segmentationRepresentationUID);
60
+ if (!actorEntry) {
61
+ return;
62
+ }
63
+ const currentImageId = viewport.getCurrentImageId();
64
+ const segImageData = actorEntry.actor.getMapper().getInputData();
65
+ const { imageIdReferenceMap } = representationData[type];
66
+ const currentSegmentationImageId = imageIdReferenceMap.get(currentImageId);
67
+ const segmentationImage = cache.getImage(currentSegmentationImageId);
68
+ segImageData.modified();
69
+ csUtils.updateVTKImageDataWithCornerstoneImage(segImageData, segmentationImage);
71
70
  });
72
71
  });
73
72
  }
@@ -5,12 +5,9 @@ import onLabelmapSegmentationDataModified from './labelmap/onLabelmapSegmentatio
5
5
  const onSegmentationDataModified = function (evt) {
6
6
  const { segmentationId } = evt.detail;
7
7
  const { type } = SegmentationState.getSegmentation(segmentationId);
8
- const toolGroupIds = SegmentationState.getToolGroupIdsWithSegmentation(segmentationId);
9
8
  if (type === SegmentationRepresentations.Labelmap) {
10
9
  onLabelmapSegmentationDataModified(evt);
11
10
  }
12
- toolGroupIds.forEach((toolGroupId) => {
13
- triggerSegmentationRender(toolGroupId);
14
- });
11
+ triggerSegmentationRender(segmentationId);
15
12
  };
16
13
  export default onSegmentationDataModified;
@@ -1,15 +1,6 @@
1
- import { getToolGroupIdsWithSegmentation, getSegmentationRepresentations, } from '../../stateManagement/segmentation/segmentationState';
2
- import { triggerSegmentationRepresentationModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
1
+ import { triggerSegmentationRender } from '../../utilities/segmentation';
3
2
  const segmentationModifiedListener = function (evt) {
4
3
  const { segmentationId } = evt.detail;
5
- const toolGroupIds = getToolGroupIdsWithSegmentation(segmentationId);
6
- toolGroupIds.forEach((toolGroupId) => {
7
- const segRepresentations = getSegmentationRepresentations(toolGroupId);
8
- segRepresentations.forEach((representation) => {
9
- if (representation.segmentationId === segmentationId) {
10
- triggerSegmentationRepresentationModified(toolGroupId, representation.segmentationRepresentationUID);
11
- }
12
- });
13
- });
4
+ triggerSegmentationRender(segmentationId);
14
5
  };
15
6
  export default segmentationModifiedListener;
@@ -1,6 +1,14 @@
1
1
  import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
2
+ import { getRepresentation } from '../../stateManagement/segmentation/segmentationState';
2
3
  const segmentationRepresentationModifiedListener = function (evt) {
3
- const { toolGroupId } = evt.detail;
4
- triggerSegmentationRender(toolGroupId);
4
+ const { segmentationRepresentationUID } = evt.detail;
5
+ const segmentationRepresentation = getRepresentation
6
+ ? getRepresentation(segmentationRepresentationUID)
7
+ : null;
8
+ if (!segmentationRepresentation) {
9
+ return;
10
+ }
11
+ const segmentationId = segmentationRepresentation?.segmentationId;
12
+ triggerSegmentationRender(segmentationId);
5
13
  };
6
14
  export default segmentationRepresentationModifiedListener;
@@ -1,6 +1,6 @@
1
1
  import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
2
2
  const segmentationRepresentationRemovedEventListener = function (evt) {
3
- const { toolGroupId, segmentationRepresentationUID } = evt.detail;
4
- triggerSegmentationRender(toolGroupId);
3
+ const { segmentationRepresentationUID } = evt.detail;
4
+ triggerSegmentationRender();
5
5
  };
6
6
  export default segmentationRepresentationRemovedEventListener;
@@ -8,7 +8,7 @@ import * as cursors from './cursors';
8
8
  import * as Types from './types';
9
9
  import * as annotation from './stateManagement/annotation';
10
10
  import * as segmentation from './stateManagement/segmentation';
11
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SegmentationDisplayTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool } from './tools';
11
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool } from './tools';
12
12
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
13
13
  import * as Enums from './enums';
14
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, ScaleOverlayTool, SculptorTool, EraserTool, SegmentationDisplayTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, };
14
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, };
package/dist/esm/index.js CHANGED
@@ -8,7 +8,7 @@ import * as cursors from './cursors';
8
8
  import * as Types from './types';
9
9
  import * as annotation from './stateManagement/annotation';
10
10
  import * as segmentation from './stateManagement/segmentation';
11
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SegmentationDisplayTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, } from './tools';
11
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, } from './tools';
12
12
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
13
13
  import * as Enums from './enums';
14
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, ScaleOverlayTool, SculptorTool, EraserTool, SegmentationDisplayTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, };
14
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, StackScrollMouseWheelTool, VolumeRotateMouseWheelTool, MIPJumpToClickTool, LengthTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ReferenceLines, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, };
@@ -15,6 +15,6 @@ 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';
19
- import { removeSegmentationsFromToolGroup } from './segmentation';
20
- export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, removeSegmentationsFromToolGroup };
18
+ import { addRepresentations } from './segmentation';
19
+ import { removeRepresentationsFromViewport } from './segmentation';
20
+ export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addRepresentations, removeRepresentationsFromViewport };
@@ -2,5 +2,5 @@ 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, removeSegmentationsFromToolGroup, } from './segmentation';
6
- export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addSegmentationRepresentations, removeSegmentationsFromToolGroup, };
5
+ import { addRepresentations, removeRepresentationsFromViewport, } from './segmentation';
6
+ export { FrameOfReferenceSpecificAnnotationManager, defaultFrameOfReferenceSpecificAnnotationManager, annotationLocking, annotationSelection, getAnnotations, addAnnotation, getNumberOfAnnotations, removeAnnotation, getAnnotation, getParentAnnotation, getChildAnnotations, clearParentAnnotation, addChildAnnotation, setAnnotationManager, getAnnotationManager, resetAnnotationManager, invalidateAnnotation, addRepresentations, removeRepresentationsFromViewport, };
@@ -1,36 +1,37 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
- import type { RepresentationConfig, Segmentation, SegmentationRepresentationConfig, SegmentationState, SegmentSpecificRepresentationConfig, ToolGroupSpecificRepresentation, ToolGroupSpecificRepresentations } from '../../types/SegmentationStateTypes';
2
+ import type { RepresentationConfig, SegmentRepresentationConfig, Segmentation, SegmentationRepresentation, SegmentationRepresentationConfig, SegmentationState } from '../../types/SegmentationStateTypes';
3
3
  export default class SegmentationStateManager {
4
4
  private state;
5
5
  readonly uid: string;
6
6
  constructor(uid?: string);
7
7
  getState(): SegmentationState;
8
- getToolGroups(): string[];
9
8
  getColorLUT(lutIndex: number): Types.ColorLUT | undefined;
10
9
  getNextColorLUTIndex(): number;
11
10
  resetState(): void;
12
11
  getSegmentation(segmentationId: string): Segmentation | undefined;
13
12
  addSegmentation(segmentation: Segmentation): void;
14
- getSegmentationRepresentations(toolGroupId: string): ToolGroupSpecificRepresentations | undefined;
15
- getAllSegmentationRepresentations(): Record<string, ToolGroupSpecificRepresentation[]>;
16
- addSegmentationRepresentation(toolGroupId: string, segmentationRepresentation: ToolGroupSpecificRepresentation): void;
13
+ removeSegmentation(segmentationId: string): void;
14
+ getRepresentation(segmentationRepresentationUID: string): SegmentationRepresentation | undefined;
15
+ addRepresentation(segmentationRepresentation: SegmentationRepresentation): void;
16
+ addRepresentationToViewport(viewportId: string, segmentationRepresentationUID: string): void;
17
+ getRepresentationsForViewport(viewportId: string): SegmentationRepresentation[];
18
+ removeRepresentation(segmentationRepresentationUID: string): void;
19
+ setActiveRepresentation(viewportId: string, segmentationRepresentationUID: string): void;
20
+ getActiveRepresentation(viewportId: string): SegmentationRepresentation | undefined;
17
21
  getGlobalConfig(): SegmentationRepresentationConfig;
18
22
  setGlobalConfig(config: SegmentationRepresentationConfig): void;
19
- getSegmentationRepresentationByUID(toolGroupId: string, segmentationRepresentationUID: string): ToolGroupSpecificRepresentation | undefined;
20
- removeSegmentation(segmentationId: string): void;
21
- removeSegmentationRepresentation(toolGroupId: string, segmentationRepresentationUID: string): void;
22
- setActiveSegmentationRepresentation(toolGroupId: string, segmentationRepresentationUID: string): void;
23
- getToolGroupSpecificConfig(toolGroupId: string): SegmentationRepresentationConfig | undefined;
24
- getSegmentationRepresentationSpecificConfig(toolGroupId: string, segmentationRepresentationUID: string): RepresentationConfig;
25
- setSegmentationRepresentationSpecificConfig(toolGroupId: string, segmentationRepresentationUID: string, config: RepresentationConfig): void;
26
- getSegmentSpecificConfig(toolGroupId: string, segmentationRepresentationUID: string, segmentIndex: number): RepresentationConfig;
27
- setSegmentSpecificConfig(toolGroupId: string, segmentationRepresentationUID: string, config: SegmentSpecificRepresentationConfig, options?: {
28
- clear: false;
29
- }): void;
30
- setSegmentationRepresentationConfig(toolGroupId: string, config: SegmentationRepresentationConfig): void;
23
+ _getRepresentationConfig(segmentationRepresentationUID: string): {
24
+ allSegments?: RepresentationConfig;
25
+ perSegment?: SegmentRepresentationConfig;
26
+ };
27
+ getAllSegmentsConfig(segmentationRepresentationUID: string): RepresentationConfig;
28
+ getPerSegmentConfig(segmentationRepresentationUID: string): SegmentRepresentationConfig;
29
+ setAllSegmentsConfig(segmentationRepresentationUID: string, config: RepresentationConfig): void;
30
+ setPerSegmentConfig(segmentationRepresentationUID: string, config: SegmentRepresentationConfig): void;
31
+ getRepresentationVisibility(viewportId: string, segmentationRepresentationUID: string): boolean;
32
+ setRepresentationVisibility(viewportId: string, segmentationRepresentationUID: string, visible: boolean): void;
31
33
  addColorLUT(colorLUT: Types.ColorLUT, lutIndex: number): void;
32
34
  removeColorLUT(colorLUTIndex: number): void;
33
- _handleActiveSegmentation(toolGroupId: string, recentlyAddedOrRemovedSegmentationRepresentation: ToolGroupSpecificRepresentation): void;
34
35
  }
35
36
  declare const defaultSegmentationStateManager: SegmentationStateManager;
36
37
  export { defaultSegmentationStateManager };
@@ -3,22 +3,20 @@ import { SegmentationRepresentations } from '../../enums';
3
3
  import getDefaultContourConfig from '../../tools/displayTools/Contour/contourConfig';
4
4
  import getDefaultLabelmapConfig from '../../tools/displayTools/Labelmap/labelmapConfig';
5
5
  import getDefaultSurfaceConfig from '../../tools/displayTools/Surface/surfaceConfig';
6
- const defaultLabelmapConfig = getDefaultLabelmapConfig();
7
- const defaultContourConfig = getDefaultContourConfig();
8
- const defaultSurfaceConfig = getDefaultSurfaceConfig();
9
6
  const newGlobalConfig = {
10
- renderInactiveSegmentations: true,
7
+ renderInactiveRepresentations: true,
11
8
  representations: {
12
- [SegmentationRepresentations.Labelmap]: defaultLabelmapConfig,
13
- [SegmentationRepresentations.Contour]: defaultContourConfig,
14
- [SegmentationRepresentations.Surface]: defaultSurfaceConfig,
9
+ [SegmentationRepresentations.Labelmap]: getDefaultLabelmapConfig(),
10
+ [SegmentationRepresentations.Contour]: getDefaultContourConfig(),
11
+ [SegmentationRepresentations.Surface]: getDefaultSurfaceConfig(),
15
12
  },
16
13
  };
17
14
  const initialDefaultState = {
18
15
  colorLUT: [],
19
16
  segmentations: [],
20
17
  globalConfig: newGlobalConfig,
21
- toolGroups: {},
18
+ representations: {},
19
+ viewports: {},
22
20
  };
23
21
  export default class SegmentationStateManager {
24
22
  constructor(uid) {
@@ -31,9 +29,6 @@ export default class SegmentationStateManager {
31
29
  getState() {
32
30
  return this.state;
33
31
  }
34
- getToolGroups() {
35
- return Object.keys(this.state.toolGroups);
36
- }
37
32
  getColorLUT(lutIndex) {
38
33
  return this.state.colorLUT[lutIndex];
39
34
  }
@@ -52,30 +47,64 @@ export default class SegmentationStateManager {
52
47
  }
53
48
  this.state.segmentations.push(segmentation);
54
49
  }
55
- getSegmentationRepresentations(toolGroupId) {
56
- const toolGroupSegRepresentationsWithConfig = this.state.toolGroups[toolGroupId];
57
- if (!toolGroupSegRepresentationsWithConfig) {
58
- return;
50
+ removeSegmentation(segmentationId) {
51
+ this.state.segmentations = this.state.segmentations.filter((segmentation) => segmentation.segmentationId !== segmentationId);
52
+ }
53
+ getRepresentation(segmentationRepresentationUID) {
54
+ return this.state.representations[segmentationRepresentationUID];
55
+ }
56
+ addRepresentation(segmentationRepresentation) {
57
+ const { segmentationRepresentationUID } = segmentationRepresentation;
58
+ this.state.representations[segmentationRepresentationUID] =
59
+ segmentationRepresentation;
60
+ }
61
+ addRepresentationToViewport(viewportId, segmentationRepresentationUID) {
62
+ if (!this.state.viewports[viewportId]) {
63
+ this.state.viewports[viewportId] = {};
59
64
  }
60
- return toolGroupSegRepresentationsWithConfig.segmentationRepresentations;
65
+ this.setActiveRepresentation(viewportId, segmentationRepresentationUID);
61
66
  }
62
- getAllSegmentationRepresentations() {
63
- const toolGroupSegReps = {};
64
- Object.entries(this.state.toolGroups).forEach(([toolGroupId, toolGroupSegRepresentationsWithConfig]) => {
65
- toolGroupSegReps[toolGroupId] =
66
- toolGroupSegRepresentationsWithConfig.segmentationRepresentations;
67
+ getRepresentationsForViewport(viewportId) {
68
+ const viewport = this.state.viewports[viewportId];
69
+ if (!viewport) {
70
+ return [];
71
+ }
72
+ return Object.keys(viewport).map((segRepUID) => {
73
+ return this.getRepresentation(segRepUID);
67
74
  });
68
- return toolGroupSegReps;
69
75
  }
70
- addSegmentationRepresentation(toolGroupId, segmentationRepresentation) {
71
- if (!this.state.toolGroups[toolGroupId]) {
72
- this.state.toolGroups[toolGroupId] = {
73
- segmentationRepresentations: [],
74
- config: {},
76
+ removeRepresentation(segmentationRepresentationUID) {
77
+ delete this.state.representations[segmentationRepresentationUID];
78
+ Object.keys(this.state.viewports).forEach((viewportId) => {
79
+ delete this.state.viewports[viewportId][segmentationRepresentationUID];
80
+ });
81
+ }
82
+ setActiveRepresentation(viewportId, segmentationRepresentationUID) {
83
+ Object.keys(this.state.viewports[viewportId]).forEach((segRepUID) => {
84
+ this.state.viewports[viewportId][segRepUID].active = false;
85
+ });
86
+ if (!this.state.viewports[viewportId]) {
87
+ this.state.viewports[viewportId] = {};
88
+ }
89
+ if (!this.state.viewports[viewportId][segmentationRepresentationUID]) {
90
+ this.state.viewports[viewportId][segmentationRepresentationUID] = {
91
+ active: false,
92
+ visible: true,
93
+ segmentsHidden: new Set(),
75
94
  };
76
95
  }
77
- this.state.toolGroups[toolGroupId].segmentationRepresentations.push(segmentationRepresentation);
78
- this._handleActiveSegmentation(toolGroupId, segmentationRepresentation);
96
+ this.state.viewports[viewportId][segmentationRepresentationUID].active =
97
+ true;
98
+ }
99
+ getActiveRepresentation(viewportId) {
100
+ if (!this.state.viewports?.[viewportId]) {
101
+ return;
102
+ }
103
+ const activeSegRep = Object.entries(this.state.viewports[viewportId]).find(([, value]) => value.active);
104
+ if (!activeSegRep) {
105
+ return;
106
+ }
107
+ return this.getRepresentation(activeSegRep[0]);
79
108
  }
80
109
  getGlobalConfig() {
81
110
  return this.state.globalConfig;
@@ -83,100 +112,51 @@ export default class SegmentationStateManager {
83
112
  setGlobalConfig(config) {
84
113
  this.state.globalConfig = config;
85
114
  }
86
- getSegmentationRepresentationByUID(toolGroupId, segmentationRepresentationUID) {
87
- const toolGroupSegRepresentations = this.getSegmentationRepresentations(toolGroupId);
88
- const segmentationData = toolGroupSegRepresentations?.find((representation) => representation.segmentationRepresentationUID ===
89
- segmentationRepresentationUID);
90
- return segmentationData;
91
- }
92
- removeSegmentation(segmentationId) {
93
- this.state.segmentations = this.state.segmentations.filter((segmentation) => segmentation.segmentationId !== segmentationId);
94
- }
95
- removeSegmentationRepresentation(toolGroupId, segmentationRepresentationUID) {
96
- const toolGroupSegmentationRepresentations = this.getSegmentationRepresentations(toolGroupId);
97
- if (!toolGroupSegmentationRepresentations ||
98
- !toolGroupSegmentationRepresentations.length) {
99
- throw new Error(`No viewport specific segmentation state found for viewport ${toolGroupId}`);
100
- }
101
- const state = toolGroupSegmentationRepresentations;
102
- const index = state.findIndex((segData) => segData.segmentationRepresentationUID === segmentationRepresentationUID);
103
- if (index === -1) {
104
- console.warn(`No viewport specific segmentation state data found for viewport ${toolGroupId} and segmentation data UID ${segmentationRepresentationUID}`);
105
- }
106
- const removedSegmentationRepresentation = toolGroupSegmentationRepresentations[index];
107
- toolGroupSegmentationRepresentations.splice(index, 1);
108
- this._handleActiveSegmentation(toolGroupId, removedSegmentationRepresentation);
109
- }
110
- setActiveSegmentationRepresentation(toolGroupId, segmentationRepresentationUID) {
111
- const toolGroupSegmentations = this.getSegmentationRepresentations(toolGroupId);
112
- if (!toolGroupSegmentations || !toolGroupSegmentations.length) {
113
- throw new Error(`No segmentation data found for toolGroupId: ${toolGroupId}`);
114
- }
115
- const segmentationData = toolGroupSegmentations.find((segmentationData) => segmentationData.segmentationRepresentationUID ===
116
- segmentationRepresentationUID);
117
- if (!segmentationData) {
118
- throw new Error(`No segmentation data found for segmentation data UID ${segmentationRepresentationUID}`);
119
- }
120
- segmentationData.active = true;
121
- this._handleActiveSegmentation(toolGroupId, segmentationData);
122
- }
123
- getToolGroupSpecificConfig(toolGroupId) {
124
- const toolGroupStateWithConfig = this.state.toolGroups[toolGroupId];
125
- if (!toolGroupStateWithConfig) {
115
+ _getRepresentationConfig(segmentationRepresentationUID) {
116
+ const segmentationRepresentation = this.getRepresentation(segmentationRepresentationUID);
117
+ if (!segmentationRepresentation) {
126
118
  return;
127
119
  }
128
- return toolGroupStateWithConfig.config;
120
+ return segmentationRepresentation.config;
129
121
  }
130
- getSegmentationRepresentationSpecificConfig(toolGroupId, segmentationRepresentationUID) {
131
- const segmentationRepresentation = this.getSegmentationRepresentationByUID(toolGroupId, segmentationRepresentationUID);
132
- if (!segmentationRepresentation) {
122
+ getAllSegmentsConfig(segmentationRepresentationUID) {
123
+ const config = this._getRepresentationConfig(segmentationRepresentationUID);
124
+ if (!config) {
133
125
  return;
134
126
  }
135
- return segmentationRepresentation.segmentationRepresentationSpecificConfig;
127
+ return config.allSegments;
136
128
  }
137
- setSegmentationRepresentationSpecificConfig(toolGroupId, segmentationRepresentationUID, config) {
138
- const segmentationRepresentation = this.getSegmentationRepresentationByUID(toolGroupId, segmentationRepresentationUID);
139
- if (!segmentationRepresentation) {
129
+ getPerSegmentConfig(segmentationRepresentationUID) {
130
+ const config = this._getRepresentationConfig(segmentationRepresentationUID);
131
+ if (!config) {
140
132
  return;
141
133
  }
142
- segmentationRepresentation.segmentationRepresentationSpecificConfig =
143
- config;
134
+ return config.perSegment;
144
135
  }
145
- getSegmentSpecificConfig(toolGroupId, segmentationRepresentationUID, segmentIndex) {
146
- const segmentationRepresentation = this.getSegmentationRepresentationByUID(toolGroupId, segmentationRepresentationUID);
147
- if (!segmentationRepresentation) {
136
+ setAllSegmentsConfig(segmentationRepresentationUID, config) {
137
+ const _config = this._getRepresentationConfig(segmentationRepresentationUID);
138
+ if (!_config) {
148
139
  return;
149
140
  }
150
- return segmentationRepresentation.segmentSpecificConfig[segmentIndex];
141
+ _config.allSegments = config;
151
142
  }
152
- setSegmentSpecificConfig(toolGroupId, segmentationRepresentationUID, config, options) {
153
- const segmentationRepresentation = this.getSegmentationRepresentationByUID(toolGroupId, segmentationRepresentationUID);
154
- if (!segmentationRepresentation) {
143
+ setPerSegmentConfig(segmentationRepresentationUID, config) {
144
+ const _config = this._getRepresentationConfig(segmentationRepresentationUID);
145
+ if (!_config) {
155
146
  return;
156
147
  }
157
- if (!segmentationRepresentation.segmentSpecificConfig || options?.clear) {
158
- segmentationRepresentation.segmentSpecificConfig = {};
159
- }
160
- Object.keys(config).forEach((key) => {
161
- segmentationRepresentation.segmentSpecificConfig[key] = config[key];
162
- });
148
+ _config.perSegment = config;
163
149
  }
164
- setSegmentationRepresentationConfig(toolGroupId, config) {
165
- let toolGroupStateWithConfig = this.state.toolGroups[toolGroupId];
166
- if (!toolGroupStateWithConfig) {
167
- this.state.toolGroups[toolGroupId] = {
168
- segmentationRepresentations: [],
169
- config: {
170
- renderInactiveSegmentations: true,
171
- representations: {},
172
- },
173
- };
174
- toolGroupStateWithConfig = this.state.toolGroups[toolGroupId];
150
+ getRepresentationVisibility(viewportId, segmentationRepresentationUID) {
151
+ const viewport = this.state.viewports[viewportId];
152
+ return viewport && viewport[segmentationRepresentationUID]?.visible;
153
+ }
154
+ setRepresentationVisibility(viewportId, segmentationRepresentationUID, visible) {
155
+ if (!this.state.viewports[viewportId]) {
156
+ this.state.viewports[viewportId] = {};
175
157
  }
176
- toolGroupStateWithConfig.config = {
177
- ...toolGroupStateWithConfig.config,
178
- ...config,
179
- };
158
+ this.state.viewports[viewportId][segmentationRepresentationUID].visible =
159
+ visible;
180
160
  }
181
161
  addColorLUT(colorLUT, lutIndex) {
182
162
  if (this.state.colorLUT[lutIndex]) {
@@ -187,29 +167,6 @@ export default class SegmentationStateManager {
187
167
  removeColorLUT(colorLUTIndex) {
188
168
  delete this.state.colorLUT[colorLUTIndex];
189
169
  }
190
- _handleActiveSegmentation(toolGroupId, recentlyAddedOrRemovedSegmentationRepresentation) {
191
- const segmentationRepresentations = this.getSegmentationRepresentations(toolGroupId);
192
- if (segmentationRepresentations.length === 0) {
193
- return;
194
- }
195
- if (segmentationRepresentations.length === 1) {
196
- segmentationRepresentations[0].active = true;
197
- return;
198
- }
199
- const activeSegmentationRepresentations = segmentationRepresentations.filter((representation) => representation.active);
200
- if (activeSegmentationRepresentations.length === 0) {
201
- segmentationRepresentations[0].active = true;
202
- return;
203
- }
204
- if (recentlyAddedOrRemovedSegmentationRepresentation.active) {
205
- segmentationRepresentations.forEach((representation) => {
206
- if (representation.segmentationRepresentationUID !==
207
- recentlyAddedOrRemovedSegmentationRepresentation.segmentationRepresentationUID) {
208
- representation.active = false;
209
- }
210
- });
211
- }
212
- }
213
170
  }
214
171
  const defaultSegmentationStateManager = new SegmentationStateManager('DEFAULT');
215
172
  export { defaultSegmentationStateManager };
@@ -1,5 +1,4 @@
1
- import { ToolGroupSpecificRepresentation } from '../../types/SegmentationStateTypes';
2
- declare function getActiveSegmentationRepresentation(toolGroupId: string): ToolGroupSpecificRepresentation;
3
- declare function getActiveSegmentation(toolGroupId: string): import("../../types/SegmentationStateTypes").Segmentation;
4
- declare function setActiveSegmentationRepresentation(toolGroupId: string, segmentationRepresentationUID: string): void;
5
- export { getActiveSegmentationRepresentation, getActiveSegmentation, setActiveSegmentationRepresentation, };
1
+ import { SegmentationRepresentation } from '../../types/SegmentationStateTypes';
2
+ declare function getActiveRepresentation(viewportId: any): SegmentationRepresentation;
3
+ declare function setActiveRepresentation(viewportId: any, segmentationRepresentationUID: any, suppressEvent?: boolean): void;
4
+ export { getActiveRepresentation, setActiveRepresentation, };