@cornerstonejs/tools 1.50.3 → 1.51.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/eventListeners/annotations/annotationCompletedListener.d.ts +2 -0
- package/dist/cjs/eventListeners/annotations/annotationCompletedListener.js +35 -0
- package/dist/cjs/eventListeners/annotations/annotationCompletedListener.js.map +1 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +2 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +174 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/index.d.ts +1 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/index.js +9 -0
- package/dist/cjs/eventListeners/annotations/contourSegmentation/index.js.map +1 -0
- package/dist/cjs/eventListeners/annotations/index.d.ts +2 -1
- package/dist/cjs/eventListeners/annotations/index.js +3 -1
- package/dist/cjs/eventListeners/annotations/index.js.map +1 -1
- package/dist/cjs/eventListeners/index.d.ts +2 -2
- package/dist/cjs/eventListeners/index.js +2 -1
- package/dist/cjs/eventListeners/index.js.map +1 -1
- package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts +3 -0
- package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +89 -0
- package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js.map +1 -0
- package/dist/cjs/eventListeners/segmentation/segmentationDataModifiedEventListener.js +5 -53
- package/dist/cjs/eventListeners/segmentation/segmentationDataModifiedEventListener.js.map +1 -1
- package/dist/cjs/init.js +2 -0
- package/dist/cjs/init.js.map +1 -1
- package/dist/cjs/stateManagement/annotation/helpers/state.d.ts +3 -1
- package/dist/cjs/stateManagement/annotation/helpers/state.js +21 -1
- package/dist/cjs/stateManagement/annotation/helpers/state.js.map +1 -1
- package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +1 -0
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js +3 -0
- package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/cjs/store/addTool.d.ts +1 -0
- package/dist/cjs/store/addTool.js +6 -1
- package/dist/cjs/store/addTool.js.map +1 -1
- package/dist/cjs/store/index.d.ts +2 -2
- package/dist/cjs/store/index.js +2 -1
- package/dist/cjs/store/index.js.map +1 -1
- package/dist/cjs/store/removeEnabledElement.js +1 -2
- package/dist/cjs/store/removeEnabledElement.js.map +1 -1
- package/dist/cjs/tools/AdvancedMagnifyTool.js +3 -10
- package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
- package/dist/cjs/tools/annotation/AngleTool.js +5 -18
- package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
- package/dist/cjs/tools/annotation/ArrowAnnotateTool.js +9 -28
- package/dist/cjs/tools/annotation/ArrowAnnotateTool.js.map +1 -1
- package/dist/cjs/tools/annotation/BidirectionalTool.js +7 -22
- package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/cjs/tools/annotation/CircleROITool.js +7 -22
- package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/CobbAngleTool.js +5 -18
- package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
- package/dist/cjs/tools/annotation/EllipticalROITool.js +7 -22
- package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/KeyImageTool.js +5 -12
- package/dist/cjs/tools/annotation/KeyImageTool.js.map +1 -1
- package/dist/cjs/tools/annotation/LengthTool.js +5 -18
- package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +4 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.js +30 -22
- package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +2 -1
- package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js +11 -0
- package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +2 -10
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +6 -22
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/ProbeTool.js +8 -23
- package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/cjs/tools/annotation/RectangleROITool.js +8 -22
- package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/SplineROITool.d.ts +8 -9
- package/dist/cjs/tools/annotation/SplineROITool.js +27 -10
- package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/UltrasoundDirectionalTool.js +5 -18
- package/dist/cjs/tools/annotation/UltrasoundDirectionalTool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +7 -6
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +8 -5
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/editLoopCommon.js +8 -8
- package/dist/cjs/tools/annotation/planarFreehandROITool/editLoopCommon.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +6 -5
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/base/ContourBaseTool.d.ts +2 -8
- package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.d.ts +3 -2
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.js +13 -1
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js +3 -9
- package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
- package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js +3 -9
- package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
- package/dist/cjs/types/AnnotationRenderContext.d.ts +11 -0
- package/dist/cjs/types/AnnotationRenderContext.js +3 -0
- package/dist/cjs/types/AnnotationRenderContext.js.map +1 -0
- package/dist/cjs/types/IToolGroup.d.ts +2 -1
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/utilities/contourSegmentation/areSameSegment.d.ts +2 -0
- package/dist/cjs/utilities/contourSegmentation/areSameSegment.js +12 -0
- package/dist/cjs/utilities/contourSegmentation/areSameSegment.js.map +1 -0
- package/dist/cjs/utilities/contourSegmentation/index.d.ts +2 -0
- package/dist/cjs/utilities/contourSegmentation/index.js +11 -0
- package/dist/cjs/utilities/contourSegmentation/index.js.map +1 -0
- package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts +3 -0
- package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.js +8 -0
- package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.js.map +1 -0
- package/dist/cjs/utilities/contours/areCoplanarContours.d.ts +2 -0
- package/dist/cjs/utilities/contours/areCoplanarContours.js +19 -0
- package/dist/cjs/utilities/contours/areCoplanarContours.js.map +1 -0
- package/dist/cjs/utilities/contours/index.d.ts +2 -1
- package/dist/cjs/utilities/contours/index.js +3 -1
- package/dist/cjs/utilities/contours/index.js.map +1 -1
- package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js +3 -22
- package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
- package/dist/cjs/utilities/math/aabb/index.d.ts +1 -0
- package/dist/cjs/utilities/math/aabb/index.js +3 -1
- package/dist/cjs/utilities/math/aabb/index.js.map +1 -1
- package/dist/cjs/utilities/math/aabb/intersectAABB.d.ts +2 -0
- package/dist/cjs/utilities/math/aabb/intersectAABB.js +10 -0
- package/dist/cjs/utilities/math/aabb/intersectAABB.js.map +1 -0
- package/dist/cjs/utilities/math/point/distanceToPointSquared.js +4 -1
- package/dist/cjs/utilities/math/point/distanceToPointSquared.js.map +1 -1
- package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.js +59 -0
- package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/combinePolyline.d.ts +4 -0
- package/dist/cjs/utilities/math/polyline/combinePolyline.js +213 -0
- package/dist/cjs/utilities/math/polyline/combinePolyline.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/containsPoint.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/containsPoint.js +36 -0
- package/dist/cjs/utilities/math/polyline/containsPoint.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getAABB.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getAABB.js +18 -0
- package/dist/cjs/utilities/math/polyline/getAABB.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getArea.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/{calculateAreaOfPoints.js → getArea.js} +3 -3
- package/dist/cjs/utilities/math/polyline/getArea.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts +5 -0
- package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.js +51 -0
- package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js +28 -0
- package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js +20 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js +22 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.js +21 -0
- package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getNormal2.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getNormal2.js +12 -0
- package/dist/cjs/utilities/math/polyline/getNormal2.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getNormal3.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getNormal3.js +29 -0
- package/dist/cjs/utilities/math/polyline/getNormal3.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/getSignedArea.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/getSignedArea.js +20 -0
- package/dist/cjs/utilities/math/polyline/getSignedArea.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/index.d.ts +14 -3
- package/dist/cjs/utilities/math/polyline/index.js +28 -6
- package/dist/cjs/utilities/math/polyline/index.js.map +1 -1
- package/dist/cjs/utilities/math/polyline/intersectPolyline.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/intersectPolyline.js +20 -0
- package/dist/cjs/utilities/math/polyline/intersectPolyline.js.map +1 -0
- package/dist/cjs/utilities/math/polyline/isClosed.d.ts +2 -0
- package/dist/cjs/utilities/math/polyline/isClosed.js +39 -0
- package/dist/cjs/utilities/math/polyline/isClosed.js.map +1 -0
- package/dist/esm/eventListeners/annotations/annotationCompletedListener.js +9 -0
- package/dist/esm/eventListeners/annotations/annotationCompletedListener.js.map +1 -0
- package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +153 -0
- package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -0
- package/dist/esm/eventListeners/annotations/contourSegmentation/index.js +2 -0
- package/dist/esm/eventListeners/annotations/contourSegmentation/index.js.map +1 -0
- package/dist/esm/eventListeners/annotations/index.js +2 -1
- package/dist/esm/eventListeners/annotations/index.js.map +1 -1
- package/dist/esm/eventListeners/index.js +2 -2
- package/dist/esm/eventListeners/index.js.map +1 -1
- package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +61 -0
- package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js.map +1 -0
- package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js +5 -53
- package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js.map +1 -1
- package/dist/esm/init.js +3 -1
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/stateManagement/annotation/helpers/state.js +19 -1
- package/dist/esm/stateManagement/annotation/helpers/state.js.map +1 -1
- package/dist/esm/store/ToolGroupManager/ToolGroup.js +3 -0
- package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
- package/dist/esm/store/addTool.js +4 -0
- package/dist/esm/store/addTool.js.map +1 -1
- package/dist/esm/store/index.js +2 -2
- package/dist/esm/store/index.js.map +1 -1
- package/dist/esm/store/removeEnabledElement.js +1 -2
- package/dist/esm/store/removeEnabledElement.js.map +1 -1
- package/dist/esm/tools/AdvancedMagnifyTool.js +4 -11
- package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
- package/dist/esm/tools/annotation/AngleTool.js +6 -19
- package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
- package/dist/esm/tools/annotation/ArrowAnnotateTool.js +10 -29
- package/dist/esm/tools/annotation/ArrowAnnotateTool.js.map +1 -1
- package/dist/esm/tools/annotation/BidirectionalTool.js +8 -23
- package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
- package/dist/esm/tools/annotation/CircleROITool.js +8 -23
- package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
- package/dist/esm/tools/annotation/CobbAngleTool.js +6 -19
- package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
- package/dist/esm/tools/annotation/EllipticalROITool.js +8 -23
- package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
- package/dist/esm/tools/annotation/KeyImageTool.js +6 -13
- package/dist/esm/tools/annotation/KeyImageTool.js.map +1 -1
- package/dist/esm/tools/annotation/LengthTool.js +6 -19
- package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
- package/dist/esm/tools/annotation/LivewireContourTool.js +31 -23
- package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js +11 -0
- package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +7 -23
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/ProbeTool.js +9 -24
- package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
- package/dist/esm/tools/annotation/RectangleROITool.js +9 -23
- package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +26 -9
- package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js +6 -19
- package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +7 -6
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +8 -5
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/editLoopCommon.js +8 -8
- package/dist/esm/tools/annotation/planarFreehandROITool/editLoopCommon.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +6 -5
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js +13 -1
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +4 -10
- package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
- package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js +4 -10
- package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
- package/dist/esm/types/AnnotationRenderContext.js +2 -0
- package/dist/esm/types/AnnotationRenderContext.js.map +1 -0
- package/dist/esm/utilities/contourSegmentation/areSameSegment.js +9 -0
- package/dist/esm/utilities/contourSegmentation/areSameSegment.js.map +1 -0
- package/dist/esm/utilities/contourSegmentation/index.js +3 -0
- package/dist/esm/utilities/contourSegmentation/index.js.map +1 -0
- package/dist/esm/utilities/contourSegmentation/isContourSegmentationAnnotation.js +4 -0
- package/dist/esm/utilities/contourSegmentation/isContourSegmentationAnnotation.js.map +1 -0
- package/dist/esm/utilities/contours/areCoplanarContours.js +16 -0
- package/dist/esm/utilities/contours/areCoplanarContours.js.map +1 -0
- package/dist/esm/utilities/contours/index.js +2 -1
- package/dist/esm/utilities/contours/index.js.map +1 -1
- package/dist/esm/utilities/contours/reverseIfAntiClockwise.js +3 -22
- package/dist/esm/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
- package/dist/esm/utilities/math/aabb/index.js +1 -0
- package/dist/esm/utilities/math/aabb/index.js.map +1 -1
- package/dist/esm/utilities/math/aabb/intersectAABB.js +7 -0
- package/dist/esm/utilities/math/aabb/intersectAABB.js.map +1 -0
- package/dist/esm/utilities/math/point/distanceToPointSquared.js +4 -1
- package/dist/esm/utilities/math/point/distanceToPointSquared.js.map +1 -1
- package/dist/esm/utilities/math/polyline/areLineSegmentsIntersecting.js +56 -0
- package/dist/esm/utilities/math/polyline/areLineSegmentsIntersecting.js.map +1 -0
- package/dist/esm/utilities/math/polyline/combinePolyline.js +187 -0
- package/dist/esm/utilities/math/polyline/combinePolyline.js.map +1 -0
- package/dist/esm/utilities/math/polyline/containsPoint.js +30 -0
- package/dist/esm/utilities/math/polyline/containsPoint.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getAABB.js +15 -0
- package/dist/esm/utilities/math/polyline/getAABB.js.map +1 -0
- package/dist/esm/utilities/math/polyline/{calculateAreaOfPoints.js → getArea.js} +2 -2
- package/dist/esm/utilities/math/polyline/getArea.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getClosestLineSegmentIntersection.js +45 -0
- package/dist/esm/utilities/math/polyline/getClosestLineSegmentIntersection.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js +22 -0
- package/dist/esm/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js +14 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js +16 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentsIntersection.js +18 -0
- package/dist/esm/utilities/math/polyline/getLineSegmentsIntersection.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getNormal2.js +6 -0
- package/dist/esm/utilities/math/polyline/getNormal2.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getNormal3.js +26 -0
- package/dist/esm/utilities/math/polyline/getNormal3.js.map +1 -0
- package/dist/esm/utilities/math/polyline/getSignedArea.js +17 -0
- package/dist/esm/utilities/math/polyline/getSignedArea.js.map +1 -0
- package/dist/esm/utilities/math/polyline/index.js +14 -3
- package/dist/esm/utilities/math/polyline/index.js.map +1 -1
- package/dist/esm/utilities/math/polyline/intersectPolyline.js +14 -0
- package/dist/esm/utilities/math/polyline/intersectPolyline.js.map +1 -0
- package/dist/esm/utilities/math/polyline/isClosed.js +13 -0
- package/dist/esm/utilities/math/polyline/isClosed.js.map +1 -0
- package/dist/types/eventListeners/annotations/annotationCompletedListener.d.ts +3 -0
- package/dist/types/eventListeners/annotations/annotationCompletedListener.d.ts.map +1 -0
- package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +3 -0
- package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts.map +1 -0
- package/dist/types/eventListeners/annotations/contourSegmentation/index.d.ts +2 -0
- package/dist/types/eventListeners/annotations/contourSegmentation/index.d.ts.map +1 -0
- package/dist/types/eventListeners/annotations/index.d.ts +2 -1
- package/dist/types/eventListeners/annotations/index.d.ts.map +1 -1
- package/dist/types/eventListeners/index.d.ts +2 -2
- package/dist/types/eventListeners/index.d.ts.map +1 -1
- package/dist/types/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts +4 -0
- package/dist/types/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts.map +1 -0
- package/dist/types/eventListeners/segmentation/segmentationDataModifiedEventListener.d.ts.map +1 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/stateManagement/annotation/helpers/state.d.ts +3 -1
- package/dist/types/stateManagement/annotation/helpers/state.d.ts.map +1 -1
- package/dist/types/store/ToolGroupManager/ToolGroup.d.ts +1 -0
- package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
- package/dist/types/store/addTool.d.ts +1 -0
- package/dist/types/store/addTool.d.ts.map +1 -1
- package/dist/types/store/index.d.ts +2 -2
- package/dist/types/store/index.d.ts.map +1 -1
- package/dist/types/store/removeEnabledElement.d.ts.map +1 -1
- package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/AngleTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/ArrowAnnotateTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/BidirectionalTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/CircleROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/CobbAngleTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/KeyImageTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/LengthTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/LivewireContourTool.d.ts +4 -1
- package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +2 -1
- package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +2 -10
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/ProbeTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/SplineROITool.d.ts +8 -9
- package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/UltrasoundDirectionalTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/closedContourEditLoop.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/drawLoop.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/editLoopCommon.d.ts.map +1 -1
- package/dist/types/tools/annotation/planarFreehandROITool/openContourEditLoop.d.ts.map +1 -1
- package/dist/types/tools/base/ContourBaseTool.d.ts +2 -8
- package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -1
- package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts +3 -2
- package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
- package/dist/types/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts.map +1 -1
- package/dist/types/tools/segmentation/RectangleROIThresholdTool.d.ts.map +1 -1
- package/dist/types/types/AnnotationRenderContext.d.ts +12 -0
- package/dist/types/types/AnnotationRenderContext.d.ts.map +1 -0
- package/dist/types/types/IToolGroup.d.ts +2 -1
- package/dist/types/types/IToolGroup.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/utilities/contourSegmentation/areSameSegment.d.ts +3 -0
- package/dist/types/utilities/contourSegmentation/areSameSegment.d.ts.map +1 -0
- package/dist/types/utilities/contourSegmentation/index.d.ts +3 -0
- package/dist/types/utilities/contourSegmentation/index.d.ts.map +1 -0
- package/dist/types/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts +4 -0
- package/dist/types/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts.map +1 -0
- package/dist/types/utilities/contours/areCoplanarContours.d.ts +3 -0
- package/dist/types/utilities/contours/areCoplanarContours.d.ts.map +1 -0
- package/dist/types/utilities/contours/index.d.ts +2 -1
- package/dist/types/utilities/contours/index.d.ts.map +1 -1
- package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts.map +1 -1
- package/dist/types/utilities/math/aabb/index.d.ts +1 -0
- package/dist/types/utilities/math/aabb/index.d.ts.map +1 -1
- package/dist/types/utilities/math/aabb/intersectAABB.d.ts +3 -0
- package/dist/types/utilities/math/aabb/intersectAABB.d.ts.map +1 -0
- package/dist/types/utilities/math/point/distanceToPointSquared.d.ts.map +1 -1
- package/dist/types/utilities/math/polyline/areLineSegmentsIntersecting.d.ts +3 -0
- package/dist/types/utilities/math/polyline/areLineSegmentsIntersecting.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/combinePolyline.d.ts +5 -0
- package/dist/types/utilities/math/polyline/combinePolyline.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/containsPoint.d.ts +3 -0
- package/dist/types/utilities/math/polyline/containsPoint.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getAABB.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getAABB.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getArea.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getArea.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts +6 -0
- package/dist/types/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getLineSegmentsIntersection.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getLineSegmentsIntersection.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getNormal2.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getNormal2.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getNormal3.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getNormal3.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/getSignedArea.d.ts +3 -0
- package/dist/types/utilities/math/polyline/getSignedArea.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/index.d.ts +14 -3
- package/dist/types/utilities/math/polyline/index.d.ts.map +1 -1
- package/dist/types/utilities/math/polyline/intersectPolyline.d.ts +3 -0
- package/dist/types/utilities/math/polyline/intersectPolyline.d.ts.map +1 -0
- package/dist/types/utilities/math/polyline/isClosed.d.ts +3 -0
- package/dist/types/utilities/math/polyline/isClosed.d.ts.map +1 -0
- package/dist/umd/index.js +1 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/eventListeners/annotations/annotationCompletedListener.ts +13 -0
- package/src/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.ts +273 -0
- package/src/eventListeners/annotations/contourSegmentation/index.ts +1 -0
- package/src/eventListeners/annotations/index.ts +6 -1
- package/src/eventListeners/index.ts +2 -0
- package/src/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.ts +117 -0
- package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +5 -99
- package/src/init.ts +12 -1
- package/src/stateManagement/annotation/helpers/state.ts +42 -2
- package/src/store/ToolGroupManager/ToolGroup.ts +10 -0
- package/src/store/addTool.ts +11 -0
- package/src/store/index.ts +2 -1
- package/src/store/removeEnabledElement.ts +2 -1
- package/src/tools/AdvancedMagnifyTool.ts +4 -21
- package/src/tools/annotation/AngleTool.ts +8 -32
- package/src/tools/annotation/ArrowAnnotateTool.ts +12 -45
- package/src/tools/annotation/BidirectionalTool.ts +11 -39
- package/src/tools/annotation/CircleROITool.ts +10 -34
- package/src/tools/annotation/CobbAngleTool.ts +9 -32
- package/src/tools/annotation/EllipticalROITool.ts +10 -34
- package/src/tools/annotation/KeyImageTool.ts +9 -23
- package/src/tools/annotation/LengthTool.ts +9 -33
- package/src/tools/annotation/LivewireContourTool.ts +58 -33
- package/src/tools/annotation/PlanarFreehandContourSegmentationTool.ts +22 -1
- package/src/tools/annotation/PlanarFreehandROITool.ts +10 -53
- package/src/tools/annotation/ProbeTool.ts +11 -36
- package/src/tools/annotation/RectangleROITool.ts +11 -33
- package/src/tools/annotation/SplineROITool.ts +53 -24
- package/src/tools/annotation/UltrasoundDirectionalTool.ts +8 -29
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +9 -11
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +8 -5
- package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +9 -8
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +7 -6
- package/src/tools/base/ContourBaseTool.ts +5 -8
- package/src/tools/base/ContourSegmentationBaseTool.ts +29 -6
- package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +3 -13
- package/src/tools/segmentation/RectangleROIThresholdTool.ts +3 -14
- package/src/types/AnnotationRenderContext.ts +13 -0
- package/src/types/IToolGroup.ts +3 -1
- package/src/types/index.ts +3 -0
- package/src/utilities/contourSegmentation/areSameSegment.ts +24 -0
- package/src/utilities/contourSegmentation/index.ts +2 -0
- package/src/utilities/contourSegmentation/isContourSegmentationAnnotation.ts +8 -0
- package/src/utilities/contours/areCoplanarContours.ts +39 -0
- package/src/utilities/contours/index.ts +2 -0
- package/src/utilities/contours/reverseIfAntiClockwise.ts +6 -25
- package/src/utilities/math/aabb/index.ts +1 -0
- package/src/utilities/math/aabb/intersectAABB.ts +19 -0
- package/src/utilities/math/point/distanceToPointSquared.ts +6 -1
- package/src/utilities/math/polyline/areLineSegmentsIntersecting.ts +118 -0
- package/src/utilities/math/polyline/combinePolyline.ts +350 -0
- package/src/utilities/math/polyline/containsPoint.ts +63 -0
- package/src/utilities/math/polyline/getAABB.ts +20 -0
- package/src/utilities/math/polyline/{calculateAreaOfPoints.ts → getArea.ts} +1 -1
- package/src/utilities/math/polyline/getClosestLineSegmentIntersection.ts +72 -0
- package/src/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.ts +42 -0
- package/src/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.ts +30 -0
- package/src/utilities/math/polyline/getLineSegmentIntersectionsIndexes.ts +35 -0
- package/src/utilities/math/polyline/getLineSegmentsIntersection.ts +47 -0
- package/src/utilities/math/polyline/getNormal2.ts +17 -0
- package/src/utilities/math/polyline/getNormal3.ts +53 -0
- package/src/utilities/math/polyline/getSignedArea.ts +47 -0
- package/src/utilities/math/polyline/index.ts +27 -8
- package/src/utilities/math/polyline/intersectPolyline.ts +34 -0
- package/src/utilities/math/polyline/isClosed.ts +26 -0
- package/dist/cjs/utilities/math/polyline/calculateAreaOfPoints.d.ts +0 -2
- package/dist/cjs/utilities/math/polyline/calculateAreaOfPoints.js.map +0 -1
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.d.ts +0 -9
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js +0 -160
- package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js.map +0 -1
- package/dist/cjs/utilities/math/polyline/pointInPolyline.d.ts +0 -2
- package/dist/cjs/utilities/math/polyline/pointInPolyline.js +0 -15
- package/dist/cjs/utilities/math/polyline/pointInPolyline.js.map +0 -1
- package/dist/esm/utilities/math/polyline/calculateAreaOfPoints.js.map +0 -1
- package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js +0 -154
- package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js.map +0 -1
- package/dist/esm/utilities/math/polyline/pointInPolyline.js +0 -12
- package/dist/esm/utilities/math/polyline/pointInPolyline.js.map +0 -1
- package/dist/types/utilities/math/polyline/calculateAreaOfPoints.d.ts +0 -3
- package/dist/types/utilities/math/polyline/calculateAreaOfPoints.d.ts.map +0 -1
- package/dist/types/utilities/math/polyline/getIntersectionWithPolyline.d.ts +0 -10
- package/dist/types/utilities/math/polyline/getIntersectionWithPolyline.d.ts.map +0 -1
- package/dist/types/utilities/math/polyline/pointInPolyline.d.ts +0 -3
- package/dist/types/utilities/math/polyline/pointInPolyline.d.ts.map +0 -1
- package/dist/umd/index.js.LICENSE.txt +0 -6
- package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +0 -275
- package/src/utilities/math/polyline/pointInPolyline.ts +0 -19
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
import * as mathPoint from '../point';
|
|
3
|
+
import getLineSegmentIntersectionsIndexes from './getLineSegmentIntersectionsIndexes';
|
|
4
|
+
import containsPoint from './containsPoint';
|
|
5
|
+
import getNormal2 from './getNormal2';
|
|
6
|
+
import { glMatrix, vec3 } from 'gl-matrix';
|
|
7
|
+
import getLineSegmentsIntersection from './getLineSegmentsIntersection';
|
|
8
|
+
|
|
9
|
+
enum PolylinePointType {
|
|
10
|
+
Vertex,
|
|
11
|
+
Intersection,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Position of the point related to the intersection region
|
|
15
|
+
enum PolylinePointPosition {
|
|
16
|
+
Outside = -1,
|
|
17
|
+
Edge = 0,
|
|
18
|
+
Inside = 1,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Direction from last point to the intersection point to know if it is entering
|
|
22
|
+
// or exiting the intersection region
|
|
23
|
+
enum PolylinePointDirection {
|
|
24
|
+
Exiting = -1,
|
|
25
|
+
Unknown = 0,
|
|
26
|
+
Entering = 1,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type PolylinePoint = {
|
|
30
|
+
type: PolylinePointType;
|
|
31
|
+
coordinates: Types.Point2;
|
|
32
|
+
position?: PolylinePointPosition;
|
|
33
|
+
visited: boolean;
|
|
34
|
+
next: PolylinePoint;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type PolylineIntersectionPoint = PolylinePoint & {
|
|
38
|
+
direction: PolylinePointDirection;
|
|
39
|
+
cloned?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Ensure all polyline point objects are pointing to the next object in case
|
|
44
|
+
* it is still not point to anyone.
|
|
45
|
+
* @param polylinePoints - Array that contains all polyline points (vertices and intersections)
|
|
46
|
+
*/
|
|
47
|
+
function ensuresNextPointers(polylinePoints: PolylinePoint[]) {
|
|
48
|
+
// Make sure all nodes point to a valid node
|
|
49
|
+
for (let i = 0, len = polylinePoints.length; i < len; i++) {
|
|
50
|
+
const currentPoint = polylinePoints[i];
|
|
51
|
+
|
|
52
|
+
if (!currentPoint.next) {
|
|
53
|
+
currentPoint.next = polylinePoints[i === len - 1 ? 0 : i + 1];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates one linked list per polyline that contains all vertices and intersections
|
|
60
|
+
* found while walking along the edges.
|
|
61
|
+
*
|
|
62
|
+
* @param targetPolyline - Target polyline
|
|
63
|
+
* @param sourcePolyline - Source polyline
|
|
64
|
+
* @returns Two linked lists with all vertices and intersections.
|
|
65
|
+
*/
|
|
66
|
+
function getSourceAndTargetPointsList(
|
|
67
|
+
targetPolyline: Types.Point2[],
|
|
68
|
+
sourcePolyline: Types.Point2[]
|
|
69
|
+
) {
|
|
70
|
+
const targetPolylinePoints: PolylinePoint[] = [];
|
|
71
|
+
const sourcePolylinePoints: PolylinePoint[] = [];
|
|
72
|
+
const sourceIntersectionsCache = new Map<
|
|
73
|
+
number,
|
|
74
|
+
PolylineIntersectionPoint[]
|
|
75
|
+
>();
|
|
76
|
+
|
|
77
|
+
const isFisrtPointInside = containsPoint(sourcePolyline, targetPolyline[0]);
|
|
78
|
+
|
|
79
|
+
let intersectionPointDirection = isFisrtPointInside
|
|
80
|
+
? PolylinePointDirection.Exiting
|
|
81
|
+
: PolylinePointDirection.Entering;
|
|
82
|
+
|
|
83
|
+
// Store all vertices and intersection for target contour
|
|
84
|
+
for (let i = 0, len = targetPolyline.length; i < len; i++) {
|
|
85
|
+
const p1 = targetPolyline[i];
|
|
86
|
+
const pointInside = containsPoint(sourcePolyline, p1);
|
|
87
|
+
const vertexPoint: PolylinePoint = {
|
|
88
|
+
type: PolylinePointType.Vertex,
|
|
89
|
+
coordinates: p1,
|
|
90
|
+
position: pointInside
|
|
91
|
+
? PolylinePointPosition.Inside
|
|
92
|
+
: PolylinePointPosition.Outside,
|
|
93
|
+
visited: false,
|
|
94
|
+
next: null,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
targetPolylinePoints.push(vertexPoint);
|
|
98
|
+
|
|
99
|
+
const q1 = targetPolyline[i === len - 1 ? 0 : i + 1];
|
|
100
|
+
const intersectionsInfo = getLineSegmentIntersectionsIndexes(
|
|
101
|
+
sourcePolyline,
|
|
102
|
+
p1,
|
|
103
|
+
q1
|
|
104
|
+
).map((intersectedLineSegment) => {
|
|
105
|
+
const sourceLineSegmentId: number = intersectedLineSegment[0];
|
|
106
|
+
const p2 = sourcePolyline[intersectedLineSegment[0]];
|
|
107
|
+
const q2 = sourcePolyline[intersectedLineSegment[1]];
|
|
108
|
+
|
|
109
|
+
// lineSegment.intersectLine returns `undefined` when the intersection
|
|
110
|
+
// is at one of the line vertices.
|
|
111
|
+
// Examples:
|
|
112
|
+
// - [(0, 0), (1, 1)] x [(1, 1), (1, 2)]
|
|
113
|
+
// - [(0, 1), (2, 1)] x [(1, 1), (1, 2)]
|
|
114
|
+
const intersectionCoordinate = getLineSegmentsIntersection(
|
|
115
|
+
p1,
|
|
116
|
+
q1,
|
|
117
|
+
p2,
|
|
118
|
+
q2
|
|
119
|
+
) as Types.Point2;
|
|
120
|
+
|
|
121
|
+
const targetStartPointDistSquared = mathPoint.distanceToPointSquared(
|
|
122
|
+
p1,
|
|
123
|
+
intersectionCoordinate
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
sourceLineSegmentId,
|
|
128
|
+
coordinate: intersectionCoordinate,
|
|
129
|
+
targetStartPointDistSquared,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
intersectionsInfo.sort(
|
|
134
|
+
(left, right) =>
|
|
135
|
+
left.targetStartPointDistSquared - right.targetStartPointDistSquared
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
intersectionsInfo.forEach((intersectionInfo) => {
|
|
139
|
+
const { sourceLineSegmentId, coordinate: intersectionCoordinate } =
|
|
140
|
+
intersectionInfo;
|
|
141
|
+
|
|
142
|
+
// Intersection point to be added to the target polyline list
|
|
143
|
+
const targetEdgePoint: PolylineIntersectionPoint = {
|
|
144
|
+
type: PolylinePointType.Intersection,
|
|
145
|
+
coordinates: intersectionCoordinate,
|
|
146
|
+
position: PolylinePointPosition.Edge,
|
|
147
|
+
direction: intersectionPointDirection,
|
|
148
|
+
visited: false,
|
|
149
|
+
next: null,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Intersection point to be added to the source polyline list.
|
|
153
|
+
// At this point there is no way to know if the point is entering or
|
|
154
|
+
// exiting the intersection region but that is not going to be used
|
|
155
|
+
// hence it is set to "unknown".
|
|
156
|
+
const sourceEdgePoint: PolylineIntersectionPoint = {
|
|
157
|
+
...targetEdgePoint,
|
|
158
|
+
direction: PolylinePointDirection.Unknown,
|
|
159
|
+
cloned: true,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
if (intersectionPointDirection === PolylinePointDirection.Entering) {
|
|
163
|
+
targetEdgePoint.next = sourceEdgePoint;
|
|
164
|
+
} else {
|
|
165
|
+
sourceEdgePoint.next = targetEdgePoint;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let sourceIntersectionPoints =
|
|
169
|
+
sourceIntersectionsCache.get(sourceLineSegmentId);
|
|
170
|
+
|
|
171
|
+
if (!sourceIntersectionPoints) {
|
|
172
|
+
sourceIntersectionPoints = [];
|
|
173
|
+
sourceIntersectionsCache.set(
|
|
174
|
+
sourceLineSegmentId,
|
|
175
|
+
sourceIntersectionPoints
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
targetPolylinePoints.push(targetEdgePoint);
|
|
180
|
+
sourceIntersectionPoints.push(sourceEdgePoint);
|
|
181
|
+
|
|
182
|
+
// Switches from "exiting" to "entering" and vice-versa
|
|
183
|
+
intersectionPointDirection *= -1;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Store all vertices and intersections for source contour
|
|
188
|
+
for (let i = 0, len = sourcePolyline.length; i < len; i++) {
|
|
189
|
+
const lineSegmentId: number = i;
|
|
190
|
+
const p1 = sourcePolyline[i];
|
|
191
|
+
const vertexPoint: PolylinePoint = {
|
|
192
|
+
type: PolylinePointType.Vertex,
|
|
193
|
+
coordinates: p1,
|
|
194
|
+
visited: false,
|
|
195
|
+
next: null,
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
sourcePolylinePoints.push(vertexPoint);
|
|
199
|
+
|
|
200
|
+
const sourceIntersectionPoints =
|
|
201
|
+
sourceIntersectionsCache.get(lineSegmentId);
|
|
202
|
+
|
|
203
|
+
if (!sourceIntersectionPoints?.length) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Calculate the distance between each intersection point to the start point
|
|
208
|
+
// of the line segment, sort them by distance and return a sorted array that
|
|
209
|
+
// contains all intersection points.
|
|
210
|
+
sourceIntersectionPoints
|
|
211
|
+
.map((intersectionPoint) => ({
|
|
212
|
+
intersectionPoint,
|
|
213
|
+
lineSegStartDistSquared: mathPoint.distanceToPointSquared(
|
|
214
|
+
p1,
|
|
215
|
+
intersectionPoint.coordinates
|
|
216
|
+
),
|
|
217
|
+
}))
|
|
218
|
+
.sort(
|
|
219
|
+
(left, right) =>
|
|
220
|
+
left.lineSegStartDistSquared - right.lineSegStartDistSquared
|
|
221
|
+
)
|
|
222
|
+
.map(({ intersectionPoint }) => intersectionPoint)
|
|
223
|
+
.forEach((intersectionPoint) =>
|
|
224
|
+
sourcePolylinePoints.push(intersectionPoint)
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
ensuresNextPointers(targetPolylinePoints);
|
|
229
|
+
ensuresNextPointers(sourcePolylinePoints);
|
|
230
|
+
|
|
231
|
+
return { targetPolylinePoints, sourcePolylinePoints };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get the next unvisited polyline points that is outside the intersection region.
|
|
236
|
+
* @param polylinePoints - All polyline points (vertices and intersections)
|
|
237
|
+
* @returns Any unvisited point that is outside the intersection region if it
|
|
238
|
+
* exists or `undefined` otherwise
|
|
239
|
+
*/
|
|
240
|
+
function getUnvisitedOutsidePoint(polylinePoints: PolylinePoint[]) {
|
|
241
|
+
for (let i = 0, len = polylinePoints.length; i < len; i++) {
|
|
242
|
+
const point = polylinePoints[i];
|
|
243
|
+
|
|
244
|
+
if (!point.visited && point.position === PolylinePointPosition.Outside) {
|
|
245
|
+
return point;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Merge two planar polylines (2D)
|
|
252
|
+
*/
|
|
253
|
+
function mergePolylines(
|
|
254
|
+
targetPolyline: Types.Point2[],
|
|
255
|
+
sourcePolyline: Types.Point2[]
|
|
256
|
+
) {
|
|
257
|
+
const targetNormal = getNormal2(targetPolyline);
|
|
258
|
+
const sourceNormal = getNormal2(sourcePolyline);
|
|
259
|
+
const dotNormals = vec3.dot(sourceNormal, targetNormal);
|
|
260
|
+
|
|
261
|
+
// Both polylines need to be CW or CCW to be merged and one of them needs to
|
|
262
|
+
// be reversed if theirs orientation are not the same
|
|
263
|
+
if (!glMatrix.equals(1, dotNormals)) {
|
|
264
|
+
sourcePolyline = sourcePolyline.slice().reverse();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const { targetPolylinePoints } = getSourceAndTargetPointsList(
|
|
268
|
+
targetPolyline,
|
|
269
|
+
sourcePolyline
|
|
270
|
+
);
|
|
271
|
+
const startPoint: PolylinePoint =
|
|
272
|
+
getUnvisitedOutsidePoint(targetPolylinePoints);
|
|
273
|
+
|
|
274
|
+
// Source polyline contains target polyline
|
|
275
|
+
if (!startPoint) {
|
|
276
|
+
return targetPolyline.slice();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const mergedPolyline = [startPoint.coordinates];
|
|
280
|
+
let currentPoint = startPoint.next;
|
|
281
|
+
|
|
282
|
+
while (currentPoint !== startPoint) {
|
|
283
|
+
if (
|
|
284
|
+
currentPoint.type === PolylinePointType.Intersection &&
|
|
285
|
+
(<PolylineIntersectionPoint>currentPoint).cloned
|
|
286
|
+
) {
|
|
287
|
+
currentPoint = currentPoint.next;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
mergedPolyline.push(currentPoint.coordinates);
|
|
292
|
+
currentPoint = currentPoint.next;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return mergedPolyline;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Subtract two planar polylines (2D)
|
|
300
|
+
*/
|
|
301
|
+
function subtractPolylines(
|
|
302
|
+
targetPolyline: Types.Point2[],
|
|
303
|
+
sourcePolyline: Types.Point2[]
|
|
304
|
+
): Types.Point2[][] {
|
|
305
|
+
const targetNormal = getNormal2(targetPolyline);
|
|
306
|
+
const sourceNormal = getNormal2(sourcePolyline);
|
|
307
|
+
const dotNormals = vec3.dot(sourceNormal, targetNormal);
|
|
308
|
+
|
|
309
|
+
// The polylines need to have different orientation (CW+CCW or CCW+CW) to be
|
|
310
|
+
// subtracted and one of them needs to be reversed if theirs orientation are
|
|
311
|
+
// the same
|
|
312
|
+
if (!glMatrix.equals(-1, dotNormals)) {
|
|
313
|
+
sourcePolyline = sourcePolyline.slice().reverse();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const { targetPolylinePoints } = getSourceAndTargetPointsList(
|
|
317
|
+
targetPolyline,
|
|
318
|
+
sourcePolyline
|
|
319
|
+
);
|
|
320
|
+
let startPoint: PolylinePoint = null;
|
|
321
|
+
const subtractedPolylines = [];
|
|
322
|
+
|
|
323
|
+
while ((startPoint = getUnvisitedOutsidePoint(targetPolylinePoints))) {
|
|
324
|
+
const subtractedPolyline = [startPoint.coordinates];
|
|
325
|
+
let currentPoint = startPoint.next;
|
|
326
|
+
|
|
327
|
+
startPoint.visited = true;
|
|
328
|
+
|
|
329
|
+
while (currentPoint !== startPoint) {
|
|
330
|
+
currentPoint.visited = true;
|
|
331
|
+
|
|
332
|
+
if (
|
|
333
|
+
currentPoint.type === PolylinePointType.Intersection &&
|
|
334
|
+
(<PolylineIntersectionPoint>currentPoint).cloned
|
|
335
|
+
) {
|
|
336
|
+
currentPoint = currentPoint.next;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
subtractedPolyline.push(currentPoint.coordinates);
|
|
341
|
+
currentPoint = currentPoint.next;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
subtractedPolylines.push(subtractedPolyline);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return subtractedPolylines;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { mergePolylines, subtractPolylines };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import isClosed from './isClosed';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a 2D point is inside the polyline.
|
|
6
|
+
*
|
|
7
|
+
* A point is inside a curve/polygon if the number of intersections between the horizontal
|
|
8
|
+
* ray emanating from the given point and to the right and the line segments is odd.
|
|
9
|
+
* https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html
|
|
10
|
+
*
|
|
11
|
+
* @param polyline - Polyline points (2D)
|
|
12
|
+
* @param point - 2D Point
|
|
13
|
+
* @returns True is the point is inside the polyline or false otherwise
|
|
14
|
+
*/
|
|
15
|
+
export default function containsPoint(
|
|
16
|
+
polyline: Types.Point2[],
|
|
17
|
+
point: Types.Point2,
|
|
18
|
+
closed?: boolean
|
|
19
|
+
): boolean {
|
|
20
|
+
if (polyline.length < 3) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const numPolylinePoints = polyline.length;
|
|
25
|
+
let numIntersections = 0;
|
|
26
|
+
|
|
27
|
+
// Test intersection agains [end, start] line segment if it should be closed
|
|
28
|
+
const shouldClose = !(closed === undefined ? isClosed(polyline) : closed);
|
|
29
|
+
const maxSegmentIndex = polyline.length - (shouldClose ? 1 : 2);
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i <= maxSegmentIndex; i++) {
|
|
32
|
+
const p1 = polyline[i];
|
|
33
|
+
|
|
34
|
+
// Calculating the next point index without using % (mod) operator like in
|
|
35
|
+
// `(i + 1) % numPolylinePoints` to make it 20% faster
|
|
36
|
+
const p2Index = i === numPolylinePoints - 1 ? 0 : i + 1;
|
|
37
|
+
const p2 = polyline[p2Index];
|
|
38
|
+
|
|
39
|
+
// Calculating min/max without using Math.min/max to make it ~3% faster
|
|
40
|
+
const maxX = p1[0] >= p2[0] ? p1[0] : p2[0];
|
|
41
|
+
const maxY = p1[1] >= p2[1] ? p1[1] : p2[1];
|
|
42
|
+
const minY = p1[1] <= p2[1] ? p1[1] : p2[1];
|
|
43
|
+
|
|
44
|
+
const mayIntersectLineSegment =
|
|
45
|
+
point[0] <= maxX && point[1] >= minY && point[1] < maxY;
|
|
46
|
+
|
|
47
|
+
if (mayIntersectLineSegment) {
|
|
48
|
+
const isVerticalLine = p1[0] === p2[0];
|
|
49
|
+
let intersects = isVerticalLine;
|
|
50
|
+
|
|
51
|
+
if (!intersects) {
|
|
52
|
+
const xIntersection =
|
|
53
|
+
((point[1] - p1[1]) * (p2[0] - p1[0])) / (p2[1] - p1[1]) + p1[0];
|
|
54
|
+
|
|
55
|
+
intersects = point[0] <= xIntersection;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
numIntersections += intersects ? 1 : 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return !!(numIntersections % 2);
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
|
|
3
|
+
export default function getAABB(polyline: Types.Point2[]): Types.AABB2 {
|
|
4
|
+
let minX = Infinity;
|
|
5
|
+
let minY = Infinity;
|
|
6
|
+
let maxX = -Infinity;
|
|
7
|
+
let maxY = -Infinity;
|
|
8
|
+
|
|
9
|
+
for (let i = 0, len = polyline.length; i < len; i++) {
|
|
10
|
+
const [x, y] = polyline[i];
|
|
11
|
+
|
|
12
|
+
// No Math.min/max calls for better performance
|
|
13
|
+
minX = minX < x ? minX : x;
|
|
14
|
+
minY = minY < y ? minY : y;
|
|
15
|
+
maxX = maxX > x ? maxX : x;
|
|
16
|
+
maxY = maxY > y ? maxY : y;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return { minX, maxX, minY, maxY };
|
|
20
|
+
}
|
|
@@ -7,7 +7,7 @@ import type { Types } from '@cornerstonejs/core';
|
|
|
7
7
|
* the points are in canvas, then the result is in canvas pixels ^2; If they are
|
|
8
8
|
* in mm, then the result is in mm^2; etc.
|
|
9
9
|
*/
|
|
10
|
-
export default function
|
|
10
|
+
export default function getArea(points: Types.Point2[]): number {
|
|
11
11
|
// Shoelace algorithm.
|
|
12
12
|
const n = points.length;
|
|
13
13
|
let area = 0.0;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { vec2 } from 'gl-matrix';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the line (`p1`,`q1`) intersects any of the other lines in the
|
|
7
|
+
* `points`, and returns the closest value.
|
|
8
|
+
* @param points - Polyline points
|
|
9
|
+
* @param p1 - Start point of the line segment
|
|
10
|
+
* @param q1 - End point of the line segment
|
|
11
|
+
* @param closed - Test the intersection against the line that connects the first to the last when closed
|
|
12
|
+
* @returns The closest line segment from polyline that intersects the line segment [p1, q1]
|
|
13
|
+
*/
|
|
14
|
+
export default function getClosestLineSegmentIntersection(
|
|
15
|
+
points: Types.Point2[],
|
|
16
|
+
p1: Types.Point2,
|
|
17
|
+
q1: Types.Point2,
|
|
18
|
+
closed = true
|
|
19
|
+
): { segment: Types.Point2; distance: number } | undefined {
|
|
20
|
+
let initialQ2Index;
|
|
21
|
+
let p2Index;
|
|
22
|
+
|
|
23
|
+
if (closed) {
|
|
24
|
+
p2Index = points.length - 1;
|
|
25
|
+
initialQ2Index = 0;
|
|
26
|
+
} else {
|
|
27
|
+
p2Index = 0;
|
|
28
|
+
initialQ2Index = 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const intersections = [];
|
|
32
|
+
|
|
33
|
+
for (let q2Index = initialQ2Index; q2Index < points.length; q2Index++) {
|
|
34
|
+
const p2 = points[p2Index];
|
|
35
|
+
const q2 = points[q2Index];
|
|
36
|
+
|
|
37
|
+
if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
|
|
38
|
+
intersections.push([p2Index, q2Index]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
p2Index = q2Index;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (intersections.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Find intersection closest to the start point
|
|
49
|
+
const distances = [];
|
|
50
|
+
|
|
51
|
+
intersections.forEach((intersection) => {
|
|
52
|
+
const intersectionPoints = [
|
|
53
|
+
points[intersection[0]],
|
|
54
|
+
points[intersection[1]],
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const midpoint = [
|
|
58
|
+
(intersectionPoints[0][0] + intersectionPoints[1][0]) / 2,
|
|
59
|
+
(intersectionPoints[0][1] + intersectionPoints[1][1]) / 2,
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
distances.push(vec2.distance(<vec2>midpoint, p1));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const minDistance = Math.min(...distances);
|
|
66
|
+
const indexOfMinDistance = distances.indexOf(minDistance);
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
segment: intersections[indexOfMinDistance],
|
|
70
|
+
distance: minDistance,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether the line (`p1`,`q1`) intersects any of the other lines in the
|
|
6
|
+
* `points`, and returns the first value.
|
|
7
|
+
*
|
|
8
|
+
* @param points - Polyline points
|
|
9
|
+
* @param p1 - First point of the line segment that is being tested
|
|
10
|
+
* @param q1 - Second point of the line segment that is being tested
|
|
11
|
+
* @param closed - Test the intersection with the line segment that connects
|
|
12
|
+
* the last and first points of the polyline
|
|
13
|
+
* @returns Indexes of the line segment points from the polyline that intersects [p1, q1]
|
|
14
|
+
*/
|
|
15
|
+
export default function getFirstLineSegmentIntersectionIndexes(
|
|
16
|
+
points: Types.Point2[],
|
|
17
|
+
p1: Types.Point2,
|
|
18
|
+
q1: Types.Point2,
|
|
19
|
+
closed = true
|
|
20
|
+
): Types.Point2 | undefined {
|
|
21
|
+
let initialI;
|
|
22
|
+
let j;
|
|
23
|
+
|
|
24
|
+
if (closed) {
|
|
25
|
+
j = points.length - 1;
|
|
26
|
+
initialI = 0;
|
|
27
|
+
} else {
|
|
28
|
+
j = 0;
|
|
29
|
+
initialI = 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = initialI; i < points.length; i++) {
|
|
33
|
+
const p2 = points[j];
|
|
34
|
+
const q2 = points[i];
|
|
35
|
+
|
|
36
|
+
if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
|
|
37
|
+
return [j, i];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
j = i;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import getLineSegmentIntersectionsIndexes from './getLineSegmentIntersectionsIndexes';
|
|
3
|
+
import getLineSegmentsIntersection from './getLineSegmentsIntersection';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns all intersections points between a line segment and a polyline
|
|
7
|
+
*/
|
|
8
|
+
export default function getLineSegmentIntersectionsCoordinates(
|
|
9
|
+
points: Types.Point2[],
|
|
10
|
+
p1: Types.Point2,
|
|
11
|
+
q1: Types.Point2,
|
|
12
|
+
closed = true
|
|
13
|
+
): Types.Point2[] {
|
|
14
|
+
const result = [];
|
|
15
|
+
const polylineIndexes = getLineSegmentIntersectionsIndexes(
|
|
16
|
+
points,
|
|
17
|
+
p1,
|
|
18
|
+
q1,
|
|
19
|
+
closed
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
for (let i = 0; i < polylineIndexes.length; i++) {
|
|
23
|
+
const p2 = points[polylineIndexes[i][0]];
|
|
24
|
+
const q2 = points[polylineIndexes[i][1]];
|
|
25
|
+
const intersection = getLineSegmentsIntersection(p1, q1, p2, q2);
|
|
26
|
+
result.push(intersection);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get all intersections between a polyline and a line segment.
|
|
6
|
+
* @param polyline - Polyline points
|
|
7
|
+
* @param p1 - Start point of line segment
|
|
8
|
+
* @param q1 - End point of line segment
|
|
9
|
+
* @param closed - Test the intersection against the line segment that connects
|
|
10
|
+
* the last to the first point when set to true
|
|
11
|
+
* @returns Start/end point indexes of all line segments that intersect (p1, q1)
|
|
12
|
+
*/
|
|
13
|
+
export default function getLineSegmentIntersectionsIndexes(
|
|
14
|
+
polyline: Types.Point2[],
|
|
15
|
+
p1: Types.Point2,
|
|
16
|
+
q1: Types.Point2,
|
|
17
|
+
closed = true
|
|
18
|
+
): Types.Point2[] {
|
|
19
|
+
const intersections: Types.Point2[] = [];
|
|
20
|
+
const numPoints = polyline.length;
|
|
21
|
+
const maxI = numPoints - (closed ? 1 : 2);
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i <= maxI; i++) {
|
|
24
|
+
const p2 = polyline[i];
|
|
25
|
+
// Do not use % operator for better performance
|
|
26
|
+
const j = i === numPoints - 1 ? 0 : i + 1;
|
|
27
|
+
const q2 = polyline[j];
|
|
28
|
+
|
|
29
|
+
if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
|
|
30
|
+
intersections.push([i, j]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return intersections;
|
|
35
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
|
|
3
|
+
// ATTENTION: this is an internal function and it should not be added to "polyline"
|
|
4
|
+
// namespace because there is another one from lineSegment.intersectLine that also
|
|
5
|
+
// finds an intersection between two line segments. This one should be removed but
|
|
6
|
+
// it is faster and able to find intersections when the intersection is one of the
|
|
7
|
+
// two points of a line segment.
|
|
8
|
+
//
|
|
9
|
+
// Example:
|
|
10
|
+
// Line 1: (0, 0), (1, 1) x Line 2 (1, 1), (1, 2)
|
|
11
|
+
// Line 1: (0, 1), (2, 1) x Line 2 (1, 1), (1, 2)
|
|
12
|
+
//
|
|
13
|
+
// This function must replace `lineSegment.intersectLine` but it requires some
|
|
14
|
+
// tests first
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Gets the intersection between the line segments (`p1`,`q1`) and (`p2`,`q2`)
|
|
18
|
+
*
|
|
19
|
+
* http://jsfiddle.net/justin_c_rounds/Gd2S2/light/
|
|
20
|
+
* https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
|
|
21
|
+
*/
|
|
22
|
+
export default function getLineSegmentsIntersection(
|
|
23
|
+
p1: Types.Point2,
|
|
24
|
+
q1: Types.Point2,
|
|
25
|
+
p2: Types.Point2,
|
|
26
|
+
q2: Types.Point2
|
|
27
|
+
): Types.Point2 {
|
|
28
|
+
const diffQ1P1 = [q1[0] - p1[0], q1[1] - p1[1]];
|
|
29
|
+
const diffQ2P2 = [q2[0] - p2[0], q2[1] - p2[1]];
|
|
30
|
+
const denominator = diffQ2P2[1] * diffQ1P1[0] - diffQ2P2[0] * diffQ1P1[1];
|
|
31
|
+
|
|
32
|
+
if (denominator == 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let a = p1[1] - p2[1];
|
|
37
|
+
let b = p1[0] - p2[0];
|
|
38
|
+
const numerator1 = diffQ2P2[0] * a - diffQ2P2[1] * b;
|
|
39
|
+
const numerator2 = diffQ1P1[0] * a - diffQ1P1[1] * b;
|
|
40
|
+
a = numerator1 / denominator;
|
|
41
|
+
b = numerator2 / denominator;
|
|
42
|
+
|
|
43
|
+
const resultX = p1[0] + a * diffQ1P1[0];
|
|
44
|
+
const resultY = p1[1] + a * diffQ1P1[1];
|
|
45
|
+
|
|
46
|
+
return [resultX, resultY];
|
|
47
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
import getSignedArea from './getSignedArea';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the normal of a 2D polyline
|
|
6
|
+
* https://www.youtube.com/watch?v=GpsKrAipXm8&t=1982s
|
|
7
|
+
*
|
|
8
|
+
* @param polyline - Planar polyline in 2D space
|
|
9
|
+
* @returns Normal of the 2D planar polyline
|
|
10
|
+
*/
|
|
11
|
+
export default function getNormal2(polyline: Types.Point2[]): Types.Point3 {
|
|
12
|
+
const area = getSignedArea(polyline);
|
|
13
|
+
|
|
14
|
+
// The normal of a 2D polyline is (0, 0, 1) or (0, 0, -1) depending if it
|
|
15
|
+
// is CW or CCW polyline
|
|
16
|
+
return [0, 0, area / Math.abs(area)] as Types.Point3;
|
|
17
|
+
}
|