@cornerstonejs/tools 1.78.3 → 1.80.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/cjs/cursors/SVGCursorDescriptor.js +7 -0
  2. package/dist/cjs/cursors/SVGCursorDescriptor.js.map +1 -1
  3. package/dist/cjs/drawingSvg/drawHeight.d.ts +3 -0
  4. package/dist/cjs/drawingSvg/drawHeight.js +49 -0
  5. package/dist/cjs/drawingSvg/drawHeight.js.map +1 -0
  6. package/dist/cjs/drawingSvg/index.d.ts +2 -1
  7. package/dist/cjs/drawingSvg/index.js +3 -1
  8. package/dist/cjs/drawingSvg/index.js.map +1 -1
  9. package/dist/cjs/index.d.ts +2 -2
  10. package/dist/cjs/index.js +3 -2
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/tools/annotation/HeightTool.d.ts +40 -0
  13. package/dist/cjs/tools/annotation/HeightTool.js +463 -0
  14. package/dist/cjs/tools/annotation/HeightTool.js.map +1 -0
  15. package/dist/cjs/tools/index.d.ts +2 -1
  16. package/dist/cjs/tools/index.js +4 -2
  17. package/dist/cjs/tools/index.js.map +1 -1
  18. package/dist/cjs/tools/segmentation/CircleROIStartEndThresholdTool.d.ts +15 -8
  19. package/dist/cjs/tools/segmentation/CircleROIStartEndThresholdTool.js +189 -62
  20. package/dist/cjs/tools/segmentation/CircleROIStartEndThresholdTool.js.map +1 -1
  21. package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts +17 -7
  22. package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js +167 -52
  23. package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
  24. package/dist/cjs/types/CINETypes.d.ts +1 -0
  25. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +26 -4
  26. package/dist/cjs/utilities/cine/playClip.js +52 -5
  27. package/dist/cjs/utilities/cine/playClip.js.map +1 -1
  28. package/dist/cjs/utilities/planar/filterAnnotationsWithinPlane.d.ts +3 -0
  29. package/dist/cjs/utilities/planar/filterAnnotationsWithinPlane.js +31 -0
  30. package/dist/cjs/utilities/planar/filterAnnotationsWithinPlane.js.map +1 -0
  31. package/dist/cjs/utilities/planar/index.d.ts +3 -1
  32. package/dist/cjs/utilities/planar/index.js +4 -1
  33. package/dist/cjs/utilities/planar/index.js.map +1 -1
  34. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +13 -2
  35. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  36. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js +0 -1
  37. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
  38. package/dist/cjs/utilities/viewport/isViewportPreScaled.js +1 -4
  39. package/dist/cjs/utilities/viewport/isViewportPreScaled.js.map +1 -1
  40. package/dist/cjs/utilities/viewport/jumpToSlice.js +4 -6
  41. package/dist/cjs/utilities/viewport/jumpToSlice.js.map +1 -1
  42. package/dist/esm/cursors/SVGCursorDescriptor.js +7 -0
  43. package/dist/esm/cursors/SVGCursorDescriptor.js.map +1 -1
  44. package/dist/esm/drawingSvg/drawHeight.js +43 -0
  45. package/dist/esm/drawingSvg/drawHeight.js.map +1 -0
  46. package/dist/esm/drawingSvg/index.js +2 -1
  47. package/dist/esm/drawingSvg/index.js.map +1 -1
  48. package/dist/esm/index.js +2 -2
  49. package/dist/esm/index.js.map +1 -1
  50. package/dist/esm/tools/annotation/HeightTool.js +439 -0
  51. package/dist/esm/tools/annotation/HeightTool.js.map +1 -0
  52. package/dist/esm/tools/index.js +2 -1
  53. package/dist/esm/tools/index.js.map +1 -1
  54. package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js +192 -66
  55. package/dist/esm/tools/segmentation/CircleROIStartEndThresholdTool.js.map +1 -1
  56. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +168 -54
  57. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
  58. package/dist/esm/utilities/cine/playClip.js +52 -5
  59. package/dist/esm/utilities/cine/playClip.js.map +1 -1
  60. package/dist/esm/utilities/planar/filterAnnotationsWithinPlane.js +27 -0
  61. package/dist/esm/utilities/planar/filterAnnotationsWithinPlane.js.map +1 -0
  62. package/dist/esm/utilities/planar/index.js +3 -1
  63. package/dist/esm/utilities/planar/index.js.map +1 -1
  64. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +11 -2
  65. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  66. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +1 -2
  67. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
  68. package/dist/esm/utilities/viewport/isViewportPreScaled.js +2 -5
  69. package/dist/esm/utilities/viewport/isViewportPreScaled.js.map +1 -1
  70. package/dist/esm/utilities/viewport/jumpToSlice.js +5 -7
  71. package/dist/esm/utilities/viewport/jumpToSlice.js.map +1 -1
  72. package/dist/types/cursors/SVGCursorDescriptor.d.ts.map +1 -1
  73. package/dist/types/drawingSvg/drawHeight.d.ts +4 -0
  74. package/dist/types/drawingSvg/drawHeight.d.ts.map +1 -0
  75. package/dist/types/drawingSvg/index.d.ts +2 -1
  76. package/dist/types/drawingSvg/index.d.ts.map +1 -1
  77. package/dist/types/index.d.ts +2 -2
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/types/tools/annotation/HeightTool.d.ts +41 -0
  80. package/dist/types/tools/annotation/HeightTool.d.ts.map +1 -0
  81. package/dist/types/tools/index.d.ts +2 -1
  82. package/dist/types/tools/index.d.ts.map +1 -1
  83. package/dist/types/tools/segmentation/CircleROIStartEndThresholdTool.d.ts +15 -8
  84. package/dist/types/tools/segmentation/CircleROIStartEndThresholdTool.d.ts.map +1 -1
  85. package/dist/types/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts +17 -7
  86. package/dist/types/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts.map +1 -1
  87. package/dist/types/types/CINETypes.d.ts +1 -0
  88. package/dist/types/types/CINETypes.d.ts.map +1 -1
  89. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +26 -4
  90. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  91. package/dist/types/utilities/cine/playClip.d.ts.map +1 -1
  92. package/dist/types/utilities/planar/filterAnnotationsWithinPlane.d.ts +4 -0
  93. package/dist/types/utilities/planar/filterAnnotationsWithinPlane.d.ts.map +1 -0
  94. package/dist/types/utilities/planar/index.d.ts +3 -1
  95. package/dist/types/utilities/planar/index.d.ts.map +1 -1
  96. package/dist/types/utilities/stackPrefetch/stackContextPrefetch.d.ts.map +1 -1
  97. package/dist/types/utilities/stackPrefetch/stackPrefetchUtils.d.ts.map +1 -1
  98. package/dist/types/utilities/viewport/isViewportPreScaled.d.ts.map +1 -1
  99. package/dist/umd/index.js +1 -1
  100. package/dist/umd/index.js.map +1 -1
  101. package/package.json +3 -3
  102. package/src/cursors/SVGCursorDescriptor.ts +7 -0
  103. package/src/drawingSvg/drawHeight.ts +90 -0
  104. package/src/drawingSvg/index.ts +2 -0
  105. package/src/index.ts +2 -0
  106. package/src/tools/annotation/HeightTool.ts +882 -0
  107. package/src/tools/index.ts +2 -0
  108. package/src/tools/segmentation/CircleROIStartEndThresholdTool.ts +310 -102
  109. package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +287 -77
  110. package/src/types/CINETypes.ts +3 -0
  111. package/src/types/ToolSpecificAnnotationTypes.ts +26 -4
  112. package/src/utilities/cine/playClip.ts +67 -8
  113. package/src/utilities/planar/filterAnnotationsWithinPlane.ts +76 -0
  114. package/src/utilities/planar/index.ts +3 -0
  115. package/src/utilities/stackPrefetch/stackContextPrefetch.ts +12 -2
  116. package/src/utilities/stackPrefetch/stackPrefetchUtils.ts +7 -5
  117. package/src/utilities/viewport/isViewportPreScaled.ts +2 -5
  118. package/src/utilities/viewport/jumpToSlice.ts +4 -4
