@cornerstonejs/tools 1.70.5 → 1.70.7

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 (151) hide show
  1. package/dist/cjs/enums/Events.d.ts +2 -0
  2. package/dist/cjs/enums/Events.js +2 -0
  3. package/dist/cjs/enums/Events.js.map +1 -1
  4. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +12 -0
  5. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  6. package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +1 -1
  7. package/dist/cjs/tools/AdvancedMagnifyTool.js +35 -43
  8. package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
  9. package/dist/cjs/tools/AdvancedMagnifyViewport.d.ts +1 -1
  10. package/dist/cjs/tools/AdvancedMagnifyViewport.js +8 -2
  11. package/dist/cjs/tools/AdvancedMagnifyViewport.js.map +1 -1
  12. package/dist/cjs/tools/AdvancedMagnifyViewportManager.d.ts +2 -1
  13. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js +32 -3
  14. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js.map +1 -1
  15. package/dist/cjs/tools/OrientationMarkerTool.d.ts +0 -2
  16. package/dist/cjs/tools/OrientationMarkerTool.js +47 -28
  17. package/dist/cjs/tools/OrientationMarkerTool.js.map +1 -1
  18. package/dist/cjs/tools/annotation/BidirectionalTool.js +15 -8
  19. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  20. package/dist/cjs/tools/annotation/CircleROITool.js +19 -18
  21. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  22. package/dist/cjs/tools/annotation/EllipticalROITool.d.ts +1 -1
  23. package/dist/cjs/tools/annotation/EllipticalROITool.js +21 -20
  24. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  25. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +27 -4
  26. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  27. package/dist/cjs/tools/annotation/RectangleROITool.js +18 -18
  28. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  29. package/dist/cjs/tools/annotation/SplineROITool.js +16 -2
  30. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  31. package/dist/cjs/tools/base/AnnotationTool.js +4 -1
  32. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  33. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +5 -0
  34. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  35. package/dist/cjs/tools/segmentation/BrushTool.js +12 -1
  36. package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
  37. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js +3 -0
  38. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  39. package/dist/cjs/tools/segmentation/strategies/compositions/preview.js +10 -2
  40. package/dist/cjs/tools/segmentation/strategies/compositions/preview.js.map +1 -1
  41. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +2 -1
  42. package/dist/cjs/utilities/cine/playClip.d.ts +1 -1
  43. package/dist/cjs/utilities/cine/playClip.js +2 -5
  44. package/dist/cjs/utilities/cine/playClip.js.map +1 -1
  45. package/dist/cjs/utilities/getCalibratedUnits.d.ts +1 -5
  46. package/dist/cjs/utilities/getCalibratedUnits.js +13 -45
  47. package/dist/cjs/utilities/getCalibratedUnits.js.map +1 -1
  48. package/dist/cjs/utilities/index.d.ts +2 -2
  49. package/dist/cjs/utilities/index.js +4 -4
  50. package/dist/cjs/utilities/index.js.map +1 -1
  51. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js +3 -0
  52. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  53. package/dist/esm/enums/Events.js +2 -0
  54. package/dist/esm/enums/Events.js.map +1 -1
  55. package/dist/esm/store/ToolGroupManager/ToolGroup.js +12 -0
  56. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  57. package/dist/esm/tools/AdvancedMagnifyTool.js +35 -43
  58. package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
  59. package/dist/esm/tools/AdvancedMagnifyViewport.js +8 -2
  60. package/dist/esm/tools/AdvancedMagnifyViewport.js.map +1 -1
  61. package/dist/esm/tools/AdvancedMagnifyViewportManager.js +38 -4
  62. package/dist/esm/tools/AdvancedMagnifyViewportManager.js.map +1 -1
  63. package/dist/esm/tools/OrientationMarkerTool.js +48 -29
  64. package/dist/esm/tools/OrientationMarkerTool.js.map +1 -1
  65. package/dist/esm/tools/annotation/BidirectionalTool.js +16 -9
  66. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  67. package/dist/esm/tools/annotation/CircleROITool.js +21 -20
  68. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  69. package/dist/esm/tools/annotation/EllipticalROITool.js +23 -22
  70. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  71. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +29 -6
  72. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  73. package/dist/esm/tools/annotation/RectangleROITool.js +19 -19
  74. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  75. package/dist/esm/tools/annotation/SplineROITool.js +17 -3
  76. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  77. package/dist/esm/tools/base/AnnotationTool.js +4 -1
  78. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  79. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +5 -0
  80. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  81. package/dist/esm/tools/segmentation/BrushTool.js +13 -2
  82. package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
  83. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +3 -0
  84. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  85. package/dist/esm/tools/segmentation/strategies/compositions/preview.js +10 -2
  86. package/dist/esm/tools/segmentation/strategies/compositions/preview.js.map +1 -1
  87. package/dist/esm/utilities/cine/playClip.js +2 -2
  88. package/dist/esm/utilities/cine/playClip.js.map +1 -1
  89. package/dist/esm/utilities/getCalibratedUnits.js +13 -41
  90. package/dist/esm/utilities/getCalibratedUnits.js.map +1 -1
  91. package/dist/esm/utilities/index.js +2 -2
  92. package/dist/esm/utilities/index.js.map +1 -1
  93. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js +3 -0
  94. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  95. package/dist/types/enums/Events.d.ts +2 -0
  96. package/dist/types/enums/Events.d.ts.map +1 -1
  97. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
  98. package/dist/types/tools/AdvancedMagnifyTool.d.ts +1 -1
  99. package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
  100. package/dist/types/tools/AdvancedMagnifyViewport.d.ts +1 -1
  101. package/dist/types/tools/AdvancedMagnifyViewport.d.ts.map +1 -1
  102. package/dist/types/tools/AdvancedMagnifyViewportManager.d.ts +2 -1
  103. package/dist/types/tools/AdvancedMagnifyViewportManager.d.ts.map +1 -1
  104. package/dist/types/tools/OrientationMarkerTool.d.ts +0 -2
  105. package/dist/types/tools/OrientationMarkerTool.d.ts.map +1 -1
  106. package/dist/types/tools/annotation/BidirectionalTool.d.ts.map +1 -1
  107. package/dist/types/tools/annotation/CircleROITool.d.ts.map +1 -1
  108. package/dist/types/tools/annotation/EllipticalROITool.d.ts +1 -1
  109. package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
  110. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  111. package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
  112. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  113. package/dist/types/tools/base/AnnotationTool.d.ts.map +1 -1
  114. package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts.map +1 -1
  115. package/dist/types/tools/segmentation/BrushTool.d.ts.map +1 -1
  116. package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts.map +1 -1
  117. package/dist/types/tools/segmentation/strategies/compositions/preview.d.ts.map +1 -1
  118. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +2 -1
  119. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  120. package/dist/types/utilities/cine/playClip.d.ts +1 -1
  121. package/dist/types/utilities/cine/playClip.d.ts.map +1 -1
  122. package/dist/types/utilities/getCalibratedUnits.d.ts +1 -5
  123. package/dist/types/utilities/getCalibratedUnits.d.ts.map +1 -1
  124. package/dist/types/utilities/index.d.ts +2 -2
  125. package/dist/types/utilities/index.d.ts.map +1 -1
  126. package/dist/types/utilities/planar/filterAnnotationsForDisplay.d.ts.map +1 -1
  127. package/dist/umd/index.js +1 -1
  128. package/dist/umd/index.js.map +1 -1
  129. package/package.json +4 -4
  130. package/src/enums/Events.ts +6 -0
  131. package/src/store/ToolGroupManager/ToolGroup.ts +16 -0
  132. package/src/tools/AdvancedMagnifyTool.ts +42 -66
  133. package/src/tools/AdvancedMagnifyViewport.ts +11 -3
  134. package/src/tools/AdvancedMagnifyViewportManager.ts +74 -3
  135. package/src/tools/OrientationMarkerTool.ts +74 -50
  136. package/src/tools/annotation/BidirectionalTool.ts +28 -15
  137. package/src/tools/annotation/CircleROITool.ts +24 -25
  138. package/src/tools/annotation/EllipticalROITool.ts +28 -39
  139. package/src/tools/annotation/PlanarFreehandROITool.ts +56 -11
  140. package/src/tools/annotation/RectangleROITool.ts +23 -23
  141. package/src/tools/annotation/SplineROITool.ts +36 -4
  142. package/src/tools/base/AnnotationTool.ts +8 -2
  143. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +7 -0
  144. package/src/tools/segmentation/BrushTool.ts +17 -1
  145. package/src/tools/segmentation/strategies/compositions/dynamicThreshold.ts +6 -0
  146. package/src/tools/segmentation/strategies/compositions/preview.ts +14 -4
  147. package/src/types/ToolSpecificAnnotationTypes.ts +2 -1
  148. package/src/utilities/cine/playClip.ts +2 -2
  149. package/src/utilities/getCalibratedUnits.ts +18 -74
  150. package/src/utilities/index.ts +6 -6
  151. package/src/utilities/planar/filterAnnotationsForDisplay.ts +3 -0
