@cornerstonejs/tools 2.2.18 → 2.2.20

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.
@@ -32,5 +32,8 @@ declare class CircleROITool extends AnnotationTool {
32
32
  renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
33
33
  _calculateCachedStats: (annotation: any, viewport: any, renderingEngine: any, enabledElement: any) => any;
34
34
  _isInsideVolume: (index1: any, index2: any, dimensions: any) => boolean;
35
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
36
+ annotationUID?: string;
37
+ }) => CircleROIAnnotation;
35
38
  }
36
39
  export default CircleROITool;
@@ -1,5 +1,5 @@
1
1
  import { AnnotationTool } from '../base';
2
- import { getEnabledElement, VolumeViewport, utilities as csUtils, } from '@cornerstonejs/core';
2
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { getCalibratedAspect, getCalibratedLengthUnitsAndScale, } from '../../utilities/getCalibratedUnits';
4
4
  import throttle from '../../utilities/throttle';
5
5
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
@@ -557,6 +557,52 @@ class CircleROITool extends AnnotationTool {
557
557
  };
558
558
  this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
559
559
  }
560
+ static { this.hydrate = (viewportId, points, options) => {
561
+ const enabledElement = getEnabledElementByViewportId(viewportId);
562
+ if (!enabledElement) {
563
+ return;
564
+ }
565
+ const { viewport } = enabledElement;
566
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
567
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
568
+ const instance = new this();
569
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
570
+ const annotation = {
571
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
572
+ data: {
573
+ handles: {
574
+ points,
575
+ textBox: {
576
+ hasMoved: false,
577
+ worldPosition: [0, 0, 0],
578
+ worldBoundingBox: {
579
+ topLeft: [0, 0, 0],
580
+ topRight: [0, 0, 0],
581
+ bottomLeft: [0, 0, 0],
582
+ bottomRight: [0, 0, 0],
583
+ },
584
+ },
585
+ activeHandleIndex: null,
586
+ },
587
+ label: '',
588
+ cachedStats: {},
589
+ },
590
+ highlighted: false,
591
+ autoGenerated: false,
592
+ invalidated: false,
593
+ isLocked: false,
594
+ isVisible: true,
595
+ metadata: {
596
+ toolName: instance.getToolName(),
597
+ viewPlaneNormal,
598
+ FrameOfReferenceUID,
599
+ referencedImageId,
600
+ ...options,
601
+ },
602
+ };
603
+ addAnnotation(annotation, viewport.element);
604
+ triggerAnnotationRenderForViewportIds([viewport.id]);
605
+ }; }
560
606
  }
561
607
  function defaultGetTextLines(data, targetId) {
562
608
  const cachedVolumeStats = data.cachedStats[targetId];
@@ -16,6 +16,9 @@ declare class LengthTool extends AnnotationTool {
16
16
  isDrawing: boolean;
17
17
  isHandleOutsideImage: boolean;
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
20
+ annotationUID?: string;
21
+ }) => LengthAnnotation;
19
22
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => LengthAnnotation;
20
23
  isPointNearTool: (element: HTMLDivElement, annotation: LengthAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
21
24
  toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: LengthAnnotation) => void;
@@ -1,5 +1,5 @@
1
1
  import { Events } from '../../enums';
