@cornerstonejs/tools 1.34.0 → 1.35.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/eventDispatchers/mouseEventHandlers/mouseDown.js +4 -4
- package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
- package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +3 -2
- package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +4 -0
- package/dist/cjs/tools/AdvancedMagnifyTool.js +8 -3
- package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
- package/dist/cjs/tools/annotation/SplineROITool.d.ts +59 -0
- package/dist/cjs/tools/annotation/SplineROITool.js +709 -0
- package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/BSpline.d.ts +5 -0
- package/dist/cjs/tools/annotation/splines/BSpline.js +14 -0
- package/dist/cjs/tools/annotation/splines/BSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/CardinalSpline.d.ts +12 -0
- package/dist/cjs/tools/annotation/splines/CardinalSpline.js +38 -0
- package/dist/cjs/tools/annotation/splines/CardinalSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/CatmullRomSpline.d.ts +5 -0
- package/dist/cjs/tools/annotation/splines/CatmullRomSpline.js +12 -0
- package/dist/cjs/tools/annotation/splines/CatmullRomSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/CubicSpline.d.ts +13 -0
- package/dist/cjs/tools/annotation/splines/CubicSpline.js +192 -0
- package/dist/cjs/tools/annotation/splines/CubicSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/LinearSpline.d.ts +5 -0
- package/dist/cjs/tools/annotation/splines/LinearSpline.js +12 -0
- package/dist/cjs/tools/annotation/splines/LinearSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/QuadraticBezier.d.ts +6 -0
- package/dist/cjs/tools/annotation/splines/QuadraticBezier.js +20 -0
- package/dist/cjs/tools/annotation/splines/QuadraticBezier.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/QuadraticSpline.d.ts +9 -0
- package/dist/cjs/tools/annotation/splines/QuadraticSpline.js +18 -0
- package/dist/cjs/tools/annotation/splines/QuadraticSpline.js.map +1 -0
- package/dist/cjs/tools/annotation/splines/Spline.d.ts +49 -0
- package/dist/cjs/tools/annotation/splines/Spline.js +420 -0
- package/dist/cjs/tools/annotation/splines/Spline.js.map +1 -0
- package/dist/cjs/tools/index.d.ts +2 -1
- package/dist/cjs/tools/index.js +3 -1
- package/dist/cjs/tools/index.js.map +1 -1
- package/dist/cjs/types/CardinalSplineProps.d.ts +5 -0
- package/dist/cjs/types/CardinalSplineProps.js +3 -0
- package/dist/cjs/types/CardinalSplineProps.js.map +1 -0
- package/dist/cjs/types/ClosestControlPoint.d.ts +4 -0
- package/dist/cjs/types/ClosestControlPoint.js +3 -0
- package/dist/cjs/types/ClosestControlPoint.js.map +1 -0
- package/dist/cjs/types/ClosestPoint.d.ts +5 -0
- package/dist/cjs/types/ClosestPoint.js +3 -0
- package/dist/cjs/types/ClosestPoint.js.map +1 -0
- package/dist/cjs/types/ClosestSplinePoint.d.ts +4 -0
- package/dist/cjs/types/ClosestSplinePoint.js +3 -0
- package/dist/cjs/types/ClosestSplinePoint.js.map +1 -0
- package/dist/cjs/types/ControlPointInfo.d.ts +5 -0
- package/dist/cjs/types/ControlPointInfo.js +3 -0
- package/dist/cjs/types/ControlPointInfo.js.map +1 -0
- package/dist/cjs/types/ISpline.d.ts +29 -0
- package/dist/cjs/types/ISpline.js +3 -0
- package/dist/cjs/types/ISpline.js.map +1 -0
- package/dist/cjs/types/SplineCurveSegment.d.ts +14 -0
- package/dist/cjs/types/SplineCurveSegment.js +3 -0
- package/dist/cjs/types/SplineCurveSegment.js.map +1 -0
- package/dist/cjs/types/SplineLineSegment.d.ts +10 -0
- package/dist/cjs/types/SplineLineSegment.js +3 -0
- package/dist/cjs/types/SplineLineSegment.js.map +1 -0
- package/dist/cjs/types/SplineProps.d.ts +4 -0
- package/dist/cjs/types/SplineProps.js +3 -0
- package/dist/cjs/types/SplineProps.js.map +1 -0
- package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +34 -0
- package/dist/cjs/types/index.d.ts +10 -1
- package/dist/cjs/utilities/index.d.ts +2 -3
- package/dist/cjs/utilities/index.js +5 -5
- package/dist/cjs/utilities/index.js.map +1 -1
- package/dist/cjs/utilities/math/aabb/distanceToPoint.d.ts +2 -0
- package/dist/cjs/utilities/math/aabb/distanceToPoint.js +11 -0
- package/dist/cjs/utilities/math/aabb/distanceToPoint.js.map +1 -0
- package/dist/cjs/utilities/math/aabb/distanceToPointSquared.d.ts +2 -0
- package/dist/cjs/utilities/math/aabb/distanceToPointSquared.js +24 -0
- package/dist/cjs/utilities/math/aabb/distanceToPointSquared.js.map +1 -0
- package/dist/cjs/utilities/math/aabb/index.d.ts +2 -0
- package/dist/cjs/utilities/math/aabb/index.js +11 -0
- package/dist/cjs/utilities/math/aabb/index.js.map +1 -0
- package/dist/cjs/utilities/math/index.d.ts +6 -5
- package/dist/cjs/utilities/math/index.js +11 -9
- package/dist/cjs/utilities/math/index.js.map +1 -1
- package/dist/cjs/utilities/math/line/distanceToPointSquared.js +5 -21
- package/dist/cjs/utilities/math/line/distanceToPointSquared.js.map +1 -1
- package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.d.ts +5 -0
- package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.js +56 -0
- package/dist/cjs/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -0
- package/dist/cjs/utilities/math/line/index.d.ts +2 -1
- package/dist/cjs/utilities/math/line/index.js +3 -1
- package/dist/cjs/utilities/math/line/index.js.map +1 -1
- package/dist/cjs/utilities/math/point/distanceToPoint.js +5 -6
- package/dist/cjs/utilities/math/point/distanceToPoint.js.map +1 -1
- package/dist/cjs/utilities/math/point/distanceToPointSquared.d.ts +4 -0
- package/dist/cjs/utilities/math/point/distanceToPointSquared.js +12 -0
- package/dist/cjs/utilities/math/point/distanceToPointSquared.js.map +1 -0
- package/dist/cjs/utilities/math/point/index.d.ts +3 -2
- package/dist/cjs/utilities/math/point/index.js +7 -3
- package/dist/cjs/utilities/math/point/index.js.map +1 -1
- package/dist/cjs/utilities/math/point/mirror.d.ts +2 -0
- package/dist/cjs/utilities/math/point/mirror.js +11 -0
- package/dist/cjs/utilities/math/point/mirror.js.map +1 -0
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js +4 -4
- package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
- package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +2 -1
- package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tools/AdvancedMagnifyTool.js +8 -3
- package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +703 -0
- package/dist/esm/tools/annotation/SplineROITool.js.map +1 -0
- package/dist/esm/tools/annotation/splines/BSpline.js +10 -0
- package/dist/esm/tools/annotation/splines/BSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/CardinalSpline.js +33 -0
- package/dist/esm/tools/annotation/splines/CardinalSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/CatmullRomSpline.js +8 -0
- package/dist/esm/tools/annotation/splines/CatmullRomSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/CubicSpline.js +165 -0
- package/dist/esm/tools/annotation/splines/CubicSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/LinearSpline.js +8 -0
- package/dist/esm/tools/annotation/splines/LinearSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/QuadraticBezier.js +16 -0
- package/dist/esm/tools/annotation/splines/QuadraticBezier.js.map +1 -0
- package/dist/esm/tools/annotation/splines/QuadraticSpline.js +14 -0
- package/dist/esm/tools/annotation/splines/QuadraticSpline.js.map +1 -0
- package/dist/esm/tools/annotation/splines/Spline.js +392 -0
- package/dist/esm/tools/annotation/splines/Spline.js.map +1 -0
- package/dist/esm/tools/index.js +2 -1
- package/dist/esm/tools/index.js.map +1 -1
- package/dist/esm/types/CardinalSplineProps.js +2 -0
- package/dist/esm/types/CardinalSplineProps.js.map +1 -0
- package/dist/esm/types/ClosestControlPoint.js +2 -0
- package/dist/esm/types/ClosestControlPoint.js.map +1 -0
- package/dist/esm/types/ClosestPoint.js +2 -0
- package/dist/esm/types/ClosestPoint.js.map +1 -0
- package/dist/esm/types/ClosestSplinePoint.js +2 -0
- package/dist/esm/types/ClosestSplinePoint.js.map +1 -0
- package/dist/esm/types/ControlPointInfo.js +2 -0
- package/dist/esm/types/ControlPointInfo.js.map +1 -0
- package/dist/esm/types/ISpline.js +2 -0
- package/dist/esm/types/ISpline.js.map +1 -0
- package/dist/esm/types/SplineCurveSegment.js +2 -0
- package/dist/esm/types/SplineCurveSegment.js.map +1 -0
- package/dist/esm/types/SplineLineSegment.js +2 -0
- package/dist/esm/types/SplineLineSegment.js.map +1 -0
- package/dist/esm/types/SplineProps.js +2 -0
- package/dist/esm/types/SplineProps.js.map +1 -0
- package/dist/esm/utilities/index.js +2 -3
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/math/aabb/distanceToPoint.js +5 -0
- package/dist/esm/utilities/math/aabb/distanceToPoint.js.map +1 -0
- package/dist/esm/utilities/math/aabb/distanceToPointSquared.js +21 -0
- package/dist/esm/utilities/math/aabb/distanceToPointSquared.js.map +1 -0
- package/dist/esm/utilities/math/aabb/index.js +3 -0
- package/dist/esm/utilities/math/aabb/index.js.map +1 -0
- package/dist/esm/utilities/math/index.js +6 -5
- package/dist/esm/utilities/math/index.js.map +1 -1
- package/dist/esm/utilities/math/line/distanceToPointSquared.js +2 -21
- package/dist/esm/utilities/math/line/distanceToPointSquared.js.map +1 -1
- package/dist/esm/utilities/math/line/distanceToPointSquaredInfo.js +30 -0
- package/dist/esm/utilities/math/line/distanceToPointSquaredInfo.js.map +1 -0
- package/dist/esm/utilities/math/line/index.js +2 -1
- package/dist/esm/utilities/math/line/index.js.map +1 -1
- package/dist/esm/utilities/math/point/distanceToPoint.js +2 -6
- package/dist/esm/utilities/math/point/distanceToPoint.js.map +1 -1
- package/dist/esm/utilities/math/point/distanceToPointSquared.js +9 -0
- package/dist/esm/utilities/math/point/distanceToPointSquared.js.map +1 -0
- package/dist/esm/utilities/math/point/index.js +3 -2
- package/dist/esm/utilities/math/point/index.js.map +1 -1
- package/dist/esm/utilities/math/point/mirror.js +8 -0
- package/dist/esm/utilities/math/point/mirror.js.map +1 -0
- package/dist/types/eventDispatchers/mouseEventHandlers/mouseDown.d.ts.map +1 -1
- package/dist/types/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/tools/AdvancedMagnifyTool.d.ts +4 -0
- package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/SplineROITool.d.ts +60 -0
- package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/BSpline.d.ts +6 -0
- package/dist/types/tools/annotation/splines/BSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/CardinalSpline.d.ts +13 -0
- package/dist/types/tools/annotation/splines/CardinalSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/CatmullRomSpline.d.ts +6 -0
- package/dist/types/tools/annotation/splines/CatmullRomSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/CubicSpline.d.ts +14 -0
- package/dist/types/tools/annotation/splines/CubicSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/LinearSpline.d.ts +6 -0
- package/dist/types/tools/annotation/splines/LinearSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/QuadraticBezier.d.ts +7 -0
- package/dist/types/tools/annotation/splines/QuadraticBezier.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/QuadraticSpline.d.ts +10 -0
- package/dist/types/tools/annotation/splines/QuadraticSpline.d.ts.map +1 -0
- package/dist/types/tools/annotation/splines/Spline.d.ts +50 -0
- package/dist/types/tools/annotation/splines/Spline.d.ts.map +1 -0
- package/dist/types/tools/index.d.ts +2 -1
- package/dist/types/tools/index.d.ts.map +1 -1
- package/dist/types/types/CardinalSplineProps.d.ts +6 -0
- package/dist/types/types/CardinalSplineProps.d.ts.map +1 -0
- package/dist/types/types/ClosestControlPoint.d.ts +5 -0
- package/dist/types/types/ClosestControlPoint.d.ts.map +1 -0
- package/dist/types/types/ClosestPoint.d.ts +6 -0
- package/dist/types/types/ClosestPoint.d.ts.map +1 -0
- package/dist/types/types/ClosestSplinePoint.d.ts +5 -0
- package/dist/types/types/ClosestSplinePoint.d.ts.map +1 -0
- package/dist/types/types/ControlPointInfo.d.ts +6 -0
- package/dist/types/types/ControlPointInfo.d.ts.map +1 -0
- package/dist/types/types/ISpline.d.ts +30 -0
- package/dist/types/types/ISpline.d.ts.map +1 -0
- package/dist/types/types/SplineCurveSegment.d.ts +15 -0
- package/dist/types/types/SplineCurveSegment.d.ts.map +1 -0
- package/dist/types/types/SplineLineSegment.d.ts +11 -0
- package/dist/types/types/SplineLineSegment.d.ts.map +1 -0
- package/dist/types/types/SplineProps.d.ts +5 -0
- package/dist/types/types/SplineProps.d.ts.map +1 -0
- package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +34 -0
- package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +10 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utilities/index.d.ts +2 -3
- package/dist/types/utilities/index.d.ts.map +1 -1
- package/dist/types/utilities/math/aabb/distanceToPoint.d.ts +3 -0
- package/dist/types/utilities/math/aabb/distanceToPoint.d.ts.map +1 -0
- package/dist/types/utilities/math/aabb/distanceToPointSquared.d.ts +3 -0
- package/dist/types/utilities/math/aabb/distanceToPointSquared.d.ts.map +1 -0
- package/dist/types/utilities/math/aabb/index.d.ts +3 -0
- package/dist/types/utilities/math/aabb/index.d.ts.map +1 -0
- package/dist/types/utilities/math/index.d.ts +6 -5
- package/dist/types/utilities/math/index.d.ts.map +1 -1
- package/dist/types/utilities/math/line/distanceToPointSquared.d.ts.map +1 -1
- package/dist/types/utilities/math/line/distanceToPointSquaredInfo.d.ts +6 -0
- package/dist/types/utilities/math/line/distanceToPointSquaredInfo.d.ts.map +1 -0
- package/dist/types/utilities/math/line/index.d.ts +2 -1
- package/dist/types/utilities/math/line/index.d.ts.map +1 -1
- package/dist/types/utilities/math/point/distanceToPoint.d.ts.map +1 -1
- package/dist/types/utilities/math/point/distanceToPointSquared.d.ts +5 -0
- package/dist/types/utilities/math/point/distanceToPointSquared.d.ts.map +1 -0
- package/dist/types/utilities/math/point/index.d.ts +3 -2
- package/dist/types/utilities/math/point/index.d.ts.map +1 -1
- package/dist/types/utilities/math/point/mirror.d.ts +3 -0
- package/dist/types/utilities/math/point/mirror.d.ts.map +1 -0
- package/dist/umd/index.js +2 -1
- package/dist/umd/index.js.LICENSE.txt +6 -0
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +8 -6
- package/src/eventDispatchers/shared/getToolsWithActionsForMouseEvent.ts +3 -2
- package/src/index.ts +2 -0
- package/src/tools/AdvancedMagnifyTool.ts +8 -3
- package/src/tools/annotation/SplineROITool.ts +1151 -0
- package/src/tools/annotation/splines/BSpline.ts +22 -0
- package/src/tools/annotation/splines/CardinalSpline.ts +45 -0
- package/src/tools/annotation/splines/CatmullRomSpline.ts +19 -0
- package/src/tools/annotation/splines/CubicSpline.ts +288 -0
- package/src/tools/annotation/splines/LinearSpline.ts +20 -0
- package/src/tools/annotation/splines/QuadraticBezier.ts +20 -0
- package/src/tools/annotation/splines/QuadraticSpline.ts +25 -0
- package/src/tools/annotation/splines/Spline.ts +729 -0
- package/src/tools/index.ts +2 -0
- package/src/types/CardinalSplineProps.ts +11 -0
- package/src/types/ClosestControlPoint.ts +6 -0
- package/src/types/ClosestPoint.ts +8 -0
- package/src/types/ClosestSplinePoint.ts +6 -0
- package/src/types/ControlPointInfo.ts +8 -0
- package/src/types/ISpline.ts +164 -0
- package/src/types/SplineCurveSegment.ts +28 -0
- package/src/types/SplineLineSegment.ts +20 -0
- package/src/types/SplineProps.ts +15 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +35 -0
- package/src/types/index.ts +21 -0
- package/src/utilities/index.ts +6 -2
- package/src/utilities/math/aabb/distanceToPoint.ts +20 -0
- package/src/utilities/math/aabb/distanceToPointSquared.ts +47 -0
- package/src/utilities/math/aabb/index.ts +2 -0
- package/src/utilities/math/index.ts +10 -8
- package/src/utilities/math/line/distanceToPointSquared.ts +3 -29
- package/src/utilities/math/line/distanceToPointSquaredInfo.ts +54 -0
- package/src/utilities/math/line/index.ts +7 -1
- package/src/utilities/math/point/distanceToPoint.ts +2 -10
- package/src/utilities/math/point/distanceToPointSquared.ts +21 -0
- package/src/utilities/math/point/index.ts +3 -3
- package/src/utilities/math/point/mirror.ts +21 -0
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { AnnotationTool } from '../base';
|
|
2
|
+
import { getEnabledElement, eventTarget, triggerEvent, } from '@cornerstonejs/core';
|
|
3
|
+
import { vec3 } from 'gl-matrix';
|
|
4
|
+
import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
|
|
5
|
+
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
|
|
6
|
+
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
|
|
7
|
+
import { drawHandles as drawHandlesSvg, drawPolyline as drawPolylineSvg, drawLinkedTextBox as drawLinkedTextBoxSvg, } from '../../drawingSvg';
|
|
8
|
+
import { state } from '../../store';
|
|
9
|
+
import { Events, MouseBindings, KeyboardBindings } from '../../enums';
|
|
10
|
+
import { resetElementCursor } from '../../cursors/elementCursor';
|
|
11
|
+
import { math, viewportFilters, drawing, throttle, roundNumber, triggerAnnotationRenderForViewportIds, getCalibratedScale, getCalibratedAreaUnits, } from '../../utilities';
|
|
12
|
+
import { CardinalSpline } from './splines/CardinalSpline';
|
|
13
|
+
import { LinearSpline } from './splines/LinearSpline';
|
|
14
|
+
import { CatmullRomSpline } from './splines/CatmullRomSpline';
|
|
15
|
+
import { BSpline } from './splines/BSpline';
|
|
16
|
+
const { getViewportIdsWithToolToRender } = viewportFilters;
|
|
17
|
+
const { getTextBoxCoordsCanvas } = drawing;
|
|
18
|
+
const SPLINE_MIN_POINTS = 3;
|
|
19
|
+
const SPLINE_CLICK_CLOSE_CURVE_DIST = 10;
|
|
20
|
+
const DEFAULT_SPLINE_CONFIG = {
|
|
21
|
+
resolution: 20,
|
|
22
|
+
controlPointAdditionDistance: 6,
|
|
23
|
+
controlPointDeletionDistance: 6,
|
|
24
|
+
showControlPointsConnectors: false,
|
|
25
|
+
controlPointAdditionEnabled: true,
|
|
26
|
+
controlPointDeletionEnabled: true,
|
|
27
|
+
};
|
|
28
|
+
var SplineTypesEnum;
|
|
29
|
+
(function (SplineTypesEnum) {
|
|
30
|
+
SplineTypesEnum["Cardinal"] = "CARDINAL";
|
|
31
|
+
SplineTypesEnum["Linear"] = "LINEAR";
|
|
32
|
+
SplineTypesEnum["CatmullRom"] = "CATMULLROM";
|
|
33
|
+
SplineTypesEnum["BSpline"] = "BSPLINE";
|
|
34
|
+
})(SplineTypesEnum || (SplineTypesEnum = {}));
|
|
35
|
+
var SplineToolActions;
|
|
36
|
+
(function (SplineToolActions) {
|
|
37
|
+
SplineToolActions["AddControlPoint"] = "addControlPoint";
|
|
38
|
+
SplineToolActions["DeleteControlPoint"] = "deleteControlPoint";
|
|
39
|
+
})(SplineToolActions || (SplineToolActions = {}));
|
|
40
|
+
class SplineROITool extends AnnotationTool {
|
|
41
|
+
constructor(toolProps = {}, defaultToolProps = {
|
|
42
|
+
supportedInteractionTypes: ['Mouse', 'Touch'],
|
|
43
|
+
configuration: {
|
|
44
|
+
preventHandleOutsideImage: false,
|
|
45
|
+
calculateStats: true,
|
|
46
|
+
getTextLines: defaultGetTextLines,
|
|
47
|
+
spline: {
|
|
48
|
+
configuration: {
|
|
49
|
+
[SplineTypesEnum.Cardinal]: {
|
|
50
|
+
Class: CardinalSpline,
|
|
51
|
+
scale: 0.5,
|
|
52
|
+
},
|
|
53
|
+
[SplineTypesEnum.CatmullRom]: {
|
|
54
|
+
Class: CatmullRomSpline,
|
|
55
|
+
},
|
|
56
|
+
[SplineTypesEnum.Linear]: {
|
|
57
|
+
Class: LinearSpline,
|
|
58
|
+
},
|
|
59
|
+
[SplineTypesEnum.BSpline]: {
|
|
60
|
+
Class: BSpline,
|
|
61
|
+
controlPointAdditionEnabled: false,
|
|
62
|
+
controlPointDeletionEnabled: false,
|
|
63
|
+
showControlPointsConnectors: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
type: SplineTypesEnum.CatmullRom,
|
|
67
|
+
drawPreviewEnabled: true,
|
|
68
|
+
lastControlPointDeletionKeys: ['Backspace', 'Delete'],
|
|
69
|
+
},
|
|
70
|
+
actions: {
|
|
71
|
+
[SplineToolActions.AddControlPoint]: {
|
|
72
|
+
method: 'addControlPointCallback',
|
|
73
|
+
bindings: [
|
|
74
|
+
{
|
|
75
|
+
mouseButton: MouseBindings.Primary,
|
|
76
|
+
modifierKey: KeyboardBindings.Shift,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
[SplineToolActions.DeleteControlPoint]: {
|
|
81
|
+
method: 'deleteControlPointCallback',
|
|
82
|
+
bindings: [
|
|
83
|
+
{
|
|
84
|
+
mouseButton: MouseBindings.Primary,
|
|
85
|
+
modifierKey: KeyboardBindings.Ctrl,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
}) {
|
|
92
|
+
super(toolProps, defaultToolProps);
|
|
93
|
+
this.isHandleOutsideImage = false;
|
|
94
|
+
this.addNewAnnotation = (evt) => {
|
|
95
|
+
const eventDetail = evt.detail;
|
|
96
|
+
const { currentPoints, element } = eventDetail;
|
|
97
|
+
const { world: worldPos, canvas: canvasPos } = currentPoints;
|
|
98
|
+
const enabledElement = getEnabledElement(element);
|
|
99
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
100
|
+
this.isDrawing = true;
|
|
101
|
+
const camera = viewport.getCamera();
|
|
102
|
+
const { viewPlaneNormal, viewUp } = camera;
|
|
103
|
+
const { type: splineType } = this.configuration.spline;
|
|
104
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
105
|
+
const spline = new splineConfig.Class();
|
|
106
|
+
const referencedImageId = this.getReferencedImageId(viewport, worldPos, viewPlaneNormal, viewUp);
|
|
107
|
+
const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
|
|
108
|
+
const annotation = {
|
|
109
|
+
highlighted: true,
|
|
110
|
+
invalidated: true,
|
|
111
|
+
metadata: {
|
|
112
|
+
toolName: this.getToolName(),
|
|
113
|
+
viewPlaneNormal: [...viewPlaneNormal],
|
|
114
|
+
viewUp: [...viewUp],
|
|
115
|
+
FrameOfReferenceUID,
|
|
116
|
+
referencedImageId,
|
|
117
|
+
},
|
|
118
|
+
data: {
|
|
119
|
+
handles: {
|
|
120
|
+
textBox: {
|
|
121
|
+
hasMoved: false,
|
|
122
|
+
worldPosition: [0, 0, 0],
|
|
123
|
+
worldBoundingBox: {
|
|
124
|
+
topLeft: [0, 0, 0],
|
|
125
|
+
topRight: [0, 0, 0],
|
|
126
|
+
bottomLeft: [0, 0, 0],
|
|
127
|
+
bottomRight: [0, 0, 0],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
points: [[...worldPos]],
|
|
131
|
+
activeHandleIndex: null,
|
|
132
|
+
},
|
|
133
|
+
spline: {
|
|
134
|
+
type: splineConfig.type,
|
|
135
|
+
instance: spline,
|
|
136
|
+
resolution: splineConfig.resolution,
|
|
137
|
+
closed: false,
|
|
138
|
+
polyline: [],
|
|
139
|
+
},
|
|
140
|
+
cachedStats: {},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
addAnnotation(annotation, element);
|
|
144
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
145
|
+
this.editData = {
|
|
146
|
+
annotation,
|
|
147
|
+
viewportIdsToRender,
|
|
148
|
+
movingTextBox: false,
|
|
149
|
+
newAnnotation: true,
|
|
150
|
+
hasMoved: false,
|
|
151
|
+
lastCanvasPoint: canvasPos,
|
|
152
|
+
};
|
|
153
|
+
this._activateDraw(element);
|
|
154
|
+
evt.preventDefault();
|
|
155
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
156
|
+
return annotation;
|
|
157
|
+
};
|
|
158
|
+
this.isPointNearTool = (element, annotation, canvasCoords, proximity) => {
|
|
159
|
+
const { instance: spline } = annotation.data.spline;
|
|
160
|
+
return spline.isPointNearCurve(canvasCoords, proximity);
|
|
161
|
+
};
|
|
162
|
+
this.toolSelectedCallback = (evt, annotation) => {
|
|
163
|
+
const eventDetail = evt.detail;
|
|
164
|
+
const { element } = eventDetail;
|
|
165
|
+
annotation.highlighted = true;
|
|
166
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
167
|
+
this.editData = {
|
|
168
|
+
annotation,
|
|
169
|
+
viewportIdsToRender,
|
|
170
|
+
movingTextBox: false,
|
|
171
|
+
};
|
|
172
|
+
const enabledElement = getEnabledElement(element);
|
|
173
|
+
const { renderingEngine } = enabledElement;
|
|
174
|
+
this._activateModify(element);
|
|
175
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
176
|
+
evt.preventDefault();
|
|
177
|
+
};
|
|
178
|
+
this.handleSelectedCallback = (evt, annotation, handle) => {
|
|
179
|
+
const eventDetail = evt.detail;
|
|
180
|
+
const { element } = eventDetail;
|
|
181
|
+
const { data } = annotation;
|
|
182
|
+
annotation.highlighted = true;
|
|
183
|
+
let movingTextBox = false;
|
|
184
|
+
let handleIndex;
|
|
185
|
+
if (handle.worldPosition) {
|
|
186
|
+
movingTextBox = true;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const { points } = data.handles;
|
|
190
|
+
handleIndex = points.findIndex((p) => p === handle);
|
|
191
|
+
}
|
|
192
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
193
|
+
this.editData = {
|
|
194
|
+
annotation,
|
|
195
|
+
viewportIdsToRender,
|
|
196
|
+
handleIndex,
|
|
197
|
+
movingTextBox,
|
|
198
|
+
};
|
|
199
|
+
this._activateModify(element);
|
|
200
|
+
const enabledElement = getEnabledElement(element);
|
|
201
|
+
const { renderingEngine } = enabledElement;
|
|
202
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
203
|
+
evt.preventDefault();
|
|
204
|
+
};
|
|
205
|
+
this._endCallback = (evt) => {
|
|
206
|
+
const eventDetail = evt.detail;
|
|
207
|
+
const { element } = eventDetail;
|
|
208
|
+
const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
|
|
209
|
+
const { data } = annotation;
|
|
210
|
+
data.handles.activeHandleIndex = null;
|
|
211
|
+
this._deactivateModify(element);
|
|
212
|
+
this._deactivateDraw(element);
|
|
213
|
+
resetElementCursor(element);
|
|
214
|
+
const enabledElement = getEnabledElement(element);
|
|
215
|
+
const { renderingEngine } = enabledElement;
|
|
216
|
+
if (this.isHandleOutsideImage &&
|
|
217
|
+
this.configuration.preventHandleOutsideImage) {
|
|
218
|
+
removeAnnotation(annotation.annotationUID);
|
|
219
|
+
}
|
|
220
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
221
|
+
if (newAnnotation) {
|
|
222
|
+
const eventType = Events.ANNOTATION_COMPLETED;
|
|
223
|
+
const eventDetail = {
|
|
224
|
+
annotation,
|
|
225
|
+
};
|
|
226
|
+
triggerEvent(eventTarget, eventType, eventDetail);
|
|
227
|
+
}
|
|
228
|
+
this.editData = null;
|
|
229
|
+
this.isDrawing = false;
|
|
230
|
+
};
|
|
231
|
+
this._keyDownCallback = (evt) => {
|
|
232
|
+
const eventDetail = evt.detail;
|
|
233
|
+
const { element } = eventDetail;
|
|
234
|
+
const key = eventDetail.key ?? '';
|
|
235
|
+
const { lastControlPointDeletionKeys } = this.configuration.spline;
|
|
236
|
+
const deleteLastPoint = lastControlPointDeletionKeys.includes(key);
|
|
237
|
+
if (!deleteLastPoint) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const { annotation } = this.editData;
|
|
241
|
+
const { data } = annotation;
|
|
242
|
+
if (data.handles.points.length === SPLINE_MIN_POINTS) {
|
|
243
|
+
this.cancel(element);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const controlPointIndex = data.handles.points.length - 1;
|
|
248
|
+
this._deleteControlPointByIndex(element, annotation, controlPointIndex);
|
|
249
|
+
}
|
|
250
|
+
evt.preventDefault();
|
|
251
|
+
};
|
|
252
|
+
this._mouseMoveCallback = (evt) => {
|
|
253
|
+
const { drawPreviewEnabled } = this.configuration.spline;
|
|
254
|
+
if (!drawPreviewEnabled) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const { element } = evt.detail;
|
|
258
|
+
const { renderingEngine } = getEnabledElement(element);
|
|
259
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
260
|
+
this.editData.lastCanvasPoint = evt.detail.currentPoints.canvas;
|
|
261
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
262
|
+
evt.preventDefault();
|
|
263
|
+
};
|
|
264
|
+
this._mouseDownCallback = (evt) => {
|
|
265
|
+
const doubleClick = evt.type === Events.MOUSE_DOUBLE_CLICK;
|
|
266
|
+
const { annotation, viewportIdsToRender } = this.editData;
|
|
267
|
+
const { data } = annotation;
|
|
268
|
+
if (data.spline.closed) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const eventDetail = evt.detail;
|
|
272
|
+
const { element } = eventDetail;
|
|
273
|
+
const { currentPoints } = eventDetail;
|
|
274
|
+
const { canvas: canvasPoint, world: worldPoint } = currentPoints;
|
|
275
|
+
const enabledElement = getEnabledElement(element);
|
|
276
|
+
const { renderingEngine } = enabledElement;
|
|
277
|
+
let closeSpline = data.handles.points.length >= 2 && doubleClick;
|
|
278
|
+
let addNewPoint = true;
|
|
279
|
+
if (data.handles.points.length >= 3) {
|
|
280
|
+
const { instance: spline } = data.spline;
|
|
281
|
+
const closestControlPoint = spline.getClosestControlPointWithinDistance(canvasPoint, SPLINE_CLICK_CLOSE_CURVE_DIST);
|
|
282
|
+
if (closestControlPoint?.index === 0) {
|
|
283
|
+
addNewPoint = false;
|
|
284
|
+
closeSpline = true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (addNewPoint) {
|
|
288
|
+
data.handles.points.push(worldPoint);
|
|
289
|
+
}
|
|
290
|
+
data.spline.closed = data.spline.closed || closeSpline;
|
|
291
|
+
annotation.invalidated = true;
|
|
292
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
293
|
+
if (data.spline.closed) {
|
|
294
|
+
this._endCallback(evt);
|
|
295
|
+
}
|
|
296
|
+
evt.preventDefault();
|
|
297
|
+
};
|
|
298
|
+
this._dragCallback = (evt) => {
|
|
299
|
+
this.isDrawing = true;
|
|
300
|
+
const eventDetail = evt.detail;
|
|
301
|
+
const { element } = eventDetail;
|
|
302
|
+
const { annotation, viewportIdsToRender, handleIndex, movingTextBox } = this.editData;
|
|
303
|
+
const { data } = annotation;
|
|
304
|
+
if (movingTextBox) {
|
|
305
|
+
const { deltaPoints } = eventDetail;
|
|
306
|
+
const worldPosDelta = deltaPoints.world;
|
|
307
|
+
const { textBox } = data.handles;
|
|
308
|
+
const { worldPosition } = textBox;
|
|
309
|
+
worldPosition[0] += worldPosDelta[0];
|
|
310
|
+
worldPosition[1] += worldPosDelta[1];
|
|
311
|
+
worldPosition[2] += worldPosDelta[2];
|
|
312
|
+
textBox.hasMoved = true;
|
|
313
|
+
}
|
|
314
|
+
else if (handleIndex === undefined) {
|
|
315
|
+
const { deltaPoints } = eventDetail;
|
|
316
|
+
const worldPosDelta = deltaPoints.world;
|
|
317
|
+
const points = data.handles.points;
|
|
318
|
+
points.forEach((point) => {
|
|
319
|
+
point[0] += worldPosDelta[0];
|
|
320
|
+
point[1] += worldPosDelta[1];
|
|
321
|
+
point[2] += worldPosDelta[2];
|
|
322
|
+
});
|
|
323
|
+
annotation.invalidated = true;
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
const { currentPoints } = eventDetail;
|
|
327
|
+
const worldPos = currentPoints.world;
|
|
328
|
+
data.handles.points[handleIndex] = [...worldPos];
|
|
329
|
+
annotation.invalidated = true;
|
|
330
|
+
}
|
|
331
|
+
this.editData.hasMoved = true;
|
|
332
|
+
const enabledElement = getEnabledElement(element);
|
|
333
|
+
const { renderingEngine } = enabledElement;
|
|
334
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
335
|
+
};
|
|
336
|
+
this.cancel = (element) => {
|
|
337
|
+
if (!this.isDrawing) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this.isDrawing = false;
|
|
341
|
+
this._deactivateDraw(element);
|
|
342
|
+
this._deactivateModify(element);
|
|
343
|
+
resetElementCursor(element);
|
|
344
|
+
const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
|
|
345
|
+
if (newAnnotation) {
|
|
346
|
+
removeAnnotation(annotation.annotationUID);
|
|
347
|
+
}
|
|
348
|
+
const enabledElement = getEnabledElement(element);
|
|
349
|
+
const { renderingEngine } = enabledElement;
|
|
350
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
351
|
+
this.editData = null;
|
|
352
|
+
return annotation.annotationUID;
|
|
353
|
+
};
|
|
354
|
+
this.triggerAnnotationModified = (annotation, enabledElement) => {
|
|
355
|
+
const { viewportId, renderingEngineId } = enabledElement;
|
|
356
|
+
const eventType = Events.ANNOTATION_MODIFIED;
|
|
357
|
+
const eventDetail = {
|
|
358
|
+
annotation,
|
|
359
|
+
viewportId,
|
|
360
|
+
renderingEngineId,
|
|
361
|
+
};
|
|
362
|
+
triggerEvent(eventTarget, eventType, eventDetail);
|
|
363
|
+
};
|
|
364
|
+
this._activateModify = (element) => {
|
|
365
|
+
state.isInteractingWithTool = true;
|
|
366
|
+
element.addEventListener(Events.MOUSE_UP, this._endCallback);
|
|
367
|
+
element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
|
|
368
|
+
element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
|
|
369
|
+
element.addEventListener(Events.TOUCH_END, this._endCallback);
|
|
370
|
+
element.addEventListener(Events.TOUCH_DRAG, this._dragCallback);
|
|
371
|
+
element.addEventListener(Events.TOUCH_TAP, this._endCallback);
|
|
372
|
+
};
|
|
373
|
+
this._deactivateModify = (element) => {
|
|
374
|
+
state.isInteractingWithTool = false;
|
|
375
|
+
element.removeEventListener(Events.MOUSE_UP, this._endCallback);
|
|
376
|
+
element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
|
|
377
|
+
element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
|
|
378
|
+
element.removeEventListener(Events.TOUCH_END, this._endCallback);
|
|
379
|
+
element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
|
|
380
|
+
element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
|
|
381
|
+
};
|
|
382
|
+
this._activateDraw = (element) => {
|
|
383
|
+
state.isInteractingWithTool = true;
|
|
384
|
+
element.addEventListener(Events.KEY_DOWN, this._keyDownCallback);
|
|
385
|
+
element.addEventListener(Events.MOUSE_MOVE, this._mouseMoveCallback);
|
|
386
|
+
element.addEventListener(Events.MOUSE_DOWN, this._mouseDownCallback);
|
|
387
|
+
element.addEventListener(Events.MOUSE_DOUBLE_CLICK, this._mouseDownCallback);
|
|
388
|
+
element.addEventListener(Events.TOUCH_TAP, this._mouseDownCallback);
|
|
389
|
+
};
|
|
390
|
+
this._deactivateDraw = (element) => {
|
|
391
|
+
state.isInteractingWithTool = false;
|
|
392
|
+
element.removeEventListener(Events.KEY_DOWN, this._keyDownCallback);
|
|
393
|
+
element.removeEventListener(Events.MOUSE_MOVE, this._mouseMoveCallback);
|
|
394
|
+
element.removeEventListener(Events.MOUSE_DOWN, this._mouseDownCallback);
|
|
395
|
+
element.removeEventListener(Events.MOUSE_DOUBLE_CLICK, this._mouseDownCallback);
|
|
396
|
+
element.removeEventListener(Events.TOUCH_TAP, this._mouseDownCallback);
|
|
397
|
+
};
|
|
398
|
+
this.renderAnnotation = (enabledElement, svgDrawingHelper) => {
|
|
399
|
+
let renderStatus = false;
|
|
400
|
+
const { viewport } = enabledElement;
|
|
401
|
+
const { worldToCanvas } = viewport;
|
|
402
|
+
const { element } = viewport;
|
|
403
|
+
if (!viewport.getRenderingEngine()) {
|
|
404
|
+
console.warn('Rendering Engine has been destroyed');
|
|
405
|
+
return renderStatus;
|
|
406
|
+
}
|
|
407
|
+
let annotations = getAnnotations(this.getToolName(), element);
|
|
408
|
+
if (!annotations?.length) {
|
|
409
|
+
return renderStatus;
|
|
410
|
+
}
|
|
411
|
+
annotations = this.filterInteractableAnnotationsForElement(element, annotations);
|
|
412
|
+
if (!annotations?.length) {
|
|
413
|
+
return renderStatus;
|
|
414
|
+
}
|
|
415
|
+
const targetId = this.getTargetId(viewport);
|
|
416
|
+
const newAnnotation = this.editData?.newAnnotation;
|
|
417
|
+
const styleSpecifier = {
|
|
418
|
+
toolGroupId: this.toolGroupId,
|
|
419
|
+
toolName: this.getToolName(),
|
|
420
|
+
viewportId: enabledElement.viewport.id,
|
|
421
|
+
};
|
|
422
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
423
|
+
const annotation = annotations[i];
|
|
424
|
+
const { annotationUID, data, highlighted } = annotation;
|
|
425
|
+
const { handles } = data;
|
|
426
|
+
const { points: controlPoints, activeHandleIndex } = handles;
|
|
427
|
+
styleSpecifier.annotationUID = annotationUID;
|
|
428
|
+
const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
|
|
429
|
+
const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
|
|
430
|
+
const color = this.getStyle('color', styleSpecifier, annotation);
|
|
431
|
+
const canvasCoordinates = controlPoints.map((p) => worldToCanvas(p));
|
|
432
|
+
const { drawPreviewEnabled } = this.configuration.spline;
|
|
433
|
+
const splineType = annotation.data.spline.type;
|
|
434
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
435
|
+
const spline = this._updateSplineInstance(element, annotation);
|
|
436
|
+
const splinePolylineCanvas = spline.getPolylinePoints();
|
|
437
|
+
const splinePolylineWorld = [];
|
|
438
|
+
for (let i = 0, len = splinePolylineCanvas.length; i < len; i++) {
|
|
439
|
+
splinePolylineWorld.push(viewport.canvasToWorld(splinePolylineCanvas[i]));
|
|
440
|
+
}
|
|
441
|
+
data.spline.polyline = splinePolylineWorld;
|
|
442
|
+
if (!data.cachedStats[targetId] ||
|
|
443
|
+
data.cachedStats[targetId].areaUnit == null) {
|
|
444
|
+
data.cachedStats[targetId] = {
|
|
445
|
+
Modality: null,
|
|
446
|
+
area: null,
|
|
447
|
+
areaUnit: null,
|
|
448
|
+
};
|
|
449
|
+
this._calculateCachedStats(annotation, element);
|
|
450
|
+
}
|
|
451
|
+
else if (annotation.invalidated) {
|
|
452
|
+
this._throttledCalculateCachedStats(annotation, element);
|
|
453
|
+
}
|
|
454
|
+
let activeHandleCanvasCoords;
|
|
455
|
+
if (!isAnnotationVisible(annotationUID)) {
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (!isAnnotationLocked(annotation) &&
|
|
459
|
+
!this.editData &&
|
|
460
|
+
activeHandleIndex !== null) {
|
|
461
|
+
activeHandleCanvasCoords = [canvasCoordinates[activeHandleIndex]];
|
|
462
|
+
}
|
|
463
|
+
if (activeHandleCanvasCoords || newAnnotation || highlighted) {
|
|
464
|
+
const handleGroupUID = '0';
|
|
465
|
+
drawHandlesSvg(svgDrawingHelper, annotationUID, handleGroupUID, canvasCoordinates, {
|
|
466
|
+
color,
|
|
467
|
+
lineDash,
|
|
468
|
+
lineWidth,
|
|
469
|
+
handleRadius: '3',
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
if (drawPreviewEnabled &&
|
|
473
|
+
spline.numControlPoints > 1 &&
|
|
474
|
+
this.editData?.lastCanvasPoint &&
|
|
475
|
+
!spline.closed) {
|
|
476
|
+
const { lastCanvasPoint } = this.editData;
|
|
477
|
+
const previewPolylinePoints = spline.getPreviewPolylinePoints(lastCanvasPoint, SPLINE_CLICK_CLOSE_CURVE_DIST);
|
|
478
|
+
drawPolylineSvg(svgDrawingHelper, annotationUID, 'previewSplineChange', previewPolylinePoints, {
|
|
479
|
+
color: '#9EA0CA',
|
|
480
|
+
lineDash,
|
|
481
|
+
lineWidth,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
if (splineConfig.showControlPointsConnectors) {
|
|
485
|
+
const controlPointsConnectors = [...canvasCoordinates];
|
|
486
|
+
if (spline.closed) {
|
|
487
|
+
controlPointsConnectors.push(canvasCoordinates[0]);
|
|
488
|
+
}
|
|
489
|
+
drawPolylineSvg(svgDrawingHelper, annotationUID, 'controlPointsConnectors', controlPointsConnectors, {
|
|
490
|
+
color: 'rgba(255, 255, 255, 0.5)',
|
|
491
|
+
lineDash,
|
|
492
|
+
lineWidth,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
drawPolylineSvg(svgDrawingHelper, annotationUID, 'lineSegments', splinePolylineCanvas, {
|
|
496
|
+
color,
|
|
497
|
+
lineDash,
|
|
498
|
+
lineWidth,
|
|
499
|
+
});
|
|
500
|
+
this._renderStats(annotation, viewport, enabledElement, svgDrawingHelper);
|
|
501
|
+
renderStatus = true;
|
|
502
|
+
annotation.invalidated = false;
|
|
503
|
+
}
|
|
504
|
+
return renderStatus;
|
|
505
|
+
};
|
|
506
|
+
this._renderStats = (annotation, viewport, enabledElement, svgDrawingHelper) => {
|
|
507
|
+
const data = annotation.data;
|
|
508
|
+
const targetId = this.getTargetId(viewport);
|
|
509
|
+
if (!data.spline.closed) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const styleSpecifier = {
|
|
513
|
+
toolGroupId: this.toolGroupId,
|
|
514
|
+
toolName: this.getToolName(),
|
|
515
|
+
viewportId: enabledElement.viewport.id,
|
|
516
|
+
};
|
|
517
|
+
const options = this.getLinkedTextBoxStyle(styleSpecifier, annotation);
|
|
518
|
+
if (!options.visibility) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const textLines = this.configuration.getTextLines(data, targetId);
|
|
522
|
+
if (!textLines || textLines.length === 0) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
const canvasCoordinates = data.handles.points.map((p) => viewport.worldToCanvas(p));
|
|
526
|
+
if (!data.handles.textBox.hasMoved) {
|
|
527
|
+
const canvasTextBoxCoords = getTextBoxCoordsCanvas(canvasCoordinates);
|
|
528
|
+
data.handles.textBox.worldPosition =
|
|
529
|
+
viewport.canvasToWorld(canvasTextBoxCoords);
|
|
530
|
+
}
|
|
531
|
+
const textBoxPosition = viewport.worldToCanvas(data.handles.textBox.worldPosition);
|
|
532
|
+
const textBoxUID = 'textBox';
|
|
533
|
+
const boundingBox = drawLinkedTextBoxSvg(svgDrawingHelper, annotation.annotationUID ?? '', textBoxUID, textLines, textBoxPosition, canvasCoordinates, {}, options);
|
|
534
|
+
const { x: left, y: top, width, height } = boundingBox;
|
|
535
|
+
data.handles.textBox.worldBoundingBox = {
|
|
536
|
+
topLeft: viewport.canvasToWorld([left, top]),
|
|
537
|
+
topRight: viewport.canvasToWorld([left + width, top]),
|
|
538
|
+
bottomLeft: viewport.canvasToWorld([left, top + height]),
|
|
539
|
+
bottomRight: viewport.canvasToWorld([left + width, top + height]),
|
|
540
|
+
};
|
|
541
|
+
};
|
|
542
|
+
this.addControlPointCallback = (evt, annotation) => {
|
|
543
|
+
const { data } = annotation;
|
|
544
|
+
const splineType = data.spline.type;
|
|
545
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
546
|
+
const maxDist = splineConfig.controlPointAdditionDistance;
|
|
547
|
+
if (splineConfig.controlPointAdditionEnabled === false) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const eventDetail = evt.detail;
|
|
551
|
+
const { element } = eventDetail;
|
|
552
|
+
const enabledElement = getEnabledElement(element);
|
|
553
|
+
const { renderingEngine, viewport } = enabledElement;
|
|
554
|
+
const { canvasToWorld } = viewport;
|
|
555
|
+
const { instance: spline } = data.spline;
|
|
556
|
+
const canvasPos = evt.detail.currentPoints.canvas;
|
|
557
|
+
const closestPointInfo = spline.getClosestPoint(canvasPos);
|
|
558
|
+
if (closestPointInfo.distance > maxDist) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const { index, point: canvasPoint } = spline.addControlPointAtU(closestPointInfo.uValue);
|
|
562
|
+
data.handles.points.splice(index, 0, canvasToWorld(canvasPoint));
|
|
563
|
+
annotation.invalidated = true;
|
|
564
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
565
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
566
|
+
};
|
|
567
|
+
this.deleteControlPointCallback = (evt, annotation) => {
|
|
568
|
+
const splineType = annotation.data.spline.type;
|
|
569
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
570
|
+
const maxDist = splineConfig.controlPointDeletionDistance;
|
|
571
|
+
if (splineConfig.controlPointDeletionEnabled === false) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
const eventDetail = evt.detail;
|
|
575
|
+
const { element, currentPoints } = eventDetail;
|
|
576
|
+
const { canvas: canvasPos } = currentPoints;
|
|
577
|
+
const { instance: spline } = annotation.data.spline;
|
|
578
|
+
const closestControlPoint = spline.getClosestControlPointWithinDistance(canvasPos, maxDist);
|
|
579
|
+
if (!closestControlPoint) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
this._deleteControlPointByIndex(element, annotation, closestControlPoint.index);
|
|
583
|
+
};
|
|
584
|
+
this._calculateCachedStats = (annotation, element) => {
|
|
585
|
+
if (!this.configuration.calculateStats) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const data = annotation.data;
|
|
589
|
+
if (!data.spline.closed) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const enabledElement = getEnabledElement(element);
|
|
593
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
594
|
+
const { cachedStats } = data;
|
|
595
|
+
const { polyline: points } = data.spline;
|
|
596
|
+
const targetIds = Object.keys(cachedStats);
|
|
597
|
+
for (let i = 0; i < targetIds.length; i++) {
|
|
598
|
+
const targetId = targetIds[i];
|
|
599
|
+
const image = this.getTargetIdImage(targetId, renderingEngine);
|
|
600
|
+
if (!image) {
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const { metadata } = image;
|
|
604
|
+
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
|
|
605
|
+
const canvasPoint = canvasCoordinates[0];
|
|
606
|
+
const originalWorldPoint = viewport.canvasToWorld(canvasPoint);
|
|
607
|
+
const deltaXPoint = viewport.canvasToWorld([
|
|
608
|
+
canvasPoint[0] + 1,
|
|
609
|
+
canvasPoint[1],
|
|
610
|
+
]);
|
|
611
|
+
const deltaYPoint = viewport.canvasToWorld([
|
|
612
|
+
canvasPoint[0],
|
|
613
|
+
canvasPoint[1] + 1,
|
|
614
|
+
]);
|
|
615
|
+
const deltaInX = vec3.distance(originalWorldPoint, deltaXPoint);
|
|
616
|
+
const deltaInY = vec3.distance(originalWorldPoint, deltaYPoint);
|
|
617
|
+
const scale = getCalibratedScale(image);
|
|
618
|
+
let area = math.polyline.calculateAreaOfPoints(canvasCoordinates) / scale / scale;
|
|
619
|
+
area *= deltaInX * deltaInY;
|
|
620
|
+
cachedStats[targetId] = {
|
|
621
|
+
Modality: metadata.Modality,
|
|
622
|
+
area,
|
|
623
|
+
areaUnit: getCalibratedAreaUnits(null, image),
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
this.triggerAnnotationModified(annotation, enabledElement);
|
|
627
|
+
return cachedStats;
|
|
628
|
+
};
|
|
629
|
+
this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
|
|
630
|
+
}
|
|
631
|
+
static { this.SplineTypes = SplineTypesEnum; }
|
|
632
|
+
static { this.Actions = SplineToolActions; }
|
|
633
|
+
_deleteControlPointByIndex(element, annotation, controlPointIndex) {
|
|
634
|
+
const enabledElement = getEnabledElement(element);
|
|
635
|
+
const { points: controlPoints } = annotation.data.handles;
|
|
636
|
+
if (controlPoints.length === 3) {
|
|
637
|
+
removeAnnotation(annotation.annotationUID);
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
controlPoints.splice(controlPointIndex, 1);
|
|
641
|
+
}
|
|
642
|
+
const { renderingEngine } = enabledElement;
|
|
643
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(element, this.getToolName());
|
|
644
|
+
annotation.invalidated = true;
|
|
645
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
646
|
+
}
|
|
647
|
+
_getSplineConfig(type) {
|
|
648
|
+
const { configuration: config } = this;
|
|
649
|
+
const splineConfigs = config.spline.configuration;
|
|
650
|
+
return Object.assign({ type }, DEFAULT_SPLINE_CONFIG, splineConfigs[type]);
|
|
651
|
+
}
|
|
652
|
+
_updateSplineScale(spline, annotation) {
|
|
653
|
+
const splineType = annotation.data.spline.type;
|
|
654
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
655
|
+
if (!(spline instanceof CardinalSpline) ||
|
|
656
|
+
spline.fixedScale ||
|
|
657
|
+
splineConfig.scale === undefined ||
|
|
658
|
+
spline.scale === splineConfig.scale) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
spline.scale = splineConfig.scale;
|
|
662
|
+
annotation.invalidated = true;
|
|
663
|
+
}
|
|
664
|
+
_updateSplineInstance(element, annotation) {
|
|
665
|
+
const enabledElement = getEnabledElement(element);
|
|
666
|
+
const { viewport } = enabledElement;
|
|
667
|
+
const { worldToCanvas } = viewport;
|
|
668
|
+
const { data } = annotation;
|
|
669
|
+
const { type: splineType, instance: spline } = annotation.data.spline;
|
|
670
|
+
const splineConfig = this._getSplineConfig(splineType);
|
|
671
|
+
const worldPoints = data.handles.points;
|
|
672
|
+
const canvasPoints = worldPoints.map(worldToCanvas);
|
|
673
|
+
spline.setControlPoints(canvasPoints);
|
|
674
|
+
spline.closed = !!data.spline?.closed;
|
|
675
|
+
if (spline.resolution !== splineConfig.resolution) {
|
|
676
|
+
spline.resolution = parseInt(splineConfig.resolution);
|
|
677
|
+
annotation.invalidated = true;
|
|
678
|
+
}
|
|
679
|
+
if (spline instanceof CardinalSpline &&
|
|
680
|
+
!spline.fixedScale &&
|
|
681
|
+
splineConfig.scale !== undefined &&
|
|
682
|
+
spline.scale !== splineConfig.scale) {
|
|
683
|
+
spline.scale = splineConfig.scale;
|
|
684
|
+
annotation.invalidated = true;
|
|
685
|
+
}
|
|
686
|
+
return spline;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function defaultGetTextLines(data, targetId) {
|
|
690
|
+
const cachedVolumeStats = data.cachedStats[targetId];
|
|
691
|
+
const { area, isEmptyArea, areaUnit } = cachedVolumeStats;
|
|
692
|
+
const textLines = [];
|
|
693
|
+
if (area) {
|
|
694
|
+
const areaLine = isEmptyArea
|
|
695
|
+
? `Area: Oblique not supported`
|
|
696
|
+
: `Area: ${roundNumber(area)} ${areaUnit}`;
|
|
697
|
+
textLines.push(areaLine);
|
|
698
|
+
}
|
|
699
|
+
return textLines;
|
|
700
|
+
}
|
|
701
|
+
SplineROITool.toolName = 'SplineROI';
|
|
702
|
+
export default SplineROITool;
|
|
703
|
+
//# sourceMappingURL=SplineROITool.js.map
|