@cornerstonejs/tools 3.6.1 → 3.7.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.
@@ -19,6 +19,10 @@ declare class AngleTool extends AnnotationTool {
19
19
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
20
20
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
21
21
  annotationUID?: string;
22
+ toolInstance?: AngleTool;
23
+ referencedImageId?: string;
24
+ viewplaneNormal?: Types.Point3;
25
+ viewUp?: Types.Point3;
22
26
  }) => AngleAnnotation;
23
27
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => AngleAnnotation;
24
28
  isPointNearTool: (element: HTMLDivElement, annotation: AngleAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
@@ -390,11 +390,7 @@ class AngleTool extends AnnotationTool {
390
390
  if (!enabledElement) {
391
391
  return;
392
392
  }
393
- const { viewport } = enabledElement;
394
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
395
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
396
- const instance = new this();
397
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
393
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(AngleTool, enabledElement, points, options);
398
394
  const annotation = {
399
395
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
400
396
  data: {
@@ -18,6 +18,10 @@ declare class ArrowAnnotateTool extends AnnotationTool {
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
19
  static hydrate: (viewportId: string, points: Types.Point3[], text?: string, options?: {
20
20
  annotationUID?: string;
21
+ toolInstance?: ArrowAnnotateTool;
22
+ referencedImageId?: string;
23
+ viewplaneNormal?: Types.Point3;
24
+ viewUp?: Types.Point3;
21
25
  }) => ArrowAnnotation;
22
26
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => ArrowAnnotation;
23
27
  isPointNearTool: (element: HTMLDivElement, annotation: ArrowAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
@@ -392,11 +392,7 @@ class ArrowAnnotateTool extends AnnotationTool {
392
392
  if (!enabledElement) {
393
393
  return;
394
394
  }
395
- const { viewport } = enabledElement;
396
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
397
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
398
- const instance = new this();
399
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
395
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(ArrowAnnotateTool, enabledElement, points, options);
400
396
  const annotation = {
401
397
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
402
398
  data: {
@@ -20,6 +20,10 @@ declare class BidirectionalTool extends AnnotationTool {
20
20
  addNewAnnotation(evt: EventTypes.InteractionEventType): BidirectionalAnnotation;
21
21
  static hydrate: (viewportId: string, axis: [[Types.Point3, Types.Point3], [Types.Point3, Types.Point3]], options?: {
22
22
  annotationUID?: string;
23
+ toolInstance?: BidirectionalTool;
24
+ referencedImageId?: string;
25
+ viewplaneNormal?: Types.Point3;
26
+ viewUp?: Types.Point3;
23
27
  }) => BidirectionalAnnotation;
24
28
  isPointNearTool: (element: HTMLDivElement, annotation: BidirectionalAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
25
29
  toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: BidirectionalAnnotation) => void;
@@ -714,22 +714,29 @@ class BidirectionalTool extends AnnotationTool {
714
714
  if (!enabledElement) {
715
715
  return;
716
716
  }
717
- const { viewport } = enabledElement;
718
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
719
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
720
- const instance = new this();
717
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(BidirectionalTool, enabledElement, [], options);
721
718
  const [majorAxis, minorAxis] = axis;
722
719
  const [major0, major1] = majorAxis;
723
720
  const [minor0, minor1] = minorAxis;
724
721
  const points = [major0, major1, minor0, minor1];
725
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
726
722
  const annotation = {
727
723
  annotationUID: options?.annotationUID || utilities.uuidv4(),
728
724
  data: {
729
725
  handles: {
730
726
  points,
731
727
  activeHandleIndex: null,
728
+ textBox: {
729
+ hasMoved: false,
730
+ worldPosition: [0, 0, 0],
731
+ worldBoundingBox: {
732
+ topLeft: [0, 0, 0],
733
+ topRight: [0, 0, 0],
734
+ bottomLeft: [0, 0, 0],
735
+ bottomRight: [0, 0, 0],
736
+ },
737
+ },
732
738
  },
739
+ cachedStats: {},
733
740
  },
734
741
  highlighted: false,
735
742
  autoGenerated: false,
@@ -746,6 +753,7 @@ class BidirectionalTool extends AnnotationTool {
746
753
  };
747
754
  addAnnotation(annotation, viewport.element);
748
755
  triggerAnnotationRenderForViewportIds([viewport.id]);
756
+ return annotation;
749
757
  }; }
750
758
  _calculateLength(pos1, pos2) {
751
759
  const dx = pos1[0] - pos2[0];
@@ -34,6 +34,10 @@ declare class CircleROITool extends AnnotationTool {
34
34
  _isInsideVolume: (index1: any, index2: any, dimensions: any) => boolean;
35
35
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
36
36
  annotationUID?: string;
37
+ toolInstance?: CircleROITool;
38
+ referencedImageId?: string;
39
+ viewplaneNormal?: Types.Point3;
40
+ viewUp?: Types.Point3;
37
41
  }) => CircleROIAnnotation;
38
42
  }
39
43
  export default CircleROITool;
@@ -570,11 +570,7 @@ class CircleROITool extends AnnotationTool {
570
570
  if (!enabledElement) {
571
571
  return;
572
572
  }
573
- const { viewport } = enabledElement;
574
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
575
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
576
- const instance = new this();
577
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
573
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(CircleROITool, enabledElement, points, options);
578
574
  const annotation = {
579
575
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
580
576
  data: {
@@ -22,6 +22,10 @@ declare class EllipticalROITool extends AnnotationTool {
22
22
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
23
23
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
24
24
  annotationUID?: string;
25
+ toolInstance?: EllipticalROITool;
26
+ referencedImageId?: string;
27
+ viewplaneNormal?: Types.Point3;
28
+ viewUp?: Types.Point3;
25
29
  }) => EllipticalROIAnnotation;
26
30
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => EllipticalROIAnnotation;
27
31
  isPointNearTool: (element: HTMLDivElement, annotation: EllipticalROIAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
@@ -636,11 +636,7 @@ class EllipticalROITool extends AnnotationTool {
636
636
  if (!enabledElement) {
637
637
  return;
638
638
  }
639
- const { viewport } = enabledElement;
640
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
641
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
642
- const instance = new this();
643
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
639
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(EllipticalROITool, enabledElement, points, options);
644
640
  const annotation = {
645
641
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
646
642
  data: {
@@ -18,6 +18,10 @@ declare class LengthTool extends AnnotationTool {
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
19
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
20
20
  annotationUID?: string;
21
+ toolInstance?: LengthTool;
22
+ referencedImageId?: string;
23
+ viewplaneNormal?: Types.Point3;
24
+ viewUp?: Types.Point3;
21
25
  }) => LengthAnnotation;
22
26
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => LengthAnnotation;
23
27
  isPointNearTool: (element: HTMLDivElement, annotation: LengthAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
@@ -361,11 +361,7 @@ class LengthTool extends AnnotationTool {
361
361
  if (!enabledElement) {
362
362
  return;
363
363
  }
364
- const { viewport } = enabledElement;
365
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
366
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
367
- const instance = new this();
368
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
364
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(LengthTool, enabledElement, points, options);
369
365
  const annotation = {
370
366
  annotationUID: options?.annotationUID || utilities.uuidv4(),
371
367
  data: {
@@ -19,6 +19,10 @@ declare class ProbeTool extends AnnotationTool {
19
19
  toolSelectedCallback(): void;
20
20
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
21
21
  annotationUID?: string;
22
+ toolInstance?: ProbeTool;
23
+ referencedImageId?: string;
24
+ viewplaneNormal?: Types.Point3;
25
+ viewUp?: Types.Point3;
22
26
  }) => ProbeAnnotation;
23
27
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => ProbeAnnotation;
24
28
  getHandleNearImagePoint(element: HTMLDivElement, annotation: ProbeAnnotation, canvasCoords: Types.Point2, proximity: number): ToolHandle | undefined;
@@ -224,11 +224,7 @@ class ProbeTool extends AnnotationTool {
224
224
  if (!enabledElement) {
225
225
  return;
226
226
  }
227
- const { viewport } = enabledElement;
228
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
229
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
230
- const instance = new this();
231
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
227
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, viewUp, instance, viewport, } = this.hydrateBase(ProbeTool, enabledElement, points, options);
232
228
  const annotation = {
233
229
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
234
230
  data: {
@@ -38,6 +38,10 @@ declare class RectangleROITool extends AnnotationTool {
38
38
  _isInsideVolume: (index1: any, index2: any, dimensions: any) => boolean;
39
39
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
40
40
  annotationUID?: string;
41
+ toolInstance?: RectangleROITool;
42
+ referencedImageId?: string;
43
+ viewplaneNormal?: Types.Point3;
44
+ viewUp?: Types.Point3;
41
45
  }) => RectangleROIAnnotation;
42
46
  }
43
47
  export default RectangleROITool;
@@ -521,11 +521,7 @@ class RectangleROITool extends AnnotationTool {
521
521
  if (!enabledElement) {
522
522
  return;
523
523
  }
524
- const { viewport } = enabledElement;
525
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
526
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
527
- const instance = new this();
528
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
524
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, viewport, } = this.hydrateBase(RectangleROITool, enabledElement, points, options);
529
525
  const annotation = {
530
526
  annotationUID: options?.annotationUID || csUtils.uuidv4(),
531
527
  data: {
@@ -68,6 +68,10 @@ declare class SplineROITool extends ContourSegmentationBaseTool {
68
68
  static hydrate: (viewportId: string, points: Types.Point3[], options?: {
69
69
  annotationUID?: string;
70
70
  splineType?: SplineTypesEnum;
71
+ toolInstance?: SplineROITool;
72
+ referencedImageId?: string;
73
+ viewplaneNormal?: Types.Point3;
74
+ viewUp?: Types.Point3;
71
75
  }) => SplineROIAnnotation;
72
76
  }
73
77
  export default SplineROITool;
@@ -726,19 +726,11 @@ class SplineROITool extends ContourSegmentationBaseTool {
726
726
  console.warn('Spline requires at least 3 control points');
727
727
  return;
728
728
  }
729
- const { viewport } = enabledElement;
730
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
731
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
732
- const instance = new this();
733
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
729
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, viewUp, instance, viewport, } = this.hydrateBase(SplineROITool, enabledElement, points, options);
734
730
  const splineType = options?.splineType || SplineTypesEnum.CatmullRom;
735
731
  const splineConfig = instance._getSplineConfig(splineType);
736
732
  const SplineClass = splineConfig.Class;
737
733
  const splineInstance = new SplineClass();
738
- const canvasPoints = points.map((point) => viewport.worldToCanvas(point));
739
- splineInstance.setControlPoints(canvasPoints);
740
- const splinePolylineCanvas = splineInstance.getPolylinePoints();
741
- const splinePolylineWorld = splinePolylineCanvas.map((point) => viewport.canvasToWorld(point));
742
734
  const annotation = {
743
735
  annotationUID: options?.annotationUID || utilities.uuidv4(),
744
736
  data: {
@@ -753,7 +745,6 @@ class SplineROITool extends ContourSegmentationBaseTool {
753
745
  },
754
746
  contour: {
755
747
  closed: true,
756
- polyline: splinePolylineWorld,
757
748
  },
758
749
  },
759
750
  highlighted: false,
@@ -1,3 +1,4 @@
1
+ import { StackViewport } from '@cornerstonejs/core';
1
2
  import type { Types } from '@cornerstonejs/core';
2
3
  import AnnotationDisplayTool from './AnnotationDisplayTool';
3
4
  import type { Annotation, Annotations, EventTypes, ToolHandle, InteractionTypes, ToolProps, PublicToolProps } from '../../types';
@@ -54,5 +55,19 @@ declare abstract class AnnotationTool extends AnnotationDisplayTool {
54
55
  restoreMemo: () => void;
55
56
  };
56
57
  protected createMemo(element: any, annotation: any, options?: any): void;
58
+ protected static hydrateBase<T extends AnnotationTool>(ToolClass: new () => T, enabledElement: Types.IEnabledElement, points: Types.Point3[], options?: {
59
+ annotationUID?: string;
60
+ toolInstance?: T;
61
+ referencedImageId?: string;
62
+ viewplaneNormal?: Types.Point3;
63
+ viewUp?: Types.Point3;
64
+ }): {
65
+ FrameOfReferenceUID: string;
66
+ referencedImageId: any;
67
+ viewPlaneNormal: Types.Point3;
68
+ viewUp: Types.Point3;
69
+ instance: T;
70
+ viewport: StackViewport | import("@cornerstonejs/core").VolumeViewport;
71
+ };
57
72
  }
58
73
  export default AnnotationTool;
@@ -1,4 +1,4 @@
1
- import { BaseVolumeViewport, cache, getEnabledElement, metaData, utilities as csUtils, } from '@cornerstonejs/core';
1
+ import { BaseVolumeViewport, cache, getEnabledElement, metaData, utilities as csUtils, StackViewport, } from '@cornerstonejs/core';
2
2
  import { vec2 } from 'gl-matrix';
3
3
  import AnnotationDisplayTool from './AnnotationDisplayTool';
4
4
  import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
@@ -266,6 +266,47 @@ class AnnotationTool extends AnnotationDisplayTool {
266
266
  createMemo(element, annotation, options) {
267
267
  this.memo ||= AnnotationTool.createAnnotationMemo(element, annotation, options);
268
268
  }
269
+ static hydrateBase(ToolClass, enabledElement, points, options = {}) {
270
+ if (!enabledElement) {
271
+ return null;
272
+ }
273
+ const { viewport } = enabledElement;
274
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
275
+ const camera = viewport.getCamera();
276
+ const viewPlaneNormal = options.viewplaneNormal ?? camera.viewPlaneNormal;
277
+ const viewUp = options.viewUp ?? camera.viewUp;
278
+ const instance = options.toolInstance || new ToolClass();
279
+ let referencedImageId;
280
+ let finalViewPlaneNormal = viewPlaneNormal;
281
+ let finalViewUp = viewUp;
282
+ if (options.referencedImageId) {
283
+ referencedImageId = options.referencedImageId;
284
+ finalViewPlaneNormal = undefined;
285
+ finalViewUp = undefined;
286
+ }
287
+ else {
288
+ if (viewport instanceof StackViewport) {
289
+ const closestImageIndex = csUtils.getClosestStackImageIndexForPoint(points[0], viewport);
290
+ if (closestImageIndex) {
291
+ referencedImageId = viewport.getImageIds()[closestImageIndex];
292
+ }
293
+ }
294
+ else if (viewport instanceof BaseVolumeViewport) {
295
+ referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
296
+ }
297
+ else {
298
+ throw new Error('Unsupported viewport type');
299
+ }
300
+ }
301
+ return {
302
+ FrameOfReferenceUID,
303
+ referencedImageId,
304
+ viewPlaneNormal: finalViewPlaneNormal,
305
+ viewUp: finalViewUp,
306
+ instance,
307
+ viewport,
308
+ };
309
+ }
269
310
  }
270
311
  AnnotationTool.toolName = 'AnnotationTool';
271
312
  export default AnnotationTool;
@@ -21,6 +21,10 @@ declare class SegmentBidirectionalTool extends BidirectionalTool {
21
21
  segmentIndex?: number;
22
22
  segmentationId?: string;
23
23
  annotationUID?: string;
24
+ toolInstance?: SegmentBidirectionalTool;
25
+ referencedImageId?: string;
26
+ viewplaneNormal?: Types.Point3;
27
+ viewUp?: Types.Point3;
24
28
  }) => SegmentBidirectionalAnnotation;
25
29
  renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
26
30
  }
@@ -201,8 +201,6 @@ class SegmentBidirectionalTool extends BidirectionalTool {
201
201
  return;
202
202
  }
203
203
  const { viewport } = enabledElement;
204
- const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
205
- const { viewPlaneNormal, viewUp } = viewport.getCamera();
206
204
  const existingAnnotations = getAllAnnotations();
207
205
  const toolAnnotations = existingAnnotations.filter((annotation) => annotation.metadata.toolName === 'SegmentBidirectional');
208
206
  const existingAnnotation = toolAnnotations.find((annotation) => {
@@ -216,19 +214,29 @@ class SegmentBidirectionalTool extends BidirectionalTool {
216
214
  if (existingAnnotation) {
217
215
  removeAnnotation(existingAnnotation.annotationUID);
218
216
  }
219
- const instance = new this();
217
+ const { FrameOfReferenceUID, referencedImageId, viewPlaneNormal, instance, } = this.hydrateBase(SegmentBidirectionalTool, enabledElement, axis[0], options);
220
218
  const [majorAxis, minorAxis] = axis;
221
219
  const [major0, major1] = majorAxis;
222
220
  const [minor0, minor1] = minorAxis;
223
221
  const points = [major0, major1, minor0, minor1];
224
- const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
225
222
  const annotation = {
226
223
  annotationUID: options?.annotationUID || utilities.uuidv4(),
227
224
  data: {
228
225
  handles: {
229
226
  points,
230
227
  activeHandleIndex: null,
228
+ textBox: {
229
+ hasMoved: false,
230
+ worldPosition: [0, 0, 0],
231
+ worldBoundingBox: {
232
+ topLeft: [0, 0, 0],
233
+ topRight: [0, 0, 0],
234
+ bottomLeft: [0, 0, 0],
235
+ bottomRight: [0, 0, 0],
236
+ },
237
+ },
231
238
  },
239
+ cachedStats: {},
232
240
  },
233
241
  highlighted: false,
234
242
  autoGenerated: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -103,7 +103,7 @@
103
103
  "canvas": "^2.11.2"
104
104
  },
105
105
  "peerDependencies": {
106
- "@cornerstonejs/core": "^3.6.1",
106
+ "@cornerstonejs/core": "^3.7.0",
107
107
  "@kitware/vtk.js": "32.12.1",
108
108
  "@types/d3-array": "^3.0.4",
109
109
  "@types/d3-interpolate": "^3.0.1",
@@ -122,5 +122,5 @@
122
122
  "type": "individual",
123
123
  "url": "https://ohif.org/donate"
124
124
  },
125
- "gitHead": "a262fd519f1ceabe2e1d1d01a382087920657f65"
125
+ "gitHead": "177fce2dd8c2278d3c8473f15df795e757d40b7e"
126
126
  }