2
- import { getEnabledElement, utilities as csUtils } from '@cornerstonejs/core';
2
+ import { getEnabledElement, utilities as csUtils, utilities, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits';
4
4
  import { AnnotationTool } from '../base';
5
5
  import throttle from '../../utilities/throttle';
@@ -29,7 +29,7 @@ class LengthTool extends AnnotationTool {
29
29
  const { currentPoints, element } = eventDetail;
30
30
  const worldPos = currentPoints.world;
31
31
  const enabledElement = getEnabledElement(element);
32
- const { viewport, renderingEngine } = enabledElement;
32
+ const { viewport } = enabledElement;
33
33
  hideElementCursor(element);
34
34
  this.isDrawing = true;
35
35
  const { viewPlaneNormal, viewUp, position: cameraPosition, } = viewport.getCamera();
@@ -344,6 +344,39 @@ class LengthTool extends AnnotationTool {
344
344
  };
345
345
  this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
346
346
  }
347
+ static { this.hydrate = (viewportId, points, options) => {
348
+ const enabledElement = getEnabledElementByViewportId(viewportId);
349
+ if (!enabledElement) {
350
+ return;
351
+ }
352
+ const { viewport } = enabledElement;
353
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
354
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
355
+ const instance = new this();
356
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
357
+ const annotation = {
358
+ annotationUID: options?.annotationUID || utilities.uuidv4(),
359
+ data: {
360
+ handles: {
361
+ points,
362
+ },
363
+ },
364
+ highlighted: false,
365
+ autoGenerated: false,
366
+ invalidated: false,
367
+ isLocked: false,
368
+ isVisible: true,
369
+ metadata: {
370
+ toolName: instance.getToolName(),
371
+ viewPlaneNormal,
372
+ FrameOfReferenceUID,
373
+ referencedImageId,
374
+ ...options,
375
+ },
376
+ };
377
+ addAnnotation(annotation, viewport.element);
378
+ triggerAnnotationRenderForViewportIds([viewport.id]);
379
+ }; }
347
380
  handleSelectedCallback(evt, annotation, handle) {
348
381
  const eventDetail = evt.detail;
349
382
  const { element } = eventDetail;
@@ -18,6 +18,9 @@ declare class ProbeTool extends AnnotationTool {
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
19
  isPointNearTool(): boolean;
20
20
  toolSelectedCallback(): void;
21
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
22
+ annotationUID?: string;
23
+ }) => ProbeAnnotation;
21
24
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => ProbeAnnotation;
22
25
  getHandleNearImagePoint(element: HTMLDivElement, annotation: ProbeAnnotation, canvasCoords: Types.Point2, proximity: number): ToolHandle | undefined;
23
26
  handleSelectedCallback(evt: EventTypes.InteractionEventType, annotation: ProbeAnnotation): void;
@@ -1,5 +1,5 @@
1
1
  import { vec2, vec3 } from 'gl-matrix';
2
- import { getEnabledElement, VolumeViewport, utilities as csUtils, } from '@cornerstonejs/core';
2
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { AnnotationTool } from '../base';
4
4
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
5
5
  import { triggerAnnotationCompleted, triggerAnnotationModified, } from '../../stateManagement/annotation/helpers/state';
@@ -220,6 +220,39 @@ class ProbeTool extends AnnotationTool {
220
220
  return false;
221
221
  }
222
222
  toolSelectedCallback() { }
223
+ static { this.hydrate = (viewportId, points, options) => {
224
+ const enabledElement = getEnabledElementByViewportId(viewportId);
225
+ if (!enabledElement) {
226
+ return;
227
+ }
228
+ const { viewport } = enabledElement;
229
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
230
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
231
+ const instance = new this();
232
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
233
+ const annotation = {
234
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
235
+ data: {
236
+ handles: {
237
+ points,
238
+ },
239
+ },
240
+ highlighted: false,
241
+ autoGenerated: false,
242
+ invalidated: false,
243
+ isLocked: false,
244
+ isVisible: true,
245
+ metadata: {
246
+ toolName: instance.getToolName(),
247
+ viewPlaneNormal,
248
+ FrameOfReferenceUID,
249
+ referencedImageId,
250
+ ...options,
251
+ },
252
+ };
253
+ addAnnotation(annotation, viewport.element);
254
+ triggerAnnotationRenderForViewportIds([viewport.id]);
255
+ }; }
223
256
  getHandleNearImagePoint(element, annotation, canvasCoords, proximity) {
224
257
  const enabledElement = getEnabledElement(element);
225
258
  const { viewport } = enabledElement;
@@ -36,5 +36,8 @@ declare class RectangleROITool extends AnnotationTool {
36
36
  };
37
37
  _calculateCachedStats: (annotation: any, viewPlaneNormal: any, viewUp: any, renderingEngine: any, enabledElement: any) => any;
38
38
  _isInsideVolume: (index1: any, index2: any, dimensions: any) => boolean;
39
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
40
+ annotationUID?: string;
41
+ }) => RectangleROIAnnotation;
39
42
  }
40
43
  export default RectangleROITool;
@@ -1,5 +1,5 @@
1
1
  import { AnnotationTool } from '../base';
2
- import { getEnabledElement, VolumeViewport, utilities as csUtils, } from '@cornerstonejs/core';
2
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits';
4
4
  import throttle from '../../utilities/throttle';
5
5
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement';
@@ -529,6 +529,42 @@ class RectangleROITool extends AnnotationTool {
529
529
  };
530
530
  this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
531
531
  }
532
+ static { this.hydrate = (viewportId, points, options) => {
533
+ const enabledElement = getEnabledElementByViewportId(viewportId);
534
+ if (!enabledElement) {
535
+ return;
536
+ }
537
+ const { viewport } = enabledElement;
538
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
539
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
540
+ const instance = new this();
541
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
542
+ const annotation = {
543
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
544
+ data: {
545
+ handles: {
546
+ points,
547
+ activeHandleIndex: null,
548
+ },
549
+ label: '',
550
+ cachedStats: {},
551
+ },
552
+ highlighted: false,
553
+ autoGenerated: false,
554
+ invalidated: false,
555
+ isLocked: false,
556
+ isVisible: true,
557
+ metadata: {
558
+ toolName: instance.getToolName(),
559
+ viewPlaneNormal,
560
+ FrameOfReferenceUID,
561
+ referencedImageId,
562
+ ...options,
563
+ },
564
+ };
565
+ addAnnotation(annotation, viewport.element);
566
+ triggerAnnotationRenderForViewportIds([viewport.id]);
567
+ }; }
532
568
  }