@@ -7,10 +7,7 @@ import {
7
7
  } from '@cornerstonejs/core';
8
8
  import type { Types } from '@cornerstonejs/core';
9
9
 
10
- import {
11
- getCalibratedAreaUnits,
12
- getCalibratedScale,
13
- } from '../../utilities/getCalibratedUnits';
10
+ import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits';
14
11
  import { roundNumber } from '../../utilities';
15
12
  import throttle from '../../utilities/throttle';
16
13
  import {
@@ -878,37 +875,35 @@ class RectangleROITool extends AnnotationTool {
878
875
  }
879
876
 
880
877
  const { dimensions, imageData, metadata } = image;
881
- const scalarData =
882
- 'getScalarData' in image ? image.getScalarData() : image.scalarData;
883
878
 
884
- const worldPos1Index = transformWorldToIndex(imageData, worldPos1);
879
+ const pos1Index = transformWorldToIndex(imageData, worldPos1);
885
880
 
886
- worldPos1Index[0] = Math.floor(worldPos1Index[0]);
887
- worldPos1Index[1] = Math.floor(worldPos1Index[1]);
888
- worldPos1Index[2] = Math.floor(worldPos1Index[2]);
881
+ pos1Index[0] = Math.floor(pos1Index[0]);
882
+ pos1Index[1] = Math.floor(pos1Index[1]);
883
+ pos1Index[2] = Math.floor(pos1Index[2]);
889
884
 
890
- const worldPos2Index = transformWorldToIndex(imageData, worldPos2);
885
+ const pos2Index = transformWorldToIndex(imageData, worldPos2);
891
886
 
892
- worldPos2Index[0] = Math.floor(worldPos2Index[0]);
893
- worldPos2Index[1] = Math.floor(worldPos2Index[1]);
894
- worldPos2Index[2] = Math.floor(worldPos2Index[2]);
887
+ pos2Index[0] = Math.floor(pos2Index[0]);
888
+ pos2Index[1] = Math.floor(pos2Index[1]);
889
+ pos2Index[2] = Math.floor(pos2Index[2]);
895
890
 
896
891
  // Check if one of the indexes are inside the volume, this then gives us
897
892
  // Some area to do stats over.
898
893
 
899
- if (this._isInsideVolume(worldPos1Index, worldPos2Index, dimensions)) {
894
+ if (this._isInsideVolume(pos1Index, pos2Index, dimensions)) {
900
895
  this.isHandleOutsideImage = false;
901
896
 
902
897
  // Calculate index bounds to iterate over
903
898
 
904
- const iMin = Math.min(worldPos1Index[0], worldPos2Index[0]);
905
- const iMax = Math.max(worldPos1Index[0], worldPos2Index[0]);
899
+ const iMin = Math.min(pos1Index[0], pos2Index[0]);
900
+ const iMax = Math.max(pos1Index[0], pos2Index[0]);
906
901
 
907
- const jMin = Math.min(worldPos1Index[1], worldPos2Index[1]);
908
- const jMax = Math.max(worldPos1Index[1], worldPos2Index[1]);
902
+ const jMin = Math.min(pos1Index[1], pos2Index[1]);
903
+ const jMax = Math.max(pos1Index[1], pos2Index[1]);
909
904
 
910
- const kMin = Math.min(worldPos1Index[2], worldPos2Index[2]);
911
- const kMax = Math.max(worldPos1Index[2], worldPos2Index[2]);
905
+ const kMin = Math.min(pos1Index[2], pos2Index[2]);
906
+ const kMax = Math.max(pos1Index[2], pos2Index[2]);
912
907
 
913
908
  const boundsIJK = [
914
909
  [iMin, iMax],
@@ -922,7 +917,12 @@ class RectangleROITool extends AnnotationTool {
922
917
  worldPos1,
923
918
  worldPos2
924
919
  );
925
- const scale = getCalibratedScale(image);
920
+
921
+ const handles = [pos1Index, pos2Index];
922
+ const { scale, areaUnits } = getCalibratedLengthUnitsAndScale(
923
+ image,
924
+ handles
925
+ );
926
926
 
927
927
  const area = Math.abs(worldWidth * worldHeight) / (scale * scale);
928
928
 
@@ -959,7 +959,7 @@ class RectangleROITool extends AnnotationTool {
959
959
  max: stats.max?.value,
960
960
  statsArray: stats.array,
961
961
  pointsInShape: pointsInShape,
962
- areaUnit: getCalibratedAreaUnits(null, image),
962
+ areaUnit: areaUnits,
963
963
  modalityUnit,
964
964
  };
965
965
  } else {
@@ -37,8 +37,7 @@ import {
37
37
  throttle,
38
38
  roundNumber,
39
39
  triggerAnnotationRenderForViewportIds,
40
- getCalibratedScale,
41
- getCalibratedAreaUnits,
40
+ getCalibratedLengthUnitsAndScale,
42
41
  } from '../../utilities';
43
42
  import getMouseModifierKey from '../../eventDispatchers/shared/getMouseModifier';
44
43
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
@@ -1163,7 +1162,40 @@ class SplineROITool extends ContourSegmentationBaseTool {
1163
1162
  const deltaInX = vec3.distance(originalWorldPoint, deltaXPoint);
1164
1163
  const deltaInY = vec3.distance(originalWorldPoint, deltaYPoint);
1165
1164
 
1166
- const scale = getCalibratedScale(image);
1165
+ const { imageData } = image;
1166
+ const { scale, areaUnits } = getCalibratedLengthUnitsAndScale(
1167
+ image,
1168
+ () => {
1169
+ const {
1170
+ maxX: canvasMaxX,
1171
+ maxY: canvasMaxY,
1172
+ minX: canvasMinX,
1173
+ minY: canvasMinY,
1174
+ } = math.polyline.getAABB(canvasCoordinates);
1175
+
1176
+ const topLeftBBWorld = viewport.canvasToWorld([
1177
+ canvasMinX,
1178
+ canvasMinY,
1179
+ ]);
1180
+
1181
+ const topLeftBBIndex = utilities.transformWorldToIndex(
1182
+ imageData,
1183
+ topLeftBBWorld
1184
+ );
1185
+
1186
+ const bottomRightBBWorld = viewport.canvasToWorld([
1187
+ canvasMaxX,
1188
+ canvasMaxY,
1189
+ ]);
1190
+
1191
+ const bottomRightBBIndex = utilities.transformWorldToIndex(
1192
+ imageData,
1193
+ bottomRightBBWorld
1194
+ );
1195
+
1196
+ return [topLeftBBIndex, bottomRightBBIndex];
1197
+ }
1198
+ );
1167
1199
  let area = math.polyline.getArea(canvasCoordinates) / scale / scale;
1168
1200
 
1169
1201
  // Convert from canvas_pixels ^2 to mm^2
@@ -1172,7 +1204,7 @@ class SplineROITool extends ContourSegmentationBaseTool {
1172
1204
  cachedStats[targetId] = {
1173
1205
  Modality: metadata.Modality,
1174
1206
  area,
1175
- areaUnit: getCalibratedAreaUnits(null, image),
1207
+ areaUnit: areaUnits,
1176
1208
  };
1177
1209
  }
1178
1210
 
@@ -266,6 +266,7 @@ abstract class AnnotationTool extends AnnotationDisplayTool {
266
266
  const { viewport } = enabledElement;
267
267
 
268
268
  const { data } = annotation;
269
+ const { isCanvasAnnotation } = data;
269
270
  const { points, textBox } = data.handles;
270
271
 
271
272
  if (textBox) {
@@ -292,10 +293,15 @@ abstract class AnnotationTool extends AnnotationDisplayTool {
292
293
 
293
294
  for (let i = 0; i < points?.length; i++) {
294
295
  const point = points[i];
295
- const annotationCanvasCoordinate = viewport.worldToCanvas(point);
296
+ const annotationCanvasCoordinate = isCanvasAnnotation
297
+ ? point.slice(0, 2)
298
+ : viewport.worldToCanvas(point);
296
299
 
297
300
  const near =
298
- vec2.distance(canvasCoords, annotationCanvasCoordinate) < proximity;
301
+ vec2.distance(
302
+ canvasCoords,
303
+ annotationCanvasCoordinate as Types.Point2
304
+ ) < proximity;
299
305
 
300
306
  if (near === true) {
301
307
  data.handles.activeHandleIndex = i;
@@ -361,6 +361,13 @@ function _setLabelmapColorAndOpacity(
361
361
 
362
362
  for (let i = 1; i < numColors; i++) {
363
363
  // Start from 1 to skip the background segment index.
364
+ const isHidden = segmentsHidden.has(i);
365
+
366
+ if (isHidden) {
367
+ outlineWidths[i - 1] = 0;
368
+ continue;
369
+ }
370
+
364
371
  outlineWidths[i - 1] =
365
372
  i === activeSegmentIndex
366
373
  ? outlineWidth + toolGroupLabelmapConfig.activeSegmentOutlineWidthDelta
@@ -2,6 +2,9 @@ import {
2
2
  utilities as csUtils,
3
3
  cache,
4
4
  getEnabledElement,
5
+ StackViewport,
6
+ eventTarget,
7
+ Enums,
5
8
  } from '@cornerstonejs/core';
6
9
  import { vec3, vec2 } from 'gl-matrix';
7
10
 
@@ -112,7 +115,6 @@ class BrushTool extends BaseTool {
112
115
  strategySpecificConfiguration: {
113
116
  THRESHOLD: {
114
117
  threshold: [-150, -70], // E.g. CT Fat // Only used during threshold strategies.
115
- dynamicRadius: 0, // in voxel counts in each direction, only used during dynamic threshold strategies.
116
118
  },
117
119
  },
118
120
  defaultStrategy: 'FILL_INSIDE_CIRCLE',
@@ -208,6 +210,20 @@ class BrushTool extends BaseTool {
208
210
  ] as LabelmapSegmentationDataVolume;
209
211
  const actors = viewport.getActors();
210
212
 
213
+ const isStackViewport = viewport instanceof StackViewport;
214
+
215
+ if (isStackViewport) {
216
+ const event = new CustomEvent(Enums.Events.ERROR_EVENT, {
217
+ detail: {
218
+ type: 'Segmentation',
219
+ message: 'Cannot perform brush operation on the selected viewport',
220
+ },
221
+ cancelable: true,
222
+ });
223
+ eventTarget.dispatchEvent(event);
224
+ return null;
225
+ }
226
+
211
227
  // we used to take the first actor here but we should take the one that is
212
228
  // probably the same size as the segmentation volume
213
229
  const volumes = actors.map((actorEntry) =>
@@ -77,9 +77,15 @@ export default {
77
77
  const { configuration, viewport } = operationData;
78
78
  const { THRESHOLD: { dynamicRadius = 0 } = {} } =
79
79
  configuration.strategySpecificConfiguration || {};
80
+
81
+ if (dynamicRadius === 0) {
82
+ return;
83
+ }
84
+
80
85
  const { spacing } = (
81
86
  viewport as Types.IStackViewport | Types.IVolumeViewport
82
87
  ).getImageData();
88
+
83
89
  const centerCanvas = [
84
90
  viewport.element.clientWidth / 2,
85
91
  viewport.element.clientHeight / 2,
@@ -4,10 +4,19 @@ import { triggerSegmentationDataModified } from '../../../../stateManagement/seg
4
4
  import { config as segmentationConfig } from '../../../../stateManagement/segmentation';
5
5
  import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
6
6
 
7
+ function lightenColor(r, g, b, a, factor = 0.4) {
8
+ return [
9
+ Math.round(r + (255 - r) * factor),
10
+ Math.round(g + (255 - g) * factor),
11
+ Math.round(b + (255 - b) * factor),
12
+ a,
13
+ ];
14
+ }
15
+
7
16
  /**
8
- * Sets up a preview to use an alternate set of colours. First fills the
17
+ * Sets up a preview to use an alternate set of colors. First fills the
9
18
  * preview segment index with the final one for all pixels, then resets
10
- * the preview colours.
19
+ * the preview colors.
11
20
  * This is only activated when the preview segment index is defined, either
12
21
  * from the initial state or from the global state.
13
22
  */
@@ -71,7 +80,8 @@ export default {
71
80
  if (!configColor && !segmentColor) {
72
81
  return;
73
82
  }
74
- const previewColor = configColor || segmentColor.map((it) => it * 0.9);
83
+ const previewColor = configColor || lightenColor(...segmentColor);
84
+
75
85
  segmentationConfig.color.setColorForSegmentIndex(
76
86
  toolGroupId,
77
87
  segmentationRepresentationUID,
@@ -88,7 +98,7 @@ export default {
88
98
  previewVoxelManager: previewVoxelManager,
89
99
  previewSegmentIndex,
90
100
  preview,
91
- } = operationData;
101
+ } = operationData || {};
92
102
  if (previewSegmentIndex === undefined) {
93
103
  return;
94
104
  }
@@ -87,8 +87,9 @@ export interface AdvancedMagnifyAnnotation extends Annotation {
87
87
  zoomFactor: number;
88
88
  sourceViewportId: string;
89
89
  magnifyViewportId: string;
90
+ isCanvasAnnotation: boolean;
90
91
  handles: {
91
- points: Types.Point3[]; // [top, right, bottom, left]
92
+ points: [Types.Point3, Types.Point3, Types.Point3, Types.Point3]; // in canvas space
92
93
  activeHandleIndex: number | null;
93
94
  };
94
95
  };
@@ -198,10 +198,10 @@ function playClip(
198
198
  * Stops an already playing clip.
199
199
  * @param element - HTML Element
200
200
  */
201
- function stopClip(element: HTMLDivElement, viewportId?: string): void {
201
+ function stopClip(element: HTMLDivElement, options = {} as any): void {
202
202
  _stopClip(element, {
203
203
  stopDynamicCine: true,
204
- viewportId,
204
+ ...options,
205
205
  });
206
206
  }
207
207
 
@@ -21,72 +21,7 @@ const UNIT_MAPPING = {
21
21
  };
22
22
 
23
23
  const EPS = 1e-3;
24
-
25
- /**
26
- * Extracts the length units and the type of calibration for those units
27
- * into the response. The length units will typically be either mm or px
28
- * while the calibration type can be any of a number of different calibration types.
29
- *
30
- * Volumetric images have no calibration type, so are just the raw mm.
31
- *
32
- * TODO: Handle region calibration
33
- *
34
- * @param handles - used to detect if the spacing information is different
35
- * between various points (eg angled ERMF or US Region).
36
- * Currently unused, but needed for correct US Region handling
37
- * @param image - to extract the calibration from
38
- * image.calibration - calibration value to extract units form
39
- * @returns String containing the units and type of calibration
40
- */
41
- const getCalibratedLengthUnits = (handles, image): string => {
42
- const { calibration, hasPixelSpacing } = image;
43
- // Anachronistic - moving to using calibration consistently, but not completed yet
44
- const units = hasPixelSpacing ? 'mm' : PIXEL_UNITS;
45
- if (
46
- !calibration ||
47
- (!calibration.type && !calibration.sequenceOfUltrasoundRegions)
48
- ) {
49
- return units;
50
- }
51
- if (calibration.type === CalibrationTypes.UNCALIBRATED) {
52
- return PIXEL_UNITS;
53
- }
54
- if (calibration.sequenceOfUltrasoundRegions) {
55
- return 'US Region';
56
- }
57
- return `${units} ${calibration.type}`;
58
- };
59
-
60
24
  const SQUARE = '\xb2';
61
- /**
62
- * Extracts the area units, including the squared sign plus calibration type.
63
- */
64
- const getCalibratedAreaUnits = (handles, image): string => {
65
- const { calibration, hasPixelSpacing } = image;
66
- const units = (hasPixelSpacing ? 'mm' : PIXEL_UNITS) + SQUARE;
67
- if (!calibration || !calibration.type) {
68
- return units;
69
- }
70
- if (calibration.sequenceOfUltrasoundRegions) {
71
- return 'US Region';
72
- }
73
- return `${units} ${calibration.type}`;
74
- };
75
-
76
- /**
77
- * Gets the scale divisor for converting from internal spacing to
78
- * image spacing for calibrated images.
79
- */
80
- const getCalibratedScale = (image, handles = []) => {
81
- if (image.calibration?.sequenceOfUltrasoundRegions) {
82
- // image.spacing / image.us.space
83
- } else if (image.calibration?.scale) {
84
- return image.calibration.scale;
85
- } else {
86
- return 1;
87
- }
88
- };
89
-
90
25
  /**
91
26
  * Extracts the calibrated length units, area units, and the scale
92
27
  * for converting from internal spacing to image spacing.
@@ -96,10 +31,9 @@ const getCalibratedScale = (image, handles = []) => {
96
31
  * @returns Object containing the units, area units, and scale
97
32
  */
98
33
  const getCalibratedLengthUnitsAndScale = (image, handles) => {
99
- const [imageIndex1, imageIndex2] = handles;
100
34
  const { calibration, hasPixelSpacing } = image;
101
35
  let units = hasPixelSpacing ? 'mm' : PIXEL_UNITS;
102
- const areaUnits = units + SQUARE;
36
+ let areaUnits = units + SQUARE;
103
37
  let scale = 1;
104
38
  let calibrationType = '';
105
39
 
@@ -115,6 +49,15 @@ const getCalibratedLengthUnitsAndScale = (image, handles) => {
115
49
  }
116
50
 
117
51
  if (calibration.sequenceOfUltrasoundRegions) {
52
+ let imageIndex1, imageIndex2;
53
+ if (Array.isArray(handles) && handles.length === 2) {
54
+ [imageIndex1, imageIndex2] = handles;
55
+ } else if (typeof handles === 'function') {
56
+ const points = handles();
57
+ imageIndex1 = points[0];
58
+ imageIndex2 = points[1];
59
+ }
60
+
118
61
  let regions = calibration.sequenceOfUltrasoundRegions.filter(
119
62
  (region) =>
120
63
  imageIndex1[0] >= region.regionLocationMinX0 &&
@@ -165,17 +108,23 @@ const getCalibratedLengthUnitsAndScale = (image, handles) => {
165
108
  );
166
109
 
167
110
  if (isSamePhysicalDelta) {
168
- scale = 1 / (physicalDeltaX * physicalDeltaY * 100);
111
+ // 1 to 1 aspect ratio, we use just one of them
112
+ scale = 1 / (physicalDeltaX * 10);
169
113
  calibrationType = 'US Region';
170
114
  units = 'mm';
115
+ areaUnits = 'mm' + SQUARE;
171
116
  } else {
117
+ // here we are showing at the aspect ratio of the physical delta
118
+ // if they are not the same, then we should show px, but the correct solution
119
+ // is to grab each point separately and scale them individually
120
+ // Todo: implement this
172
121
  return { units: PIXEL_UNITS, areaUnits: PIXEL_UNITS + SQUARE, scale };
173
122
  }
174
123
  } else if (calibration.scale) {
175
124
  scale = calibration.scale;
176
125
  }
177
126
 
178
- // everything except REGION/Uncalibratted
127
+ // everything except REGION/Uncalibrated
179
128
  const types = [
180
129
  CalibrationTypes.ERMF,
181
130
  CalibrationTypes.USER,
@@ -272,13 +221,8 @@ const getCalibratedProbeUnitsAndValue = (image, handles) => {
272
221
  */
273
222
  const getCalibratedAspect = (image) => image.calibration?.aspect || 1;
274
223
 
275
- export default getCalibratedLengthUnits;
276
-
277
224
  export {
278
- getCalibratedAreaUnits,
279
- getCalibratedLengthUnits,
280
225
  getCalibratedLengthUnitsAndScale,
281
- getCalibratedScale,
282
226
  getCalibratedAspect,
283
227
  getCalibratedProbeUnitsAndValue,
284
228
  };
@@ -12,9 +12,9 @@ import isObject from './isObject';
12
12
  import clip from './clip';
13
13
  import calibrateImageSpacing from './calibrateImageSpacing';
14
14
  import {
15
- getCalibratedLengthUnits,
16
- getCalibratedAreaUnits,
17
- getCalibratedScale,
15
+ getCalibratedLengthUnitsAndScale,
16
+ getCalibratedProbeUnitsAndValue,
17
+ getCalibratedAspect,
18
18
  } from './getCalibratedUnits';
19
19
  import triggerAnnotationRenderForViewportIds from './triggerAnnotationRenderForViewportIds';
20
20
  import triggerAnnotationRenderForToolGroupIds from './triggerAnnotationRenderForToolGroupIds';
@@ -67,9 +67,9 @@ export {
67
67
  touch,
68
68
  triggerEvent,
69
69
  calibrateImageSpacing,
70
- getCalibratedLengthUnits,
71
- getCalibratedAreaUnits,
72
- getCalibratedScale,
70
+ getCalibratedLengthUnitsAndScale,
71
+ getCalibratedProbeUnitsAndValue,
72
+ getCalibratedAspect,
73
73
  segmentation,
74
74
  contours,
75
75
  triggerAnnotationRenderForViewportIds,
@@ -47,6 +47,9 @@ export default function filterAnnotationsForDisplay(
47
47
  if (!annotation.isVisible) {
48
48
  return false;
49
49
  }
50
+ if (annotation.data.isCanvasAnnotation) {
51
+ return true;
52
+ }
50
53
  return viewport.isReferenceViewable(annotation.metadata, filterOptions);
51
54
  });
52
55
  }