@cornerstonejs/tools 0.12.0 → 0.14.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.
- package/dist/cjs/cursors/SVGMouseCursor.js +2 -2
- package/dist/cjs/cursors/SVGMouseCursor.js.map +1 -1
- package/dist/cjs/drawingSvg/drawArrow.js +0 -2
- package/dist/cjs/drawingSvg/drawArrow.js.map +1 -1
- package/dist/cjs/drawingSvg/drawTextBox.js +9 -0
- package/dist/cjs/drawingSvg/drawTextBox.js.map +1 -1
- package/dist/cjs/enums/ToolBindings.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +5 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/stateManagement/annotation/config/ToolStyle.d.ts +18 -0
- package/dist/cjs/stateManagement/annotation/config/ToolStyle.js +129 -0
- package/dist/cjs/stateManagement/annotation/config/ToolStyle.js.map +1 -0
- package/dist/cjs/stateManagement/annotation/config/getFont.d.ts +2 -2
- package/dist/cjs/stateManagement/annotation/config/getFont.js +4 -6
- package/dist/cjs/stateManagement/annotation/config/getFont.js.map +1 -1
- package/dist/cjs/stateManagement/annotation/config/helpers.d.ts +4 -0
- package/dist/cjs/stateManagement/annotation/config/helpers.js +26 -0
- package/dist/cjs/stateManagement/annotation/config/helpers.js.map +1 -0
- package/dist/cjs/stateManagement/annotation/config/index.d.ts +2 -5
- package/dist/cjs/stateManagement/annotation/config/index.js +3 -9
- package/dist/cjs/stateManagement/annotation/config/index.js.map +1 -1
- package/dist/cjs/stateManagement/index.d.ts +1 -4
- package/dist/cjs/stateManagement/index.js +1 -10
- package/dist/cjs/stateManagement/index.js.map +1 -1
- package/dist/cjs/tools/MagnifyTool.d.ts +24 -0
- package/dist/cjs/tools/MagnifyTool.js +169 -0
- package/dist/cjs/tools/MagnifyTool.js.map +1 -0
- package/dist/cjs/tools/annotation/AngleTool.d.ts +37 -0
- package/dist/cjs/tools/annotation/AngleTool.js +442 -0
- package/dist/cjs/tools/annotation/AngleTool.js.map +1 -0
- package/dist/cjs/tools/annotation/{ArrowTool.d.ts → ArrowAnnotateTool.d.ts} +2 -2
- package/dist/cjs/tools/annotation/{ArrowTool.js → ArrowAnnotateTool.js} +16 -11
- package/dist/cjs/tools/annotation/ArrowAnnotateTool.js.map +1 -0
- package/dist/cjs/tools/annotation/BidirectionalTool.js +11 -8
- package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/cjs/tools/annotation/DragProbeTool.d.ts +23 -0
- package/dist/cjs/tools/annotation/DragProbeTool.js +109 -0
- package/dist/cjs/tools/annotation/DragProbeTool.js.map +1 -0
- package/dist/cjs/tools/annotation/EllipticalROITool.js +42 -30
- package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/LengthTool.js +11 -8
- package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +0 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/ProbeTool.js +8 -4
- package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js +11 -8
- package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js +16 -10
- package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
- package/dist/cjs/tools/base/AnnotationTool.d.ts +3 -3
- package/dist/cjs/tools/base/AnnotationTool.js +10 -10
- package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
- package/dist/cjs/tools/index.d.ts +5 -2
- package/dist/cjs/tools/index.js +9 -3
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js +10 -7
- package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js +10 -7
- package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/RectangleScissorsTool.js +0 -3
- package/dist/cjs/tools/segmentation/RectangleScissorsTool.js.map +1 -1
- package/dist/cjs/types/AnnotationStyle.d.ts +29 -0
- package/dist/cjs/types/AnnotationStyle.js +3 -0
- package/dist/cjs/types/AnnotationStyle.js.map +1 -0
- package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +24 -0
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/utilities/math/angle/angleBetweenLines.d.ts +4 -0
- package/dist/cjs/utilities/math/angle/angleBetweenLines.js +17 -0
- package/dist/cjs/utilities/math/angle/angleBetweenLines.js.map +1 -0
- package/dist/cjs/utilities/viewportFilters/filterViewportsWithToolEnabled.js +3 -0
- package/dist/cjs/utilities/viewportFilters/filterViewportsWithToolEnabled.js.map +1 -1
- package/dist/esm/cursors/SVGMouseCursor.js +2 -2
- package/dist/esm/cursors/SVGMouseCursor.js.map +1 -1
- package/dist/esm/drawingSvg/drawArrow.js +0 -2
- package/dist/esm/drawingSvg/drawArrow.js.map +1 -1
- package/dist/esm/drawingSvg/drawTextBox.js +9 -0
- package/dist/esm/drawingSvg/drawTextBox.js.map +1 -1
- package/dist/esm/enums/ToolBindings.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stateManagement/annotation/config/ToolStyle.d.ts +18 -0
- package/dist/esm/stateManagement/annotation/config/ToolStyle.js +136 -0
- package/dist/esm/stateManagement/annotation/config/ToolStyle.js.map +1 -0
- package/dist/esm/stateManagement/annotation/config/getFont.d.ts +2 -2
- package/dist/esm/stateManagement/annotation/config/getFont.js +4 -6
- package/dist/esm/stateManagement/annotation/config/getFont.js.map +1 -1
- package/dist/esm/stateManagement/annotation/config/helpers.d.ts +4 -0
- package/dist/esm/stateManagement/annotation/config/helpers.js +20 -0
- package/dist/esm/stateManagement/annotation/config/helpers.js.map +1 -0
- package/dist/esm/stateManagement/annotation/config/index.d.ts +2 -5
- package/dist/esm/stateManagement/annotation/config/index.js +2 -5
- package/dist/esm/stateManagement/annotation/config/index.js.map +1 -1
- package/dist/esm/stateManagement/index.d.ts +1 -4
- package/dist/esm/stateManagement/index.js +1 -4
- package/dist/esm/stateManagement/index.js.map +1 -1
- package/dist/esm/tools/MagnifyTool.d.ts +24 -0
- package/dist/esm/tools/MagnifyTool.js +163 -0
- package/dist/esm/tools/MagnifyTool.js.map +1 -0
- package/dist/esm/tools/annotation/AngleTool.d.ts +37 -0
- package/dist/esm/tools/annotation/AngleTool.js +417 -0
- package/dist/esm/tools/annotation/AngleTool.js.map +1 -0
- package/dist/esm/tools/annotation/{ArrowTool.d.ts → ArrowAnnotateTool.d.ts} +2 -2
- package/dist/esm/tools/annotation/{ArrowTool.js → ArrowAnnotateTool.js} +17 -12
- package/dist/esm/tools/annotation/ArrowAnnotateTool.js.map +1 -0
- package/dist/esm/tools/annotation/BidirectionalTool.js +12 -9
- package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/esm/tools/annotation/DragProbeTool.d.ts +23 -0
- package/dist/esm/tools/annotation/DragProbeTool.js +103 -0
- package/dist/esm/tools/annotation/DragProbeTool.js.map +1 -0
- package/dist/esm/tools/annotation/EllipticalROITool.js +43 -31
- package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/esm/tools/annotation/LengthTool.js +12 -9
- package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +1 -2
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/ProbeTool.js +9 -5
- package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js +12 -9
- package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js +16 -10
- package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
- package/dist/esm/tools/base/AnnotationTool.d.ts +3 -3
- package/dist/esm/tools/base/AnnotationTool.js +10 -10
- package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
- package/dist/esm/tools/index.d.ts +5 -2
- package/dist/esm/tools/index.js +5 -2
- package/dist/esm/tools/index.js.map +1 -1
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +11 -8
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
- package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js +11 -8
- package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
- package/dist/esm/tools/segmentation/RectangleScissorsTool.js +1 -4
- package/dist/esm/tools/segmentation/RectangleScissorsTool.js.map +1 -1
- package/dist/esm/types/AnnotationStyle.d.ts +29 -0
- package/dist/esm/types/AnnotationStyle.js +2 -0
- package/dist/esm/types/AnnotationStyle.js.map +1 -0
- package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +24 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utilities/math/angle/angleBetweenLines.d.ts +4 -0
- package/dist/esm/utilities/math/angle/angleBetweenLines.js +14 -0
- package/dist/esm/utilities/math/angle/angleBetweenLines.js.map +1 -0
- package/dist/esm/utilities/viewportFilters/filterViewportsWithToolEnabled.js +3 -0
- package/dist/esm/utilities/viewportFilters/filterViewportsWithToolEnabled.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/stateManagement/annotation/config/annotationStyle.d.ts +0 -5
- package/dist/cjs/stateManagement/annotation/config/annotationStyle.js +0 -74
- package/dist/cjs/stateManagement/annotation/config/annotationStyle.js.map +0 -1
- package/dist/cjs/stateManagement/annotation/config/getStyle.d.ts +0 -2
- package/dist/cjs/stateManagement/annotation/config/getStyle.js +0 -22
- package/dist/cjs/stateManagement/annotation/config/getStyle.js.map +0 -1
- package/dist/cjs/stateManagement/annotation/config/setAnnotationStyle.d.ts +0 -2
- package/dist/cjs/stateManagement/annotation/config/setAnnotationStyle.js +0 -17
- package/dist/cjs/stateManagement/annotation/config/setAnnotationStyle.js.map +0 -1
- package/dist/cjs/stateManagement/annotation/config/setGlobalStyle.d.ts +0 -1
- package/dist/cjs/stateManagement/annotation/config/setGlobalStyle.js +0 -8
- package/dist/cjs/stateManagement/annotation/config/setGlobalStyle.js.map +0 -1
- package/dist/cjs/stateManagement/annotation/config/setToolStyle.d.ts +0 -1
- package/dist/cjs/stateManagement/annotation/config/setToolStyle.js +0 -17
- package/dist/cjs/stateManagement/annotation/config/setToolStyle.js.map +0 -1
- package/dist/cjs/tools/annotation/ArrowTool.js.map +0 -1
- package/dist/esm/stateManagement/annotation/config/annotationStyle.d.ts +0 -5
- package/dist/esm/stateManagement/annotation/config/annotationStyle.js +0 -70
- package/dist/esm/stateManagement/annotation/config/annotationStyle.js.map +0 -1
- package/dist/esm/stateManagement/annotation/config/getStyle.d.ts +0 -2
- package/dist/esm/stateManagement/annotation/config/getStyle.js +0 -16
- package/dist/esm/stateManagement/annotation/config/getStyle.js.map +0 -1
- package/dist/esm/stateManagement/annotation/config/setAnnotationStyle.d.ts +0 -2
- package/dist/esm/stateManagement/annotation/config/setAnnotationStyle.js +0 -12
- package/dist/esm/stateManagement/annotation/config/setAnnotationStyle.js.map +0 -1
- package/dist/esm/stateManagement/annotation/config/setGlobalStyle.d.ts +0 -1
- package/dist/esm/stateManagement/annotation/config/setGlobalStyle.js +0 -5
- package/dist/esm/stateManagement/annotation/config/setGlobalStyle.js.map +0 -1
- package/dist/esm/stateManagement/annotation/config/setToolStyle.d.ts +0 -1
- package/dist/esm/stateManagement/annotation/config/setToolStyle.js +0 -11
- package/dist/esm/stateManagement/annotation/config/setToolStyle.js.map +0 -1
- package/dist/esm/tools/annotation/ArrowTool.js.map +0 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const base_1 = require("./base");
|
|
7
|
+
const enums_1 = require("../enums");
|
|
8
|
+
const core_1 = require("@cornerstonejs/core");
|
|
9
|
+
const viewportFilters_1 = require("../utilities/viewportFilters");
|
|
10
|
+
const triggerAnnotationRenderForViewportIds_1 = __importDefault(require("../utilities/triggerAnnotationRenderForViewportIds"));
|
|
11
|
+
const store_1 = require("../store");
|
|
12
|
+
const core_2 = require("@cornerstonejs/core");
|
|
13
|
+
const elementCursor_1 = require("../cursors/elementCursor");
|
|
14
|
+
const MAGNIFY_VIEWPORT_ID = 'maginify-viewport';
|
|
15
|
+
class MagnifyTool extends base_1.BaseTool {
|
|
16
|
+
constructor(toolProps = {}, defaultToolProps = {
|
|
17
|
+
supportedInteractionTypes: ['Mouse', 'Touch'],
|
|
18
|
+
configuration: {
|
|
19
|
+
magnifySize: 10,
|
|
20
|
+
magnifyWidth: 250,
|
|
21
|
+
magnifyHeight: 250,
|
|
22
|
+
},
|
|
23
|
+
}) {
|
|
24
|
+
super(toolProps, defaultToolProps);
|
|
25
|
+
this.preMouseDownCallback = (evt) => {
|
|
26
|
+
const eventDetail = evt.detail;
|
|
27
|
+
const { currentPoints, element } = eventDetail;
|
|
28
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
29
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
30
|
+
if (!(viewport instanceof core_1.StackViewport)) {
|
|
31
|
+
throw new Error('MagnifyTool only works on StackViewports');
|
|
32
|
+
}
|
|
33
|
+
const referencedImageId = this._getReferencedImageId(viewport);
|
|
34
|
+
if (!referencedImageId) {
|
|
35
|
+
throw new Error('MagnifyTool: No referenced image id found, reconstructed planes not supported yet');
|
|
36
|
+
}
|
|
37
|
+
const viewportIdsToRender = (0, viewportFilters_1.getViewportIdsWithToolToRender)(element, this.getToolName());
|
|
38
|
+
this.editData = {
|
|
39
|
+
referencedImageId,
|
|
40
|
+
viewportIdsToRender,
|
|
41
|
+
enabledElement,
|
|
42
|
+
renderingEngine,
|
|
43
|
+
currentPoints,
|
|
44
|
+
};
|
|
45
|
+
this._createMagnificationViewport();
|
|
46
|
+
this._activateDraw(element);
|
|
47
|
+
(0, elementCursor_1.hideElementCursor)(element);
|
|
48
|
+
evt.preventDefault();
|
|
49
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
50
|
+
return true;
|
|
51
|
+
};
|
|
52
|
+
this._createMagnificationViewport = () => {
|
|
53
|
+
const { enabledElement, referencedImageId, viewportIdsToRender, renderingEngine, currentPoints, } = this.editData;
|
|
54
|
+
const { viewport } = enabledElement;
|
|
55
|
+
const { element } = viewport;
|
|
56
|
+
const { voiRange } = viewport.getProperties();
|
|
57
|
+
const { canvas: canvasPos, world: worldPos } = currentPoints;
|
|
58
|
+
let magnifyToolElement;
|
|
59
|
+
magnifyToolElement = element.querySelector('.magnifyTool');
|
|
60
|
+
if (magnifyToolElement === null) {
|
|
61
|
+
const magnifyElement = document.createElement('div');
|
|
62
|
+
magnifyElement.classList.add('magnifyTool');
|
|
63
|
+
magnifyElement.style.display = 'block';
|
|
64
|
+
magnifyElement.style.width = `${this.configuration.magnifyWidth}px`;
|
|
65
|
+
magnifyElement.style.height = `${this.configuration.magnifyHeight}px`;
|
|
66
|
+
magnifyElement.style.position = 'absolute';
|
|
67
|
+
magnifyToolElement = magnifyElement;
|
|
68
|
+
const viewportElement = element.querySelector('.viewport-element');
|
|
69
|
+
viewportElement.appendChild(magnifyElement);
|
|
70
|
+
const viewportInput = {
|
|
71
|
+
viewportId: MAGNIFY_VIEWPORT_ID,
|
|
72
|
+
type: core_2.Enums.ViewportType.STACK,
|
|
73
|
+
element: magnifyToolElement,
|
|
74
|
+
};
|
|
75
|
+
renderingEngine.enableElement(viewportInput);
|
|
76
|
+
}
|
|
77
|
+
magnifyToolElement.style.top = `${canvasPos[1] - this.configuration.magnifyHeight / 2}px`;
|
|
78
|
+
magnifyToolElement.style.left = `${canvasPos[0] - this.configuration.magnifyWidth / 2}px`;
|
|
79
|
+
const magnifyViewport = renderingEngine.getViewport(MAGNIFY_VIEWPORT_ID);
|
|
80
|
+
magnifyViewport.setStack([referencedImageId]).then(() => {
|
|
81
|
+
magnifyViewport.setProperties({ voiRange });
|
|
82
|
+
const { parallelScale } = viewport.getCamera();
|
|
83
|
+
const { focalPoint, position, viewPlaneNormal } = magnifyViewport.getCamera();
|
|
84
|
+
const distance = Math.sqrt(Math.pow(focalPoint[0] - position[0], 2) +
|
|
85
|
+
Math.pow(focalPoint[1] - position[1], 2) +
|
|
86
|
+
Math.pow(focalPoint[2] - position[2], 2));
|
|
87
|
+
const updatedFocalPoint = [
|
|
88
|
+
worldPos[0],
|
|
89
|
+
worldPos[1],
|
|
90
|
+
worldPos[2],
|
|
91
|
+
];
|
|
92
|
+
const updatedPosition = [
|
|
93
|
+
updatedFocalPoint[0] + distance * viewPlaneNormal[0],
|
|
94
|
+
updatedFocalPoint[1] + distance * viewPlaneNormal[1],
|
|
95
|
+
updatedFocalPoint[2] + distance * viewPlaneNormal[2],
|
|
96
|
+
];
|
|
97
|
+
magnifyViewport.setCamera({
|
|
98
|
+
parallelScale: parallelScale * (1 / this.configuration.magnifySize),
|
|
99
|
+
focalPoint: updatedFocalPoint,
|
|
100
|
+
position: updatedPosition,
|
|
101
|
+
});
|
|
102
|
+
magnifyViewport.render();
|
|
103
|
+
});
|
|
104
|
+
magnifyToolElement.style.display = 'block';
|
|
105
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
106
|
+
};
|
|
107
|
+
this._mouseDragCallback = (evt) => {
|
|
108
|
+
const eventDetail = evt.detail;
|
|
109
|
+
const { currentPoints, deltaPoints, element } = eventDetail;
|
|
110
|
+
const deltaPointsWorld = deltaPoints.world;
|
|
111
|
+
const canvasPos = currentPoints.canvas;
|
|
112
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
113
|
+
const { renderingEngine } = enabledElement;
|
|
114
|
+
const magnifyViewport = renderingEngine.getViewport(MAGNIFY_VIEWPORT_ID);
|
|
115
|
+
const magnifyElement = element.querySelector('.magnifyTool');
|
|
116
|
+
if (!magnifyElement) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
magnifyElement.style.top = `${canvasPos[1] - this.configuration.magnifyHeight / 2}px`;
|
|
120
|
+
magnifyElement.style.left = `${canvasPos[0] - this.configuration.magnifyWidth / 2}px`;
|
|
121
|
+
const { focalPoint, position } = magnifyViewport.getCamera();
|
|
122
|
+
const updatedPosition = [
|
|
123
|
+
position[0] + deltaPointsWorld[0],
|
|
124
|
+
position[1] + deltaPointsWorld[1],
|
|
125
|
+
position[2] + deltaPointsWorld[2],
|
|
126
|
+
];
|
|
127
|
+
const updatedFocalPoint = [
|
|
128
|
+
focalPoint[0] + deltaPointsWorld[0],
|
|
129
|
+
focalPoint[1] + deltaPointsWorld[1],
|
|
130
|
+
focalPoint[2] + deltaPointsWorld[2],
|
|
131
|
+
];
|
|
132
|
+
magnifyViewport.setCamera({
|
|
133
|
+
focalPoint: updatedFocalPoint,
|
|
134
|
+
position: updatedPosition,
|
|
135
|
+
});
|
|
136
|
+
magnifyViewport.render();
|
|
137
|
+
};
|
|
138
|
+
this._mouseUpCallback = (evt) => {
|
|
139
|
+
const { element } = evt.detail;
|
|
140
|
+
const magnifyToolElement = element.querySelector('.magnifyTool');
|
|
141
|
+
magnifyToolElement.style.display = 'none';
|
|
142
|
+
this._deactivateDraw(element);
|
|
143
|
+
(0, elementCursor_1.resetElementCursor)(element);
|
|
144
|
+
};
|
|
145
|
+
this._activateDraw = (element) => {
|
|
146
|
+
store_1.state.isInteractingWithTool = true;
|
|
147
|
+
element.addEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
148
|
+
element.addEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
149
|
+
element.addEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
150
|
+
};
|
|
151
|
+
this._deactivateDraw = (element) => {
|
|
152
|
+
store_1.state.isInteractingWithTool = false;
|
|
153
|
+
element.removeEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
154
|
+
element.removeEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
155
|
+
element.removeEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
_getReferencedImageId(viewport) {
|
|
159
|
+
const targetId = this.getTargetId(viewport);
|
|
160
|
+
let referencedImageId;
|
|
161
|
+
if (viewport instanceof core_1.StackViewport) {
|
|
162
|
+
referencedImageId = targetId.split('imageId:')[1];
|
|
163
|
+
}
|
|
164
|
+
return referencedImageId;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.default = MagnifyTool;
|
|
168
|
+
MagnifyTool.toolName = 'Magnify';
|
|
169
|
+
//# sourceMappingURL=MagnifyTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MagnifyTool.js","sourceRoot":"","sources":["../../../src/tools/MagnifyTool.ts"],"names":[],"mappings":";;;;;AAAA,iCAAkC;AAClC,oCAAkC;AAElC,8CAAuE;AAGvE,kEAA8E;AAC9E,+HAAuG;AACvG,oCAAiC;AACjC,8CAA4C;AAE5C,4DAGkC;AAGlC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,MAAqB,WAAY,SAAQ,eAAQ;IAY/C,YACE,YAA6B,EAAE,EAC/B,mBAA8B;QAC5B,yBAAyB,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;QAC7C,aAAa,EAAE;YACb,WAAW,EAAE,EAAE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ToolHandle, PublicToolProps, ToolProps, InteractionTypes } from '../../types';
|
|
4
|
+
import { AngleAnnotation } from '../../types/ToolSpecificAnnotationTypes';
|
|
5
|
+
declare class AngleTool extends AnnotationTool {
|
|
6
|
+
static toolName: string;
|
|
7
|
+
touchDragCallback: any;
|
|
8
|
+
mouseDragCallback: any;
|
|
9
|
+
angleStartedNotYetCompleted: boolean;
|
|
10
|
+
_throttledCalculateCachedStats: any;
|
|
11
|
+
editData: {
|
|
12
|
+
annotation: any;
|
|
13
|
+
viewportIdsToRender: string[];
|
|
14
|
+
handleIndex?: number;
|
|
15
|
+
movingTextBox?: boolean;
|
|
16
|
+
newAnnotation?: boolean;
|
|
17
|
+
hasMoved?: boolean;
|
|
18
|
+
} | null;
|
|
19
|
+
isDrawing: boolean;
|
|
20
|
+
isHandleOutsideImage: boolean;
|
|
21
|
+
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
|
|
22
|
+
addNewAnnotation: (evt: EventTypes.MouseDownActivateEventType) => AngleAnnotation;
|
|
23
|
+
isPointNearTool: (element: HTMLDivElement, annotation: AngleAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
|
|
24
|
+
toolSelectedCallback: (evt: EventTypes.MouseDownEventType, annotation: AngleAnnotation, interactionType: InteractionTypes) => void;
|
|
25
|
+
handleSelectedCallback(evt: EventTypes.MouseDownEventType, annotation: AngleAnnotation, handle: ToolHandle, interactionType?: string): void;
|
|
26
|
+
_mouseUpCallback: (evt: EventTypes.MouseUpEventType | EventTypes.MouseClickEventType) => void;
|
|
27
|
+
_mouseDragCallback: (evt: EventTypes.MouseDragEventType | EventTypes.MouseMoveEventType) => void;
|
|
28
|
+
cancel: (element: HTMLDivElement) => any;
|
|
29
|
+
_activateModify: (element: HTMLDivElement) => void;
|
|
30
|
+
_deactivateModify: (element: HTMLDivElement) => void;
|
|
31
|
+
_activateDraw: (element: HTMLDivElement) => void;
|
|
32
|
+
_deactivateDraw: (element: HTMLDivElement) => void;
|
|
33
|
+
renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: any) => void;
|
|
34
|
+
_getTextLines(data: any, targetId: any): string[];
|
|
35
|
+
_calculateCachedStats(annotation: any, renderingEngine: any, enabledElement: any): any;
|
|
36
|
+
}
|
|
37
|
+
export default AngleTool;
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const enums_1 = require("../../enums");
|
|
26
|
+
const core_1 = require("@cornerstonejs/core");
|
|
27
|
+
const base_1 = require("../base");
|
|
28
|
+
const throttle_1 = __importDefault(require("../../utilities/throttle"));
|
|
29
|
+
const annotationState_1 = require("../../stateManagement/annotation/annotationState");
|
|
30
|
+
const annotationLocking_1 = require("../../stateManagement/annotation/annotationLocking");
|
|
31
|
+
const lineSegment = __importStar(require("../../utilities/math/line"));
|
|
32
|
+
const angleBetweenLines_1 = __importDefault(require("../../utilities/math/angle/angleBetweenLines"));
|
|
33
|
+
const drawingSvg_1 = require("../../drawingSvg");
|
|
34
|
+
const store_1 = require("../../store");
|
|
35
|
+
const viewportFilters_1 = require("../../utilities/viewportFilters");
|
|
36
|
+
const drawing_1 = require("../../utilities/drawing");
|
|
37
|
+
const triggerAnnotationRenderForViewportIds_1 = __importDefault(require("../../utilities/triggerAnnotationRenderForViewportIds"));
|
|
38
|
+
const elementCursor_1 = require("../../cursors/elementCursor");
|
|
39
|
+
class AngleTool extends base_1.AnnotationTool {
|
|
40
|
+
constructor(toolProps = {}, defaultToolProps = {
|
|
41
|
+
supportedInteractionTypes: ['Mouse', 'Touch'],
|
|
42
|
+
configuration: {
|
|
43
|
+
shadow: true,
|
|
44
|
+
preventHandleOutsideImage: false,
|
|
45
|
+
},
|
|
46
|
+
}) {
|
|
47
|
+
super(toolProps, defaultToolProps);
|
|
48
|
+
this.addNewAnnotation = (evt) => {
|
|
49
|
+
if (this.angleStartedNotYetCompleted) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.angleStartedNotYetCompleted = true;
|
|
53
|
+
const eventDetail = evt.detail;
|
|
54
|
+
const { currentPoints, element } = eventDetail;
|
|
55
|
+
const worldPos = currentPoints.world;
|
|
56
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
57
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
58
|
+
(0, elementCursor_1.hideElementCursor)(element);
|
|
59
|
+
this.isDrawing = true;
|
|
60
|
+
const camera = viewport.getCamera();
|
|
61
|
+
const { viewPlaneNormal, viewUp } = camera;
|
|
62
|
+
const referencedImageId = this.getReferencedImageId(viewport, worldPos, viewPlaneNormal, viewUp);
|
|
63
|
+
const annotation = {
|
|
64
|
+
highlighted: true,
|
|
65
|
+
invalidated: true,
|
|
66
|
+
metadata: {
|
|
67
|
+
toolName: this.getToolName(),
|
|
68
|
+
viewPlaneNormal: [...viewPlaneNormal],
|
|
69
|
+
viewUp: [...viewUp],
|
|
70
|
+
FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
|
|
71
|
+
referencedImageId,
|
|
72
|
+
},
|
|
73
|
+
data: {
|
|
74
|
+
handles: {
|
|
75
|
+
points: [[...worldPos], [...worldPos]],
|
|
76
|
+
activeHandleIndex: null,
|
|
77
|
+
textBox: {
|
|
78
|
+
hasMoved: false,
|
|
79
|
+
worldPosition: [0, 0, 0],
|
|
80
|
+
worldBoundingBox: {
|
|
81
|
+
topLeft: [0, 0, 0],
|
|
82
|
+
topRight: [0, 0, 0],
|
|
83
|
+
bottomLeft: [0, 0, 0],
|
|
84
|
+
bottomRight: [0, 0, 0],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
label: '',
|
|
89
|
+
cachedStats: {},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
(0, annotationState_1.addAnnotation)(element, annotation);
|
|
93
|
+
const viewportIdsToRender = (0, viewportFilters_1.getViewportIdsWithToolToRender)(element, this.getToolName());
|
|
94
|
+
this.editData = {
|
|
95
|
+
annotation,
|
|
96
|
+
viewportIdsToRender,
|
|
97
|
+
handleIndex: 1,
|
|
98
|
+
movingTextBox: false,
|
|
99
|
+
newAnnotation: true,
|
|
100
|
+
hasMoved: false,
|
|
101
|
+
};
|
|
102
|
+
this._activateDraw(element);
|
|
103
|
+
evt.preventDefault();
|
|
104
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
105
|
+
return annotation;
|
|
106
|
+
};
|
|
107
|
+
this.isPointNearTool = (element, annotation, canvasCoords, proximity) => {
|
|
108
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
109
|
+
const { viewport } = enabledElement;
|
|
110
|
+
const { data } = annotation;
|
|
111
|
+
const [point1, point2, point3] = data.handles.points;
|
|
112
|
+
const canvasPoint1 = viewport.worldToCanvas(point1);
|
|
113
|
+
const canvasPoint2 = viewport.worldToCanvas(point2);
|
|
114
|
+
const canvasPoint3 = viewport.worldToCanvas(point3);
|
|
115
|
+
const line1 = {
|
|
116
|
+
start: {
|
|
117
|
+
x: canvasPoint1[0],
|
|
118
|
+
y: canvasPoint1[1],
|
|
119
|
+
},
|
|
120
|
+
end: {
|
|
121
|
+
x: canvasPoint2[0],
|
|
122
|
+
y: canvasPoint2[1],
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const line2 = {
|
|
126
|
+
start: {
|
|
127
|
+
x: canvasPoint2[0],
|
|
128
|
+
y: canvasPoint2[1],
|
|
129
|
+
},
|
|
130
|
+
end: {
|
|
131
|
+
x: canvasPoint3[0],
|
|
132
|
+
y: canvasPoint3[1],
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
const distanceToPoint = lineSegment.distanceToPoint([line1.start.x, line1.start.y], [line1.end.x, line1.end.y], [canvasCoords[0], canvasCoords[1]]);
|
|
136
|
+
const distanceToPoint2 = lineSegment.distanceToPoint([line2.start.x, line2.start.y], [line2.end.x, line2.end.y], [canvasCoords[0], canvasCoords[1]]);
|
|
137
|
+
if (distanceToPoint <= proximity || distanceToPoint2 <= proximity) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
142
|
+
this.toolSelectedCallback = (evt, annotation, interactionType) => {
|
|
143
|
+
const eventDetail = evt.detail;
|
|
144
|
+
const { element } = eventDetail;
|
|
145
|
+
annotation.highlighted = true;
|
|
146
|
+
const viewportIdsToRender = (0, viewportFilters_1.getViewportIdsWithToolToRender)(element, this.getToolName());
|
|
147
|
+
this.editData = {
|
|
148
|
+
annotation,
|
|
149
|
+
viewportIdsToRender,
|
|
150
|
+
movingTextBox: false,
|
|
151
|
+
};
|
|
152
|
+
this._activateModify(element);
|
|
153
|
+
(0, elementCursor_1.hideElementCursor)(element);
|
|
154
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
155
|
+
const { renderingEngine } = enabledElement;
|
|
156
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
157
|
+
evt.preventDefault();
|
|
158
|
+
};
|
|
159
|
+
this._mouseUpCallback = (evt) => {
|
|
160
|
+
const eventDetail = evt.detail;
|
|
161
|
+
const { element } = eventDetail;
|
|
162
|
+
const { annotation, viewportIdsToRender, newAnnotation, hasMoved } = this.editData;
|
|
163
|
+
const { data } = annotation;
|
|
164
|
+
if (newAnnotation && !hasMoved) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (this.angleStartedNotYetCompleted && data.handles.points.length === 2) {
|
|
168
|
+
this.editData.handleIndex = 2;
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.angleStartedNotYetCompleted = false;
|
|
172
|
+
annotation.highlighted = false;
|
|
173
|
+
data.handles.activeHandleIndex = null;
|
|
174
|
+
this._deactivateModify(element);
|
|
175
|
+
this._deactivateDraw(element);
|
|
176
|
+
(0, elementCursor_1.resetElementCursor)(element);
|
|
177
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
178
|
+
const { renderingEngine } = enabledElement;
|
|
179
|
+
if (this.isHandleOutsideImage &&
|
|
180
|
+
this.configuration.preventHandleOutsideImage) {
|
|
181
|
+
(0, annotationState_1.removeAnnotation)(annotation.annotationUID, element);
|
|
182
|
+
}
|
|
183
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
184
|
+
if (newAnnotation) {
|
|
185
|
+
const eventType = enums_1.Events.ANNOTATION_COMPLETED;
|
|
186
|
+
const eventDetail = {
|
|
187
|
+
annotation,
|
|
188
|
+
};
|
|
189
|
+
(0, core_1.triggerEvent)(core_1.eventTarget, eventType, eventDetail);
|
|
190
|
+
}
|
|
191
|
+
this.editData = null;
|
|
192
|
+
this.isDrawing = false;
|
|
193
|
+
};
|
|
194
|
+
this._mouseDragCallback = (evt) => {
|
|
195
|
+
this.isDrawing = true;
|
|
196
|
+
const eventDetail = evt.detail;
|
|
197
|
+
const { element } = eventDetail;
|
|
198
|
+
const { annotation, viewportIdsToRender, handleIndex, movingTextBox } = this.editData;
|
|
199
|
+
const { data } = annotation;
|
|
200
|
+
if (movingTextBox) {
|
|
201
|
+
const { deltaPoints } = eventDetail;
|
|
202
|
+
const worldPosDelta = deltaPoints.world;
|
|
203
|
+
const { textBox } = data.handles;
|
|
204
|
+
const { worldPosition } = textBox;
|
|
205
|
+
worldPosition[0] += worldPosDelta[0];
|
|
206
|
+
worldPosition[1] += worldPosDelta[1];
|
|
207
|
+
worldPosition[2] += worldPosDelta[2];
|
|
208
|
+
textBox.hasMoved = true;
|
|
209
|
+
}
|
|
210
|
+
else if (handleIndex === undefined) {
|
|
211
|
+
const { deltaPoints } = eventDetail;
|
|
212
|
+
const worldPosDelta = deltaPoints.world;
|
|
213
|
+
const points = data.handles.points;
|
|
214
|
+
points.forEach((point) => {
|
|
215
|
+
point[0] += worldPosDelta[0];
|
|
216
|
+
point[1] += worldPosDelta[1];
|
|
217
|
+
point[2] += worldPosDelta[2];
|
|
218
|
+
});
|
|
219
|
+
annotation.invalidated = true;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const { currentPoints } = eventDetail;
|
|
223
|
+
const worldPos = currentPoints.world;
|
|
224
|
+
data.handles.points[handleIndex] = [...worldPos];
|
|
225
|
+
annotation.invalidated = true;
|
|
226
|
+
}
|
|
227
|
+
this.editData.hasMoved = true;
|
|
228
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
229
|
+
const { renderingEngine } = enabledElement;
|
|
230
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
231
|
+
};
|
|
232
|
+
this.cancel = (element) => {
|
|
233
|
+
if (this.isDrawing) {
|
|
234
|
+
this.isDrawing = false;
|
|
235
|
+
this._deactivateDraw(element);
|
|
236
|
+
this._deactivateModify(element);
|
|
237
|
+
(0, elementCursor_1.resetElementCursor)(element);
|
|
238
|
+
const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
|
|
239
|
+
const { data } = annotation;
|
|
240
|
+
annotation.highlighted = false;
|
|
241
|
+
data.handles.activeHandleIndex = null;
|
|
242
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
243
|
+
const { renderingEngine } = enabledElement;
|
|
244
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
245
|
+
if (newAnnotation) {
|
|
246
|
+
const eventType = enums_1.Events.ANNOTATION_COMPLETED;
|
|
247
|
+
const eventDetail = {
|
|
248
|
+
annotation,
|
|
249
|
+
};
|
|
250
|
+
(0, core_1.triggerEvent)(core_1.eventTarget, eventType, eventDetail);
|
|
251
|
+
}
|
|
252
|
+
this.editData = null;
|
|
253
|
+
return annotation.annotationUID;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
this._activateModify = (element) => {
|
|
257
|
+
store_1.state.isInteractingWithTool = true;
|
|
258
|
+
element.addEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
259
|
+
element.addEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
260
|
+
element.addEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
261
|
+
};
|
|
262
|
+
this._deactivateModify = (element) => {
|
|
263
|
+
store_1.state.isInteractingWithTool = false;
|
|
264
|
+
element.removeEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
265
|
+
element.removeEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
266
|
+
element.removeEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
267
|
+
};
|
|
268
|
+
this._activateDraw = (element) => {
|
|
269
|
+
store_1.state.isInteractingWithTool = true;
|
|
270
|
+
element.addEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
271
|
+
element.addEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
272
|
+
element.addEventListener(enums_1.Events.MOUSE_MOVE, this._mouseDragCallback);
|
|
273
|
+
element.addEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
274
|
+
};
|
|
275
|
+
this._deactivateDraw = (element) => {
|
|
276
|
+
store_1.state.isInteractingWithTool = false;
|
|
277
|
+
element.removeEventListener(enums_1.Events.MOUSE_UP, this._mouseUpCallback);
|
|
278
|
+
element.removeEventListener(enums_1.Events.MOUSE_DRAG, this._mouseDragCallback);
|
|
279
|
+
element.removeEventListener(enums_1.Events.MOUSE_MOVE, this._mouseDragCallback);
|
|
280
|
+
element.removeEventListener(enums_1.Events.MOUSE_CLICK, this._mouseUpCallback);
|
|
281
|
+
};
|
|
282
|
+
this.renderAnnotation = (enabledElement, svgDrawingHelper) => {
|
|
283
|
+
var _a;
|
|
284
|
+
const { viewport } = enabledElement;
|
|
285
|
+
const { element } = viewport;
|
|
286
|
+
let annotations = (0, annotationState_1.getAnnotations)(element, this.getToolName());
|
|
287
|
+
if (!(annotations === null || annotations === void 0 ? void 0 : annotations.length)) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
annotations = this.filterInteractableAnnotationsForElement(element, annotations);
|
|
291
|
+
if (!(annotations === null || annotations === void 0 ? void 0 : annotations.length)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const targetId = this.getTargetId(viewport);
|
|
295
|
+
const renderingEngine = viewport.getRenderingEngine();
|
|
296
|
+
const styleSpecifier = {
|
|
297
|
+
toolGroupId: this.toolGroupId,
|
|
298
|
+
toolName: this.getToolName(),
|
|
299
|
+
viewportId: enabledElement.viewport.id,
|
|
300
|
+
};
|
|
301
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
302
|
+
const annotation = annotations[i];
|
|
303
|
+
const { annotationUID, data } = annotation;
|
|
304
|
+
const { points, activeHandleIndex } = data.handles;
|
|
305
|
+
styleSpecifier.annotationUID = annotationUID;
|
|
306
|
+
const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
|
|
307
|
+
const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
|
|
308
|
+
const color = this.getStyle('color', styleSpecifier, annotation);
|
|
309
|
+
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
|
|
310
|
+
if (!data.cachedStats[targetId]) {
|
|
311
|
+
data.cachedStats[targetId] = {
|
|
312
|
+
angle: null,
|
|
313
|
+
};
|
|
314
|
+
this._calculateCachedStats(annotation, renderingEngine, enabledElement);
|
|
315
|
+
}
|
|
316
|
+
else if (annotation.invalidated) {
|
|
317
|
+
this._throttledCalculateCachedStats(annotation, renderingEngine, enabledElement);
|
|
318
|
+
}
|
|
319
|
+
let activeHandleCanvasCoords;
|
|
320
|
+
if (!(0, annotationLocking_1.isAnnotationLocked)(annotation) &&
|
|
321
|
+
!this.editData &&
|
|
322
|
+
activeHandleIndex !== null) {
|
|
323
|
+
activeHandleCanvasCoords = [canvasCoordinates[activeHandleIndex]];
|
|
324
|
+
}
|
|
325
|
+
if (activeHandleCanvasCoords) {
|
|
326
|
+
const handleGroupUID = '0';
|
|
327
|
+
(0, drawingSvg_1.drawHandles)(svgDrawingHelper, annotationUID, handleGroupUID, canvasCoordinates, {
|
|
328
|
+
color,
|
|
329
|
+
lineDash,
|
|
330
|
+
lineWidth,
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
let lineUID = '1';
|
|
334
|
+
(0, drawingSvg_1.drawLine)(svgDrawingHelper, annotationUID, lineUID, canvasCoordinates[0], canvasCoordinates[1], {
|
|
335
|
+
color,
|
|
336
|
+
width: lineWidth,
|
|
337
|
+
lineDash,
|
|
338
|
+
});
|
|
339
|
+
if (canvasCoordinates.length !== 3) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
lineUID = '2';
|
|
343
|
+
(0, drawingSvg_1.drawLine)(svgDrawingHelper, annotationUID, lineUID, canvasCoordinates[1], canvasCoordinates[2], {
|
|
344
|
+
color,
|
|
345
|
+
width: lineWidth,
|
|
346
|
+
lineDash,
|
|
347
|
+
});
|
|
348
|
+
if (!viewport.getRenderingEngine()) {
|
|
349
|
+
console.warn('Rendering Engine has been destroyed');
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (!((_a = data.cachedStats[targetId]) === null || _a === void 0 ? void 0 : _a.angle)) {
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
const textLines = this._getTextLines(data, targetId);
|
|
356
|
+
if (!data.handles.textBox.hasMoved) {
|
|
357
|
+
const canvasTextBoxCoords = (0, drawing_1.getTextBoxCoordsCanvas)(canvasCoordinates);
|
|
358
|
+
data.handles.textBox.worldPosition =
|
|
359
|
+
viewport.canvasToWorld(canvasTextBoxCoords);
|
|
360
|
+
}
|
|
361
|
+
const textBoxPosition = viewport.worldToCanvas(data.handles.textBox.worldPosition);
|
|
362
|
+
const textBoxUID = '1';
|
|
363
|
+
const boundingBox = (0, drawingSvg_1.drawLinkedTextBox)(svgDrawingHelper, annotationUID, textBoxUID, textLines, textBoxPosition, canvasCoordinates, {}, this.getLinkedTextBoxStyle(styleSpecifier, annotation));
|
|
364
|
+
const { x: left, y: top, width, height } = boundingBox;
|
|
365
|
+
data.handles.textBox.worldBoundingBox = {
|
|
366
|
+
topLeft: viewport.canvasToWorld([left, top]),
|
|
367
|
+
topRight: viewport.canvasToWorld([left + width, top]),
|
|
368
|
+
bottomLeft: viewport.canvasToWorld([left, top + height]),
|
|
369
|
+
bottomRight: viewport.canvasToWorld([left + width, top + height]),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
this._throttledCalculateCachedStats = (0, throttle_1.default)(this._calculateCachedStats, 100, { trailing: true });
|
|
374
|
+
}
|
|
375
|
+
handleSelectedCallback(evt, annotation, handle, interactionType = 'mouse') {
|
|
376
|
+
const eventDetail = evt.detail;
|
|
377
|
+
const { element } = eventDetail;
|
|
378
|
+
const { data } = annotation;
|
|
379
|
+
annotation.highlighted = true;
|
|
380
|
+
let movingTextBox = false;
|
|
381
|
+
let handleIndex;
|
|
382
|
+
if (handle.worldPosition) {
|
|
383
|
+
movingTextBox = true;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
handleIndex = data.handles.points.findIndex((p) => p === handle);
|
|
387
|
+
}
|
|
388
|
+
const viewportIdsToRender = (0, viewportFilters_1.getViewportIdsWithToolToRender)(element, this.getToolName());
|
|
389
|
+
this.editData = {
|
|
390
|
+
annotation,
|
|
391
|
+
viewportIdsToRender,
|
|
392
|
+
handleIndex,
|
|
393
|
+
movingTextBox,
|
|
394
|
+
};
|
|
395
|
+
this._activateModify(element);
|
|
396
|
+
(0, elementCursor_1.hideElementCursor)(element);
|
|
397
|
+
const enabledElement = (0, core_1.getEnabledElement)(element);
|
|
398
|
+
const { renderingEngine } = enabledElement;
|
|
399
|
+
(0, triggerAnnotationRenderForViewportIds_1.default)(renderingEngine, viewportIdsToRender);
|
|
400
|
+
evt.preventDefault();
|
|
401
|
+
}
|
|
402
|
+
_getTextLines(data, targetId) {
|
|
403
|
+
const cachedVolumeStats = data.cachedStats[targetId];
|
|
404
|
+
const { angle } = cachedVolumeStats;
|
|
405
|
+
if (angle === undefined) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const textLines = [`${angle.toFixed(2)} ${String.fromCharCode(176)}`];
|
|
409
|
+
return textLines;
|
|
410
|
+
}
|
|
411
|
+
_calculateCachedStats(annotation, renderingEngine, enabledElement) {
|
|
412
|
+
const data = annotation.data;
|
|
413
|
+
const { viewportId, renderingEngineId } = enabledElement;
|
|
414
|
+
if (data.handles.points.length !== 3) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const worldPos1 = data.handles.points[0];
|
|
418
|
+
const worldPos2 = data.handles.points[1];
|
|
419
|
+
const worldPos3 = data.handles.points[2];
|
|
420
|
+
const { cachedStats } = data;
|
|
421
|
+
const targetIds = Object.keys(cachedStats);
|
|
422
|
+
for (let i = 0; i < targetIds.length; i++) {
|
|
423
|
+
const targetId = targetIds[i];
|
|
424
|
+
const angle = (0, angleBetweenLines_1.default)([worldPos1, worldPos2], [worldPos2, worldPos3]);
|
|
425
|
+
cachedStats[targetId] = {
|
|
426
|
+
angle,
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
annotation.invalidated = false;
|
|
430
|
+
const eventType = enums_1.Events.ANNOTATION_MODIFIED;
|
|
431
|
+
const eventDetail = {
|
|
432
|
+
annotation,
|
|
433
|
+
viewportId,
|
|
434
|
+
renderingEngineId,
|
|
435
|
+
};
|
|
436
|
+
(0, core_1.triggerEvent)(core_1.eventTarget, eventType, eventDetail);
|
|
437
|
+
return cachedStats;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
AngleTool.toolName = 'Angle';
|
|
441
|
+
exports.default = AngleTool;
|
|
442
|
+
//# sourceMappingURL=AngleTool.js.map
|