@cornerstonejs/tools 2.18.9 → 2.19.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.
@@ -47,11 +47,13 @@ function _drawTextGroup(svgDrawingHelper, annotationUID, textUID, textLines = ['
47
47
  };
48
48
  setAttributesIfNecessary(textAttributes, textElement);
49
49
  setAttributesIfNecessary(textGroupAttributes, existingTextGroup);
50
+ existingTextGroup.setAttribute('data-annotation-uid', annotationUID);
50
51
  textGroupBoundingBox = _drawTextBackground(existingTextGroup, background);
51
52
  svgDrawingHelper.setNodeTouched(svgNodeHash);
52
53
  }
53
54
  else {
54
55
  const textGroup = document.createElementNS(svgns, 'g');
56
+ textGroup.setAttribute('data-annotation-uid', annotationUID);
55
57
  textGroup.setAttribute('transform', `translate(${x} ${y})`);
56
58
  const textElement = _createTextElement(svgDrawingHelper, options);
57
59
  for (let i = 0; i < textLines.length; i++) {
@@ -83,6 +85,7 @@ function _createTextElement(svgDrawingHelper, options) {
83
85
  textElement.setAttribute('font-family', fontFamily);
84
86
  textElement.setAttribute('font-size', fontSize);
85
87
  textElement.setAttribute('style', combinedStyle);
88
+ textElement.setAttribute('pointer-events', 'visible');
86
89
  return textElement;
87
90
  }
88
91
  function _createTextSpan(text) {
@@ -11,7 +11,7 @@ import * as Types from './types';
11
11
  import * as annotation from './stateManagement/annotation';
12
12
  import * as segmentation from './stateManagement/segmentation';
13
13
  import * as splines from './tools/annotation/splines';
14
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool } from './tools';
14
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool } from './tools';
15
15
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
16
16
  import * as Enums from './enums';
17
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, };
17
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, };
package/dist/esm/index.js CHANGED
@@ -11,7 +11,7 @@ import * as Types from './types';
11
11
  import * as annotation from './stateManagement/annotation';
12
12
  import * as segmentation from './stateManagement/segmentation';
13
13
  import * as splines from './tools/annotation/splines';
14
- import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, } from './tools';
14
+ import { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, KeyImageTool, CrosshairsTool, ReferenceLinesTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, OverlayGridTool, SegmentationIntersectionTool, EraserTool, SculptorTool, SegmentSelectTool, WindowLevelRegionTool, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, } from './tools';
15
15
  import VideoRedactionTool from './tools/annotation/VideoRedactionTool';
16
16
  import * as Enums from './enums';
