@cornerstonejs/tools 1.34.0 → 1.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,22 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { CubicSpline } from './CubicSpline';
|
|
3
|
+
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
const TRANSFORM_MATRIX = mat4.multiplyScalar(
|
|
6
|
+
mat4.create(),
|
|
7
|
+
mat4.fromValues(
|
|
8
|
+
1, 4, 1, 0,
|
|
9
|
+
-3, 0, 3, 0,
|
|
10
|
+
3, -6, 3, 0,
|
|
11
|
+
-1, 3, -3, 1,
|
|
12
|
+
),
|
|
13
|
+
1 / 6
|
|
14
|
+
) as number[];
|
|
15
|
+
|
|
16
|
+
class BSpline extends CubicSpline {
|
|
17
|
+
protected getTransformMatrix(): number[] {
|
|
18
|
+
return TRANSFORM_MATRIX;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { BSpline as default, BSpline };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CubicSpline } from './CubicSpline';
|
|
2
|
+
import { CardinalSplineProps } from '../../../types';
|
|
3
|
+
|
|
4
|
+
class CardinalSpline extends CubicSpline {
|
|
5
|
+
private _scale: number;
|
|
6
|
+
private _fixedScale: boolean;
|
|
7
|
+
|
|
8
|
+
constructor(props?: CardinalSplineProps) {
|
|
9
|
+
super(props);
|
|
10
|
+
this._scale = props?.scale ?? 0.5;
|
|
11
|
+
this._fixedScale = props?.fixedScale ?? false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get scale() {
|
|
15
|
+
return this._scale;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public set scale(scale: number) {
|
|
19
|
+
if (this._fixedScale || this._scale === scale) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this._scale = scale;
|
|
24
|
+
this.invalidated = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public get fixedScale() {
|
|
28
|
+
return this._fixedScale;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected getTransformMatrix(): number[] {
|
|
32
|
+
const { scale: s } = this;
|
|
33
|
+
const s2 = 2 * s;
|
|
34
|
+
|
|
35
|
+
// prettier-ignore
|
|
36
|
+
return [
|
|
37
|
+
0, 1, 0, 0,
|
|
38
|
+
-s, 0, s, 0,
|
|
39
|
+
s2, s - 3, 3 - s2, -s,
|
|
40
|
+
-s, 2 - s, s - 2, s
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { CardinalSpline as default, CardinalSpline };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CardinalSpline } from './CardinalSpline';
|
|
2
|
+
|
|
3
|
+
// Catmull-Rom spline matrix is a Cardinal spline with scale equal to 1/2. Then
|
|
4
|
+
// it can inherit from CubicSpline using the matrix below or inherit from
|
|
5
|
+
// CardinalSpline using a fixed scale equal to 0.5.
|
|
6
|
+
//
|
|
7
|
+
// Transformation Matrix:
|
|
8
|
+
// 0, 2, 0, 0,
|
|
9
|
+
// -1, 0, 1, 0,
|
|
10
|
+
// 2, -5, 4, -1,
|
|
11
|
+
// -1, 3, -3, 1
|
|
12
|
+
|
|
13
|
+
class CatmullRomSpline extends CardinalSpline {
|
|
14
|
+
constructor() {
|
|
15
|
+
super({ scale: 0.5, fixedScale: true });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { CatmullRomSpline as default, CatmullRomSpline };
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { vec4, mat4 } from 'gl-matrix';
|
|
2
|
+
import { Types } from '@cornerstonejs/core';
|
|
3
|
+
import { Spline } from './Spline';
|
|
4
|
+
import * as math from '../../../utilities/math';
|
|
5
|
+
import type { SplineCurveSegment, SplineLineSegment } from '../../../types';
|
|
6
|
+
|
|
7
|
+
// The `u` in Parameter Space used when spliting a curve segment into line segments must
|
|
8
|
+
// be greater than or equal to `curveSegmentIndex` and smaller than `curveSegmentIndex + 1`.
|
|
9
|
+
// In this case we are using `curveSegmentIndex + 1 - MAX_U_ERROR`
|
|
10
|
+
const MAX_U_ERROR = 1e-8;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Base class for all cubic splines
|
|
14
|
+
*/
|
|
15
|
+
abstract class CubicSpline extends Spline {
|
|
16
|
+
protected getPreviewCurveSegments(
|
|
17
|
+
controlPointPreview: Types.Point2,
|
|
18
|
+
closeSpline: boolean
|
|
19
|
+
): SplineCurveSegment[] {
|
|
20
|
+
const previewNumCurveSegments = this._getNumCurveSegments() + 1;
|
|
21
|
+
const startCurveSegIndex = Math.max(0, previewNumCurveSegments - 2);
|
|
22
|
+
const endCurveSegIndex = closeSpline
|
|
23
|
+
? previewNumCurveSegments
|
|
24
|
+
: previewNumCurveSegments - 1;
|
|
25
|
+
const transformMatrix = this.getTransformMatrix();
|
|
26
|
+
const controlPoints = [...this.controlPoints];
|
|
27
|
+
const curveSegments: SplineCurveSegment[] = [];
|
|
28
|
+
|
|
29
|
+
if (!closeSpline) {
|
|
30
|
+
controlPoints.push(controlPointPreview);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (let i = startCurveSegIndex; i <= endCurveSegIndex; i++) {
|
|
34
|
+
const curveSegment = this._getCurveSegment(
|
|
35
|
+
i,
|
|
36
|
+
transformMatrix,
|
|
37
|
+
controlPoints,
|
|
38
|
+
closeSpline
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
curveSegments.push(curveSegment);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return curveSegments;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected getSplineCurves(): SplineCurveSegment[] {
|
|
48
|
+
const numCurveSegments = this._getNumCurveSegments();
|
|
49
|
+
const curveSegments: SplineCurveSegment[] = new Array(numCurveSegments);
|
|
50
|
+
|
|
51
|
+
if (numCurveSegments <= 0) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const transformMatrix = this.getTransformMatrix();
|
|
56
|
+
let previousCurveSegmentsLength = 0;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < numCurveSegments; i++) {
|
|
59
|
+
const curveSegment = this._getCurveSegment(i, transformMatrix);
|
|
60
|
+
|
|
61
|
+
curveSegment.previousCurveSegmentsLength = previousCurveSegmentsLength;
|
|
62
|
+
curveSegments[i] = curveSegment;
|
|
63
|
+
|
|
64
|
+
previousCurveSegmentsLength += curveSegment.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return curveSegments;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private _getNumCurveSegments(
|
|
71
|
+
controlPoints: Types.Point2[] = this.controlPoints,
|
|
72
|
+
closed: boolean = this.closed
|
|
73
|
+
): number {
|
|
74
|
+
return closed
|
|
75
|
+
? controlPoints.length
|
|
76
|
+
: Math.max(0, controlPoints.length - 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get a point on a spline curve given `u` value
|
|
81
|
+
*
|
|
82
|
+
* @param u - `u` value in Parameter Space that must be between 0 and N where N is the number of
|
|
83
|
+
* curve segments for opened splines or any negative/positive number for closed splines
|
|
84
|
+
* @returns - Point (x, y) on the spline. It may return `undefined` when `u` is smaller than 0
|
|
85
|
+
* or greater than N for opened splines
|
|
86
|
+
*/
|
|
87
|
+
private _getPoint(
|
|
88
|
+
u: number,
|
|
89
|
+
transformMatrix: number[],
|
|
90
|
+
controlPoints: Types.Point2[] = this.controlPoints,
|
|
91
|
+
closed: boolean = this.closed
|
|
92
|
+
): Types.Point2 {
|
|
93
|
+
const numCurveSegments = this._getNumCurveSegments(controlPoints, closed);
|
|
94
|
+
const uInt = Math.floor(u);
|
|
95
|
+
let curveSegmentIndex = uInt % numCurveSegments;
|
|
96
|
+
|
|
97
|
+
// `t` must be between 0 and 1
|
|
98
|
+
const t = u - uInt;
|
|
99
|
+
|
|
100
|
+
const curveSegmentIndexOutOfBounds =
|
|
101
|
+
curveSegmentIndex < 0 || curveSegmentIndex >= numCurveSegments;
|
|
102
|
+
|
|
103
|
+
if (curveSegmentIndexOutOfBounds) {
|
|
104
|
+
if (this.closed) {
|
|
105
|
+
// Wraps around when the index is negative or greater than or equal to `numSegments`
|
|
106
|
+
curveSegmentIndex =
|
|
107
|
+
(numCurveSegments + curveSegmentIndex) % numCurveSegments;
|
|
108
|
+
} else {
|
|
109
|
+
// Point is not on the spline curve
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { p0, p1, p2, p3 } = this._getCurveSegmentPoints(
|
|
115
|
+
curveSegmentIndex,
|
|
116
|
+
controlPoints,
|
|
117
|
+
closed
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// Formula to find any point on a cubic spline curve given a `t` value
|
|
121
|
+
//
|
|
122
|
+
// P(t) = [1 t t2 t3] | m00 m01 m02 m03 | | P0 |
|
|
123
|
+
// | m10 m11 m12 m13 | | P1 |
|
|
124
|
+
// | m20 m21 m22 m23 | | P2 |
|
|
125
|
+
// | m30 m31 m32 m33 | | P3 |
|
|
126
|
+
|
|
127
|
+
const tt = t * t;
|
|
128
|
+
const ttt = tt * t;
|
|
129
|
+
const tValues = vec4.fromValues(1, t, tt, ttt);
|
|
130
|
+
|
|
131
|
+
// Influential field values which tell us how much P0, P1, P2 and P3 influence
|
|
132
|
+
// each point of the curve
|
|
133
|
+
const qValues = vec4.transformMat4(
|
|
134
|
+
vec4.create(),
|
|
135
|
+
tValues,
|
|
136
|
+
transformMatrix as mat4
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return [
|
|
140
|
+
vec4.dot(qValues, vec4.fromValues(p0[0], p1[0], p2[0], p3[0])),
|
|
141
|
+
vec4.dot(qValues, vec4.fromValues(p0[1], p1[1], p2[1], p3[1])),
|
|
142
|
+
] as Types.Point2;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private _getCurveSegmentPoints(
|
|
146
|
+
curveSegmentIndex: number,
|
|
147
|
+
controlPoints: Types.Point2[] = this.controlPoints,
|
|
148
|
+
closed: boolean = this.closed
|
|
149
|
+
) {
|
|
150
|
+
const numCurveSegments = this._getNumCurveSegments(controlPoints, closed);
|
|
151
|
+
const p1Index = curveSegmentIndex;
|
|
152
|
+
const p0Index = p1Index - 1;
|
|
153
|
+
const p2Index = closed ? (p1Index + 1) % numCurveSegments : p1Index + 1;
|
|
154
|
+
const p3Index = p2Index + 1;
|
|
155
|
+
const p1 = controlPoints[p1Index];
|
|
156
|
+
const p2 = controlPoints[p2Index];
|
|
157
|
+
let p0;
|
|
158
|
+
let p3;
|
|
159
|
+
|
|
160
|
+
// P0 shall be negative when P1/P2 are the start/end points of the first curve segment
|
|
161
|
+
if (p0Index >= 0) {
|
|
162
|
+
p0 = controlPoints[p0Index];
|
|
163
|
+
} else {
|
|
164
|
+
p0 = closed
|
|
165
|
+
? controlPoints[controlPoints.length - 1]
|
|
166
|
+
: math.point.mirror(p2, p1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// P3 shall be negative when P1/P2 are the start/end points of the last curve segment
|
|
170
|
+
if (p3Index < controlPoints.length) {
|
|
171
|
+
p3 = controlPoints[p3Index];
|
|
172
|
+
} else {
|
|
173
|
+
p3 = closed ? controlPoints[0] : math.point.mirror(p1, p2);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { p0, p1, p2, p3 };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private _getLineSegments(
|
|
180
|
+
curveSegmentIndex: number,
|
|
181
|
+
transformMatrix: number[],
|
|
182
|
+
controlPoints: Types.Point2[] = this.controlPoints,
|
|
183
|
+
closed: boolean = this.closed
|
|
184
|
+
): SplineLineSegment[] {
|
|
185
|
+
const numCurveSegments = this._getNumCurveSegments(controlPoints, closed);
|
|
186
|
+
const numLineSegments = this.resolution + 1;
|
|
187
|
+
const inc = 1 / numLineSegments;
|
|
188
|
+
const minU = curveSegmentIndex;
|
|
189
|
+
let maxU = minU + 1;
|
|
190
|
+
|
|
191
|
+
// 'u' must be greater than or equal to 0 and smaller than N where N is the number of segments
|
|
192
|
+
// otherwise it does not find the spline segment when it is not a closed curve because it is
|
|
193
|
+
// 0-based indexed. In this case `u` needs to get very close to the end point but never touch it
|
|
194
|
+
if (!closed && curveSegmentIndex === numCurveSegments - 1) {
|
|
195
|
+
maxU -= MAX_U_ERROR;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const lineSegments: SplineLineSegment[] = [];
|
|
199
|
+
let startPoint: Types.Point2;
|
|
200
|
+
let endPoint: Types.Point2;
|
|
201
|
+
let previousLineSegmentsLength = 0;
|
|
202
|
+
|
|
203
|
+
for (let i = 0, u = minU; i <= numLineSegments; i++, u += inc) {
|
|
204
|
+
// `u` may be greater than maxU in the last FOR loop due to number precision issue
|
|
205
|
+
u = u > maxU ? maxU : u;
|
|
206
|
+
|
|
207
|
+
const point = this._getPoint(u, transformMatrix, controlPoints, closed);
|
|
208
|
+
|
|
209
|
+
if (!i) {
|
|
210
|
+
startPoint = point;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
endPoint = point;
|
|
215
|
+
|
|
216
|
+
const dx = endPoint[0] - startPoint[0];
|
|
217
|
+
const dy = endPoint[1] - startPoint[1];
|
|
218
|
+
const length = Math.sqrt(dx ** 2 + dy ** 2);
|
|
219
|
+
const aabb: Types.AABB2 = {
|
|
220
|
+
minX: startPoint[0] <= endPoint[0] ? startPoint[0] : endPoint[0],
|
|
221
|
+
maxX: startPoint[0] >= endPoint[0] ? startPoint[0] : endPoint[0],
|
|
222
|
+
minY: startPoint[1] <= endPoint[1] ? startPoint[1] : endPoint[1],
|
|
223
|
+
maxY: startPoint[1] >= endPoint[1] ? startPoint[1] : endPoint[1],
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
lineSegments.push({
|
|
227
|
+
points: {
|
|
228
|
+
start: startPoint,
|
|
229
|
+
end: endPoint,
|
|
230
|
+
},
|
|
231
|
+
aabb,
|
|
232
|
+
length,
|
|
233
|
+
previousLineSegmentsLength,
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
startPoint = endPoint;
|
|
237
|
+
previousLineSegmentsLength += length;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return lineSegments;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private _getCurveSegment(
|
|
244
|
+
curveSegmentIndex: number,
|
|
245
|
+
transformMatrix: number[] = this.getTransformMatrix(),
|
|
246
|
+
controlPoints: Types.Point2[] = this.controlPoints,
|
|
247
|
+
closed: boolean = this.closed
|
|
248
|
+
): SplineCurveSegment {
|
|
249
|
+
// Cubic spline curves are mainly controlled by P1 and P2 points but
|
|
250
|
+
// they are also influenced by previous (P0) and next (P3) poins. For
|
|
251
|
+
// Cardinal, Linear and Catmull-Rom splines P1 and P2 are also known as
|
|
252
|
+
// knots because they are the connection between two curve segments.
|
|
253
|
+
const { p0, p1, p2, p3 } = this._getCurveSegmentPoints(
|
|
254
|
+
curveSegmentIndex,
|
|
255
|
+
controlPoints,
|
|
256
|
+
closed
|
|
257
|
+
);
|
|
258
|
+
const lineSegments = this._getLineSegments(
|
|
259
|
+
curveSegmentIndex,
|
|
260
|
+
transformMatrix,
|
|
261
|
+
controlPoints,
|
|
262
|
+
closed
|
|
263
|
+
);
|
|
264
|
+
let curveSegmentLength = 0;
|
|
265
|
+
let minX = Infinity;
|
|
266
|
+
let minY = Infinity;
|
|
267
|
+
let maxX = -Infinity;
|
|
268
|
+
let maxY = -Infinity;
|
|
269
|
+
|
|
270
|
+
lineSegments.forEach(({ aabb: lineSegAABB, length: lineSegLength }) => {
|
|
271
|
+
minX = Math.min(minX, lineSegAABB.minX);
|
|
272
|
+
minY = Math.min(minY, lineSegAABB.minY);
|
|
273
|
+
maxX = Math.max(maxX, lineSegAABB.maxX);
|
|
274
|
+
maxY = Math.max(maxY, lineSegAABB.maxY);
|
|
275
|
+
curveSegmentLength += lineSegLength;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
controlPoints: { p0, p1, p2, p3 },
|
|
280
|
+
aabb: { minX, minY, maxX, maxY },
|
|
281
|
+
length: curveSegmentLength,
|
|
282
|
+
previousCurveSegmentsLength: 0,
|
|
283
|
+
lineSegments,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { CubicSpline as default, CubicSpline };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CardinalSpline } from './CardinalSpline';
|
|
2
|
+
|
|
3
|
+
// TODO: LinearSpline should inherit from Spline
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Linear spline matrix is the same one from Cardinal spline with scale equal
|
|
7
|
+
* to 0. Then it can inherit from Spline using the matrix below or inherit from
|
|
8
|
+
* CardinalSpline fixing the scale to 0
|
|
9
|
+
*
|
|
10
|
+
* Transformation Matrix:
|
|
11
|
+
* 1, 0,
|
|
12
|
+
* -1, -1,
|
|
13
|
+
*/
|
|
14
|
+
class LinearSpline extends CardinalSpline {
|
|
15
|
+
constructor() {
|
|
16
|
+
super({ scale: 0, fixedScale: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { LinearSpline as default, LinearSpline };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QuadraticSpline } from './QuadraticSpline';
|
|
2
|
+
|
|
3
|
+
// prettier-ignore
|
|
4
|
+
const TRANSFORM_MATRIX = [
|
|
5
|
+
1, 0, 0,
|
|
6
|
+
-2, 2, 0,
|
|
7
|
+
1, -2, 1,
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
class QuadraticBezier extends QuadraticSpline {
|
|
11
|
+
public hasTangentPoints() {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected getTransformMatrix(): number[] {
|
|
16
|
+
return TRANSFORM_MATRIX;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { QuadraticBezier as default, QuadraticBezier };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
import { Spline } from './Spline';
|
|
3
|
+
import type { SplineLineSegment, SplineCurveSegment } from '../../../types/';
|
|
4
|
+
|
|
5
|
+
abstract class QuadraticSpline extends Spline {
|
|
6
|
+
// TODO: QuadraticSpline :: getSplineCurves
|
|
7
|
+
protected getSplineCurves(): SplineCurveSegment[] {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// TODO: QuadraticSpline :: getLineSegments
|
|
12
|
+
protected getLineSegments(): SplineLineSegment[] {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO: QuadraticSpline :: getPreviewCurveSegments
|
|
17
|
+
public getPreviewCurveSegments(
|
|
18
|
+
controlPointPreview: Types.Point2,
|
|
19
|
+
closeSpline: boolean
|
|
20
|
+
): SplineCurveSegment[] {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { QuadraticSpline as default, QuadraticSpline };
|