533
569
  function defaultGetTextLines(data, targetId) {
534
570
  const cachedVolumeStats = data.cachedStats[targetId];
@@ -65,5 +65,9 @@ declare class SplineROITool extends ContourSegmentationBaseTool {
65
65
  private _getSplineConfig;
66
66
  private _updateSplineInstance;
67
67
  private _calculateCachedStats;
68
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
69
+ annotationUID?: string;
70
+ splineType?: SplineTypesEnum;
71
+ }) => SplineROIAnnotation;
68
72
  }
69
73
  export default SplineROITool;
@@ -1,6 +1,6 @@
1
- import { getEnabledElement, eventTarget, triggerEvent, utilities, } from '@cornerstonejs/core';
1
+ import { getEnabledElement, eventTarget, triggerEvent, utilities, getEnabledElementByViewportId, } from '@cornerstonejs/core';
2
2
  import { vec3 } from 'gl-matrix';
3
- import { getChildAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
3
+ import { addAnnotation, getChildAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
4
4
  import { drawHandles as drawHandlesSvg, drawPolyline as drawPolylineSvg, drawLinkedTextBox as drawLinkedTextBoxSvg, } from '../../drawingSvg';
5
5
  import { state } from '../../store/state';
6
6
  import { Events, MouseBindings, KeyboardBindings, ChangeTypes, } from '../../enums';
@@ -116,8 +116,6 @@ class SplineROITool extends ContourSegmentationBaseTool {
116
116
  viewportIdsToRender,
117
117
  movingTextBox: false,
118
118
  };
119
- const enabledElement = getEnabledElement(element);
120
- const { renderingEngine } = enabledElement;
121
119
  this._activateModify(element);
122
120
  triggerAnnotationRenderForViewportIds(viewportIdsToRender);
123
121
  evt.preventDefault();
@@ -711,6 +709,61 @@ class SplineROITool extends ContourSegmentationBaseTool {
711
709
  }
712
710
  return spline;
713
711
  }
712
+ static { this.hydrate = (viewportId, points, options) => {
713
+ const enabledElement = getEnabledElementByViewportId(viewportId);
714
+ if (!enabledElement) {
715
+ return;
716
+ }
717
+ if (points.length < SPLINE_MIN_POINTS) {
718
+ console.warn('Spline requires at least 3 control points');
719
+ return;
720
+ }
721
+ const { viewport } = enabledElement;
722
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
723
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
724
+ const instance = new this();
725
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
726
+ const splineType = options?.splineType || SplineTypesEnum.CatmullRom;
727
+ const splineConfig = instance._getSplineConfig(splineType);
728
+ const SplineClass = splineConfig.Class;
729
+ const splineInstance = new SplineClass();
730
+ const canvasPoints = points.map((point) => viewport.worldToCanvas(point));
731
+ splineInstance.setControlPoints(canvasPoints);
732
+ const splinePolylineCanvas = splineInstance.getPolylinePoints();
733
+ const splinePolylineWorld = splinePolylineCanvas.map((point) => viewport.canvasToWorld(point));
734
+ const annotation = {
735
+ annotationUID: options?.annotationUID || utilities.uuidv4(),
736
+ data: {
737
+ handles: {
738
+ points,
739
+ },
740
+ label: '',
741
+ cachedStats: {},
742
+ spline: {
743
+ type: splineType,
744
+ instance: splineInstance,
745
+ },
746
+ contour: {
747
+ closed: true,
748
+ polyline: splinePolylineWorld,
749
+ },
750
+ },
751
+ highlighted: false,
752
+ autoGenerated: false,
753
+ invalidated: true,
754
+ isLocked: false,
755
+ isVisible: true,
756
+ metadata: {
757
+ toolName: instance.getToolName(),
758
+ viewPlaneNormal,
759
+ FrameOfReferenceUID,
760
+ referencedImageId,
761
+ ...options,
762
+ },
763
+ };
764
+ addAnnotation(annotation, viewport.element);
765
+ triggerAnnotationRenderForViewportIds([viewport.id]);
766
+ }; }
714
767
  }
715
768
  function defaultGetTextLines(data, targetId) {
716
769
  const cachedVolumeStats = data.cachedStats[targetId];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.2.18",
3
+ "version": "2.2.20",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.2.18",
107
+ "@cornerstonejs/core": "^2.2.20",
108
108
  "@kitware/vtk.js": "32.1.1",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "3e486c530e2b20c8f1368f5c3e62dd4e59510700"
126
+ "gitHead": "94477145875a9cd4b23d0f6f7b822f8dbba56ee6"
127
127
  }