17
- export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, };
17
+ export { VideoRedactionTool, init, destroy, addTool, removeTool, cancelActiveManipulations, BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, ZoomTool, StackScrollTool, PlanarRotateTool, MIPJumpToClickTool, LabelTool, LengthTool, HeightTool, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, SplineContourSegmentationTool, BidirectionalTool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, MagnifyTool, AdvancedMagnifyTool, ReferenceCursors, ScaleOverlayTool, SculptorTool, EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, BrushTool, OrientationMarkerTool, SegmentSelectTool, synchronizers, Synchronizer, SynchronizerManager, PaintFillTool, Types, state, ToolGroupManager, store, Enums, CONSTANTS, drawing, annotation, segmentation, utilities, cursors, VolumeRotateTool, RegionSegmentPlusTool, RegionSegmentTool, WholeBodySegmentTool, LabelmapBaseTool, splines, };
@@ -0,0 +1,35 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { AnnotationTool } from '../base';
3
+ import type { EventTypes, PublicToolProps, ToolProps, SVGDrawingHelper, Annotation, InteractionTypes, ToolHandle } from '../../types';
4
+ import type { LabelAnnotation } from '../../types/ToolSpecificAnnotationTypes';
5
+ declare class LabelTool extends AnnotationTool {
6
+ static toolName: any;
7
+ editData: {
8
+ annotation: Annotation;
9
+ viewportIdsToRender: string[];
10
+ newAnnotation?: boolean;
11
+ hasMoved?: boolean;
12
+ offset: Types.Point3;
13
+ } | null;
14
+ isDrawing: boolean;
15
+ isHandleOutsideImage: boolean;
16
+ constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
17
+ isPointNearTool: (element: HTMLDivElement, annotation: LabelAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
18
+ static hydrate: (viewportId: string, position: Types.Point3, text: string, options?: {
19
+ annotationUID?: string;
20
+ }) => LabelAnnotation;
21
+ addNewAnnotation: (evt: EventTypes.InteractionEventType) => LabelAnnotation;
22
+ handleSelectedCallback(evt: EventTypes.InteractionEventType, annotation: Annotation, handle: ToolHandle, interactionType: InteractionTypes): void;
23
+ toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: LabelAnnotation) => void;
24
+ _endCallback: (evt: EventTypes.InteractionEventType) => void;
25
+ _dragCallback: (evt: EventTypes.InteractionEventType) => void;
26
+ _doneChangingTextCallback(element: any, annotation: any, updatedText: any): void;
27
+ cancel: (element: HTMLDivElement) => string;
28
+ _activateModify: (element: HTMLDivElement) => void;
29
+ _deactivateModify: (element: HTMLDivElement) => void;
30
+ _activateDraw: (element: HTMLDivElement) => void;
31
+ _deactivateDraw: (element: HTMLDivElement) => void;
32
+ renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
33
+ _isInsideVolume(index1: any, index2: any, dimensions: any): boolean;
34
+ }
35
+ export default LabelTool;
@@ -0,0 +1,323 @@
1
+ import { vec2 } from 'gl-matrix';
2
+ import { Events } from '../../enums';
3
+ import { getEnabledElement, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
4
+ import { AnnotationTool } from '../base';
5
+ import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
6
+ import { drawTextBox as drawTextBoxSvg } from '../../drawingSvg';
7
+ import { state } from '../../store/state';
8
+ import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
9
+ import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
10
+ import { triggerAnnotationCompleted, triggerAnnotationModified, } from '../../stateManagement/annotation/helpers/state';
11
+ import { resetElementCursor, hideElementCursor, } from '../../cursors/elementCursor';
12
+ class LabelTool extends AnnotationTool {
13
+ constructor(toolProps = {}, defaultToolProps = {
14
+ supportedInteractionTypes: ['Mouse', 'Touch'],
15
+ configuration: {
16
+ shadow: true,
17
+ getTextCallback,
18
+ changeTextCallback,
19
+ preventHandleOutsideImage: false,
20
+ },
21
+ }) {
22
+ super(toolProps, defaultToolProps);
23
+ this.isPointNearTool = (element, annotation, canvasCoords, proximity) => {
24
+ const enabledElement = getEnabledElement(element);
25
+ const { viewport } = enabledElement;
26
+ const { annotationUID } = annotation;
27
+ const point = annotation.data.handles.points[0];
28
+ const annotationCanvasCoordinate = viewport.worldToCanvas(point);
29
+ const dist = vec2.distance(canvasCoords, annotationCanvasCoordinate);
30
+ if (dist < proximity) {
31
+ return true;
32
+ }
33
+ const svgLayer = element.querySelector('svg');
34
+ if (!svgLayer) {
35
+ return false;
36
+ }
37
+ const textGroup = svgLayer.querySelector(`g[data-annotation-uid="${annotationUID}"]`);
38
+ if (!textGroup) {
39
+ return false;
40
+ }
41
+ const textGroupElement = textGroup;
42
+ const bbox = textGroupElement.getBBox();
43
+ const transform = textGroupElement.getAttribute('transform');
44
+ let translateX = 0;
45
+ let translateY = 0;
46
+ if (transform) {
47
+ const matches = transform.match(/translate\(([-\d.]+)\s+([-\d.]+)\)/);
48
+ if (matches) {
49
+ translateX = parseFloat(matches[1]);
50
+ translateY = parseFloat(matches[2]);
51
+ }
52
+ }
53
+ const x = bbox.x + translateX;
54
+ const y = bbox.y + translateY;
55
+ const isNear = canvasCoords[0] >= x &&
56
+ canvasCoords[0] <= x + bbox.width &&
57
+ canvasCoords[1] >= y &&
58
+ canvasCoords[1] <= y + bbox.height;
59
+ return isNear;
60
+ };
61
+ this.addNewAnnotation = (evt) => {
62
+ const eventDetail = evt.detail;
63
+ const { currentPoints, element } = eventDetail;
64
+ const worldPos = currentPoints.world;
65
+ const enabledElement = getEnabledElement(element);
66
+ const { viewport } = enabledElement;
67
+ hideElementCursor(element);
68
+ this.isDrawing = true;
69
+ const camera = viewport.getCamera();
70
+ const { viewPlaneNormal, viewUp } = camera;
71
+ const referencedImageId = this.getReferencedImageId(viewport, worldPos, viewPlaneNormal, viewUp);
72
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
73
+ const annotation = {
74
+ annotationUID: null,
75
+ highlighted: true,
76
+ invalidated: true,
77
+ metadata: {
78
+ toolName: this.getToolName(),
79
+ viewPlaneNormal: [...viewPlaneNormal],
80
+ viewUp: [...viewUp],
81
+ FrameOfReferenceUID,
82
+ referencedImageId,
83
+ ...viewport.getViewReference({ points: [worldPos] }),
84
+ },
85
+ data: {
86
+ text: '',
87
+ handles: {
88
+ points: [[...worldPos], [...worldPos]],
89
+ },
90
+ label: '',
91
+ },
92
+ };
93
+ addAnnotation(annotation, element);
94
+ const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
95
+ evt.preventDefault();
96
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
97
+ this.configuration.getTextCallback((text) => {
98
+ if (!text) {
99
+ removeAnnotation(annotation.annotationUID);
100
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
101
+ this.isDrawing = false;
102
+ return;
103
+ }
104
+ resetElementCursor(element);
105
+ annotation.data.text = text;
106
+ triggerAnnotationCompleted(annotation);
107
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
108
+ });
109
+ this.createMemo(element, annotation, { newAnnotation: true });
110
+ return annotation;
111
+ };
112
+ this.toolSelectedCallback = (evt, annotation) => {
113
+ const eventDetail = evt.detail;
114
+ const { element, currentPoints } = eventDetail;
115
+ annotation.highlighted = true;
116
+ const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
117
+ let offset = [0, 0, 0];
118
+ if (currentPoints && currentPoints.world) {
119
+ const initialWorldPos = currentPoints.world;
120
+ const anchorWorldPos = annotation.data.handles.points[0];
121
+ offset = [
122
+ anchorWorldPos[0] - initialWorldPos[0],
123
+ anchorWorldPos[1] - initialWorldPos[1],
124
+ anchorWorldPos[2] - initialWorldPos[2],
125
+ ];
126
+ }
127
+ this.editData = {
128
+ annotation,
129
+ viewportIdsToRender,
130
+ offset,
131
+ };
132
+ this._activateModify(element);
133
+ hideElementCursor(element);
134
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
135
+ evt.preventDefault();
136
+ };
137
+ this._endCallback = (evt) => {
138
+ const eventDetail = evt.detail;
139
+ const { element } = eventDetail;
140
+ const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
141
+ this._deactivateDraw(element);
142
+ this._deactivateModify(element);
143
+ resetElementCursor(element);
144
+ if (newAnnotation) {
145
+ this.createMemo(element, annotation, { newAnnotation });
146
+ }
147
+ this.editData = null;
148
+ this.isDrawing = false;
149
+ this.doneEditMemo();
150
+ if (this.isHandleOutsideImage &&
151
+ this.configuration.preventHandleOutsideImage) {
152
+ removeAnnotation(annotation.annotationUID);
153
+ }
154
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
155
+ if (newAnnotation) {
156
+ triggerAnnotationCompleted(annotation);
157
+ }
158
+ };
159
+ this._dragCallback = (evt) => {
160
+ const eventDetail = evt.detail;
161
+ const { currentPoints } = eventDetail;
162
+ const worldPos = currentPoints.world;
163
+ const { annotation, viewportIdsToRender, offset } = this.editData;
164
+ if (offset) {
165
+ annotation.data.handles.points[0] = [
166
+ worldPos[0] + offset[0],
167
+ worldPos[1] + offset[1],
168
+ worldPos[2] + offset[2],
169
+ ];
170
+ }
171
+ else {
172
+ annotation.data.handles.points[0] = [...worldPos];
173
+ }
174
+ annotation.invalidated = true;
175
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
176
+ };
177
+ this.cancel = (element) => {
178
+ if (this.isDrawing) {
179
+ this.isDrawing = false;
180
+ this._deactivateModify(element);
181
+ resetElementCursor(element);
182
+ const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
183
+ const { data } = annotation;
184
+ annotation.highlighted = false;
185
+ data.handles.activeHandleIndex = null;
186
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
187
+ if (newAnnotation) {
188
+ triggerAnnotationCompleted(annotation);
189
+ }
190
+ this.editData = null;
191
+ return annotation.annotationUID;
192
+ }
193
+ };
194
+ this._activateModify = (element) => {
195
+ state.isInteractingWithTool = true;
196
+ element.addEventListener(Events.MOUSE_UP, this._endCallback);
197
+ element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
198
+ element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
199
+ element.addEventListener(Events.TOUCH_TAP, this._endCallback);
200
+ element.addEventListener(Events.TOUCH_END, this._endCallback);
201
+ element.addEventListener(Events.TOUCH_DRAG, this._dragCallback);
202
+ };
203
+ this._deactivateModify = (element) => {
204
+ state.isInteractingWithTool = false;
205
+ element.removeEventListener(Events.MOUSE_UP, this._endCallback);
206
+ element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
207
+ element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
208
+ element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
209
+ element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
210
+ element.removeEventListener(Events.TOUCH_END, this._endCallback);
211
+ };
212
+ this._activateDraw = (element) => {
213
+ state.isInteractingWithTool = true;
214
+ element.addEventListener(Events.MOUSE_UP, this._endCallback);
215
+ element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
216
+ element.addEventListener(Events.MOUSE_MOVE, this._dragCallback);
217
+ element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
218
+ element.addEventListener(Events.TOUCH_TAP, this._endCallback);
219
+ element.addEventListener(Events.TOUCH_END, this._endCallback);
220
+ element.addEventListener(Events.TOUCH_DRAG, this._dragCallback);
221
+ };
222
+ this._deactivateDraw = (element) => {
223
+ state.isInteractingWithTool = false;
224
+ element.removeEventListener(Events.MOUSE_UP, this._endCallback);
225
+ element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
226
+ element.removeEventListener(Events.MOUSE_MOVE, this._dragCallback);
227
+ element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
228
+ element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
229
+ element.removeEventListener(Events.TOUCH_END, this._endCallback);
230
+ element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
231
+ };
232
+ this.renderAnnotation = (enabledElement, svgDrawingHelper) => {
233
+ let renderStatus = false;
234
+ const { viewport } = enabledElement;
235
+ const { element } = viewport;
236
+ let annotations = getAnnotations(this.getToolName(), element);
237
+ if (!annotations?.length) {
238
+ return renderStatus;
239
+ }
240
+ annotations = this.filterInteractableAnnotationsForElement(element, annotations);
241
+ const styleSpecifier = {
242
+ toolGroupId: this.toolGroupId,
243
+ toolName: this.getToolName(),
244
+ viewportId: enabledElement.viewport.id,
245
+ };
246
+ for (let i = 0; i < annotations.length; i++) {
247
+ const annotation = annotations[i];
248
+ const { annotationUID, data } = annotation;
249
+ const point = data.handles.points[0];
250
+ styleSpecifier.annotationUID = annotationUID;
251
+ const canvasCoordinates = viewport.worldToCanvas(point);
252
+ renderStatus = true;
253
+ if (!viewport.getRenderingEngine()) {
254
+ console.warn('Rendering Engine has been destroyed');
255
+ return renderStatus;
256
+ }
257
+ if (!data.text) {
258
+ continue;
259
+ }
260
+ const options = this.getLinkedTextBoxStyle(styleSpecifier, annotation);
261
+ const textBoxUID = '1';
262
+ drawTextBoxSvg(svgDrawingHelper, annotationUID, textBoxUID, [data.text], canvasCoordinates, {
263
+ ...options,
264
+ padding: 0,
265
+ });
266
+ }
267
+ return renderStatus;
268
+ };
269
+ }
270
+ static { this.hydrate = (viewportId, position, text, options) => {
271
+ const enabledElement = getEnabledElementByViewportId(viewportId);
272
+ if (!enabledElement) {
273
+ return;
274
+ }
275
+ const { viewport } = enabledElement;
276
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
277
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
278
+ const instance = new this();
279
+ const referencedImageId = instance.getReferencedImageId(viewport, position, viewPlaneNormal, viewUp);
280
+ const annotation = {
281
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
282
+ data: {
283
+ text,
284
+ handles: {
285
+ points: [position],
286
+ },
287
+ },
288
+ highlighted: false,
289
+ autoGenerated: false,
290
+ invalidated: false,
291
+ isLocked: false,
292
+ isVisible: true,
293
+ metadata: {
294
+ toolName: instance.getToolName(),
295
+ viewPlaneNormal,
296
+ FrameOfReferenceUID,
297
+ referencedImageId,
298
+ ...options,
299
+ },
300
+ };
301
+ addAnnotation(annotation, viewport.element);
302
+ triggerAnnotationRenderForViewportIds([viewport.id]);
303
+ }; }
304
+ handleSelectedCallback(evt, annotation, handle, interactionType) { }
305
+ _doneChangingTextCallback(element, annotation, updatedText) {
306
+ annotation.data.text = updatedText;
307
+ const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
308
+ triggerAnnotationRenderForViewportIds(viewportIdsToRender);
309
+ triggerAnnotationModified(annotation, element);
310
+ }
311
+ _isInsideVolume(index1, index2, dimensions) {
312
+ return (csUtils.indexWithinDimensions(index1, dimensions) &&
313
+ csUtils.indexWithinDimensions(index2, dimensions));
314
+ }
315
+ }
316
+ function getTextCallback(doneChangingTextCallback) {
317
+ return doneChangingTextCallback(prompt('Enter your annotation:'));
318
+ }
319
+ function changeTextCallback(data, eventData, doneChangingTextCallback) {
320
+ return doneChangingTextCallback(prompt('Enter your annotation:'));
321
+ }
322
+ LabelTool.toolName = 'Label';
323
+ export default LabelTool;
@@ -18,6 +18,7 @@ import ScaleOverlayTool from './ScaleOverlayTool';
18
18
  import SculptorTool from './SculptorTool';
19
19
  import VolumeRotateTool from './VolumeRotateTool';
20
20
  import BidirectionalTool from './annotation/BidirectionalTool';
21
+ import LabelTool from './annotation/LabelTool';
21
22
  import LengthTool from './annotation/LengthTool';
22
23
  import HeightTool from './annotation/HeightTool';
23
24
  import ProbeTool from './annotation/ProbeTool';
@@ -53,4 +54,4 @@ import PaintFillTool from './segmentation/PaintFillTool';
53
54
  import OrientationMarkerTool from './OrientationMarkerTool';
54
55
  import SegmentSelectTool from './segmentation/SegmentSelectTool';
55
56
  import * as strategies from './segmentation/strategies';
56
- export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, strategies, };
57
+ export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, strategies, };
@@ -18,6 +18,7 @@ import ScaleOverlayTool from './ScaleOverlayTool';
18
18
  import SculptorTool from './SculptorTool';
