@cornerstonejs/tools 1.57.0 → 1.57.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 (89) hide show
  1. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +3 -3
  2. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
  3. package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
  4. package/dist/cjs/tools/annotation/LengthTool.js +4 -10
  5. package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
  6. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +4 -0
  7. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  8. package/dist/cjs/tools/annotation/SplineROITool.js +25 -20
  9. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  10. package/dist/cjs/tools/base/BaseTool.js +1 -1
  11. package/dist/cjs/tools/base/BaseTool.js.map +1 -1
  12. package/dist/cjs/tools/base/ContourBaseTool.js +5 -11
  13. package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
  14. package/dist/cjs/types/AnnotationTypes.d.ts +2 -7
  15. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +0 -8
  16. package/dist/cjs/utilities/contours/interpolation/findAnnotationForInterpolation.js +4 -0
  17. package/dist/cjs/utilities/contours/interpolation/findAnnotationForInterpolation.js.map +1 -1
  18. package/dist/cjs/utilities/contours/interpolation/getInterpolationData.js +4 -1
  19. package/dist/cjs/utilities/contours/interpolation/getInterpolationData.js.map +1 -1
  20. package/dist/cjs/utilities/contours/interpolation/interpolate.js +7 -4
  21. package/dist/cjs/utilities/contours/interpolation/interpolate.js.map +1 -1
  22. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.d.ts +1 -1
  23. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js +12 -45
  24. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  25. package/dist/cjs/utilities/planar/filterAnnotationsWithinSlice.js.map +1 -1
  26. package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js +1 -1
  27. package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -1
  28. package/dist/cjs/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js +2 -2
  29. package/dist/cjs/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js.map +1 -1
  30. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +3 -3
  31. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
  32. package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
  33. package/dist/esm/tools/annotation/LengthTool.js +4 -6
  34. package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
  35. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +4 -0
  36. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  37. package/dist/esm/tools/annotation/SplineROITool.js +25 -20
  38. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  39. package/dist/esm/tools/base/BaseTool.js +1 -1
  40. package/dist/esm/tools/base/BaseTool.js.map +1 -1
  41. package/dist/esm/tools/base/ContourBaseTool.js +5 -7
  42. package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
  43. package/dist/esm/utilities/contours/interpolation/findAnnotationForInterpolation.js +4 -0
  44. package/dist/esm/utilities/contours/interpolation/findAnnotationForInterpolation.js.map +1 -1
  45. package/dist/esm/utilities/contours/interpolation/getInterpolationData.js +4 -1
  46. package/dist/esm/utilities/contours/interpolation/getInterpolationData.js.map +1 -1
  47. package/dist/esm/utilities/contours/interpolation/interpolate.js +7 -4
  48. package/dist/esm/utilities/contours/interpolation/interpolate.js.map +1 -1
  49. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js +13 -45
  50. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  51. package/dist/esm/utilities/planar/filterAnnotationsWithinSlice.js.map +1 -1
  52. package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js +1 -1
  53. package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -1
  54. package/dist/esm/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js +2 -2
  55. package/dist/esm/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js.map +1 -1
  56. package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts.map +1 -1
  57. package/dist/types/tools/annotation/CobbAngleTool.d.ts.map +1 -1
  58. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  59. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  60. package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -1
  61. package/dist/types/types/AnnotationTypes.d.ts +2 -7
  62. package/dist/types/types/AnnotationTypes.d.ts.map +1 -1
  63. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +0 -8
  64. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  65. package/dist/types/utilities/contours/interpolation/findAnnotationForInterpolation.d.ts.map +1 -1
  66. package/dist/types/utilities/contours/interpolation/getInterpolationData.d.ts.map +1 -1
  67. package/dist/types/utilities/contours/interpolation/interpolate.d.ts.map +1 -1
  68. package/dist/types/utilities/planar/filterAnnotationsForDisplay.d.ts +1 -1
  69. package/dist/types/utilities/planar/filterAnnotationsForDisplay.d.ts.map +1 -1
  70. package/dist/types/utilities/planar/filterAnnotationsWithinSlice.d.ts.map +1 -1
  71. package/dist/umd/index.js +1 -1
  72. package/dist/umd/index.js.map +1 -1
  73. package/package.json +3 -3
  74. package/src/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.ts +10 -3
  75. package/src/tools/annotation/CobbAngleTool.ts +2 -3
  76. package/src/tools/annotation/LengthTool.ts +8 -8
  77. package/src/tools/annotation/PlanarFreehandROITool.ts +6 -0
  78. package/src/tools/annotation/SplineROITool.ts +34 -27
  79. package/src/tools/base/BaseTool.ts +1 -1
  80. package/src/tools/base/ContourBaseTool.ts +5 -7
  81. package/src/types/AnnotationTypes.ts +5 -27
  82. package/src/types/ToolSpecificAnnotationTypes.ts +0 -8
  83. package/src/utilities/contours/interpolation/findAnnotationForInterpolation.ts +4 -0
  84. package/src/utilities/contours/interpolation/getInterpolationData.ts +5 -2
  85. package/src/utilities/contours/interpolation/interpolate.ts +8 -4
  86. package/src/utilities/planar/filterAnnotationsForDisplay.ts +20 -70
  87. package/src/utilities/planar/filterAnnotationsWithinSlice.ts +0 -1
  88. package/src/utilities/segmentation/InterpolationManager/InterpolationManager.ts +1 -1
  89. package/src/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.57.0",