@@ -3,6 +3,7 @@ import {
3
3
  utilities as csUtils,
4
4
  getEnabledElement,
5
5
  StackViewport,
6
+ VideoViewport,
6
7
  VolumeViewport,
7
8
  cache,
8
9
  BaseVolumeViewport,
@@ -152,7 +153,14 @@ function playClip(
152
153
  const delta = newStepIndex - currentStepIndex;
153
154
 
154
155
  if (delta) {
155
- playClipContext.scroll(delta);
156
+ try {
157
+ playClipContext.scroll(delta);
158
+ } catch (e) {
159
+ console.warn('Play clip not scrolling', e);
160
+ _stopClipWithData(playClipData);
161
+ triggerEvent(element, CINE_EVENTS.CLIP_STOPPED, eventDetail);
162
+ return;
163
+ }
156
164
  }
157
165
  };
158
166
 
@@ -160,9 +168,14 @@ function playClip(
160
168
  dynamicVolumesPlayingMap.set(volume.volumeId, element);
161
169
  }
162
170
 
163
- // If playClipTimeouts array is available, not empty and its elements are NOT uniform ...
164
- // ... (at least one timeout is different from the others), use alternate setTimeout implementation
165
- if (
171
+ if (playClipContext.play) {
172
+ playClipData.framesPerSecond = playClipContext.play(
173
+ playClipOptions.framesPerSecond
174
+ );
175
+
176
+ // If playClipTimeouts array is available, not empty and its elements are NOT uniform ...
177
+ // ... (at least one timeout is different from the others), use alternate setTimeout implementation
178
+ } else if (
166
179
  playClipTimeouts &&
167
180
  playClipTimeouts.length > 0 &&
168
181
  playClipIsTimeVarying
@@ -213,6 +226,7 @@ function _stopClip(
213
226
  const enabledElement = getEnabledElement(element);
214
227
 
215
228
  let toolState;
229
+ const viewport = enabledElement?.viewport;
216
230
  if (!enabledElement) {
217
231
  if (viewportId) {
218
232
  toolState = getToolStateByViewportId(viewportId);
@@ -228,10 +242,9 @@ function _stopClip(
228
242
  _stopClipWithData(toolState);
229
243
  }
230
244
 
231
- if (
232
- stopDynamicCine &&
233
- enabledElement?.viewport instanceof BaseVolumeViewport
234
- ) {
245
+ if (viewport instanceof VideoViewport) {
246
+ viewport.pause();
247
+ } else if (stopDynamicCine && viewport instanceof BaseVolumeViewport) {
235
248
  _stopDynamicVolumeCine(element);
236
249
  }
237
250
  }
@@ -374,6 +387,45 @@ function _createStackViewportCinePlayContext(
374
387
  };
375
388
  }
376
389
 
390
+ function _createVideoViewportCinePlayContext(
391
+ viewport: VideoViewport,
392
+ waitForRendered: number
393
+ ): CINETypes.CinePlayContext {
394
+ return {
395
+ get numScrollSteps(): number {
396
+ return viewport.getNumberOfSlices();
397
+ },
398
+ get currentStepIndex(): number {
399
+ return viewport.getSliceIndex();
400
+ },
401
+ get frameTimeVectorEnabled(): boolean {
402
+ // It is always in acquired orientation
403
+ return true;
404
+ },
405
+ waitForRenderedCount: 0,
406
+ scroll(delta: number): void {
407
+ if (
408
+ this.waitForRenderedCount <= waitForRendered &&
409
+ viewport.viewportStatus !== ViewportStatus.RENDERED
410
+ ) {
411
+ this.waitForRenderedCount++;
412
+ return;
413
+ }
414
+ this.waitForRenderedCount = 0;
415
+ scroll(viewport, { delta, debounceLoading: debounced });
416
+ },
417
+ play(fps?: number): number {
418
+ if (fps) {
419
+ // This is a bit of a kludge to correspond to playback rates
420
+ // for other viewports
421
+ viewport.setPlaybackRate(fps / 24);
422
+ }
423
+ viewport.play();
424
+ return viewport.getFrameRate();
425
+ },
426
+ };
427
+ }
428
+
377
429
  function _createVolumeViewportCinePlayContext(
378
430
  viewport: VolumeViewport,
379
431
  volume: Types.IImageVolume
@@ -475,6 +527,13 @@ function _createCinePlayContext(
475
527
  return _createVolumeViewportCinePlayContext(viewport, volume);
476
528
  }
477
529
 
530
+ if (viewport instanceof VideoViewport) {
531
+ return _createVideoViewportCinePlayContext(
532
+ viewport,
533
+ playClipOptions.waitForRendered ?? 30
534
+ );
535
+ }
536
+
478
537
  throw new Error('Unknown viewport type');
479
538
  }
480
539
 
@@ -0,0 +1,76 @@
1
+ import { vec3 } from 'gl-matrix';
2
+ import { CONSTANTS, metaData } from '@cornerstonejs/core';
3
+ import type { Types } from '@cornerstonejs/core';
4
+ import { Annotations, Annotation } from '../../types';
5
+
6
+ const { EPSILON } = CONSTANTS;
7
+
8
+ const PARALLEL_THRESHOLD = 1 - EPSILON;
9
+
10
+ /**
11
+ * given some `Annotations`, and the slice defined by the camera's normal
12
+ * direction and the spacing in the normal, filter the `Annotations` which
13
+ * is within the slice.
14
+ *
15
+ * @param annotations - Annotations
16
+ * @param camera - The camera
17
+ * @param spacingInNormalDirection - The spacing in the normal direction
18
+ * @returns The filtered `Annotations`.
19
+ */
20
+ export function filterAnnotationsWithinSamePlane(
21
+ annotations: Annotations,
22
+ camera: Types.ICamera
23
+ ): Annotations {
24
+ const { viewPlaneNormal } = camera;
25
+
26
+ // The reason we use parallel normals instead of actual orientation is that
27
+ // flipped action is done through camera API, so we can't rely on the
28
+ // orientation (viewplaneNormal and viewUp) since even the same image and
29
+ // same slice if flipped will have different orientation, but still rendering
30
+ // the same slice. Instead, we choose to use the parallel normals to filter
31
+ // the annotations and later we fine tune it with the annotation within slice
32
+ // logic down below.
33
+ const annotationsWithParallelNormals = annotations.filter(
34
+ (td: Annotation) => {
35
+ let annotationViewPlaneNormal = td.metadata.viewPlaneNormal;
36
+
37
+ if (!annotationViewPlaneNormal) {
38
+ // This code is run to set the annotation view plane normal
39
+ // for historical data which was saved without the normal.
40
+ const { referencedImageId } = td.metadata;
41
+ const { imageOrientationPatient } = metaData.get(
42
+ 'imagePlaneModule',
43
+ referencedImageId
44
+ );
45
+ const rowCosineVec = vec3.fromValues(
46
+ imageOrientationPatient[0],
47
+ imageOrientationPatient[1],
48
+ imageOrientationPatient[2]
49
+ );
50
+
51
+ const colCosineVec = vec3.fromValues(
52
+ imageOrientationPatient[3],
53
+ imageOrientationPatient[4],
54
+ imageOrientationPatient[5]
55
+ );
56
+
57
+ annotationViewPlaneNormal = vec3.create() as Types.Point3;
58
+
59
+ vec3.cross(annotationViewPlaneNormal, rowCosineVec, colCosineVec);
60
+ td.metadata.viewPlaneNormal = annotationViewPlaneNormal;
61
+ }
62
+ const isParallel =
63
+ Math.abs(vec3.dot(viewPlaneNormal, annotationViewPlaneNormal)) >
64
+ PARALLEL_THRESHOLD;
65
+
66
+ return annotationViewPlaneNormal && isParallel;
67
+ }
68
+ );
69
+
70
+ // No in plane annotations.
71
+ if (!annotationsWithParallelNormals.length) {
72
+ return [];
73
+ }
74
+
75
+ return annotationsWithParallelNormals;
76
+ }
@@ -3,6 +3,7 @@ import getWorldWidthAndHeightFromCorners from './getWorldWidthAndHeightFromCorne
3
3
  import filterAnnotationsForDisplay from './filterAnnotationsForDisplay';
4
4
  import getPointInLineOfSightWithCriteria from './getPointInLineOfSightWithCriteria';
5
5
  import { isPlaneIntersectingAABB } from './isPlaneIntersectingAABB';
6
+ import { filterAnnotationsWithinSamePlane } from './filterAnnotationsWithinPlane';
6
7
 
7
8
  export default {
8
9
  filterAnnotationsWithinSlice,
@@ -10,6 +11,7 @@ export default {
10
11
  filterAnnotationsForDisplay,
11
12
  getPointInLineOfSightWithCriteria,
12
13
  isPlaneIntersectingAABB,
14
+ filterAnnotationsWithinSamePlane,
13
15
  };
14
16
 
15
17
  export {
@@ -18,4 +20,5 @@ export {
18
20
  filterAnnotationsForDisplay,
19
21
  getPointInLineOfSightWithCriteria,
20
22
  isPlaneIntersectingAABB,
23
+ filterAnnotationsWithinSamePlane,
21
24
  };
@@ -64,7 +64,10 @@ const resetPrefetchDelay = 5;
64
64
  const enable = (element): void => {
65
65
  const stack = getStackData(element);
66
66
 
67
- if (!stack || !stack.imageIds || stack.imageIds.length === 0) {
67
+ if (!stack) {
68
+ return;
69
+ }
70
+ if (!stack.imageIds?.length) {
68
71
  console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
69
72
  return;
70
73
  }
@@ -90,6 +93,9 @@ const enable = (element): void => {
90
93
 
91
94
  function prefetch(element) {
92
95
  const stack = getStackData(element);
96
+ if (!stack) {
97
+ return;
98
+ }
93
99
  if (!stack?.imageIds?.length) {
94
100
  console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
95
101
  return;
@@ -273,7 +279,11 @@ const signum = (x) => (x < 0 ? -1 : 1);
273
279
 
274
280
  const updateToolState = (element, usage?: number) => {
275
281
  const stack = getStackData(element);
276
- if (!stack || !stack.imageIds || stack.imageIds.length === 0) {
282
+ if (!stack) {
283
+ // Other viewport type - no message
284
+ return;
285
+ }
286
+ if (!stack.imageIds?.length) {
277
287
  console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
278
288
  return;
279
289
  }
@@ -1,4 +1,10 @@
1
- import { getEnabledElement, StackViewport, Enums } from '@cornerstonejs/core';
1
+ import {
2
+ getEnabledElement,
3
+ StackViewport,
4
+ Enums,
5
+ VideoViewport,
6
+ WSIViewport,
7
+ } from '@cornerstonejs/core';
2
8
  import { getToolState } from './state';
3
9
 
4
10
  export const requestType = Enums.RequestType.Prefetch;
@@ -54,10 +60,6 @@ export function getStackData(element) {
54
60
  if (!(viewport instanceof StackViewport)) {
55
61
  // we shouldn't throw error here, since the viewport might have
56
62
  // changed from stack to volume during prefetch
57
- console.warn(
58
- 'stackPrefetch: element must be a StackViewport, VolumeViewport stackPrefetch not yet implemented'
59
- );
60
-
61
63
  return null;
62
64
  }
63
65
 
@@ -3,6 +3,7 @@ import {
3
3
  StackViewport,
4
4
  Types,
5
5
  BaseVolumeViewport,
6
+ utilities,
6
7
  } from '@cornerstonejs/core';
7
8
 
8
9
  function isViewportPreScaled(
@@ -10,11 +11,7 @@ function isViewportPreScaled(
10
11
  targetId: string
11
12
  ): boolean {
12
13
  if (viewport instanceof BaseVolumeViewport) {
13
- const targetIdTokens = targetId.split('volumeId:');
14
- const volumeId =
15
- targetIdTokens.length > 1
16
- ? targetIdTokens[1].split('?')[0]
17
- : targetIdTokens[0];
14
+ const volumeId = utilities.getVolumeId(targetId);
18
15
  const volume = cache.getVolume(volumeId);
19
16
  return !!volume?.scaling && Object.keys(volume.scaling).length > 0;
20
17
  } else if (viewport instanceof StackViewport) {
@@ -54,11 +54,11 @@ function _getImageSliceData(
54
54
  ? viewport.getTargetImageIdIndex()
55
55
  : viewport.getCurrentImageIdIndex(),
56
56
  };
57
- } else if (viewport instanceof VolumeViewport) {
58
- return csUtils.getImageSliceDataForVolumeViewport(viewport);
59
- } else {
60
- throw new Error('Unsupported viewport type');
61
57
  }
58
+ return {
59
+ numberOfSlices: viewport.getNumberOfSlices(),
60
+ imageIndex: viewport.getSliceIndex(),
61
+ };
62
62
  }
63
63
 
64
64
  function _getImageIndexToJump(