@cornerstonejs/tools 1.72.5 → 1.73.0

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 (56) hide show
  1. package/dist/cjs/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js +3 -0
  2. package/dist/cjs/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js.map +1 -1
  3. package/dist/cjs/stateManagement/annotation/utilities/defineProperties.d.ts +4 -0
  4. package/dist/cjs/stateManagement/annotation/utilities/defineProperties.js +27 -0
  5. package/dist/cjs/stateManagement/annotation/utilities/defineProperties.js.map +1 -0
  6. package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +1 -0
  7. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +15 -2
  8. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  9. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js +32 -0
  10. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  11. package/dist/cjs/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +1 -1
  12. package/dist/cjs/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js.map +1 -1
  13. package/dist/cjs/types/AnnotationTypes.d.ts +2 -2
  14. package/dist/cjs/utilities/annotationHydration.d.ts +7 -0
  15. package/dist/cjs/utilities/annotationHydration.js +84 -0
  16. package/dist/cjs/utilities/annotationHydration.js.map +1 -0
  17. package/dist/cjs/utilities/index.d.ts +2 -1
  18. package/dist/cjs/utilities/index.js +3 -1
  19. package/dist/cjs/utilities/index.js.map +1 -1
  20. package/dist/esm/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js +3 -0
  21. package/dist/esm/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.js.map +1 -1
  22. package/dist/esm/stateManagement/annotation/utilities/defineProperties.js +23 -0
  23. package/dist/esm/stateManagement/annotation/utilities/defineProperties.js.map +1 -0
  24. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +15 -2
  25. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  26. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js +32 -0
  27. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  28. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js +1 -1
  29. package/dist/esm/tools/displayTools/Contour/contourHandler/handleContourSegmentation.js.map +1 -1
  30. package/dist/esm/utilities/annotationHydration.js +83 -0
  31. package/dist/esm/utilities/annotationHydration.js.map +1 -0
  32. package/dist/esm/utilities/index.js +2 -1
  33. package/dist/esm/utilities/index.js.map +1 -1
  34. package/dist/types/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.d.ts.map +1 -1
  35. package/dist/types/stateManagement/annotation/utilities/defineProperties.d.ts +5 -0
  36. package/dist/types/stateManagement/annotation/utilities/defineProperties.d.ts.map +1 -0
  37. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +1 -0
  38. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  39. package/dist/types/tools/annotation/planarFreehandROITool/renderMethods.d.ts.map +1 -1
  40. package/dist/types/types/AnnotationTypes.d.ts +2 -2
  41. package/dist/types/types/AnnotationTypes.d.ts.map +1 -1
  42. package/dist/types/utilities/annotationHydration.d.ts +8 -0
  43. package/dist/types/utilities/annotationHydration.d.ts.map +1 -0
  44. package/dist/types/utilities/index.d.ts +2 -1
  45. package/dist/types/utilities/index.d.ts.map +1 -1
  46. package/dist/umd/index.js +1 -1
  47. package/dist/umd/index.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +7 -0
  50. package/src/stateManagement/annotation/utilities/defineProperties.ts +26 -0
  51. package/src/tools/annotation/PlanarFreehandROITool.ts +31 -2
  52. package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +67 -0
  53. package/src/tools/displayTools/Contour/contourHandler/handleContourSegmentation.ts +1 -1
  54. package/src/types/AnnotationTypes.ts +2 -2
  55. package/src/utilities/annotationHydration.ts +143 -0
  56. package/src/utilities/index.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.72.5",
3
+ "version": "1.73.0",
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.72.5",
32
+ "@cornerstonejs/core": "^1.73.0",
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": "475e831d61c00535b40c108a8b940e5bdf3ae0f6"
62
+ "gitHead": "7d9375494668c1b3857c560643e490470d35523d"
63
63
  }