3
+ "version": "1.57.2",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.57.0",
32
+ "@cornerstonejs/core": "^1.57.2",
33
33
  "@icr/polyseg-wasm": "0.4.0",
34
34
  "@types/offscreencanvas": "2019.7.3",
35
35
  "comlink": "^4.4.1",
@@ -59,5 +59,5 @@
59
59
  "type": "individual",
60
60
  "url": "https://ohif.org/donate"
61
61
  },
62
- "gitHead": "1699f915a5e7a5cf9295707fb5b62fe01d7e491b"
62
+ "gitHead": "d3508439e829a86ef8dfaa95147935a95ea3cd82"
63
63
  }
@@ -43,8 +43,10 @@ export default async function contourSegmentationCompletedListener(
43
43
  }
44
44
 
45
45
  const viewport = getViewport(sourceAnnotation);
46
- const contourSegmentationAnnotations =
47
- getValidContourSegmentationAnnotations(sourceAnnotation);
46
+ const contourSegmentationAnnotations = getValidContourSegmentationAnnotations(
47
+ viewport,
48
+ sourceAnnotation
49
+ );
48
50
 
49
51
  if (!contourSegmentationAnnotations.length) {
50
52
  return;
@@ -143,6 +145,7 @@ function convertContourPolylineToCanvasSpace(
143
145
  }
144
146
 
145
147
  function getValidContourSegmentationAnnotations(
148
+ viewport: Types.IViewport,
146
149
  sourceAnnotation: ContourSegmentationAnnotation
147
150
  ): ContourSegmentationAnnotation[] {
148
151
  const { annotationUID: sourceAnnotationUID } = sourceAnnotation;
@@ -155,10 +158,14 @@ function getValidContourSegmentationAnnotations(
155
158
  targetAnnotation.annotationUID !== sourceAnnotationUID &&
156
159
  contourSegUtils.isContourSegmentationAnnotation(targetAnnotation) &&
157
160
  contourSegUtils.areSameSegment(targetAnnotation, sourceAnnotation) &&
158
- contourUtils.areCoplanarContours(targetAnnotation, sourceAnnotation)
161
+ viewport.isReferenceViewable(targetAnnotation.metadata)
159
162
  ) as ContourSegmentationAnnotation[];
160
163
  }
161
164
 
165
+ /**
166
+ * Finds other contours on the same slice which intersect the source polyline,
167
+ * represented as canvas points.
168
+ */
162
169
  function findIntersectingContour(
163
170
  viewport: Types.IViewport,
164
171
  sourcePolyline: Types.Point2[],
@@ -796,7 +796,7 @@ class CobbAngleTool extends AnnotationTool {
796
796
  data.cachedStats[targetId].points.canvas;
797
797
  const { arc1Angle, arc2Angle } = data.cachedStats[targetId];
798
798
 
799
- if (this.configuration.showArcLines){
799
+ if (this.configuration.showArcLines) {
800
800
  lineUID = 'arc1';
801
801
 
802
802
  drawLineSvg(
@@ -826,7 +826,6 @@ class CobbAngleTool extends AnnotationTool {
826
826
  );
827
827
  }
828
828
 
829
-
830
829
  if (!data.cachedStats[targetId]?.angle) {
831
830
  continue;
832
831
  }
@@ -880,7 +879,7 @@ class CobbAngleTool extends AnnotationTool {
880
879
  bottomRight: viewport.canvasToWorld([left + width, top + height]),
881
880
  };
882
881
 
883
- if (this.configuration.showArcLines){
882
+ if (this.configuration.showArcLines) {
884
883
  const arc1TextBoxUID = 'arcAngle1';
885
884
 
886
885
  const arc1TextLine = [
@@ -138,9 +138,11 @@ class LengthTool extends AnnotationTool {
138
138
  hideElementCursor(element);
139
139
  this.isDrawing = true;
140
140
 
141
- const camera = viewport.getCamera();
142
- const { viewPlaneNormal, viewUp } = camera;
143
-
141
+ const {
142
+ viewPlaneNormal,
143
+ viewUp,
144
+ position: cameraPosition,
145
+ } = viewport.getCamera();
144
146
  const referencedImageId = this.getReferencedImageId(
145
147
  viewport,
146
148
  worldPos,
@@ -148,17 +150,15 @@ class LengthTool extends AnnotationTool {
148
150
  viewUp
149
151
  );
150
152
 
151
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
152
-
153
153
  const annotation = {
154
154
  highlighted: true,
155
155
  invalidated: true,
156
156
  metadata: {
157
+ ...viewport.getViewReference({ points: [worldPos] }),
157
158
  toolName: this.getToolName(),
158
- viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
159
- viewUp: <Types.Point3>[...viewUp],
160
- FrameOfReferenceUID,
161
159
  referencedImageId,
160
+ viewUp,
161
+ cameraPosition,
162
162
  },
163
163
  data: {
164
164
  handles: {
@@ -531,6 +531,11 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
531
531
  const worldPos = evt.detail.currentPoints.world;
532
532
  const contourAnnotation = super.createAnnotation(evt);
533
533
 
534
+ const onInterpolationComplete = (annotation) => {
535
+ // Clear out the handles because they aren't used for straight freeform
536
+ annotation.data.handles.points.length = 0;
537
+ };
538
+
534
539
  return <PlanarFreehandROIAnnotation>csUtils.deepMerge(contourAnnotation, {
535
540
  data: {
536
541
  contour: {
@@ -539,6 +544,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
539
544
  label: '',
540
545
  cachedStats: {},
541
546
  },
547
+ onInterpolationComplete,
542
548
  });
543
549
  }
544
550
 
@@ -692,29 +692,27 @@ class SplineROITool extends ContourSegmentationBaseTool {
692
692
  const spline = annotation.data.spline.instance;
693
693
 
694
694
  // Update current and all child annotations/splines
695
- if (annotation.invalidated) {
696
- const splineAnnotationsGroup = [
695
+ const splineAnnotationsGroup = [
696
+ annotation,
697
+ ...getChildAnnotations(annotation),
698
+ ].filter((annotation) =>
699
+ this._isSplineROIAnnotation(annotation)
700
+ ) as SplineROIAnnotation[];
701
+
702
+ splineAnnotationsGroup.forEach((annotation) => {
703
+ const spline = this._updateSplineInstance(element, annotation);
704
+ const splinePolylineCanvas = spline.getPolylinePoints();
705
+
706
+ this.updateContourPolyline(
697
707
  annotation,
698
- ...getChildAnnotations(annotation),
699
- ].filter((annotation) =>
700
- this._isSplineROIAnnotation(annotation)
701
- ) as SplineROIAnnotation[];
702
-
703
- splineAnnotationsGroup.forEach((annotation) => {
704
- const spline = this._updateSplineInstance(element, annotation);
705
- const splinePolylineCanvas = spline.getPolylinePoints();
706
-
707
- this.updateContourPolyline(
708
- annotation,
709
- {
710
- points: splinePolylineCanvas,
711
- closed: data.contour.closed,
712
- targetWindingDirection: ContourWindingDirection.Clockwise,
713
- },
714
- viewport
715
- );
716
- });
717
- }
708
+ {
709
+ points: splinePolylineCanvas,
710
+ closed: data.contour.closed,
711
+ targetWindingDirection: ContourWindingDirection.Clockwise,
712
+ },
713
+ viewport
714
+ );
715
+ });
718
716
 
719
717
  // Let the base class render the contour
720
718
  super.renderAnnotationInstance(renderContext);
@@ -1069,6 +1067,14 @@ class SplineROITool extends ContourSegmentationBaseTool {
1069
1067
  const splineConfig = this._getSplineConfig(splineType);
1070
1068
  const worldPoints = data.handles.points;
1071
1069
  const canvasPoints = worldPoints.map(worldToCanvas);
1070
+ const resolution =
1071
+ splineConfig.resolution !== undefined
1072
+ ? parseInt(splineConfig.resolution)
1073
+ : undefined;
1074
+ const scale =
1075
+ splineConfig.scale !== undefined
1076
+ ? parseFloat(splineConfig.scale)
1077
+ : undefined;
1072
1078
 
1073
1079
  spline.setControlPoints(canvasPoints);
1074
1080
  spline.closed = !!data.contour.closed;
@@ -1076,9 +1082,10 @@ class SplineROITool extends ContourSegmentationBaseTool {
1076
1082
  // Update spline resolution in case it has changed
1077
1083
  if (
1078
1084
  !spline.fixedResolution &&
1079
- spline.resolution !== splineConfig.resolution
1085
+ resolution !== undefined &&
1086
+ spline.resolution !== resolution
1080
1087
  ) {
1081
- spline.resolution = parseInt(splineConfig.resolution);
1088
+ spline.resolution = resolution;
1082
1089
  annotation.invalidated = true;
1083
1090
  }
1084
1091
 
@@ -1086,10 +1093,10 @@ class SplineROITool extends ContourSegmentationBaseTool {
1086
1093
  if (
1087
1094
  spline instanceof CardinalSpline &&
1088
1095
  !spline.fixedScale &&
1089
- splineConfig.scale !== undefined &&
1090
- spline.scale !== splineConfig.scale
1096
+ scale !== undefined &&
1097
+ spline.scale !== scale
1091
1098
  ) {
1092
- spline.scale = splineConfig.scale;
1099
+ spline.scale = scale;
1093
1100
  annotation.invalidated = true;
1094
1101
  }
1095
1102
 
@@ -243,7 +243,7 @@ abstract class BaseTool implements IBaseTool {
243
243
  * @returns targetId
244
244
  */
245
245
  protected getTargetId(viewport: Types.IViewport): string | undefined {
246
- const targetId = viewport.getTargetId?.();
246
+ const targetId = viewport.getReferenceId?.();
247
247
  if (targetId) {
248
248
  return targetId;
249
249
  }
@@ -110,7 +110,7 @@ abstract class ContourBaseTool extends AnnotationTool {
110
110
  const { viewport } = enabledElement;
111
111
 
112
112
  const camera = viewport.getCamera();
113
- const { viewPlaneNormal, viewUp } = camera;
113
+ const { viewPlaneNormal, viewUp, position: cameraPosition } = camera;
114
114
 
115
115
  const referencedImageId = this.getReferencedImageId(
116
116
  viewport,
@@ -119,19 +119,17 @@ abstract class ContourBaseTool extends AnnotationTool {
119
119
  viewUp
120
120
  );
121
121
 
122
- const referencedSliceIndex = viewport.getCurrentImageIdIndex();
123
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
122
+ const viewReference = viewport.getViewReference({ points: [worldPos] });
124
123
 
125
124
  return <ContourAnnotation>{
126
125
  highlighted: true,
127
126
  invalidated: true,
128
127
  metadata: {
129
128
  toolName: this.getToolName(),
130
- viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
131
- viewUp: <Types.Point3>[...viewUp],
132
- FrameOfReferenceUID,
129
+ ...viewReference,
133
130
  referencedImageId,
134
- referencedSliceIndex,
131
+ viewUp,
132
+ cameraPosition,
135
133
  },
136
134
  data: {
137
135
  handles: {
@@ -28,41 +28,19 @@ type Annotation = {
28
28
  /** If the annotation is auto generated from other annotations*/
29
29
  autoGenerated?: boolean;
30
30
  /** Metadata for annotation */
31
- metadata: {
32
- /**
33
- * The position of the camera in world space
34
- */
35
- cameraPosition?: Types.Point3;
36
- /**
37
- * The focal point of the camera in world space
38
- */
39
- cameraFocalPoint?: Types.Point3;
40
- /**
41
- * The normal on which the tool was drawn
42
- */
43
- viewPlaneNormal?: Types.Point3;
44
- /**
45
- * The viewUp on which the tool was drawn.
46
- */
47
- viewUp?: Types.Point3;
48
- /**
49
- * The FrameOfReferenceUID
50
- */
51
- FrameOfReferenceUID: string;
31
+ metadata: Types.ViewReference & {
52
32
  /**
53
33
  * The registered name of the tool
54
34
  */
55
35
  toolName: string;
56
36
  /**
57
- * An optional property used when annotating on a slice in a StackViewport,
58
- * or when annotating in a VolumeViewport on a viewPlane that corresponds to
59
- * original slice-based image data.
37
+ * The position of the camera in world space.
60
38
  */
61
- referencedImageId?: string;
39
+ cameraPosition?: Types.Point3;
62
40
  /**
63
- * VolumeId of the volume that the tool was configured to work on.
41
+ * The viewUp for the view position
64
42
  */
65
- volumeId?: string;
43
+ viewUp?: Types.Point3;
66
44
  };
67
45
  /**
68
46
  * Data for annotation, Derivatives need to define their own data types.
@@ -262,15 +262,7 @@ export type PlanarFreehandContourSegmentationAnnotation =
262
262
 
263
263
  export type InterpolationROIAnnotation = ContourAnnotation & {
264
264
  metadata: {
265
- cameraPosition?: Types.Point3;
266
- cameraFocalPoint?: Types.Point3;
267
- viewPlaneNormal?: Types.Point3;
268
- viewUp?: Types.Point3;
269
265
  annotationUID?: string;
270
- FrameOfReferenceUID: string;
271
- referencedImageId?: string;
272
- toolName: string;
273
- referencedSliceIndex?: number;
274
266
  };
275
267
  interpolationUID?: string;
276
268
  /**
@@ -30,6 +30,10 @@ function findAnnotationsForInterpolation(
30
30
  },
31
31
  ]);
32
32
  const rangeToInterpolate = getRangeToInterpolate(interpolationData);
33
+ if (!rangeToInterpolate) {
34
+ console.warn('No annotations found to interpolate', interpolationData);
35
+ return;
36
+ }
33
37
  const sliceEdited = _getSlicePositionOfToolData(
34
38
  interpolationData,
35
39
  toolData.annotationUID
@@ -43,10 +43,13 @@ export default function getInterpolationData(
43
43
  viewport.element
44
44
  );
45
45
 
46
+ if (!annotations) {
47
+ return interpolationDatas;
48
+ }
49
+
46
50
  for (let i = 0; i < sliceData.numberOfSlices; i++) {
47
51
  const imageAnnotations = annotations.filter(
48
- (x) =>
49
- (x as InterpolationROIAnnotation).metadata.referencedSliceIndex === i
52
+ (x) => x.metadata.sliceIndex === i
50
53
  );
51
54
 
52
55
  if (!imageAnnotations?.length) {
@@ -76,7 +76,11 @@ function interpolate(viewportData: InterpolationViewportData) {
76
76
  function startInterpolation(viewportData: InterpolationViewportData) {
77
77
  const toolData = viewportData.annotation;
78
78
  const { interpolationData, interpolationList } =
79
- findAnnotationsForInterpolation(toolData, viewportData);
79
+ findAnnotationsForInterpolation(toolData, viewportData) || {};
80
+
81
+ if (!interpolationData || !interpolationList) {
82
+ return;
83
+ }
80
84
 
81
85
  const eventData = {
82
86
  toolName: toolData.metadata.toolName,
@@ -247,9 +251,9 @@ function _addInterpolatedContour(
247
251
  referencedToolData
248
252
  );
249
253
 
250
- const targetId = viewport.getTargetId({ sliceIndex });
254
+ const targetId = viewport.getReferenceId({ sliceIndex });
251
255
  interpolatedAnnotation.metadata.referencedImageId = targetId;
252
- interpolatedAnnotation.metadata.referencedSliceIndex = sliceIndex;
256
+ interpolatedAnnotation.metadata.sliceIndex = sliceIndex;
253
257
  annotationState.state.addAnnotation(interpolatedAnnotation, viewport.element);
254
258
  referencedToolData.onInterpolationComplete?.(
255
259
  interpolatedAnnotation,
@@ -289,7 +293,7 @@ function _editInterpolatedContour(
289
293
  const annotation = annotations[i] as InterpolationROIAnnotation;
290
294
  if (
291
295
  annotation.interpolationUID === referencedToolData.interpolationUID &&
292
- annotation.metadata.referencedSliceIndex === sliceIndex
296
+ annotation.metadata.sliceIndex === sliceIndex
293
297
  ) {
294
298
  toolDataIndex = i;
295
299
  break;
@@ -1,16 +1,12 @@
1
1
  import {
2
2
  StackViewport,
3
3
  VolumeViewport,
4
- VideoViewport,
5
4
  Types,
6
5
  utilities as csUtils,
7
6
  } from '@cornerstonejs/core';
8
7
 
9
8
  import filterAnnotationsWithinSlice from './filterAnnotationsWithinSlice';
10
9
  import type { Annotations } from '../../types';
11
- import annotationFrameRange from '../annotationFrameRange';
12
-
13
- const baseUrlExtractor = /(videoId:|imageId:|volumeId:)([a-zA-Z]*:)/;
14
10
 
15
11
  /**
16
12
  * Given the viewport and the annotations, it filters the annotations array and only
@@ -20,71 +16,10 @@ const baseUrlExtractor = /(videoId:|imageId:|volumeId:)([a-zA-Z]*:)/;
20
16
  */
21
17
  export default function filterAnnotationsForDisplay(
22
18
  viewport: Types.IViewport,
23
- annotations: Annotations
19
+ annotations: Annotations,
20
+ filterOptions: Types.ReferenceCompatibleOptions = {}
24
21
  ): Annotations {
25
- if (viewport instanceof StackViewport) {
26
- // 1. Get the currently displayed imageId from the StackViewport
27
- const imageId = viewport.getCurrentImageId();
28
-
29
- // 2. remove the dataLoader scheme since it might be an annotation that was
30
- // created on the volumeViewport initially and has the volumeLoader scheme
31
- // but shares the same imageId
32
- const colonIndex = imageId.indexOf(':');
33
- const imageURI = imageId.substring(colonIndex + 1);
34
-
35
- // 3. Filter annotation in the frame of reference by the referenced image ID property
36
- // Note: With the current implementation drawing on the stack (PT stack) will not
37
- // show the annotation on a volume that does not share the same imageURIs (CT Volume),
38
- // and we don't have a proper way to check distance either since a stack can be
39
- // composed of multiple unrelated images
40
- return annotations.filter((annotation) => {
41
- if (!annotation.isVisible) {
42
- return false;
43
- }
44
-
45
- // The referenced image id can be a targetId, so handle removing the
46
- // imageId portion to make the base comparison work.
47
- const imageId = annotation.metadata.referencedImageId?.replace(
48
- 'imageId:',
49
- ''
50
- );
51
-
52
- if (imageId === undefined) {
53
- // This annotation was not drawn on a non-coplanar reformat, and such does
54
- // not have a referenced imageId.
55
- return false;
56
- }
57
-
58
- const colonIndex = imageId.indexOf(':');
59
- const referenceImageURI = imageId.substring(colonIndex + 1);
60
- return referenceImageURI === imageURI;
61
- });
62
- } else if (viewport instanceof VideoViewport) {
63
- const frameOfReferenceUID: string = viewport.getFrameOfReferenceUID();
64
-
65
- return annotations.filter((annotation) => {
66
- if (!annotation.isVisible) {
67
- return false;
68
- }
69
- if (annotation.metadata.FrameOfReferenceUID !== frameOfReferenceUID) {
70
- return false;
71
- }
72
- const testURI = annotation.metadata.referencedImageId.replace(
73
- baseUrlExtractor,
74
- ''
75
- );
76
-
77
- if (!viewport.hasImageURI(testURI)) {
78
- return false;
79
- }
80
- const range = annotationFrameRange.getFrameRange(annotation);
81
- const frameNumber = viewport.getFrameNumber();
82
- if (Array.isArray(range)) {
83
- return frameNumber >= range[0] && frameNumber <= range[1];
84
- }
85
- return Math.abs(frameNumber - range) < 1;
86
- });
87
- } else if (viewport instanceof VolumeViewport) {
22
+ if (viewport instanceof VolumeViewport) {
88
23
  const camera = viewport.getCamera();
89
24
 
90
25
  const { spacingInNormalDirection } =
@@ -96,7 +31,22 @@ export default function filterAnnotationsForDisplay(
96
31
  camera,
97
32
  spacingInNormalDirection
98
33
  );
99
- } else {
100
- throw new Error(`Viewport Type ${viewport.type} not supported`);
101
34
  }
35
+ if (viewport instanceof StackViewport) {
36
+ // 1. Get the currently displayed imageId from the StackViewport
37
+ const imageId = viewport.getCurrentImageId();
38
+
39
+ // 2. remove the dataLoader scheme since it might be an annotation that was
40
+ // created on the volumeViewport initially and has the volumeLoader scheme
41
+ // but shares the same imageId
42
+ const colonIndex = imageId.indexOf(':');
43
+
44
+ filterOptions.imageURI = imageId.substring(colonIndex + 1);
45
+ }
46
+ return annotations.filter((annotation) => {
47
+ if (!annotation.isVisible) {
48
+ return false;
49
+ }
50
+ return viewport.isReferenceViewable(annotation.metadata, filterOptions);
51
+ });
102
52
  }
@@ -2,7 +2,6 @@ import { vec3 } from 'gl-matrix';
2
2
  import { CONSTANTS, metaData } from '@cornerstonejs/core';
3
3
  import type { Types } from '@cornerstonejs/core';
4
4
  import { Annotations, Annotation } from '../../types';
5
- import { debug } from 'console';
6
5
 
7
6
  const { EPSILON } = CONSTANTS;
8
7
 
@@ -84,7 +84,7 @@ export default class InterpolationManager {
84
84
  if (
85
85
  sliceIndex !== undefined &&
86
86
  metadata &&
87
- sliceIndex !== (metadata as any).referencedSliceIndex
87
+ sliceIndex !== metadata.sliceIndex
88
88
  ) {
89
89
  continue;
90
90
  }
@@ -21,7 +21,7 @@ export default function deleteRelatedAnnotations(
21
21
  { key: 'interpolationUID', value: viewportData.interpolationUID },
22
22
  ]);
23
23
 
24
- const referencedSliceIndex = annotation.metadata.referencedSliceIndex;
24
+ const referencedSliceIndex = annotation.metadata.sliceIndex as number;
25
25
  let minInterpolation = -1;
26
26
  let maxInterpolation = viewportData.sliceData.numberOfSlices;
27
27
  for (const [sliceIndex, annotations] of interpolationAnnotations.entries()) {
@@ -87,7 +87,7 @@ export default function deleteRelatedAnnotations(
87
87
  viewport: viewportData.viewport,
88
88
  sliceData: {
89
89
  numberOfSlices: viewportData.sliceData.numberOfSlices,
90
- imageIndex: nextAnnotation.metadata.referencedSliceIndex,
90
+ imageIndex: nextAnnotation.metadata.sliceIndex as number,
91
91
  },
92
92
  annotation: nextAnnotation,
93
93
  interpolationUID: nextAnnotation.interpolationUID,