19
19
  import VolumeRotateTool from './VolumeRotateTool';
20
20
  import BidirectionalTool from './annotation/BidirectionalTool';
21
+ import LabelTool from './annotation/LabelTool';
21
22
  import LengthTool from './annotation/LengthTool';
22
23
  import HeightTool from './annotation/HeightTool';
23
24
  import ProbeTool from './annotation/ProbeTool';
@@ -53,4 +54,4 @@ import PaintFillTool from './segmentation/PaintFillTool';
53
54
  import OrientationMarkerTool from './OrientationMarkerTool';
54
55
  import SegmentSelectTool from './segmentation/SegmentSelectTool';
55
56
  import * as strategies from './segmentation/strategies';
56
- export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, strategies, };
57
+ export { BaseTool, AnnotationTool, AnnotationDisplayTool, PanTool, TrackballRotateTool, DragProbeTool, WindowLevelTool, WindowLevelRegionTool, StackScrollTool, PlanarRotateTool, ZoomTool, MIPJumpToClickTool, ReferenceCursors, CrosshairsTool, ReferenceLinesTool, OverlayGridTool, SegmentationIntersectionTool, BidirectionalTool, LabelTool, LengthTool, HeightTool, ProbeTool, RectangleROITool, EllipticalROITool, CircleROITool, ETDRSGridTool, SplineROITool, PlanarFreehandROITool, PlanarFreehandContourSegmentationTool, LivewireContourTool, LivewireContourSegmentationTool, ArrowAnnotateTool, AngleTool, CobbAngleTool, UltrasoundDirectionalTool, KeyImageTool, AnnotationEraserTool as EraserTool, RectangleScissorsTool, CircleScissorsTool, SphereScissorsTool, RectangleROIThresholdTool, RectangleROIStartEndThresholdTool, CircleROIStartEndThresholdTool, SplineContourSegmentationTool, BrushTool, MagnifyTool, AdvancedMagnifyTool, PaintFillTool, ScaleOverlayTool, OrientationMarkerTool, SculptorTool, SegmentSelectTool, VolumeRotateTool, RegionSegmentTool, RegionSegmentPlusTool, WholeBodySegmentTool, LabelmapBaseTool, strategies, };
@@ -322,6 +322,14 @@ export interface ArrowAnnotation extends Annotation {
322
322
  };
323
323
  };
324
324
  }
325
+ export interface LabelAnnotation extends Annotation {
326
+ data: {
327
+ text: string;
328
+ handles: {
329
+ points: Types.Point3[];
330
+ };
331
+ };
332
+ }
325
333
  export interface AngleAnnotation extends Annotation {
326
334
  data: {
327
335
  handles: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.18.9",
3
+ "version": "2.19.1",
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.18.9",
107
+ "@cornerstonejs/core": "^2.19.1",
108
108
  "@kitware/vtk.js": "32.9.0",
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": "e3ff43396e9170f4350143ed1f48218c8afb90de"
126
+ "gitHead": "4c1746d12f5f5f15a0e1651330a1aa4f6b72b60e"
127
127
  }