@@ -19,6 +19,11 @@ import {
19
19
  import { checkAndDefineIsLockedProperty } from './annotationLocking';
20
20
  import { checkAndDefineIsVisibleProperty } from './annotationVisibility';
21
21
 
22
+ import {
23
+ checkAndDefineTextBoxProperty,
24
+ checkAndDefineCachedStatsProperty,
25
+ } from './utilities/defineProperties';
26
+
22
27
  /**
23
28
  * This is the default annotation manager. It stores annotations by default
24
29
  * based on the FrameOfReferenceUID. However, it is possible to override the
@@ -236,6 +241,8 @@ class FrameOfReferenceSpecificAnnotationManager implements IAnnotationManager {
236
241
  toolSpecificAnnotations.push(annotation);
237
242
  checkAndDefineIsLockedProperty(annotation);
238
243
  checkAndDefineIsVisibleProperty(annotation);
244
+ checkAndDefineTextBoxProperty(annotation);
245
+ checkAndDefineCachedStatsProperty(annotation);
239
246
  };
240
247
 
241
248
  /**
@@ -0,0 +1,26 @@
1
+ import { Annotation } from '../../../types';
2
+
3
+ const checkAndDefineTextBoxProperty = (annotation: Annotation) => {
4
+ if (!annotation.data) {
5
+ annotation.data = {};
6
+ }
7
+ if (!annotation.data.handles) {
8
+ annotation.data.handles = {};
9
+ }
10
+ if (!annotation.data.handles.textBox) {
11
+ annotation.data.handles.textBox = {};
12
+ }
13
+ return annotation;
14
+ };
15
+
16
+ const checkAndDefineCachedStatsProperty = (annotation: Annotation) => {
17
+ if (!annotation.data) {
18
+ annotation.data = {};
19
+ }
20
+ if (!annotation.data.cachedStats) {
21
+ annotation.data.cachedStats = {};
22
+ }
23
+ return annotation;
24
+ };
25
+
26
+ export { checkAndDefineTextBoxProperty, checkAndDefineCachedStatsProperty };
@@ -170,6 +170,12 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
170
170
  annotation: PlanarFreehandROIAnnotation
171
171
  ) => void;
172
172
 
173
+ private renderPointContourWithMarker: (
174
+ enabledElement: Types.IEnabledElement,
175
+ svgDrawingHelper: SVGDrawingHelper,
176
+ annotation: PlanarFreehandROIAnnotation
177
+ ) => void;
178
+
173
179
  constructor(
174
180
  toolProps: PublicToolProps = {},
175
181
  defaultToolProps: ToolProps = {
@@ -242,6 +248,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
242
248
  */
243
249
  epsilon: 0.1,
244
250
  },
251
+ displayOnePointAsCrosshairs: false,
245
252
  calculateStats: true,
246
253
  getTextLines: defaultGetTextLines,
247
254
  statsCalculator: BasicStatsCalculator,
@@ -578,7 +585,18 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
578
585
  if (!(isDrawing || isEditingOpen || isEditingClosed)) {
579
586
  // No annotations are currently being modified, so we can just use the
580
587
  // render contour method to render all of them
581
- this.renderContour(enabledElement, svgDrawingHelper, annotation);
588
+ if (
589
+ this.configuration.displayOnePointAsCrosshairs &&
590
+ annotation.data.contour.polyline.length === 1
591
+ ) {
592
+ this.renderPointContourWithMarker(
593
+ enabledElement,
594
+ svgDrawingHelper,
595
+ annotation
596
+ );
597
+ } else {
598
+ this.renderContour(enabledElement, svgDrawingHelper, annotation);
599
+ }
582
600
  } else {
583
601
  // The active annotation will need special rendering treatment. Render all
584
602
  // other annotations not being interacted with using the standard renderContour
@@ -610,7 +628,18 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
610
628
  );
611
629
  }
612
630
  } else {
613
- this.renderContour(enabledElement, svgDrawingHelper, annotation);
631
+ if (
632
+ this.configuration.displayOnePointAsCrosshairs &&
633
+ annotation.data.contour.polyline.length === 1
634
+ ) {
635
+ this.renderPointContourWithMarker(
636
+ enabledElement,
637
+ svgDrawingHelper,
638
+ annotation
639
+ );
640
+ } else {
641
+ this.renderContour(enabledElement, svgDrawingHelper, annotation);
642
+ }
614
643
  }
615
644
 
616
645
  // Todo: return boolean flag for each rendering route in the planar tool.
@@ -407,6 +407,71 @@ function renderOpenContourBeingEdited(
407
407
  );
408
408
  }
409
409
 
