@cornerstonejs/tools 1.48.2 → 1.49.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/enums/AnnotationStyleStates.d.ts +2 -1
- package/dist/cjs/enums/AnnotationStyleStates.js +1 -0
- package/dist/cjs/enums/AnnotationStyleStates.js.map +1 -1
- package/dist/cjs/enums/ChangeTypes.d.ts +8 -0
- package/dist/cjs/enums/ChangeTypes.js +12 -0
- package/dist/cjs/enums/ChangeTypes.js.map +1 -0
- package/dist/cjs/enums/Events.d.ts +2 -0
- package/dist/cjs/enums/Events.js +2 -0
- package/dist/cjs/enums/Events.js.map +1 -1
- package/dist/cjs/enums/index.d.ts +2 -1
- package/dist/cjs/enums/index.js +3 -1
- package/dist/cjs/enums/index.js.map +1 -1
- package/dist/cjs/eventDispatchers/annotationInterpolationEventDispatcher.d.ts +5 -0
- package/dist/cjs/eventDispatchers/annotationInterpolationEventDispatcher.js +23 -0
- package/dist/cjs/eventDispatchers/annotationInterpolationEventDispatcher.js.map +1 -0
- package/dist/cjs/eventDispatchers/index.d.ts +2 -1
- package/dist/cjs/eventDispatchers/index.js +3 -1
- package/dist/cjs/eventDispatchers/index.js.map +1 -1
- package/dist/cjs/init.js +3 -0
- package/dist/cjs/init.js.map +1 -1
- package/dist/cjs/stateManagement/annotation/config/getState.js +3 -0
- package/dist/cjs/stateManagement/annotation/config/getState.js.map +1 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +1 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.js +1 -1
- package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js +1 -0
- package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +2 -2
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +9 -4
- package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/SplineROITool.d.ts +4 -1
- package/dist/cjs/tools/annotation/SplineROITool.js +51 -20
- package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +12 -3
- package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +9 -5
- package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +3 -3
- package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/cjs/tools/base/ContourBaseTool.js +4 -0
- package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.js +21 -9
- package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourConfig.js +8 -3
- package/dist/cjs/tools/displayTools/Contour/contourConfig.js.map +1 -1
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +0 -1
- package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/cjs/types/AnnotationStyle.d.ts +2 -2
- package/dist/cjs/types/AnnotationTypes.d.ts +1 -0
- package/dist/cjs/types/ContourSegmentationAnnotation.d.ts +1 -0
- package/dist/cjs/types/ContourTypes.d.ts +3 -0
- package/dist/cjs/types/EventTypes.d.ts +19 -1
- package/dist/cjs/types/InterpolationTypes.d.ts +18 -0
- package/dist/cjs/types/InterpolationTypes.js +3 -0
- package/dist/cjs/types/InterpolationTypes.js.map +1 -0
- package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +14 -0
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/utilities/contours/PointsArray.d.ts +29 -0
- package/dist/cjs/utilities/contours/PointsArray.js +104 -0
- package/dist/cjs/utilities/contours/PointsArray.js.map +1 -0
- package/dist/cjs/utilities/contours/index.d.ts +3 -1
- package/dist/cjs/utilities/contours/index.js +28 -1
- package/dist/cjs/utilities/contours/index.js.map +1 -1
- package/dist/cjs/utilities/contours/interpolation/acceptAutogeneratedInterpolations.d.ts +3 -0
- package/dist/cjs/utilities/contours/interpolation/acceptAutogeneratedInterpolations.js +11 -0
- package/dist/cjs/utilities/contours/interpolation/acceptAutogeneratedInterpolations.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/createPolylineToolData.d.ts +2 -0
- package/dist/cjs/utilities/contours/interpolation/createPolylineToolData.js +39 -0
- package/dist/cjs/utilities/contours/interpolation/createPolylineToolData.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/findAnnotationForInterpolation.d.ts +7 -0
- package/dist/cjs/utilities/contours/interpolation/findAnnotationForInterpolation.js +107 -0
- package/dist/cjs/utilities/contours/interpolation/findAnnotationForInterpolation.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationData.d.ts +7 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationData.js +30 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationData.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationDataCollection.d.ts +4 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationDataCollection.js +21 -0
- package/dist/cjs/utilities/contours/interpolation/getInterpolationDataCollection.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/index.d.ts +2 -0
- package/dist/cjs/utilities/contours/interpolation/index.js +9 -0
- package/dist/cjs/utilities/contours/interpolation/index.js.map +1 -0
- package/dist/cjs/utilities/contours/interpolation/interpolate.d.ts +3 -0
- package/dist/cjs/utilities/contours/interpolation/interpolate.js +343 -0
- package/dist/cjs/utilities/contours/interpolation/interpolate.js.map +1 -0
- package/dist/cjs/utilities/contours/reverseIfAntiClockwise.d.ts +2 -0
- package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js +34 -0
- package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js.map +1 -0
- package/dist/cjs/utilities/getViewportForAnnotation.d.ts +2 -0
- package/dist/cjs/utilities/getViewportForAnnotation.js +19 -0
- package/dist/cjs/utilities/getViewportForAnnotation.js.map +1 -0
- package/dist/cjs/utilities/index.d.ts +2 -1
- package/dist/cjs/utilities/index.js +3 -1
- package/dist/cjs/utilities/index.js.map +1 -1
- package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js +2 -1
- package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
- package/dist/cjs/utilities/planarFreehandROITool/index.d.ts +3 -3
- package/dist/cjs/utilities/planarFreehandROITool/index.js +4 -4
- package/dist/cjs/utilities/planarFreehandROITool/index.js.map +1 -1
- package/dist/cjs/utilities/planarFreehandROITool/smoothAnnotation.d.ts +3 -0
- package/dist/cjs/utilities/planarFreehandROITool/{interpolateAnnotation.js → smoothAnnotation.js} +5 -5
- package/dist/cjs/utilities/planarFreehandROITool/smoothAnnotation.js.map +1 -0
- package/dist/cjs/utilities/planarFreehandROITool/{interpolatePoints.d.ts → smoothPoints.d.ts} +1 -1
- package/dist/cjs/utilities/planarFreehandROITool/{interpolatePoints.js → smoothPoints.js} +11 -8
- package/dist/cjs/utilities/planarFreehandROITool/smoothPoints.js.map +1 -0
- package/dist/cjs/utilities/polyData/utils.d.ts +2 -1
- package/dist/cjs/utilities/polyData/utils.js +4 -2
- package/dist/cjs/utilities/polyData/utils.js.map +1 -1
- package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.d.ts +11 -0
- package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js +159 -0
- package/dist/cjs/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -0
- package/dist/cjs/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.d.ts +2 -0
- package/dist/cjs/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js +96 -0
- package/dist/cjs/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js.map +1 -0
- package/dist/cjs/utilities/triggerAnnotationRenderForViewportIds.js +7 -2
- package/dist/cjs/utilities/triggerAnnotationRenderForViewportIds.js.map +1 -1
- package/dist/esm/enums/AnnotationStyleStates.js +1 -0
- package/dist/esm/enums/AnnotationStyleStates.js.map +1 -1
- package/dist/esm/enums/ChangeTypes.js +10 -0
- package/dist/esm/enums/ChangeTypes.js.map +1 -0
- package/dist/esm/enums/Events.js +2 -0
- package/dist/esm/enums/Events.js.map +1 -1
- package/dist/esm/enums/index.js +2 -1
- package/dist/esm/enums/index.js.map +1 -1
- package/dist/esm/eventDispatchers/annotationInterpolationEventDispatcher.js +18 -0
- package/dist/esm/eventDispatchers/annotationInterpolationEventDispatcher.js.map +1 -0
- package/dist/esm/eventDispatchers/index.js +2 -1
- package/dist/esm/eventDispatchers/index.js.map +1 -1
- package/dist/esm/init.js +3 -0
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/stateManagement/annotation/config/getState.js +3 -0
- package/dist/esm/stateManagement/annotation/config/getState.js.map +1 -1
- package/dist/esm/tools/annotation/LivewireContourTool.js +2 -2
- package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js +1 -0
- package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js +9 -4
- package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
- package/dist/esm/tools/annotation/SplineROITool.js +49 -21
- package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +11 -2
- package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +8 -4
- package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +2 -2
- package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
- package/dist/esm/tools/base/ContourBaseTool.js +4 -0
- package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js +12 -1
- package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourConfig.js +8 -3
- package/dist/esm/tools/displayTools/Contour/contourConfig.js.map +1 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js +0 -1
- package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
- package/dist/esm/types/InterpolationTypes.js +2 -0
- package/dist/esm/types/InterpolationTypes.js.map +1 -0
- package/dist/esm/utilities/contours/PointsArray.js +98 -0
- package/dist/esm/utilities/contours/PointsArray.js.map +1 -0
- package/dist/esm/utilities/contours/index.js +3 -1
- package/dist/esm/utilities/contours/index.js.map +1 -1
- package/dist/esm/utilities/contours/interpolation/acceptAutogeneratedInterpolations.js +5 -0
- package/dist/esm/utilities/contours/interpolation/acceptAutogeneratedInterpolations.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/createPolylineToolData.js +36 -0
- package/dist/esm/utilities/contours/interpolation/createPolylineToolData.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/findAnnotationForInterpolation.js +102 -0
- package/dist/esm/utilities/contours/interpolation/findAnnotationForInterpolation.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/getInterpolationData.js +27 -0
- package/dist/esm/utilities/contours/interpolation/getInterpolationData.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/getInterpolationDataCollection.js +15 -0
- package/dist/esm/utilities/contours/interpolation/getInterpolationDataCollection.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/index.js +3 -0
- package/dist/esm/utilities/contours/interpolation/index.js.map +1 -0
- package/dist/esm/utilities/contours/interpolation/interpolate.js +314 -0
- package/dist/esm/utilities/contours/interpolation/interpolate.js.map +1 -0
- package/dist/esm/utilities/contours/reverseIfAntiClockwise.js +31 -0
- package/dist/esm/utilities/contours/reverseIfAntiClockwise.js.map +1 -0
- package/dist/esm/utilities/getViewportForAnnotation.js +16 -0
- package/dist/esm/utilities/getViewportForAnnotation.js.map +1 -0
- package/dist/esm/utilities/index.js +2 -1
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js +1 -1
- package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
- package/dist/esm/utilities/planarFreehandROITool/index.js +3 -3
- package/dist/esm/utilities/planarFreehandROITool/index.js.map +1 -1
- package/dist/esm/utilities/planarFreehandROITool/{interpolateAnnotation.js → smoothAnnotation.js} +4 -4
- package/dist/esm/utilities/planarFreehandROITool/smoothAnnotation.js.map +1 -0
- package/dist/esm/utilities/planarFreehandROITool/{interpolatePoints.js → smoothPoints.js} +9 -6
- package/dist/esm/utilities/planarFreehandROITool/smoothPoints.js.map +1 -0
- package/dist/esm/utilities/polyData/utils.js +4 -2
- package/dist/esm/utilities/polyData/utils.js.map +1 -1
- package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js +150 -0
- package/dist/esm/utilities/segmentation/InterpolationManager/InterpolationManager.js.map +1 -0
- package/dist/esm/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js +67 -0
- package/dist/esm/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.js.map +1 -0
- package/dist/esm/utilities/triggerAnnotationRenderForViewportIds.js +7 -2
- package/dist/esm/utilities/triggerAnnotationRenderForViewportIds.js.map +1 -1
- package/dist/types/enums/AnnotationStyleStates.d.ts +2 -1
- package/dist/types/enums/AnnotationStyleStates.d.ts.map +1 -1
- package/dist/types/enums/ChangeTypes.d.ts +9 -0
- package/dist/types/enums/ChangeTypes.d.ts.map +1 -0
- package/dist/types/enums/Events.d.ts +2 -0
- package/dist/types/enums/Events.d.ts.map +1 -1
- package/dist/types/enums/index.d.ts +2 -1
- package/dist/types/eventDispatchers/annotationInterpolationEventDispatcher.d.ts +6 -0
- package/dist/types/eventDispatchers/annotationInterpolationEventDispatcher.d.ts.map +1 -0
- package/dist/types/eventDispatchers/index.d.ts +2 -1
- package/dist/types/init.d.ts.map +1 -1
- package/dist/types/stateManagement/annotation/config/getState.d.ts.map +1 -1
- package/dist/types/tools/annotation/LivewireContourTool.d.ts +1 -1
- package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts.map +1 -1
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +2 -2
- package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
- package/dist/types/tools/annotation/SplineROITool.d.ts +4 -1
- package/dist/types/tools/annotation/SplineROITool.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/base/ContourBaseTool.d.ts.map +1 -1
- package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Contour/contourConfig.d.ts.map +1 -1
- package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts.map +1 -1
- package/dist/types/types/AnnotationStyle.d.ts +2 -2
- package/dist/types/types/AnnotationStyle.d.ts.map +1 -1
- package/dist/types/types/AnnotationTypes.d.ts +1 -0
- package/dist/types/types/AnnotationTypes.d.ts.map +1 -1
- package/dist/types/types/ContourSegmentationAnnotation.d.ts +1 -0
- package/dist/types/types/ContourSegmentationAnnotation.d.ts.map +1 -1
- package/dist/types/types/ContourTypes.d.ts +3 -0
- package/dist/types/types/ContourTypes.d.ts.map +1 -1
- package/dist/types/types/EventTypes.d.ts +19 -1
- package/dist/types/types/EventTypes.d.ts.map +1 -1
- package/dist/types/types/InterpolationTypes.d.ts +19 -0
- package/dist/types/types/InterpolationTypes.d.ts.map +1 -0
- package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +14 -0
- package/dist/types/types/ToolSpecificAnnotationTypes.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/contours/PointsArray.d.ts +30 -0
- package/dist/types/utilities/contours/PointsArray.d.ts.map +1 -0
- package/dist/types/utilities/contours/index.d.ts +3 -1
- package/dist/types/utilities/contours/index.d.ts.map +1 -1
- package/dist/types/utilities/contours/interpolation/acceptAutogeneratedInterpolations.d.ts +4 -0
- package/dist/types/utilities/contours/interpolation/acceptAutogeneratedInterpolations.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/createPolylineToolData.d.ts +3 -0
- package/dist/types/utilities/contours/interpolation/createPolylineToolData.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/findAnnotationForInterpolation.d.ts +8 -0
- package/dist/types/utilities/contours/interpolation/findAnnotationForInterpolation.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/getInterpolationData.d.ts +8 -0
- package/dist/types/utilities/contours/interpolation/getInterpolationData.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/getInterpolationDataCollection.d.ts +5 -0
- package/dist/types/utilities/contours/interpolation/getInterpolationDataCollection.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/index.d.ts +3 -0
- package/dist/types/utilities/contours/interpolation/index.d.ts.map +1 -0
- package/dist/types/utilities/contours/interpolation/interpolate.d.ts +4 -0
- package/dist/types/utilities/contours/interpolation/interpolate.d.ts.map +1 -0
- package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts +3 -0
- package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts.map +1 -0
- package/dist/types/utilities/getViewportForAnnotation.d.ts +3 -0
- package/dist/types/utilities/getViewportForAnnotation.d.ts.map +1 -0
- package/dist/types/utilities/index.d.ts +2 -1
- package/dist/types/utilities/index.d.ts.map +1 -1
- package/dist/types/utilities/planar/filterAnnotationsForDisplay.d.ts.map +1 -1
- package/dist/types/utilities/planarFreehandROITool/index.d.ts +3 -3
- package/dist/types/utilities/planarFreehandROITool/index.d.ts.map +1 -1
- package/dist/types/utilities/planarFreehandROITool/smoothAnnotation.d.ts +4 -0
- package/dist/types/utilities/planarFreehandROITool/smoothAnnotation.d.ts.map +1 -0
- package/dist/types/utilities/planarFreehandROITool/{interpolatePoints.d.ts → smoothPoints.d.ts} +2 -2
- package/dist/types/utilities/planarFreehandROITool/smoothPoints.d.ts.map +1 -0
- package/dist/types/utilities/polyData/utils.d.ts +2 -1
- package/dist/types/utilities/polyData/utils.d.ts.map +1 -1
- package/dist/types/utilities/segmentation/InterpolationManager/InterpolationManager.d.ts +12 -0
- package/dist/types/utilities/segmentation/InterpolationManager/InterpolationManager.d.ts.map +1 -0
- package/dist/types/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.d.ts +3 -0
- package/dist/types/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.d.ts.map +1 -0
- package/dist/types/utilities/triggerAnnotationRenderForViewportIds.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/enums/AnnotationStyleStates.ts +3 -0
- package/src/enums/ChangeTypes.ts +32 -0
- package/src/enums/Events.ts +16 -0
- package/src/enums/index.js +2 -0
- package/src/eventDispatchers/annotationInterpolationEventDispatcher.ts +42 -0
- package/src/eventDispatchers/index.js +2 -0
- package/src/init.ts +3 -0
- package/src/stateManagement/annotation/config/getState.ts +16 -2
- package/src/tools/annotation/LivewireContourTool.ts +3 -8
- package/src/tools/annotation/PlanarFreehandContourSegmentationTool.ts +6 -0
- package/src/tools/annotation/PlanarFreehandROITool.ts +47 -25
- package/src/tools/annotation/SplineROITool.ts +80 -28
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +15 -3
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +10 -6
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +3 -3
- package/src/tools/base/ContourBaseTool.ts +4 -0
- package/src/tools/base/ContourSegmentationBaseTool.ts +11 -1
- package/src/tools/displayTools/Contour/contourConfig.ts +8 -3
- package/src/tools/displayTools/Contour/contourDisplay.ts +1 -3
- package/src/types/AnnotationStyle.ts +3 -1
- package/src/types/AnnotationTypes.ts +2 -0
- package/src/types/ContourSegmentationAnnotation.ts +1 -0
- package/src/types/ContourTypes.ts +8 -0
- package/src/types/EventTypes.ts +43 -0
- package/src/types/InterpolationTypes.ts +42 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +15 -0
- package/src/types/index.ts +6 -0
- package/src/utilities/contours/PointsArray.ts +165 -0
- package/src/utilities/contours/index.ts +4 -1
- package/src/utilities/contours/interpolation/acceptAutogeneratedInterpolations.ts +16 -0
- package/src/utilities/contours/interpolation/createPolylineToolData.ts +56 -0
- package/src/utilities/contours/interpolation/findAnnotationForInterpolation.ts +225 -0
- package/src/utilities/contours/interpolation/getInterpolationData.ts +75 -0
- package/src/utilities/contours/interpolation/getInterpolationDataCollection.ts +31 -0
- package/src/utilities/contours/interpolation/index.ts +3 -0
- package/src/utilities/contours/interpolation/interpolate.ts +695 -0
- package/src/utilities/contours/reverseIfAntiClockwise.ts +50 -0
- package/src/utilities/getViewportForAnnotation.ts +29 -0
- package/src/utilities/index.ts +2 -0
- package/src/utilities/livewire/LivewireScissors.ts +1 -1
- package/src/utilities/planar/filterAnnotationsForDisplay.ts +6 -1
- package/src/utilities/planarFreehandROITool/index.ts +3 -3
- package/src/utilities/planarFreehandROITool/{interpolateAnnotation.ts → smoothAnnotation.ts} +5 -3
- package/src/utilities/planarFreehandROITool/{interpolatePoints.ts → smoothPoints.ts} +12 -6
- package/src/utilities/polyData/utils.ts +12 -5
- package/src/utilities/segmentation/InterpolationManager/InterpolationManager.ts +207 -0
- package/src/utilities/segmentation/InterpolationManager/deleteRelatedAnnotations.ts +97 -0
- package/src/utilities/triggerAnnotationRenderForViewportIds.ts +7 -2
- package/dist/cjs/utilities/planarFreehandROITool/interpolateAnnotation.d.ts +0 -3
- package/dist/cjs/utilities/planarFreehandROITool/interpolateAnnotation.js.map +0 -1
- package/dist/cjs/utilities/planarFreehandROITool/interpolatePoints.js.map +0 -1
- package/dist/esm/utilities/planarFreehandROITool/interpolateAnnotation.js.map +0 -1
- package/dist/esm/utilities/planarFreehandROITool/interpolatePoints.js.map +0 -1
- package/dist/types/utilities/planarFreehandROITool/interpolateAnnotation.d.ts +0 -4
- package/dist/types/utilities/planarFreehandROITool/interpolateAnnotation.d.ts.map +0 -1
- package/dist/types/utilities/planarFreehandROITool/interpolatePoints.d.ts.map +0 -1
|
@@ -0,0 +1,695 @@
|
|
|
1
|
+
import { triggerEvent } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
import { vec3 } from 'gl-matrix';
|
|
4
|
+
|
|
5
|
+
import createPolylineToolData from './createPolylineToolData';
|
|
6
|
+
import findAnnotationsForInterpolation from './findAnnotationForInterpolation';
|
|
7
|
+
import type { InterpolationViewportData } from '../../../types/InterpolationTypes';
|
|
8
|
+
import type { InterpolationROIAnnotation } from '../../../types/ToolSpecificAnnotationTypes';
|
|
9
|
+
import type { AnnotationInterpolationCompletedEventDetail } from '../../../types/EventTypes';
|
|
10
|
+
import EventTypes from '../../../enums/Events';
|
|
11
|
+
import * as annotationState from '../../../stateManagement/annotation';
|
|
12
|
+
import { PointsArray } from '../PointsArray';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An XYZ encoded points that also includes an indicator I for whether the
|
|
16
|
+
* point is included in the original contour.
|
|
17
|
+
*/
|
|
18
|
+
type PointsXYZI = Types.PointsXYZ & {
|
|
19
|
+
I?: boolean[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const dP = 0.2; // Aim for < 0.2mm between interpolated nodes when super-sampling.
|
|
23
|
+
|
|
24
|
+
let interpolating = false;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* interpolate - Interpolate missing contours in the ROIContours.
|
|
28
|
+
* If input is tool data collection, it is expected to be sorted in the order of stack image in which it was drawn
|
|
29
|
+
*
|
|
30
|
+
* @param viewportData - Object
|
|
31
|
+
* @returns null
|
|
32
|
+
*/
|
|
33
|
+
function interpolate(viewportData: InterpolationViewportData) {
|
|
34
|
+
if (interpolating || !viewportData.annotation) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
interpolating = true;
|
|
38
|
+
try {
|
|
39
|
+
startInterpolation(viewportData);
|
|
40
|
+
} finally {
|
|
41
|
+
interpolating = false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Start the actual interpolation from the list
|
|
47
|
+
* @param viewportData - Object
|
|
48
|
+
* @returns null
|
|
49
|
+
*/
|
|
50
|
+
function startInterpolation(viewportData: InterpolationViewportData) {
|
|
51
|
+
const toolData = viewportData.annotation;
|
|
52
|
+
const { interpolationData, interpolationList } =
|
|
53
|
+
findAnnotationsForInterpolation(toolData, viewportData);
|
|
54
|
+
|
|
55
|
+
const eventData = {
|
|
56
|
+
toolName: toolData.metadata.toolName,
|
|
57
|
+
toolType: toolData.metadata.toolName,
|
|
58
|
+
viewport: viewportData.viewport,
|
|
59
|
+
};
|
|
60
|
+
for (let i = 0; i < interpolationList.length; i++) {
|
|
61
|
+
if (interpolationList[i]) {
|
|
62
|
+
_linearlyInterpolateBetween(
|
|
63
|
+
interpolationList[i].list,
|
|
64
|
+
interpolationList[i].pair,
|
|
65
|
+
interpolationData,
|
|
66
|
+
eventData
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const { id, renderingEngineId, element } = viewportData.viewport;
|
|
72
|
+
|
|
73
|
+
const eventDetails: AnnotationInterpolationCompletedEventDetail = {
|
|
74
|
+
annotation: toolData,
|
|
75
|
+
element,
|
|
76
|
+
viewportId: id,
|
|
77
|
+
renderingEngineId,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
if (interpolationList.length) {
|
|
81
|
+
triggerEvent(
|
|
82
|
+
viewportData.viewport.element,
|
|
83
|
+
EventTypes.ANNOTATION_INTERPOLATION_PROCESS_COMPLETED,
|
|
84
|
+
eventDetails
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* _linearlyInterpolateBetween - Linearly interpolate all the slices in the
|
|
91
|
+
* indices array between the contourPair.
|
|
92
|
+
*
|
|
93
|
+
* @param indices - natural[], An array of slice indices to interpolate.
|
|
94
|
+
* @param annotationPair - natural[2], The slice indices of the reference contours.
|
|
95
|
+
* @param interpolationData - object
|
|
96
|
+
* @param eventData - object
|
|
97
|
+
* @returns null
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
function _linearlyInterpolateBetween(
|
|
101
|
+
indices,
|
|
102
|
+
annotationPair,
|
|
103
|
+
interpolationData,
|
|
104
|
+
eventData
|
|
105
|
+
) {
|
|
106
|
+
const c1 = _generateClosedContour(
|
|
107
|
+
interpolationData.get(annotationPair[0])[0].data.contour.polyline
|
|
108
|
+
);
|
|
109
|
+
const c2 = _generateClosedContour(
|
|
110
|
+
interpolationData.get(annotationPair[1])[0].data.contour.polyline
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const { c1Interp, c2Interp } = _generateInterpolationContourPair(c1, c2);
|
|
114
|
+
|
|
115
|
+
// Using the newly constructed contours, interpolate each ROI.
|
|
116
|
+
indices.forEach(function (index) {
|
|
117
|
+
_linearlyInterpolateContour(
|
|
118
|
+
c1Interp,
|
|
119
|
+
c2Interp,
|
|
120
|
+
index,
|
|
121
|
+
annotationPair,
|
|
122
|
+
interpolationData,
|
|
123
|
+
c1.x.length > c2.x.length,
|
|
124
|
+
eventData
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* _linearlyInterpolateContour - Inserts a linearly interpolated contour at
|
|
131
|
+
* specified slice index.
|
|
132
|
+
*
|
|
133
|
+
* @param c1Interp - object, The first reference contour.
|
|
134
|
+
* @param c2Interp - object, The second reference contour.
|
|
135
|
+
* @param sliceIndex - Number, The slice index to interpolate.
|
|
136
|
+
* @param annotationPair - Number[], The slice indicies of the reference contours.
|
|
137
|
+
* @param interpolationData - object[], Data for the slice location of contours
|
|
138
|
+
* for the ROIContour.
|
|
139
|
+
* @param c1HasMoreNodes - boolean, True if c1 has more nodes than c2.
|
|
140
|
+
* @param eventData - object
|
|
141
|
+
* @returns null
|
|
142
|
+
*/
|
|
143
|
+
function _linearlyInterpolateContour(
|
|
144
|
+
c1Interp,
|
|
145
|
+
c2Interp,
|
|
146
|
+
sliceIndex,
|
|
147
|
+
annotationPair,
|
|
148
|
+
interpolationData,
|
|
149
|
+
c1HasMoreNodes,
|
|
150
|
+
eventData
|
|
151
|
+
) {
|
|
152
|
+
const [startIndex, endIndex] = annotationPair;
|
|
153
|
+
const zInterp = (sliceIndex - startIndex) / (endIndex - startIndex);
|
|
154
|
+
const interpolated3DPoints = _generateInterpolatedOpenContour(
|
|
155
|
+
c1Interp,
|
|
156
|
+
c2Interp,
|
|
157
|
+
zInterp,
|
|
158
|
+
c1HasMoreNodes
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const nearestAnnotation = interpolationData.get(
|
|
162
|
+
annotationPair[zInterp > 0.5 ? 1 : 0]
|
|
163
|
+
)[0];
|
|
164
|
+
|
|
165
|
+
// A bit adhoc figuring out how many handles to use, but this seems to generate
|
|
166
|
+
// enough handles for use.
|
|
167
|
+
const handleCount = Math.round(
|
|
168
|
+
Math.max(
|
|
169
|
+
8,
|
|
170
|
+
interpolationData.get(startIndex)[0].data.handles.points.length * 2,
|
|
171
|
+
interpolationData.get(endIndex)[0].data.handles.points.length * 2
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
const handlePoints = _subselect(interpolated3DPoints, handleCount);
|
|
175
|
+
|
|
176
|
+
if (interpolationData.has(sliceIndex)) {
|
|
177
|
+
_editInterpolatedContour(
|
|
178
|
+
interpolated3DPoints,
|
|
179
|
+
handlePoints,
|
|
180
|
+
sliceIndex,
|
|
181
|
+
nearestAnnotation,
|
|
182
|
+
eventData
|
|
183
|
+
);
|
|
184
|
+
} else {
|
|
185
|
+
_addInterpolatedContour(
|
|
186
|
+
interpolated3DPoints,
|
|
187
|
+
handlePoints,
|
|
188
|
+
sliceIndex,
|
|
189
|
+
nearestAnnotation,
|
|
190
|
+
eventData
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function _subselect(points, count = 10) {
|
|
196
|
+
const handles = [];
|
|
197
|
+
const { length } = points.x;
|
|
198
|
+
if (!length) {
|
|
199
|
+
return handles;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < count; i++) {
|
|
202
|
+
const handleIndex = Math.floor((length * i) / count);
|
|
203
|
+
handles.push(
|
|
204
|
+
vec3.fromValues(
|
|
205
|
+
points.x[handleIndex],
|
|
206
|
+
points.y[handleIndex],
|
|
207
|
+
points.z[handleIndex]
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
return handles;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* _addInterpolatedContour - Adds a new contour to the imageId.
|
|
216
|
+
*
|
|
217
|
+
* @param interpolated3DPoints - object, The polygon to add to the ROIContour.
|
|
218
|
+
* @param sliceIndex - Number, The slice index to interpolate..
|
|
219
|
+
* @param referencedToolData - The toolData of another polygon in the
|
|
220
|
+
* ROIContour, to assign appropriate metadata to the new polygon.
|
|
221
|
+
* @param eventData - object
|
|
222
|
+
* @returns null
|
|
223
|
+
*/
|
|
224
|
+
function _addInterpolatedContour(
|
|
225
|
+
interpolated3DPoints: Types.PointsXYZ,
|
|
226
|
+
handlePoints: Types.Point3[],
|
|
227
|
+
sliceIndex: number,
|
|
228
|
+
referencedToolData,
|
|
229
|
+
eventData
|
|
230
|
+
) {
|
|
231
|
+
const points = PointsArray.fromXYZ(interpolated3DPoints).points;
|
|
232
|
+
const { viewport } = eventData;
|
|
233
|
+
|
|
234
|
+
const interpolatedAnnotation = createPolylineToolData(
|
|
235
|
+
points,
|
|
236
|
+
handlePoints,
|
|
237
|
+
referencedToolData
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const targetId = viewport.getTargetId({ sliceIndex });
|
|
241
|
+
interpolatedAnnotation.metadata.referencedImageId = targetId;
|
|
242
|
+
interpolatedAnnotation.metadata.referencedSliceIndex = sliceIndex;
|
|
243
|
+
annotationState.state.addAnnotation(interpolatedAnnotation, viewport.element);
|
|
244
|
+
referencedToolData.postInterpolateAction?.(
|
|
245
|
+
interpolatedAnnotation,
|
|
246
|
+
referencedToolData
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* _editInterpolatedContour - Edits an interpolated polygon on the imageId
|
|
252
|
+
* that corresponds to the specified ROIContour.
|
|
253
|
+
*
|
|
254
|
+
* @param interpolated3DPoints - object, The polygon to add to the ROIContour.
|
|
255
|
+
* @param sliceIndex - Number, The slice index to interpolate.
|
|
256
|
+
* @param referencedToolData - type, The toolData of another polygon in the
|
|
257
|
+
* ROIContour, to assign appropriate metadata to the new polygon.
|
|
258
|
+
* @param eventData - object
|
|
259
|
+
* @returns null
|
|
260
|
+
*/
|
|
261
|
+
function _editInterpolatedContour(
|
|
262
|
+
interpolated3DPoints: Types.PointsXYZ,
|
|
263
|
+
handlePoints: Types.Point3[],
|
|
264
|
+
sliceIndex,
|
|
265
|
+
referencedToolData,
|
|
266
|
+
eventData
|
|
267
|
+
) {
|
|
268
|
+
const { viewport } = eventData;
|
|
269
|
+
const annotations = annotationState.state.getAnnotations(
|
|
270
|
+
referencedToolData.metadata.toolName,
|
|
271
|
+
viewport.element
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
// Find the index of the polygon on this slice corresponding to
|
|
275
|
+
// The ROIContour.
|
|
276
|
+
let toolDataIndex;
|
|
277
|
+
|
|
278
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
279
|
+
const annotation = annotations[i] as InterpolationROIAnnotation;
|
|
280
|
+
if (
|
|
281
|
+
annotation.interpolationUID === referencedToolData.interpolationUID &&
|
|
282
|
+
annotation.metadata.referencedSliceIndex === sliceIndex
|
|
283
|
+
) {
|
|
284
|
+
toolDataIndex = i;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (toolDataIndex === undefined) {
|
|
289
|
+
console.warn(
|
|
290
|
+
'Unable to find referenced slice index in the tool data',
|
|
291
|
+
sliceIndex,
|
|
292
|
+
annotations
|
|
293
|
+
);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const oldToolData = annotations[toolDataIndex] as InterpolationROIAnnotation;
|
|
298
|
+
const points = PointsArray.fromXYZ(interpolated3DPoints).points;
|
|
299
|
+
const interpolatedAnnotation = createPolylineToolData(
|
|
300
|
+
points,
|
|
301
|
+
handlePoints,
|
|
302
|
+
oldToolData
|
|
303
|
+
);
|
|
304
|
+
// To update existing annotation, not intend to add or remove
|
|
305
|
+
interpolatedAnnotation.annotationUID = oldToolData.annotationUID;
|
|
306
|
+
annotationState.state.removeAnnotation(oldToolData.annotationUID);
|
|
307
|
+
annotationState.state.addAnnotation(interpolatedAnnotation, viewport.element);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* _generateInterpolatedOpenContour - Interpolate an open contour between c1ir
|
|
312
|
+
* and c2ir at the zInterp position.
|
|
313
|
+
*
|
|
314
|
+
* @param c1ir - object, The interpolated c1 contour with
|
|
315
|
+
* superfluous nodes removed.
|
|
316
|
+
* @param c2ir - object, The interpolated c2 contour with
|
|
317
|
+
* superfluous nodes removed.
|
|
318
|
+
* @param zInterp - Number, The z- coordinate of the desired
|
|
319
|
+
* interpolation.
|
|
320
|
+
* @param c1HasMoreNodes - boolean, True if c1 has more original nodes
|
|
321
|
+
* than c2.
|
|
322
|
+
* @returns object, The interpolated contour at z=zInterp.
|
|
323
|
+
*/
|
|
324
|
+
function _generateInterpolatedOpenContour(
|
|
325
|
+
c1ir,
|
|
326
|
+
c2ir,
|
|
327
|
+
zInterp,
|
|
328
|
+
c1HasMoreNodes
|
|
329
|
+
): PointsXYZI {
|
|
330
|
+
const cInterp = {
|
|
331
|
+
x: [],
|
|
332
|
+
y: [],
|
|
333
|
+
z: [],
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const indices = c1HasMoreNodes ? c1ir.I : c2ir.I;
|
|
337
|
+
|
|
338
|
+
for (let i = 0; i < c1ir.x.length; i++) {
|
|
339
|
+
if (indices[i]) {
|
|
340
|
+
cInterp.x.push(c1ir.x[i] + (c2ir.x[i] - c1ir.x[i]) * zInterp);
|
|
341
|
+
cInterp.y.push(c1ir.y[i] + (c2ir.y[i] - c1ir.y[i]) * zInterp);
|
|
342
|
+
cInterp.z.push(c1ir.z[i] + (c2ir.z[i] - c1ir.z[i]) * zInterp);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return cInterp;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* _generateInterpolationContourPair - generates two aligned contours with an
|
|
351
|
+
* equal number of nodes from which an intermediate contour may be interpolated.
|
|
352
|
+
*
|
|
353
|
+
* @param c1 - The first contour.
|
|
354
|
+
* @param c2 - The second contour.
|
|
355
|
+
* @returns - An object containing the two contours.
|
|
356
|
+
*/
|
|
357
|
+
function _generateInterpolationContourPair(c1, c2) {
|
|
358
|
+
const cumPerim1 = _getCumulativePerimeter(c1);
|
|
359
|
+
const cumPerim2 = _getCumulativePerimeter(c2);
|
|
360
|
+
|
|
361
|
+
const interpNodes = Math.max(
|
|
362
|
+
Math.ceil(cumPerim1[cumPerim1.length - 1] / dP),
|
|
363
|
+
Math.ceil(cumPerim2[cumPerim2.length - 1] / dP)
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
const cumPerim1Norm = _normalisedCumulativePerimeter(cumPerim1);
|
|
367
|
+
const cumPerim2Norm = _normalisedCumulativePerimeter(cumPerim2);
|
|
368
|
+
|
|
369
|
+
const numNodes1 = interpNodes + c2.x.length;
|
|
370
|
+
const numNodes2 = interpNodes + c1.x.length;
|
|
371
|
+
|
|
372
|
+
// concatinate p && cumPerimNorm
|
|
373
|
+
const perim1Interp = _getInterpolatedPerim(numNodes1, cumPerim1Norm);
|
|
374
|
+
const perim2Interp = _getInterpolatedPerim(numNodes2, cumPerim2Norm);
|
|
375
|
+
|
|
376
|
+
const perim1Ind = _getIndicatorArray(c1, numNodes1);
|
|
377
|
+
const perim2Ind = _getIndicatorArray(c2, numNodes2);
|
|
378
|
+
|
|
379
|
+
const nodesPerSegment1 = _getNodesPerSegment(perim1Interp, perim1Ind);
|
|
380
|
+
const nodesPerSegment2 = _getNodesPerSegment(perim2Interp, perim2Ind);
|
|
381
|
+
|
|
382
|
+
const c1i = _getSuperSampledContour(c1, nodesPerSegment1);
|
|
383
|
+
const c2i = _getSuperSampledContour(c2, nodesPerSegment2);
|
|
384
|
+
|
|
385
|
+
// Keep c2i fixed and shift the starting node of c1i to minimise the total length of segments.
|
|
386
|
+
_shiftSuperSampledContourInPlace(c1i, c2i);
|
|
387
|
+
|
|
388
|
+
return _reduceContoursToOriginNodes(c1i, c2i);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* _reduceContoursToOriginNodes - Removes any nodes from the contours that don't
|
|
393
|
+
* correspond to an original contour node.
|
|
394
|
+
*
|
|
395
|
+
* @param c1i - The first super-sampled contour.
|
|
396
|
+
* @param c2i - The second super-sampled contour.
|
|
397
|
+
* @returns An object containing the two reduced contours.
|
|
398
|
+
*/
|
|
399
|
+
function _reduceContoursToOriginNodes(c1i: PointsXYZI, c2i: PointsXYZI) {
|
|
400
|
+
const c1Interp = {
|
|
401
|
+
x: [],
|
|
402
|
+
y: [],
|
|
403
|
+
z: [],
|
|
404
|
+
I: [],
|
|
405
|
+
};
|
|
406
|
+
const c2Interp = {
|
|
407
|
+
x: [],
|
|
408
|
+
y: [],
|
|
409
|
+
z: [],
|
|
410
|
+
I: [],
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
for (let i = 0; i < c1i.x.length; i++) {
|
|
414
|
+
if (c1i.I[i] || c2i.I[i]) {
|
|
415
|
+
c1Interp.x.push(c1i.x[i]);
|
|
416
|
+
c1Interp.y.push(c1i.y[i]);
|
|
417
|
+
c1Interp.z.push(c1i.z[i]);
|
|
418
|
+
c1Interp.I.push(c1i.I[i]);
|
|
419
|
+
|
|
420
|
+
c2Interp.x.push(c2i.x[i]);
|
|
421
|
+
c2Interp.y.push(c2i.y[i]);
|
|
422
|
+
c2Interp.z.push(c2i.z[i]);
|
|
423
|
+
c2Interp.I.push(c2i.I[i]);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
c1Interp,
|
|
429
|
+
c2Interp,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* _shiftSuperSampledContourInPlace - Shifts the indices of c1i around to
|
|
435
|
+
* minimize: SUM (|c1i[i]-c2i[i]|) from 0 to N.
|
|
436
|
+
*
|
|
437
|
+
* @param c1i - The contour to shift.
|
|
438
|
+
* @param c2i - The reference contour.
|
|
439
|
+
* modifies c1i
|
|
440
|
+
* @returns null
|
|
441
|
+
*/
|
|
442
|
+
function _shiftSuperSampledContourInPlace(c1i, c2i) {
|
|
443
|
+
const c1iLength = c1i.x.length;
|
|
444
|
+
|
|
445
|
+
const optimal = {
|
|
446
|
+
startingNode: 0,
|
|
447
|
+
totalSquaredXYLengths: Infinity,
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
for (let startingNode = 0; startingNode < c1iLength; startingNode++) {
|
|
451
|
+
let node = startingNode;
|
|
452
|
+
|
|
453
|
+
// NOTE: 1) Ignore calculating Z, as the sum of all squared Z distances will always be a constant.
|
|
454
|
+
// NOTE: 2) Don't need actual length, so don't worry about square rooting.
|
|
455
|
+
let totalSquaredXYLengths = 0;
|
|
456
|
+
|
|
457
|
+
for (let iteration = 0; iteration < c1iLength; iteration++) {
|
|
458
|
+
totalSquaredXYLengths +=
|
|
459
|
+
(c1i.x[node] - c2i.x[iteration]) ** 2 +
|
|
460
|
+
(c1i.y[node] - c2i.y[iteration]) ** 2 +
|
|
461
|
+
(c1i.z[node] - c2i.z[iteration]) ** 2;
|
|
462
|
+
|
|
463
|
+
node++;
|
|
464
|
+
|
|
465
|
+
if (node === c1iLength) {
|
|
466
|
+
node = 0;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (totalSquaredXYLengths < optimal.totalSquaredXYLengths) {
|
|
471
|
+
optimal.totalSquaredXYLengths = totalSquaredXYLengths;
|
|
472
|
+
optimal.startingNode = startingNode;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const node = optimal.startingNode;
|
|
477
|
+
|
|
478
|
+
_shiftCircularArray(c1i.x, node);
|
|
479
|
+
_shiftCircularArray(c1i.y, node);
|
|
480
|
+
_shiftCircularArray(c1i.z, node);
|
|
481
|
+
_shiftCircularArray(c1i.I, node);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* _shiftCircularArray - Shift the circular array by the count.
|
|
486
|
+
*
|
|
487
|
+
* @param arr - Array, The array.
|
|
488
|
+
* @param count - Number, The shift.
|
|
489
|
+
* @returns The shifted array.
|
|
490
|
+
*/
|
|
491
|
+
function _shiftCircularArray(arr, count) {
|
|
492
|
+
count -= arr.length * Math.floor(count / arr.length);
|
|
493
|
+
const slicedArray = arr.splice(0, count);
|
|
494
|
+
arr.push(...slicedArray);
|
|
495
|
+
return arr;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* _getSuperSampledContour - Generates a super sampled contour with additional
|
|
500
|
+
* nodes added per segment.
|
|
501
|
+
*
|
|
502
|
+
* @param c - object, The original contour.
|
|
503
|
+
* @param nodesPerSegment - Number[], An array of the number of nodes to add
|
|
504
|
+
* per line segment.
|
|
505
|
+
* @returns object, The super sampled contour.
|
|
506
|
+
*/
|
|
507
|
+
function _getSuperSampledContour(c, nodesPerSegment) {
|
|
508
|
+
const ci = {
|
|
509
|
+
x: [],
|
|
510
|
+
y: [],
|
|
511
|
+
z: [],
|
|
512
|
+
I: [],
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// Length - 1, produces 'open' polygon.
|
|
516
|
+
for (let n = 0; n < c.x.length - 1; n++) {
|
|
517
|
+
// Add original node.
|
|
518
|
+
ci.x.push(c.x[n]);
|
|
519
|
+
ci.y.push(c.y[n]);
|
|
520
|
+
ci.z.push(c.z[n]);
|
|
521
|
+
ci.I.push(true);
|
|
522
|
+
|
|
523
|
+
// Add linearly interpolated nodes.
|
|
524
|
+
const xSpacing = (c.x[n + 1] - c.x[n]) / (nodesPerSegment[n] + 1);
|
|
525
|
+
const ySpacing = (c.y[n + 1] - c.y[n]) / (nodesPerSegment[n] + 1);
|
|
526
|
+
const zSpacing = (c.z[n + 1] - c.z[n]) / (nodesPerSegment[n] + 1);
|
|
527
|
+
|
|
528
|
+
// Add other nodesPerSegment - 1 other nodes (as already put in original node).
|
|
529
|
+
for (let i = 0; i < nodesPerSegment[n] - 1; i++) {
|
|
530
|
+
ci.x.push(ci.x[ci.x.length - 1] + xSpacing);
|
|
531
|
+
ci.y.push(ci.y[ci.y.length - 1] + ySpacing);
|
|
532
|
+
ci.z.push(ci.z[ci.z.length - 1] + zSpacing);
|
|
533
|
+
ci.I.push(false);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return ci;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* _getNodesPerSegment - Returns an array of the number of interpolated nodes
|
|
542
|
+
* to be added along each line segment of a polygon.
|
|
543
|
+
*
|
|
544
|
+
* @param perimInterp - Number[], Normalized array of original and added nodes.
|
|
545
|
+
* @param perimInd - boolean[], The indicator array describing the location of
|
|
546
|
+
* the original contour's nodes.
|
|
547
|
+
* @returns Number[], An array containing the number of nodes to be
|
|
548
|
+
* added per original line segment.
|
|
549
|
+
*/
|
|
550
|
+
function _getNodesPerSegment(perimInterp, perimInd) {
|
|
551
|
+
const idx = [];
|
|
552
|
+
|
|
553
|
+
for (let i = 0; i < perimInterp.length; ++i) {
|
|
554
|
+
idx[i] = i;
|
|
555
|
+
}
|
|
556
|
+
idx.sort(function (a, b) {
|
|
557
|
+
return perimInterp[a] < perimInterp[b] ? -1 : 1;
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
const perimIndSorted = [];
|
|
561
|
+
|
|
562
|
+
for (let i = 0; i < perimInd.length; i++) {
|
|
563
|
+
perimIndSorted.push(perimInd[idx[i]]);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const indicesOfOriginNodes = perimIndSorted.reduce(function (
|
|
567
|
+
arr,
|
|
568
|
+
elementValue,
|
|
569
|
+
i
|
|
570
|
+
) {
|
|
571
|
+
if (elementValue) {
|
|
572
|
+
arr.push(i);
|
|
573
|
+
}
|
|
574
|
+
return arr;
|
|
575
|
+
},
|
|
576
|
+
[]);
|
|
577
|
+
|
|
578
|
+
const nodesPerSegment = [];
|
|
579
|
+
|
|
580
|
+
for (let i = 0; i < indicesOfOriginNodes.length - 1; i++) {
|
|
581
|
+
nodesPerSegment.push(indicesOfOriginNodes[i + 1] - indicesOfOriginNodes[i]);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return nodesPerSegment;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* _getIndicatorArray - Produces an array of the location of the original nodes
|
|
589
|
+
* in a super sampled contour.
|
|
590
|
+
*
|
|
591
|
+
* @param contour - object, The original contour.
|
|
592
|
+
* @param numNodes - Number, The number of nodes added.
|
|
593
|
+
* @returns boolean[], The indicator array of original node locations.
|
|
594
|
+
*/
|
|
595
|
+
function _getIndicatorArray(contour, numNodes) {
|
|
596
|
+
const perimInd = [];
|
|
597
|
+
|
|
598
|
+
for (let i = 0; i < numNodes - 2; i++) {
|
|
599
|
+
perimInd.push(false);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
for (let i = 0; i < contour.x.length; i++) {
|
|
603
|
+
perimInd.push(true);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return perimInd;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* _getInterpolatedPerim - Adds additional interpolated nodes to the
|
|
611
|
+
* normalized perimeter array.
|
|
612
|
+
*
|
|
613
|
+
* @param numNodes - object, The number of nodes to add.
|
|
614
|
+
* @param cumPerimNorm - The cumulative perimeter array.
|
|
615
|
+
* @returns Number[], The array of nodes.
|
|
616
|
+
*/
|
|
617
|
+
function _getInterpolatedPerim(numNodes, cumPerimNorm) {
|
|
618
|
+
const diff = 1 / (numNodes - 1);
|
|
619
|
+
const linspace = [diff];
|
|
620
|
+
|
|
621
|
+
// Length - 2 as we are discarding 0 an 1 for efficiency (no need to calculate them).
|
|
622
|
+
for (let i = 1; i < numNodes - 2; i++) {
|
|
623
|
+
linspace.push(linspace[linspace.length - 1] + diff);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return linspace.concat(cumPerimNorm);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* _normalizedCumulativePerimeter - Normalizes the cumulative perimeter array.
|
|
631
|
+
*
|
|
632
|
+
* @param cumPerim - An array of the cumulative perimeter at each of a contour.
|
|
633
|
+
* @returns The normalized array.
|
|
634
|
+
*/
|
|
635
|
+
function _normalisedCumulativePerimeter(cumPerim) {
|
|
636
|
+
const cumPerimNorm = [];
|
|
637
|
+
|
|
638
|
+
for (let i = 0; i < cumPerim.length; i++) {
|
|
639
|
+
cumPerimNorm.push(cumPerim[i] / cumPerim[cumPerim.length - 1]);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return cumPerimNorm;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* _getCumulativePerimeter - Returns an array of the the cumulative perimeter at
|
|
647
|
+
* each node of the contour.
|
|
648
|
+
*
|
|
649
|
+
* @param contour - The contour.
|
|
650
|
+
* @returns An array of the cumulative perimeter at each node.
|
|
651
|
+
*/
|
|
652
|
+
function _getCumulativePerimeter(contour: Types.PointsXYZ): number[] {
|
|
653
|
+
const cumulativePerimeter = [0];
|
|
654
|
+
|
|
655
|
+
for (let i = 1; i < contour.x.length; i++) {
|
|
656
|
+
const lengthOfSegment = Math.sqrt(
|
|
657
|
+
(contour.x[i] - contour.x[i - 1]) ** 2 +
|
|
658
|
+
(contour.y[i] - contour.y[i - 1]) ** 2 +
|
|
659
|
+
(contour.z[i] - contour.z[i - 1]) ** 2
|
|
660
|
+
);
|
|
661
|
+
|
|
662
|
+
cumulativePerimeter.push(cumulativePerimeter[i - 1] + lengthOfSegment);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return cumulativePerimeter;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* _generateClosedContour - Generate a clockwise contour object from the points
|
|
670
|
+
* of a clockwise or anti-clockwise polygon.
|
|
671
|
+
*
|
|
672
|
+
* @param points - The points to generate the contour from.
|
|
673
|
+
* @returns The generated contour object.
|
|
674
|
+
*/
|
|
675
|
+
function _generateClosedContour(points): Types.PointsXYZ {
|
|
676
|
+
const c = {
|
|
677
|
+
x: [],
|
|
678
|
+
y: [],
|
|
679
|
+
z: [],
|
|
680
|
+
};
|
|
681
|
+
for (let i = 0; i < points.length; i++) {
|
|
682
|
+
c.x[i] = points[i][0];
|
|
683
|
+
c.y[i] = points[i][1];
|
|
684
|
+
c.z[i] = points[i][2];
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Push last node to create closed contour.
|
|
688
|
+
c.x.push(c.x[0]);
|
|
689
|
+
c.y.push(c.y[0]);
|
|
690
|
+
c.z.push(c.z[0]);
|
|
691
|
+
|
|
692
|
+
return c;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export default interpolate;
|