@cornerstonejs/tools 5.8.1 → 5.10.2

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 (128) hide show
  1. package/dist/esm/config.js +3 -1
  2. package/dist/esm/cursors/setCursorForElement.js +3 -1
  3. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownActivate.js +3 -1
  4. package/dist/esm/eventDispatchers/touchEventHandlers/touchStartActivate.js +3 -1
  5. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +3 -1
  6. package/dist/esm/stateManagement/annotation/AnnotationRenderingEngine.js +3 -1
  7. package/dist/esm/stateManagement/segmentation/SegmentationRenderingEngine.js +4 -2
  8. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +9 -3
  9. package/dist/esm/stateManagement/segmentation/addColorLUT.js +3 -1
  10. package/dist/esm/stateManagement/segmentation/config/segmentationColor.js +3 -1
  11. package/dist/esm/stateManagement/segmentation/helpers/normalizeSegmentationInput.js +2 -0
  12. package/dist/esm/stateManagement/segmentation/internalAddRepresentationData.js +3 -1
  13. package/dist/esm/stateManagement/segmentation/internalAddSegmentationRepresentation.js +3 -1
  14. package/dist/esm/stateManagement/segmentation/removeSegmentationRepresentations.js +3 -1
  15. package/dist/esm/stateManagement/segmentation/segmentIndex.js +3 -1
  16. package/dist/esm/stateManagement/segmentation/utilities/convertContourHoles.js +9 -7
  17. package/dist/esm/stateManagement/segmentation/utilities/decimateContours.js +6 -4
  18. package/dist/esm/stateManagement/segmentation/utilities/getPolylineMap.js +3 -1
  19. package/dist/esm/stateManagement/segmentation/utilities/removeContourHoles.js +5 -3
  20. package/dist/esm/stateManagement/segmentation/utilities/removeContourIslands.js +5 -3
  21. package/dist/esm/stateManagement/segmentation/utilities/smoothContours.js +6 -4
  22. package/dist/esm/store/SynchronizerManager/Synchronizer.js +4 -2
  23. package/dist/esm/store/ToolGroupManager/ToolGroup.js +17 -15
  24. package/dist/esm/store/ToolGroupManager/createToolGroup.js +3 -1
  25. package/dist/esm/store/filterToolsWithAnnotationsForElement.js +3 -1
  26. package/dist/esm/tools/AdvancedMagnifyTool.js +3 -1
  27. package/dist/esm/tools/CrosshairsTool.js +4 -2
  28. package/dist/esm/tools/MIPJumpToClickTool.js +3 -1
  29. package/dist/esm/tools/OrientationControllerTool.js +6 -4
  30. package/dist/esm/tools/OverlayGridTool.js +5 -3
  31. package/dist/esm/tools/ReferenceCursors.js +3 -1
  32. package/dist/esm/tools/ReferenceLinesTool.js +3 -1
  33. package/dist/esm/tools/SculptorTool.js +7 -5
  34. package/dist/esm/tools/SegmentationIntersectionTool.js +3 -1
  35. package/dist/esm/tools/VolumeCroppingControlTool.js +5 -3
  36. package/dist/esm/tools/VolumeCroppingTool.js +5 -3
  37. package/dist/esm/tools/WindowLevelRegionTool.js +3 -1
  38. package/dist/esm/tools/annotation/AngleTool.js +3 -1
  39. package/dist/esm/tools/annotation/ArrowAnnotateTool.js +3 -1
  40. package/dist/esm/tools/annotation/BidirectionalTool.js +3 -1
  41. package/dist/esm/tools/annotation/CircleROITool.js +30 -33
  42. package/dist/esm/tools/annotation/CobbAngleTool.js +3 -1
  43. package/dist/esm/tools/annotation/DragProbeTool.js +3 -1
  44. package/dist/esm/tools/annotation/ETDRSGridTool.js +3 -1
  45. package/dist/esm/tools/annotation/EllipticalROITool.js +35 -38
  46. package/dist/esm/tools/annotation/HeightTool.js +3 -1
  47. package/dist/esm/tools/annotation/KeyImageTool.js +3 -1
  48. package/dist/esm/tools/annotation/LabelTool.js +3 -1
  49. package/dist/esm/tools/annotation/LengthTool.js +4 -2
  50. package/dist/esm/tools/annotation/LivewireContourTool.js +3 -1
  51. package/dist/esm/tools/annotation/PlanarFreehandROITool.d.ts +13 -2
  52. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +28 -81
  53. package/dist/esm/tools/annotation/ProbeTool.js +3 -1
  54. package/dist/esm/tools/annotation/RectangleROITool.js +31 -20
  55. package/dist/esm/tools/annotation/SplineROITool.js +3 -1
  56. package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js +3 -1
  57. package/dist/esm/tools/annotation/UltrasoundPleuraBLineTool/UltrasoundPleuraBLineTool.js +5 -3
  58. package/dist/esm/tools/annotation/VideoRedactionTool.js +3 -1
  59. package/dist/esm/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.js +3 -1
  60. package/dist/esm/tools/base/AnnotationTool.js +3 -1
  61. package/dist/esm/tools/base/ContourBaseTool.js +3 -1
  62. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +4 -2
  63. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +3 -1
  64. package/dist/esm/tools/displayTools/Contour/contourHandler/utils.js +3 -1
  65. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +4 -2
  66. package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/legacyVolumePlan.js +4 -2
  67. package/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.js +3 -1
  68. package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +6 -4
  69. package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js +3 -1
  70. package/dist/esm/tools/segmentation/CircleScissorsTool.js +3 -1
  71. package/dist/esm/tools/segmentation/LabelmapEditWithContour.js +3 -1
  72. package/dist/esm/tools/segmentation/PaintFillTool.js +3 -1
  73. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +3 -1
  74. package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js +3 -1
  75. package/dist/esm/tools/segmentation/RectangleScissorsTool.js +3 -1
  76. package/dist/esm/tools/segmentation/SegmentBidirectionalTool.js +3 -1
  77. package/dist/esm/tools/segmentation/SegmentSelectTool.d.ts +6 -1
  78. package/dist/esm/tools/segmentation/SegmentSelectTool.js +30 -4
  79. package/dist/esm/tools/segmentation/SphereScissorsTool.js +3 -1
  80. package/dist/esm/tools/segmentation/strategies/compositions/circularCursor.js +3 -1
  81. package/dist/esm/tools/segmentation/strategies/compositions/index.js +1 -1
  82. package/dist/esm/types/SegmentationStateTypes.d.ts +4 -0
  83. package/dist/esm/utilities/calibrateImageSpacing.js +3 -1
  84. package/dist/esm/utilities/cine/playClip.js +3 -1
  85. package/dist/esm/utilities/contourSegmentation/applyContourStroke.js +3 -1
  86. package/dist/esm/utilities/contourSegmentation/contourSegmentationOperation.js +4 -2
  87. package/dist/esm/utilities/contourSegmentation/convertContourSegmentation.js +3 -1
  88. package/dist/esm/utilities/contourSegmentation/logicalOperators.js +6 -4
  89. package/dist/esm/utilities/contourSegmentation/mergeMultipleAnnotations.js +3 -1
  90. package/dist/esm/utilities/contourSegmentation/sharedOperations.js +3 -1
  91. package/dist/esm/utilities/contours/generateContourSetsFromLabelmap.js +3 -1
  92. package/dist/esm/utilities/contours/interpolation/findAnnotationForInterpolation.js +3 -1
  93. package/dist/esm/utilities/contours/interpolation/interpolate.js +3 -1
  94. package/dist/esm/utilities/dynamicVolume/generateImageFromTimeData.js +4 -2
  95. package/dist/esm/utilities/dynamicVolume/getDataInTime.js +3 -1
  96. package/dist/esm/utilities/index.d.ts +2 -1
  97. package/dist/esm/utilities/index.js +2 -1
  98. package/dist/esm/utilities/livewire/LivewireScissors.js +3 -1
  99. package/dist/esm/utilities/math/basic/Calculator.js +3 -1
  100. package/dist/esm/utilities/math/polyline/addCanvasPointsToArray.js +3 -1
  101. package/dist/esm/utilities/math/polyline/combinePolyline.js +4 -2
  102. package/dist/esm/utilities/math/polyline/getSubPixelSpacingAndXYDirections.js +12 -6
  103. package/dist/esm/utilities/math/polyline/intersectPolylines.js +4 -2
  104. package/dist/esm/utilities/math/polyline/subtractPolylines.js +4 -2
  105. package/dist/esm/utilities/sampleAreaAnnotationVoxels.d.ts +44 -0
  106. package/dist/esm/utilities/sampleAreaAnnotationVoxels.js +63 -0
  107. package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js +5 -3
  108. package/dist/esm/utilities/segmentation/growCut/runFloodFillSegmentation.js +10 -5
  109. package/dist/esm/utilities/segmentation/growCut/runGrowCut.js +3 -1
  110. package/dist/esm/utilities/segmentation/growCut/runGrowCutForSphere.js +3 -1
  111. package/dist/esm/utilities/segmentation/growCut/runOneClickGrowCut.js +10 -8
  112. package/dist/esm/utilities/segmentation/isLineInSegment.js +3 -1
  113. package/dist/esm/utilities/segmentation/islandRemoval.js +3 -1
  114. package/dist/esm/utilities/segmentation/segmentContourAction.js +4 -2
  115. package/dist/esm/utilities/segmentation/utilsForWorker.js +4 -2
  116. package/dist/esm/utilities/spatial/areViewportsSpatiallyLinked.js +2 -1
  117. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +5 -3
  118. package/dist/esm/utilities/stackPrefetch/stackPrefetch.js +4 -2
  119. package/dist/esm/utilities/triggerAnnotationRenderForToolGroupIds.js +4 -2
  120. package/dist/esm/utilities/triggerAnnotationRenderForViewportIds.js +4 -2
  121. package/dist/esm/utilities/voi/colorbar/Colorbar.js +3 -1
  122. package/dist/esm/utilities/voi/windowlevel/extractWindowLevelRegionToolData.js +3 -1
  123. package/dist/esm/utilities/vtkjs/OrientationControllerWidget/index.js +4 -2
  124. package/dist/esm/version.d.ts +1 -1
  125. package/dist/esm/version.js +1 -1
  126. package/dist/esm/workers/computeWorker.js +5 -3
  127. package/package.json +4 -5
  128. package/LICENSE +0 -21