410
+ /**
411
+ * Renders a point `PlanarFreehandROIAnnotation` annotation by drawing a circle and a crosshair
412
+ */
413
+
414
+ function renderPointContourWithMarker(
415
+ enabledElement: Types.IEnabledElement,
416
+ svgDrawingHelper: SVGDrawingHelper,
417
+ annotation: PlanarFreehandROIAnnotation
418
+ ): void {
419
+ if (annotation.parentAnnotationUID) {
420
+ return;
421
+ }
422
+ const { viewport } = enabledElement;
423
+ const options = this._getRenderingOptions(enabledElement, annotation);
424
+ const canvasPolyline = annotation.data.contour.polyline.map((worldPos) =>
425
+ viewport.worldToCanvas(worldPos)
426
+ );
427
+ const childContours = getContourHolesDataCanvas(annotation, viewport);
428
+ const polylineUID = '1';
429
+
430
+ const center = canvasPolyline[0];
431
+ const radius = 6;
432
+ const numberOfPoints = 100;
433
+ const circlePoints = [];
434
+
435
+ for (let i = 0; i < numberOfPoints; i++) {
436
+ const angle = (i / numberOfPoints) * 2 * Math.PI;
437
+ const x = center[0] + radius * Math.cos(angle);
438
+ const y = center[1] + radius * Math.sin(angle);
439
+ circlePoints.push([x, y]);
440
+ }
441
+
442
+ const crosshair = [
443
+ [center[0] - radius * 2, center[1]],
444
+ [center[0] + radius * 2, center[1]],
445
+ [center[0], center[1] - radius * 2],
446
+ [center[0], center[1] + radius * 2],
447
+ ] as Types.Point2[];
448
+
449
+ drawPathSvg(
450
+ svgDrawingHelper,
451
+ annotation.annotationUID,
452
+ polylineUID + '-crosshair_v',
453
+ [crosshair[0], crosshair[1]],
454
+ options
455
+ );
456
+
457
+ drawPathSvg(
458
+ svgDrawingHelper,
459
+ annotation.annotationUID,
460
+ polylineUID + '-crosshair_h',
461
+ [crosshair[2], crosshair[3]],
462
+ options
463
+ );
464
+
465
+ const allContours = [circlePoints, ...childContours];
466
+
467
+ drawPathSvg(
468
+ svgDrawingHelper,
469
+ annotation.annotationUID,
470
+ polylineUID,
471
+ allContours,
472
+ options
473
+ );
474
+ }
410
475
  /**
411
476
  * Registers the render methods of various contour states to the tool instance.
412
477
  */