@@ -1,7 +1,7 @@
1
1
  var _a;
2
2
  import { AnnotationTool, BaseTool, measurementTargetFilters } from '../base/index.js';
3
3
  import { vec2, vec3 } from 'gl-matrix';
4
- import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, EPSILON, } from '@cornerstonejs/core';
4
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
5
5
  import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits.js';
6
6
  import throttle from '../../utilities/throttle.js';
7
7
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState.js';
@@ -18,12 +18,16 @@ import { getPixelValueUnits } from '../../utilities/getPixelValueUnits.js';
18
18
  import { viewportSupportsImageSlices } from '../../utilities/viewportCapabilities.js';
19
19
  import { isViewportPreScaled } from '../../utilities/viewport/isViewportPreScaled.js';
20
20
  import { getCanvasCircleCorners, getCanvasCircleRadius, } from '../../utilities/math/circle/index.js';
21
- import { getCanvasEllipseCorners, pointInEllipse, } from '../../utilities/math/ellipse/index.js';
21
+ import { getCanvasEllipseCorners } from '../../utilities/math/ellipse/index.js';
22
22
  import { BasicStatsCalculator } from '../../utilities/math/basic/index.js';
23
23
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers.js';
24
24
  import { createGetTextLines, } from '../../utilities/defaultGetTextLines.js';
25
25
  import getEllipseWorldCoordinates from '../../utilities/getEllipseWorldCoordinates.js';
26
+ import sampleAreaAnnotationVoxels from '../../utilities/sampleAreaAnnotationVoxels.js';
27
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
28
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.CircleROITool');
26
29
  const { transformWorldToIndex } = csUtils;
30
+ const { createCircleShape } = csUtils.voxelSlab;
27
31
  class CircleROITool extends AnnotationTool {
28
32
  constructor(toolProps = {}, defaultToolProps = {
29
33
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -402,7 +406,7 @@ class CircleROITool extends AnnotationTool {
402
406
  }
403
407
  }
404
408
  if (!viewport.getRenderingEngine()) {
405
- console.warn('Rendering Engine has been destroyed');
409
+ cs3dLogger.warn('Rendering Engine has been destroyed');
406
410
  return renderStatus;
407
411
  }
408
412
  let activeHandleCanvasCoords;
@@ -541,41 +545,34 @@ class CircleROITool extends AnnotationTool {
541
545
  ]);
542
546
  isHandleOutsideAnyTarget ||= isHandleOutsideTarget;
543
547
  if (!isHandleOutsideTarget) {
544
- const iMin = Math.min(pos1Index[0], pos2Index[0]);
545
- const iMax = Math.max(pos1Index[0], pos2Index[0]);
546
- const jMin = Math.min(pos1Index[1], pos2Index[1]);
547
- const jMax = Math.max(pos1Index[1], pos2Index[1]);
548
- const kMin = Math.min(pos1Index[2], pos2Index[2]);
549
- const kMax = Math.max(pos1Index[2], pos2Index[2]);
550
- const boundsIJK = [
551
- [iMin, iMax],
552
- [jMin, jMax],
553
- [kMin, kMax],
554
- ];
555
- const center = points[0];
556
- const xRadius = Math.abs(topLeftWorld[0] - bottomRightWorld[0]) / 2;
557
- const yRadius = Math.abs(topLeftWorld[1] - bottomRightWorld[1]) / 2;
558
- const zRadius = Math.abs(topLeftWorld[2] - bottomRightWorld[2]) / 2;
559
- const ellipseObj = {
560
- center,
561
- xRadius: xRadius < EPSILON / 2 ? 0 : xRadius,
562
- yRadius: yRadius < EPSILON / 2 ? 0 : yRadius,
563
- zRadius: zRadius < EPSILON / 2 ? 0 : zRadius,
564
- };
565
548
  const pixelUnitsOptions = {
566
549
  isPreScaled: isViewportPreScaled(viewport, targetId),
567
550
  isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
568
551
  };
569
552
  const modalityUnit = getPixelValueUnits(metadata.Modality, annotation.metadata.referencedImageId, pixelUnitsOptions);
570
- let pointsInShape;
571
- if (voxelManager) {
572
- pointsInShape = voxelManager.forEach(this.configuration.statsCalculator.statsCallback, {
573
- isInObject: (pointLPS) => pointInEllipse(ellipseObj, pointLPS, { fast: true }),
574
- boundsIJK,
575
- imageData,
576
- returnPoints: this.configuration.storePointData,
577
- });
578
- }
553
+ const worldRadius = vec3.distance(points[0], points[1]);
554
+ const pointsInShape = sampleAreaAnnotationVoxels({
555
+ annotation,
556
+ image,
557
+ voxelManager: voxelManager,
558
+ points: points,
559
+ boundsMargin: worldRadius,
560
+ createShape: ({ volume, planePoint, viewPlaneNormal }) => {
561
+ if (!(worldRadius > 0)) {
562
+ return null;
563
+ }
564
+ return createCircleShape({
565
+ volume,
566
+ planePoint,
567
+ viewPlaneNormal,
568
+ centerWorld: points[0],
569
+ radius: worldRadius,
570
+ });
571
+ },
572
+ minimumPoints: 2,
573
+ onSample: this.configuration.statsCalculator.statsCallback,
574
+ storePointData: this.configuration.storePointData,
575
+ });
579
576
  const stats = this.configuration.statsCalculator.getStatistics();
580
577
  cachedStats[targetId] = {
581
578
  ...cachedStats[targetId],
@@ -16,6 +16,8 @@ import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnota
16
16
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
17
17
  import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility.js';
18
18
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers.js';
19
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
20
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.CobbAngleTool');
19
21
  class CobbAngleTool extends AnnotationTool {
20
22
  constructor(toolProps = {}, defaultToolProps = {
21
23
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -343,7 +345,7 @@ class CobbAngleTool extends AnnotationTool {
343
345
  activeHandleCanvasCoords = [canvasCoordinates[activeHandleIndex]];
344
346
  }
345
347
  if (!viewport.getRenderingEngine()) {
346
- console.warn('Rendering Engine has been destroyed');
348
+ cs3dLogger.warn('Rendering Engine has been destroyed');
347
349
  return renderStatus;
348
350
  }
349
351
  if (!isAnnotationVisible(annotationUID)) {
@@ -6,6 +6,8 @@ import { Events } from '../../enums/index.js';
6
6
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
7
7
  import getViewportICamera from '../../utilities/getViewportICamera.js';
8
8
  import ProbeTool from './ProbeTool.js';
9
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
10
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.DragProbeTool');
9
11
  class DragProbeTool extends ProbeTool {
10
12
  constructor(toolProps = {}, defaultToolProps = {
11
13
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -99,7 +101,7 @@ class DragProbeTool extends ProbeTool {
99
101
  this._calculateCachedStats(annotation, renderingEngine, enabledElement);
100
102
  }
101
103
  if (!viewport.getRenderingEngine()) {
102
- console.warn('Rendering Engine has been destroyed');
104
+ cs3dLogger.warn('Rendering Engine has been destroyed');
103
105
  return renderStatus;
104
106
  }
105
107
  const handleGroupUID = '0';
@@ -12,6 +12,8 @@ import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCur
12
12
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
13
13
  import { getCanvasCircleRadius } from '../../utilities/math/circle/index.js';
14
14
  import { vec3 } from 'gl-matrix';
15
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
16
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.ETDRSGridTool');
15
17
  const CROSSHAIR_SIZE = 5;
16
18
  class ETDRSGridTool extends AnnotationTool {
17
19
  constructor(toolProps = {}, defaultToolProps = {
@@ -282,7 +284,7 @@ class ETDRSGridTool extends AnnotationTool {
282
284
  const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
283
285
  const center = canvasCoordinates[0];
284
286
  if (!viewport.getRenderingEngine()) {
285
- console.warn('Rendering Engine has been destroyed');
287
+ cs3dLogger.warn('Rendering Engine has been destroyed');
286
288
  return renderStatus;
287
289
  }
288
290
  if (!isAnnotationVisible(annotationUID)) {
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  import { AnnotationTool } from '../base/index.js';
3
- import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, EPSILON, } from '@cornerstonejs/core';
3
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
4
4
  import { getCalibratedAspect, getCalibratedLengthUnitsAndScale, } from '../../utilities/getCalibratedUnits.js';
5
5
  import throttle from '../../utilities/throttle.js';
6
6
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState.js';
@@ -13,16 +13,20 @@ import { ChangeTypes, Events } from '../../enums/index.js';
13
13
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters/index.js';
14
14
  import getViewportICamera from '../../utilities/getViewportICamera.js';
15
15
  import getWorldWidthAndHeightFromTwoPoints from '../../utilities/planar/getWorldWidthAndHeightFromTwoPoints.js';
16
- import { pointInEllipse, getCanvasEllipseCorners, } from '../../utilities/math/ellipse/index.js';
16
+ import sampleAreaAnnotationVoxels from '../../utilities/sampleAreaAnnotationVoxels.js';
17
+ import { getCanvasEllipseCorners } from '../../utilities/math/ellipse/index.js';
17
18
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
18
19
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
19
20
  import { getPixelValueUnits } from '../../utilities/getPixelValueUnits.js';
20
21
  import { viewportSupportsImageSlices } from '../../utilities/viewportCapabilities.js';
21
22
  import { isViewportPreScaled } from '../../utilities/viewport/isViewportPreScaled.js';
22
23
  import { BasicStatsCalculator } from '../../utilities/math/basic/index.js';
23
- import { vec2 } from 'gl-matrix';
24
+ import { vec2, vec3 } from 'gl-matrix';
24
25
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers.js';
26
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
27
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.EllipticalROITool');
25
28
  const { transformWorldToIndex } = csUtils;
29
+ const { createEllipseShape } = csUtils.voxelSlab;
26
30
  class EllipticalROITool extends AnnotationTool {
27
31
  constructor(toolProps = {}, defaultToolProps = {
28
32
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -436,7 +440,7 @@ class EllipticalROITool extends AnnotationTool {
436
440
  }
437
441
  }
438
442
  if (!viewport.getRenderingEngine()) {
439
- console.warn('Rendering Engine has been destroyed');
443
+ cs3dLogger.warn('Rendering Engine has been destroyed');
440
444
  return renderStatus;
441
445
  }
442
446
  let activeHandleCanvasCoords;
@@ -524,31 +528,6 @@ class EllipticalROITool extends AnnotationTool {
524
528
  pos2Index[1] = Math.floor(pos2Index[1]);
525
529
  pos2Index[2] = Math.floor(pos2Index[2]);
526
530
  if (this._isInsideVolume(pos1Index, pos2Index, dimensions)) {
527
- const iMin = Math.min(pos1Index[0], pos2Index[0]);
528
- const iMax = Math.max(pos1Index[0], pos2Index[0]);
529
- const jMin = Math.min(pos1Index[1], pos2Index[1]);
530
- const jMax = Math.max(pos1Index[1], pos2Index[1]);
531
- const kMin = Math.min(pos1Index[2], pos2Index[2]);
532
- const kMax = Math.max(pos1Index[2], pos2Index[2]);
533
- const boundsIJK = [
534
- [iMin, iMax],
535
- [jMin, jMax],
536
- [kMin, kMax],
537
- ];
538
- const center = [
539
- (topLeftWorld[0] + bottomRightWorld[0]) / 2,
540
- (topLeftWorld[1] + bottomRightWorld[1]) / 2,
541
- (topLeftWorld[2] + bottomRightWorld[2]) / 2,
542
- ];
543
- const xRadius = Math.abs(topLeftWorld[0] - bottomRightWorld[0]) / 2;
544
- const yRadius = Math.abs(topLeftWorld[1] - bottomRightWorld[1]) / 2;
545
- const zRadius = Math.abs(topLeftWorld[2] - bottomRightWorld[2]) / 2;
546
- const ellipseObj = {
547
- center,
548
- xRadius: xRadius < EPSILON / 2 ? 0 : xRadius,
549
- yRadius: yRadius < EPSILON / 2 ? 0 : yRadius,
550
- zRadius: zRadius < EPSILON / 2 ? 0 : zRadius,
551
- };
552
531
  const { worldWidth, worldHeight } = getWorldWidthAndHeightFromTwoPoints(viewPlaneNormal, viewUp, worldPos1, worldPos2);
553
532
  const isEmptyArea = worldWidth === 0 && worldHeight === 0;
554
533
  const handles = [pos1Index, pos2Index];
@@ -564,15 +543,33 @@ class EllipticalROITool extends AnnotationTool {
564
543
  isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
565
544
  };
566
545
  const modalityUnit = getPixelValueUnits(metadata.Modality, annotation.metadata.referencedImageId, pixelUnitsOptions);
567
- let pointsInShape;
568
- if (voxelManager) {
569
- pointsInShape = voxelManager.forEach(this.configuration.statsCalculator.statsCallback, {
570
- isInObject: (pointLPS) => pointInEllipse(ellipseObj, pointLPS, { fast: true }),
571
- boundsIJK,
572
- imageData,
573
- returnPoints: this.configuration.storePointData,
574
- });
575
- }
546
+ const majorRadius = vec3.distance(points[2], points[3]) / 2;
547
+ const minorRadius = vec3.distance(points[0], points[1]) / 2;
548
+ const pointsInShape = sampleAreaAnnotationVoxels({
549
+ annotation,
550
+ image,
551
+ voxelManager: voxelManager,
552
+ points: points,
553
+ boundsMargin: Math.max(majorRadius, minorRadius),
554
+ createShape: ({ volume, planePoint, viewPlaneNormal: normal }) => {
555
+ if (!(majorRadius > 0) || !(minorRadius > 0)) {
556
+ return null;
557
+ }
558
+ const majorAxis = vec3.sub(vec3.create(), points[3], points[2]);
559
+ return createEllipseShape({
560
+ volume,
561
+ planePoint,
562
+ viewPlaneNormal: normal,
563
+ centerWorld: vec3.lerp(vec3.create(), points[2], points[3], 0.5),
564
+ majorAxis,
565
+ majorRadius,
566
+ minorRadius,
567
+ });
568
+ },
569
+ minimumPoints: 4,
570
+ onSample: this.configuration.statsCalculator.statsCallback,
571
+ storePointData: this.configuration.storePointData,
572
+ });
576
573
  const stats = this.configuration.statsCalculator.getStatistics();
577
574
  cachedStats[targetId] = {
578
575
  Modality: metadata.Modality,
@@ -14,6 +14,8 @@ import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters/
14
14
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
15
15
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
16
16
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers.js';
17
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
18
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.HeightTool');
17
19
  const { transformWorldToIndex } = csUtils;
18
20
  class HeightTool extends AnnotationTool {
19
21
  constructor(toolProps = {}, defaultToolProps = {
@@ -276,7 +278,7 @@ class HeightTool extends AnnotationTool {
276
278
  });
277
279
  renderStatus = true;
278
280
  if (!viewport.getRenderingEngine()) {
279
- console.warn('Rendering Engine has been destroyed');
281
+ cs3dLogger.warn('Rendering Engine has been destroyed');
280
282
  return renderStatus;
281
283
  }
282
284
  const textLines = this.configuration.getTextLines(data, targetId);
@@ -8,6 +8,8 @@ import { state } from '../../store/state.js';
8
8
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters/index.js';
9
9
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
10
10
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
11
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
12
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.KeyImageTool');
11
13
  class KeyImageTool extends AnnotationTool {
12
14
  constructor(toolProps = {}, defaultToolProps = {
13
15
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -196,7 +198,7 @@ class KeyImageTool extends AnnotationTool {
196
198
  }
197
199
  renderStatus = true;
198
200
  if (!viewport.getRenderingEngine()) {
199
- console.warn('Rendering Engine has been destroyed');
201
+ cs3dLogger.warn('Rendering Engine has been destroyed');
200
202
  return renderStatus;
201
203
  }
202
204
  }
@@ -12,6 +12,8 @@ import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnota
12
12
  import { triggerAnnotationCompleted, triggerAnnotationModified, } from '../../stateManagement/annotation/helpers/state.js';
13
13
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
14
14
  import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility.js';
15
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
16
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.LabelTool');
15
17
  class LabelTool extends AnnotationTool {
16
18
  constructor(toolProps = {}, defaultToolProps = {
17
19
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -239,7 +241,7 @@ class LabelTool extends AnnotationTool {
239
241
  const canvasCoordinates = viewport.worldToCanvas(point);
240
242
  renderStatus = true;
241
243
  if (!viewport.getRenderingEngine()) {
242
- console.warn('Rendering Engine has been destroyed');
244
+ cs3dLogger.warn('Rendering Engine has been destroyed');
243
245
  return renderStatus;
244
246
  }
245
247
  if (!isAnnotationVisible(annotationUID)) {
@@ -15,6 +15,8 @@ import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters/
15
15
  import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds.js';
16
16
  import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor.js';
17
17
  import { getStyleProperty } from '../../stateManagement/annotation/config/helpers.js';
18
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
19
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.LengthTool');
18
20
  class LengthTool extends AnnotationTool {
19
21
  constructor(toolProps = {}, defaultToolProps = {
20
22
  supportedInteractionTypes: ['Mouse', 'Touch'],
@@ -258,7 +260,7 @@ class LengthTool extends AnnotationTool {
258
260
  this._throttledCalculateCachedStats(annotation, renderingEngine, enabledElement);
259
261
  }
260
262
  if (!viewport.getRenderingEngine()) {
261
- console.warn('Rendering Engine has been destroyed');
263
+ cs3dLogger.warn('Rendering Engine has been destroyed');
262
264
  return renderStatus;
263
265
  }
264
266
  let activeHandleCanvasCoords;
@@ -289,7 +291,7 @@ class LengthTool extends AnnotationTool {
289
291
  }, dataId);
290
292
  renderStatus = true;
291
293
  if (!viewport.getRenderingEngine()) {
292
- console.warn('Rendering Engine has been destroyed');
294
+ cs3dLogger.warn('Rendering Engine has been destroyed');
293
295
  return renderStatus;
294
296
  }
295
297
  const textLines = this.configuration.getTextLines(data, targetId);
@@ -15,6 +15,8 @@ import { LivewirePath } from '../../utilities/livewire/LiveWirePath.js';
15
15
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters/index.js';
16
16
  import ContourSegmentationBaseTool from '../base/ContourSegmentationBaseTool.js';
17
17
  import { getCalibratedLengthUnitsAndScale, throttle } from '../../utilities/index.js';
18
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
19
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.LivewireContourTool');
18
20
  const CLICK_CLOSE_CURVE_SQR_DIST = 10 ** 2;
19
21
  class LivewireContourTool extends ContourSegmentationBaseTool {
20
22
  constructor(toolProps = {}, defaultToolProps = {
@@ -272,7 +274,7 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
272
274
  textBox.hasMoved = true;
273
275
  }
274
276
  else if (handleIndex === undefined) {
275
- console.warn('Drag annotation not implemented');
277
+ cs3dLogger.warn('Drag annotation not implemented');
276
278
  }
277
279
  else {
278
280
  const { currentPoints } = eventDetail;
@@ -35,10 +35,10 @@ declare class PlanarFreehandROITool extends ContourSegmentationBaseTool {
35
35
  protected renderAnnotationInstance(renderContext: AnnotationRenderContext): boolean;
36
36
  _calculateStatsIfActive(annotation: PlanarFreehandROIAnnotation, targetId: string, viewport: any, renderingEngine: any, enabledElement: any): void;
37
37
  private _calculateCachedStats;
38
- protected updateClosedCachedStats({ viewport, points, imageData, metadata, voxelManager, cachedStats, targetId, modalityUnit, canvasCoordinates, calibratedScale, deltaInX, deltaInY, }: {
39
- viewport: any;
38
+ protected updateClosedCachedStats({ points, imageData, image, metadata, voxelManager, cachedStats, targetId, modalityUnit, canvasCoordinates, calibratedScale, deltaInX, deltaInY, annotation, }: {
40
39
  points: any;
41
40
  imageData: any;
41
+ image: any;
42
42
  metadata: any;
43
43
  voxelManager: any;
44
44
  cachedStats: any;
@@ -48,7 +48,18 @@ declare class PlanarFreehandROITool extends ContourSegmentationBaseTool {
48
48
  calibratedScale: any;
49
49
  deltaInX: any;
50
50
  deltaInY: any;
51
+ annotation: any;
51
52
  }): void;
53
+ protected sampleVoxelsInContour({ annotation, points, image, voxelManager, }: {
54
+ annotation: any;
55
+ points: any;
56
+ image: any;
57
+ voxelManager: any;
58
+ }): {
59
+ value: number;
60
+ pointLPS: Types.Point3;
61
+ pointIJK: Types.Point3;
62
+ }[];
52
63
  protected updateOpenCachedStats({ targetId, metadata, cachedStats, modalityUnit, calibratedScale, imageData, points, }: {
53
64
  targetId: any;
54
65
  metadata: any;
@@ -14,13 +14,13 @@ import registerOpenContourEditLoop from './planarFreehandROITool/openContourEdit
14
14
  import registerOpenContourEndEditLoop from './planarFreehandROITool/openContourEndEditLoop.js';
15
15
  import registerRenderMethods from './planarFreehandROITool/renderMethods.js';
16
16
  import { triggerAnnotationModified } from '../../stateManagement/annotation/helpers/state.js';
17
- import { getLineSegmentIntersectionsCoordinates } from '../../utilities/math/polyline/index.js';
18
17
  import { isViewportPreScaled } from '../../utilities/viewport/isViewportPreScaled.js';
19
18
  import { BasicStatsCalculator } from '../../utilities/math/basic/index.js';
20
19
  import ContourSegmentationBaseTool from '../base/ContourSegmentationBaseTool.js';
21
20
  import { KeyboardBindings, ChangeTypes, MeasurementType } from '../../enums/index.js';
22
21
  import { getPixelValueUnits } from '../../utilities/getPixelValueUnits.js';
23
- import snapIndexBounds from '../../utilities/boundingBox/snapIndexBounds.js';
22
+ import sampleAreaAnnotationVoxels from '../../utilities/sampleAreaAnnotationVoxels.js';
23
+ const { createPolylineShape } = csUtils.voxelSlab;
24
24
  const { pointCanProjectOnLine } = polyline;
25
25
  const { EPSILON } = CONSTANTS;
26
26
  const PARALLEL_THRESHOLD = 1 - EPSILON;
@@ -181,6 +181,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
181
181
  canvasCoordinates,
182
182
  points,
183
183
  imageData,
184
+ image,
184
185
  metadata,
185
186
  voxelManager,
186
187
  cachedStats,
@@ -188,6 +189,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
188
189
  calibratedScale,
189
190
  deltaInX,
190
191
  deltaInY,
192
+ annotation,
191
193
  };
192
194
  if (closed) {
193
195
  this.updateClosedCachedStats(statsArgs);
@@ -411,89 +413,17 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
411
413
  }
412
414
  }
413
415
  }
414
- updateClosedCachedStats({ viewport, points, imageData, metadata, voxelManager, cachedStats, targetId, modalityUnit, canvasCoordinates, calibratedScale, deltaInX, deltaInY, }) {
416
+ updateClosedCachedStats({ points, imageData, image, metadata, voxelManager, cachedStats, targetId, modalityUnit, canvasCoordinates, calibratedScale, deltaInX, deltaInY, annotation, }) {
415
417
  const { areaUnit, unit } = calibratedScale;
416
418
  const indexPoints = points.map((point) => imageData.worldToIndex(point));
417
- const dims = imageData.getDimensions();
418
- let iMin = Number.MAX_SAFE_INTEGER;
419
- let iMax = Number.MIN_SAFE_INTEGER;
420
- let jMin = Number.MAX_SAFE_INTEGER;
421
- let jMax = Number.MIN_SAFE_INTEGER;
422
- let kMin = Number.MAX_SAFE_INTEGER;
423
- let kMax = Number.MIN_SAFE_INTEGER;
424
- for (let j = 0; j < points.length; j++) {
425
- const worldPosIndex = indexPoints[j];
426
- iMin = Math.min(iMin, worldPosIndex[0]);
427
- iMax = Math.max(iMax, worldPosIndex[0]);
428
- jMin = Math.min(jMin, worldPosIndex[1]);
429
- jMax = Math.max(jMax, worldPosIndex[1]);
430
- kMin = Math.min(kMin, worldPosIndex[2]);
431
- kMax = Math.max(kMax, worldPosIndex[2]);
432
- }
433
- iMin = Math.max(0, Math.min(dims[0] - 1, iMin));
434
- iMax = Math.max(0, Math.min(dims[0] - 1, iMax));
435
- jMin = Math.max(0, Math.min(dims[1] - 1, jMin));
436
- jMax = Math.max(0, Math.min(dims[1] - 1, jMax));
437
- kMin = Math.max(0, Math.min(dims[2] - 1, kMin));
438
- kMax = Math.max(0, Math.min(dims[2] - 1, kMax));
439
- [iMin, iMax] = snapIndexBounds(iMin, iMax);
440
- [jMin, jMax] = snapIndexBounds(jMin, jMax);
441
- [kMin, kMax] = snapIndexBounds(kMin, kMax);
442
419
  const area = polyline.getArea(canvasCoordinates) * deltaInX * deltaInY;
443
420
  const perimeter = PlanarFreehandROITool.calculateLengthInIndex(calibratedScale, indexPoints, closed);
444
- const iDelta = 0.01 * (iMax - iMin);
445
- const jDelta = 0.01 * (jMax - jMin);
446
- const kDelta = 0.01 * (kMax - kMin);
447
- iMin = Math.floor(iMin - iDelta);
448
- iMax = Math.ceil(iMax + iDelta);
449
- jMin = Math.floor(jMin - jDelta);
450
- jMax = Math.ceil(jMax + jDelta);
451
- kMin = Math.floor(kMin - kDelta);
452
- kMax = Math.ceil(kMax + kDelta);
453
- const boundsIJK = [
454
- [iMin, iMax],
455
- [jMin, jMax],
456
- [kMin, kMax],
457
- ];
458
- const worldPosEnd = imageData.indexToWorld([iMax, jMax, kMax]);
459
- const canvasPosEnd = viewport.worldToCanvas(worldPosEnd);
460
- let curRow = 0;
461
- let intersections = [];
462
- let intersectionCounter = 0;
463
- let pointsInShape;
464
- if (voxelManager) {
465
- pointsInShape = voxelManager.forEach(this.configuration.statsCalculator.statsCallback, {
466
- imageData,
467
- isInObject: (pointLPS, _pointIJK) => {
468
- let result = true;
469
- const point = viewport.worldToCanvas(pointLPS);
470
- if (point[1] != curRow) {
471
- intersectionCounter = 0;
472
- curRow = point[1];
473
- intersections = getLineSegmentIntersectionsCoordinates(canvasCoordinates, point, [canvasPosEnd[0], point[1]]);
474
- intersections.sort((function (index) {
475
- return function (a, b) {
476
- return a[index] === b[index]
477
- ? 0
478
- : a[index] < b[index]
479
- ? -1
480
- : 1;
481
- };
482
- })(0));
483
- }
484
- if (intersections.length && point[0] > intersections[0][0]) {
485
- intersections.shift();
486
- intersectionCounter++;
487
- }
488
- if (intersectionCounter % 2 === 0) {
489
- result = false;
490
- }
491
- return result;
492
- },
493
- boundsIJK,
494
- returnPoints: this.configuration.storePointData,
495
- });
496
- }
421
+ const pointsInShape = this.sampleVoxelsInContour({
422
+ annotation,
423
+ points,
424
+ image,
425
+ voxelManager,
426
+ });
497
427
  const stats = this.configuration.statsCalculator.getStatistics();
498
428
  const namedArea = {
499
429
  name: 'area',
@@ -522,6 +452,23 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
522
452
  unit,
523
453
  };
524
454
  }
455
+ sampleVoxelsInContour({ annotation, points, image, voxelManager, }) {
456
+ return sampleAreaAnnotationVoxels({
457
+ annotation,
458
+ image,
459
+ voxelManager,
460
+ points,
461
+ createShape: ({ volume, planePoint, viewPlaneNormal }) => createPolylineShape({
462
+ volume,
463
+ planePoint,
464
+ viewPlaneNormal,
465
+ polyline: points,
466
+ }),
467
+ minimumPoints: 3,
468
+ onSample: this.configuration.statsCalculator.statsCallback,
469
+ storePointData: this.configuration.storePointData,
470
+ });
471
+ }
525
472
  updateOpenCachedStats({ targetId, metadata, cachedStats, modalityUnit, calibratedScale, imageData, points, }) {
526
473
  const { unit } = calibratedScale;
527
474
  const indexPoints = points.map((point) => imageData.worldToIndex(point));
@@ -16,6 +16,8 @@ import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnota
16
16
  import { getPixelValueUnits } from '../../utilities/getPixelValueUnits.js';
17
17
  import { viewportSupportsImageSlices } from '../../utilities/viewportCapabilities.js';
18
18
  import { isViewportPreScaled } from '../../utilities/viewport/isViewportPreScaled.js';
19
+ import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
20
+ const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('tools.annotation.ProbeTool');
19
21
  const { transformWorldToIndex } = csUtils;
20
22
  class ProbeTool extends AnnotationTool {
21
23
  constructor(toolProps = {}, defaultToolProps) {
@@ -191,7 +193,7 @@ class ProbeTool extends AnnotationTool {
191
193
  }
192
194
  }
193
195
  if (!viewport.getRenderingEngine()) {
194
- console.warn('Rendering Engine has been destroyed');
196
+ cs3dLogger.warn('Rendering Engine has been destroyed');
195
197
  return renderStatus;
196
198
  }
197
199
  if (!isAnnotationVisible(annotationUID)) {