@@ -414,6 +479,8 @@ function registerRenderMethods(toolInstance) {
414
479
  toolInstance.renderContour = renderContour.bind(toolInstance);
415
480
  toolInstance.renderClosedContour = renderClosedContour.bind(toolInstance);
416
481
  toolInstance.renderOpenContour = renderOpenContour.bind(toolInstance);
482
+ toolInstance.renderPointContourWithMarker =
483
+ renderPointContourWithMarker.bind(toolInstance);
417
484
  toolInstance.renderOpenUShapedContour =
418
485
  renderOpenUShapedContour.bind(toolInstance);
419
486
 
@@ -163,7 +163,7 @@ function addContourSetsToElement(
163
163
  highlighted: false,
164
164
  autoGenerated: false,
165
165
  invalidated: false,
166
- isLocked: false,
166
+ isLocked: true,
167
167
  isVisible: true,
168
168
  metadata: {
169
169
  referencedImageId: viewport.getCurrentImageId(),
@@ -55,9 +55,9 @@ type Annotation = {
55
55
  /** annotation text box information */
56
56
  textBox?: {
57
57
  /** whether the text box has moved */
58
- hasMoved: boolean;
58
+ hasMoved?: boolean;
59
59
  /** the world location of the text box */
60
- worldPosition: Types.Point3;
60
+ worldPosition?: Types.Point3;
61
61
  /** text box bounding box information */
62
62
  worldBoundingBox?: {
63
63
  /** Top left location of the text box in the world space */
@@ -0,0 +1,143 @@
1
+ import {
2
+ Types,
3
+ utilities,
4
+ BaseVolumeViewport,
5
+ StackViewport,
6
+ cache,
7
+ metaData,
8
+ } from '@cornerstonejs/core';
9
+ import { Annotation } from '../types';
10
+ import { addAnnotation } from '../stateManagement';
11
+ import { vec3 } from 'gl-matrix';
12
+
13
+ function annotationHydration(
14
+ viewport: Types.IViewport,
15
+ toolName: string,
16
+ worldPoints: Types.Point3[],
17
+ options?: {
18
+ FrameOfReferenceUID?: string;
19
+ annotationUID?: string;
20
+ }
21
+ ): Annotation {
22
+ const viewReference = viewport.getViewReference();
23
+ const { viewPlaneNormal, FrameOfReferenceUID } = viewReference;
24
+ const annotation = {
25
+ annotationUID: options?.annotationUID || utilities.uuidv4(),
26
+ data: {
27
+ handles: {
28
+ points: worldPoints,
29
+ },
30
+ },
31
+ highlighted: false,
32
+ autoGenerated: false,
33
+ invalidated: false,
34
+ isLocked: false,
35
+ isVisible: true,
36
+ metadata: {
37
+ toolName,
38
+ viewPlaneNormal,
39
+ FrameOfReferenceUID,
40
+ referencedImageId: getReferencedImageId(
41
+ viewport,
42
+ worldPoints[0],
43
+ viewPlaneNormal
44
+ ),
45
+ ...options,
46
+ },
47
+ };
48
+ addAnnotation(annotation, viewport.element);
49
+ return annotation;
50
+ }
51
+
52
+ function getReferencedImageId(
53
+ viewport: Types.IViewport,
54
+ worldPos: Types.Point3,
55
+ viewPlaneNormal: Types.Point3
56
+ ): string {
57
+ let referencedImageId;
58
+
59
+ if (viewport instanceof StackViewport) {
60
+ referencedImageId = getClosestImageIdForStackViewport(
61
+ viewport,
62
+ worldPos,
63
+ viewPlaneNormal
64
+ );
65
+ } else if (viewport instanceof BaseVolumeViewport) {
66
+ const targetId = getTargetId(viewport);
67
+ const volumeId = utilities.getVolumeId(targetId);
68
+ const imageVolume = cache.getVolume(volumeId);
69
+
70
+ referencedImageId = utilities.getClosestImageId(
71
+ imageVolume,
72
+ worldPos,
73
+ viewPlaneNormal
74
+ );
75
+ } else {
76
+ throw new Error(
77
+ 'getReferencedImageId: viewport must be a StackViewport or BaseVolumeViewport'
78
+ );
79
+ }
80
+
81
+ return referencedImageId;
82
+ }
83
+
84
+ function getTargetId(viewport: Types.IViewport): string | undefined {
85
+ const targetId = viewport.getReferenceId?.();
86
+ if (targetId) {
87
+ return targetId;
88
+ }
89
+ if (viewport instanceof BaseVolumeViewport) {
90
+ return `volumeId:${getTargetVolumeId(viewport)}`;
91
+ }
92
+ throw new Error('getTargetId: viewport must have a getTargetId method');
93
+ }
94
+
95
+ function getTargetVolumeId(viewport: Types.IViewport): string | undefined {
96
+ const actorEntries = viewport.getActors();
97
+
98
+ if (!actorEntries) {
99
+ return;
100
+ }
101
+ return actorEntries.find(
102
+ (actorEntry) => actorEntry.actor.getClassName() === 'vtkVolume'
103
+ )?.uid;
104
+ }
105
+
106
+ function getClosestImageIdForStackViewport(
107
+ viewport: StackViewport,
108
+ worldPos: Types.Point3,
109
+ viewPlaneNormal: Types.Point3
110
+ ): string {
111
+ const imageIds = viewport.getImageIds();
112
+ if (!imageIds || !imageIds.length) {
113
+ return;
114
+ }
115
+
116
+ const distanceImagePairs = imageIds.map((imageId) => {
117
+ const { imagePositionPatient } = metaData.get('imagePlaneModule', imageId);
118
+ const distance = calculateDistanceToImage(
119
+ worldPos,
120
+ imagePositionPatient,
121
+ viewPlaneNormal
122
+ );
123
+ return { imageId, distance };
124
+ });
125
+
126
+ distanceImagePairs.sort((a, b) => a.distance - b.distance);
127
+
128
+ return distanceImagePairs[0].imageId;
129
+ }
130
+
131
+ function calculateDistanceToImage(
132
+ worldPos: Types.Point3,
133
+ ImagePositionPatient: Types.Point3,
134
+ viewPlaneNormal: Types.Point3
135
+ ): number {
136
+ const dir = vec3.create();
137
+ vec3.sub(dir, worldPos, ImagePositionPatient);
138
+
139
+ const dot = vec3.dot(dir, viewPlaneNormal);
140
+
141
+ return Math.abs(dot);
142
+ }
143
+ export { annotationHydration };
@@ -28,7 +28,7 @@ import { pointToString } from './pointToString';
28
28
  import annotationFrameRange from './annotationFrameRange';
29
29
  import pointInSurroundingSphereCallback from './pointInSurroundingSphereCallback';
30
30
  import getViewportForAnnotation from './getViewportForAnnotation';
31
-
31
+ import { annotationHydration } from './annotationHydration';
32
32
  // name spaces
33
33
  import * as contours from './contours';
34
34
  import * as segmentation from './segmentation';
@@ -97,4 +97,5 @@ export {
97
97
  voi,
98
98
  annotationFrameRange,
99
99
  contourSegmentation,
100
+ annotationHydration,
100
101
  };