@cornerstonejs/tools 0.56.2 → 0.56.4
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/package.json +5 -4
- package/src/constants/COLOR_LUT.ts +262 -0
- package/src/constants/index.ts +3 -0
- package/src/cursors/ImageMouseCursor.ts +39 -0
- package/src/cursors/MouseCursor.ts +114 -0
- package/src/cursors/SVGCursorDescriptor.ts +462 -0
- package/src/cursors/SVGMouseCursor.ts +145 -0
- package/src/cursors/elementCursor.ts +69 -0
- package/src/cursors/index.ts +24 -0
- package/src/cursors/setCursorForElement.ts +33 -0
- package/src/drawingSvg/_getHash.ts +9 -0
- package/src/drawingSvg/_setAttributesIfNecessary.ts +13 -0
- package/src/drawingSvg/_setNewAttributesIfValid.ts +10 -0
- package/src/drawingSvg/clearByToolType.ts +26 -0
- package/src/drawingSvg/draw.ts +16 -0
- package/src/drawingSvg/drawArrow.ts +82 -0
- package/src/drawingSvg/drawCircle.ts +62 -0
- package/src/drawingSvg/drawEllipse.ts +71 -0
- package/src/drawingSvg/drawHandles.ts +87 -0
- package/src/drawingSvg/drawLine.ts +70 -0
- package/src/drawingSvg/drawLink.ts +76 -0
- package/src/drawingSvg/drawLinkedTextBox.ts +64 -0
- package/src/drawingSvg/drawPolyline.ts +80 -0
- package/src/drawingSvg/drawRect.ts +70 -0
- package/src/drawingSvg/drawTextBox.ts +213 -0
- package/src/drawingSvg/getSvgDrawingHelper.ts +98 -0
- package/src/drawingSvg/index.ts +23 -0
- package/src/enums/AnnotationStyleStates.ts +22 -0
- package/src/enums/Events.ts +242 -0
- package/src/enums/SegmentationRepresentations.ts +12 -0
- package/src/enums/ToolBindings.ts +37 -0
- package/src/enums/ToolModes.ts +31 -0
- package/src/enums/Touch.ts +8 -0
- package/src/enums/index.js +16 -0
- package/src/eventDispatchers/annotationModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/cameraModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/imageRenderedEventDispatcher.ts +37 -0
- package/src/eventDispatchers/imageSpacingCalibratedEventDispatcher.ts +50 -0
- package/src/eventDispatchers/index.js +15 -0
- package/src/eventDispatchers/keyboardEventHandlers/index.js +4 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyDown.ts +29 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyUp.ts +33 -0
- package/src/eventDispatchers/keyboardToolEventDispatcher.ts +28 -0
- package/src/eventDispatchers/mouseEventHandlers/index.js +19 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDoubleClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +196 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDownActivate.ts +35 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDrag.ts +25 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseMove.ts +70 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseUp.ts +9 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseWheel.ts +13 -0
- package/src/eventDispatchers/mouseToolEventDispatcher.ts +64 -0
- package/src/eventDispatchers/shared/customCallbackHandler.ts +73 -0
- package/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +58 -0
- package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +61 -0
- package/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +64 -0
- package/src/eventDispatchers/shared/getMouseModifier.ts +30 -0
- package/src/eventDispatchers/shared/getToolsWithModesForMouseEvent.ts +56 -0
- package/src/eventDispatchers/shared/getToolsWithModesForTouchEvent.ts +54 -0
- package/src/eventDispatchers/touchEventHandlers/index.js +15 -0
- package/src/eventDispatchers/touchEventHandlers/touchDrag.ts +23 -0
- package/src/eventDispatchers/touchEventHandlers/touchEnd.ts +9 -0
- package/src/eventDispatchers/touchEventHandlers/touchPress.ts +13 -0
- package/src/eventDispatchers/touchEventHandlers/touchStart.ts +174 -0
- package/src/eventDispatchers/touchEventHandlers/touchStartActivate.ts +36 -0
- package/src/eventDispatchers/touchEventHandlers/touchTap.ts +9 -0
- package/src/eventDispatchers/touchToolEventDispatcher.ts +51 -0
- package/src/eventListeners/annotations/annotationModifiedListener.ts +22 -0
- package/src/eventListeners/annotations/annotationSelectionListener.ts +29 -0
- package/src/eventListeners/annotations/index.ts +4 -0
- package/src/eventListeners/index.ts +28 -0
- package/src/eventListeners/keyboard/index.ts +16 -0
- package/src/eventListeners/keyboard/keyDownListener.ts +99 -0
- package/src/eventListeners/mouse/getMouseEventPoints.ts +66 -0
- package/src/eventListeners/mouse/index.ts +55 -0
- package/src/eventListeners/mouse/mouseDoubleClickListener.ts +55 -0
- package/src/eventListeners/mouse/mouseDownListener.ts +519 -0
- package/src/eventListeners/mouse/mouseMoveListener.ts +33 -0
- package/src/eventListeners/segmentation/index.ts +11 -0
- package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +61 -0
- package/src/eventListeners/segmentation/segmentationModifiedEventListener.ts +32 -0
- package/src/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.ts +15 -0
- package/src/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.ts +16 -0
- package/src/eventListeners/touch/getTouchEventPoints.ts +75 -0
- package/src/eventListeners/touch/index.ts +37 -0
- package/src/eventListeners/touch/preventGhostClick.js +72 -0
- package/src/eventListeners/touch/touchStartListener.ts +499 -0
- package/src/eventListeners/wheel/index.ts +27 -0
- package/src/eventListeners/wheel/normalizeWheel.ts +69 -0
- package/src/eventListeners/wheel/wheelListener.ts +51 -0
- package/src/index.ts +133 -0
- package/src/init.ts +187 -0
- package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +399 -0
- package/src/stateManagement/annotation/annotationLocking.ts +178 -0
- package/src/stateManagement/annotation/annotationSelection.ts +163 -0
- package/src/stateManagement/annotation/annotationState.ts +180 -0
- package/src/stateManagement/annotation/annotationVisibility.ts +156 -0
- package/src/stateManagement/annotation/config/ToolStyle.ts +265 -0
- package/src/stateManagement/annotation/config/getFont.ts +36 -0
- package/src/stateManagement/annotation/config/getState.ts +26 -0
- package/src/stateManagement/annotation/config/helpers.ts +55 -0
- package/src/stateManagement/annotation/config/index.ts +5 -0
- package/src/stateManagement/annotation/helpers/state.ts +83 -0
- package/src/stateManagement/annotation/index.ts +15 -0
- package/src/stateManagement/index.js +40 -0
- package/src/stateManagement/segmentation/SegmentationStateManager.ts +491 -0
- package/src/stateManagement/segmentation/activeSegmentation.ts +60 -0
- package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +77 -0
- package/src/stateManagement/segmentation/addSegmentations.ts +27 -0
- package/src/stateManagement/segmentation/config/index.ts +29 -0
- package/src/stateManagement/segmentation/config/segmentationColor.ts +132 -0
- package/src/stateManagement/segmentation/config/segmentationConfig.ts +195 -0
- package/src/stateManagement/segmentation/config/segmentationVisibility.ts +171 -0
- package/src/stateManagement/segmentation/helpers/index.ts +3 -0
- package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +35 -0
- package/src/stateManagement/segmentation/helpers/validateSegmentationInput.ts +41 -0
- package/src/stateManagement/segmentation/index.ts +22 -0
- package/src/stateManagement/segmentation/removeSegmentationsFromToolGroup.ts +85 -0
- package/src/stateManagement/segmentation/segmentIndex.ts +38 -0
- package/src/stateManagement/segmentation/segmentLocking.ts +72 -0
- package/src/stateManagement/segmentation/segmentationState.ts +429 -0
- package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +157 -0
- package/src/store/SynchronizerManager/Synchronizer.ts +344 -0
- package/src/store/SynchronizerManager/createSynchronizer.ts +41 -0
- package/src/store/SynchronizerManager/destroy.ts +14 -0
- package/src/store/SynchronizerManager/destroySynchronizer.ts +25 -0
- package/src/store/SynchronizerManager/getAllSynchronizers.ts +12 -0
- package/src/store/SynchronizerManager/getSynchronizer.ts +13 -0
- package/src/store/SynchronizerManager/getSynchronizersForViewport.ts +44 -0
- package/src/store/SynchronizerManager/index.js +15 -0
- package/src/store/ToolGroupManager/ToolGroup.ts +679 -0
- package/src/store/ToolGroupManager/createToolGroup.ts +33 -0
- package/src/store/ToolGroupManager/destroy.ts +24 -0
- package/src/store/ToolGroupManager/destroyToolGroup.ts +26 -0
- package/src/store/ToolGroupManager/getAllToolGroups.ts +12 -0
- package/src/store/ToolGroupManager/getToolGroup.ts +14 -0
- package/src/store/ToolGroupManager/getToolGroupForViewport.ts +44 -0
- package/src/store/ToolGroupManager/getToolGroupsWithToolName.ts +33 -0
- package/src/store/ToolGroupManager/index.ts +17 -0
- package/src/store/addEnabledElement.ts +137 -0
- package/src/store/addTool.ts +56 -0
- package/src/store/cancelActiveManipulations.ts +30 -0
- package/src/store/filterMoveableAnnotationTools.ts +61 -0
- package/src/store/filterToolsWithAnnotationsForElement.ts +51 -0
- package/src/store/filterToolsWithMoveableHandles.ts +51 -0
- package/src/store/index.ts +29 -0
- package/src/store/removeEnabledElement.ts +132 -0
- package/src/store/state.ts +57 -0
- package/src/store/svgNodeCache.ts +7 -0
- package/src/synchronizers/callbacks/areViewportsCoplanar .ts +12 -0
- package/src/synchronizers/callbacks/cameraSyncCallback.ts +33 -0
- package/src/synchronizers/callbacks/stackImageSyncCallback.ts +157 -0
- package/src/synchronizers/callbacks/voiSyncCallback.ts +51 -0
- package/src/synchronizers/callbacks/zoomPanSyncCallback.ts +43 -0
- package/src/synchronizers/index.ts +11 -0
- package/src/synchronizers/synchronizers/createCameraPositionSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createStackImageSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createVOISynchronizer.ts +24 -0
- package/src/synchronizers/synchronizers/createZoomPanSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/index.ts +11 -0
- package/src/tools/CrosshairsTool.ts +2693 -0
- package/src/tools/MIPJumpToClickTool.ts +99 -0
- package/src/tools/MagnifyTool.ts +319 -0
- package/src/tools/PanTool.ts +58 -0
- package/src/tools/PlanarRotateTool.ts +77 -0
- package/src/tools/ReferenceCursors.ts +466 -0
- package/src/tools/ReferenceLinesTool.ts +279 -0
- package/src/tools/ScaleOverlayTool.ts +685 -0
- package/src/tools/StackScrollTool.ts +97 -0
- package/src/tools/StackScrollToolMouseWheelTool.ts +58 -0
- package/src/tools/TrackballRotateTool.ts +141 -0
- package/src/tools/VolumeRotateMouseWheelTool.ts +86 -0
- package/src/tools/WindowLevelTool.ts +260 -0
- package/src/tools/ZoomTool.ts +293 -0
- package/src/tools/annotation/AngleTool.ts +835 -0
- package/src/tools/annotation/ArrowAnnotateTool.ts +820 -0
- package/src/tools/annotation/BidirectionalTool.ts +1350 -0
- package/src/tools/annotation/CircleROITool.ts +1070 -0
- package/src/tools/annotation/CobbAngleTool.ts +815 -0
- package/src/tools/annotation/DragProbeTool.ts +213 -0
- package/src/tools/annotation/EllipticalROITool.ts +1223 -0
- package/src/tools/annotation/LengthTool.ts +861 -0
- package/src/tools/annotation/PlanarFreehandROITool.ts +636 -0
- package/src/tools/annotation/ProbeTool.ts +681 -0
- package/src/tools/annotation/RectangleROITool.ts +1028 -0
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +488 -0
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +462 -0
- package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +331 -0
- package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +612 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +407 -0
- package/src/tools/base/AnnotationDisplayTool.ts +228 -0
- package/src/tools/base/AnnotationTool.ts +307 -0
- package/src/tools/base/BaseTool.ts +215 -0
- package/src/tools/base/index.ts +4 -0
- package/src/tools/displayTools/Contour/addContourToElement.ts +135 -0
- package/src/tools/displayTools/Contour/contourDisplay.ts +252 -0
- package/src/tools/displayTools/Contour/index.ts +3 -0
- package/src/tools/displayTools/Contour/removeContourFromElement.ts +35 -0
- package/src/tools/displayTools/Labelmap/addLabelmapToElement.ts +57 -0
- package/src/tools/displayTools/Labelmap/index.ts +4 -0
- package/src/tools/displayTools/Labelmap/labelmapConfig.ts +37 -0
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +461 -0
- package/src/tools/displayTools/Labelmap/removeLabelmapFromElement.ts +27 -0
- package/src/tools/displayTools/Labelmap/validateRepresentationData.ts +30 -0
- package/src/tools/displayTools/SegmentationDisplayTool.ts +198 -0
- package/src/tools/index.ts +84 -0
- package/src/tools/segmentation/BrushTool.ts +474 -0
- package/src/tools/segmentation/CircleScissorsTool.ts +365 -0
- package/src/tools/segmentation/PaintFillTool.ts +370 -0
- package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +471 -0
- package/src/tools/segmentation/RectangleROIThresholdTool.ts +281 -0
- package/src/tools/segmentation/RectangleScissorsTool.ts +382 -0
- package/src/tools/segmentation/SphereScissorsTool.ts +368 -0
- package/src/tools/segmentation/strategies/eraseCircle.ts +30 -0
- package/src/tools/segmentation/strategies/eraseRectangle.ts +81 -0
- package/src/tools/segmentation/strategies/eraseSphere.ts +27 -0
- package/src/tools/segmentation/strategies/fillCircle.ts +185 -0
- package/src/tools/segmentation/strategies/fillRectangle.ts +110 -0
- package/src/tools/segmentation/strategies/fillSphere.ts +88 -0
- package/src/tools/segmentation/strategies/index.ts +9 -0
- package/src/types/AnnotationGroupSelector.ts +7 -0
- package/src/types/AnnotationStyle.ts +42 -0
- package/src/types/AnnotationTypes.ts +109 -0
- package/src/types/BoundsIJK.ts +5 -0
- package/src/types/CINETypes.ts +32 -0
- package/src/types/ContourTypes.ts +26 -0
- package/src/types/CursorTypes.ts +12 -0
- package/src/types/EventTypes.ts +657 -0
- package/src/types/FloodFillTypes.ts +19 -0
- package/src/types/IAnnotationManager.ts +89 -0
- package/src/types/IDistance.ts +16 -0
- package/src/types/IPoints.ts +18 -0
- package/src/types/ISetToolModeOptions.ts +29 -0
- package/src/types/ISynchronizerEventHandler.ts +11 -0
- package/src/types/IToolClassReference.ts +5 -0
- package/src/types/IToolGroup.ts +72 -0
- package/src/types/ITouchPoints.ts +14 -0
- package/src/types/InteractionTypes.ts +6 -0
- package/src/types/InternalToolTypes.ts +19 -0
- package/src/types/JumpToSliceOptions.ts +7 -0
- package/src/types/LabelmapTypes.ts +41 -0
- package/src/types/PlanarBoundingBox.ts +8 -0
- package/src/types/SVGDrawingHelper.ts +10 -0
- package/src/types/ScrollOptions.ts +9 -0
- package/src/types/SegmentationStateTypes.ts +248 -0
- package/src/types/ToolHandle.ts +26 -0
- package/src/types/ToolProps.ts +16 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +311 -0
- package/src/types/index.ts +115 -0
- package/src/utilities/boundingBox/extend2DBoundingBoxInViewAxis.ts +29 -0
- package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +57 -0
- package/src/utilities/boundingBox/index.ts +4 -0
- package/src/utilities/calibrateImageSpacing.ts +46 -0
- package/src/utilities/cine/events.ts +9 -0
- package/src/utilities/cine/index.ts +5 -0
- package/src/utilities/cine/playClip.ts +435 -0
- package/src/utilities/cine/state.ts +18 -0
- package/src/utilities/clip.js +30 -0
- package/src/utilities/debounce.js +217 -0
- package/src/utilities/drawing/getTextBoxCoordsCanvas.ts +45 -0
- package/src/utilities/drawing/index.ts +3 -0
- package/src/utilities/dynamicVolume/getDataInTime.ts +110 -0
- package/src/utilities/dynamicVolume/index.ts +2 -0
- package/src/utilities/getAnnotationNearPoint.ts +130 -0
- package/src/utilities/getModalityUnit.ts +11 -0
- package/src/utilities/getToolsWithModesForElement.ts +52 -0
- package/src/utilities/index.ts +68 -0
- package/src/utilities/isObject.js +29 -0
- package/src/utilities/math/angle/angleBetweenLines.ts +29 -0
- package/src/utilities/math/circle/_types.ts +6 -0
- package/src/utilities/math/circle/getCanvasCircleCorners.ts +23 -0
- package/src/utilities/math/circle/getCanvasCircleRadius.ts +16 -0
- package/src/utilities/math/circle/index.ts +4 -0
- package/src/utilities/math/ellipse/getCanvasEllipseCorners.ts +26 -0
- package/src/utilities/math/ellipse/index.ts +4 -0
- package/src/utilities/math/ellipse/pointInEllipse.ts +38 -0
- package/src/utilities/math/ellipse/pointInEllipsoidWithConstraint.ts +35 -0
- package/src/utilities/math/index.ts +8 -0
- package/src/utilities/math/line/distanceToPoint.ts +24 -0
- package/src/utilities/math/line/distanceToPointSquared.ts +44 -0
- package/src/utilities/math/line/index.ts +5 -0
- package/src/utilities/math/line/intersectLine.ts +92 -0
- package/src/utilities/math/midPoint.ts +24 -0
- package/src/utilities/math/point/distanceToPoint.ts +22 -0
- package/src/utilities/math/point/index.ts +3 -0
- package/src/utilities/math/polyline/addCanvasPointsToArray.ts +62 -0
- package/src/utilities/math/polyline/calculateAreaOfPoints.ts +23 -0
- package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +182 -0
- package/src/utilities/math/polyline/getSubPixelSpacingAndXYDirections.ts +99 -0
- package/src/utilities/math/polyline/index.ts +19 -0
- package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +36 -0
- package/src/utilities/math/polyline/pointCanProjectOnLine.ts +57 -0
- package/src/utilities/math/polyline/pointsAreWithinCloseContourProximity.ts +15 -0
- package/src/utilities/math/rectangle/distanceToPoint.ts +82 -0
- package/src/utilities/math/rectangle/index.ts +3 -0
- package/src/utilities/math/sphere/index.ts +3 -0
- package/src/utilities/math/sphere/pointInSphere.ts +31 -0
- package/src/utilities/math/vec2/findClosestPoint.ts +40 -0
- package/src/utilities/math/vec2/index.ts +4 -0
- package/src/utilities/math/vec2/liangBarksyClip.ts +84 -0
- package/src/utilities/orientation/getOrientationStringLPS.ts +52 -0
- package/src/utilities/orientation/index.ts +4 -0
- package/src/utilities/orientation/invertOrientationStringLPS.ts +21 -0
- package/src/utilities/planar/filterAnnotationsForDisplay.ts +68 -0
- package/src/utilities/planar/filterAnnotationsWithinSlice.ts +85 -0
- package/src/utilities/planar/getPointInLineOfSightWithCriteria.ts +104 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromCorners.ts +51 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromTwoPoints.ts +51 -0
- package/src/utilities/planar/index.ts +18 -0
- package/src/utilities/planarFreehandROITool/index.ts +7 -0
- package/src/utilities/planarFreehandROITool/interpolateAnnotation.ts +87 -0
- package/src/utilities/planarFreehandROITool/interpolatePoints.ts +214 -0
- package/src/utilities/planarFreehandROITool/interpolation/algorithms/bspline.ts +55 -0
- package/src/utilities/planarFreehandROITool/interpolation/interpolateSegmentPoints.ts +90 -0
- package/src/utilities/pointInShapeCallback.ts +138 -0
- package/src/utilities/pointInSurroundingSphereCallback.ts +188 -0
- package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +76 -0
- package/src/utilities/rectangleROITool/index.ts +3 -0
- package/src/utilities/scroll.ts +62 -0
- package/src/utilities/segmentation/brushSizeForToolGroup.ts +72 -0
- package/src/utilities/segmentation/brushThresholdForToolGroup.ts +65 -0
- package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +74 -0
- package/src/utilities/segmentation/createMergedLabelmapForIndex.ts +65 -0
- package/src/utilities/segmentation/floodFill.ts +194 -0
- package/src/utilities/segmentation/getDefaultRepresentationConfig.ts +20 -0
- package/src/utilities/segmentation/index.ts +33 -0
- package/src/utilities/segmentation/isValidRepresentationConfig.ts +22 -0
- package/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +91 -0
- package/src/utilities/segmentation/thresholdSegmentationByRange.ts +129 -0
- package/src/utilities/segmentation/thresholdVolumeByRange.ts +150 -0
- package/src/utilities/segmentation/triggerSegmentationRender.ts +206 -0
- package/src/utilities/segmentation/utilities.ts +116 -0
- package/src/utilities/stackPrefetch/index.ts +8 -0
- package/src/utilities/stackPrefetch/stackPrefetch.ts +405 -0
- package/src/utilities/stackPrefetch/state.ts +17 -0
- package/src/utilities/throttle.js +69 -0
- package/src/utilities/touch/index.ts +246 -0
- package/src/utilities/triggerAnnotationRender.ts +237 -0
- package/src/utilities/triggerAnnotationRenderForViewportIds.ts +18 -0
- package/src/utilities/viewport/index.ts +5 -0
- package/src/utilities/viewport/isViewportPreScaled.ts +24 -0
- package/src/utilities/viewport/jumpToSlice.ts +73 -0
- package/src/utilities/viewport/jumpToWorld.ts +58 -0
- package/src/utilities/viewportFilters/filterViewportsWithFrameOfReferenceUID.ts +28 -0
- package/src/utilities/viewportFilters/filterViewportsWithParallelNormals.ts +26 -0
- package/src/utilities/viewportFilters/filterViewportsWithSameOrientation.ts +15 -0
- package/src/utilities/viewportFilters/filterViewportsWithToolEnabled.ts +72 -0
- package/src/utilities/viewportFilters/getViewportIdsWithToolToRender.ts +45 -0
- package/src/utilities/viewportFilters/index.ts +11 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEnabledElement,
|
|
3
|
+
cache,
|
|
4
|
+
StackViewport,
|
|
5
|
+
triggerEvent,
|
|
6
|
+
eventTarget,
|
|
7
|
+
utilities as csUtils,
|
|
8
|
+
} from '@cornerstonejs/core';
|
|
9
|
+
import type { Types } from '@cornerstonejs/core';
|
|
10
|
+
|
|
11
|
+
import { addAnnotation, getAnnotations } from '../../stateManagement';
|
|
12
|
+
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
|
|
13
|
+
import { Events } from '../../enums';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
drawHandles as drawHandlesSvg,
|
|
17
|
+
drawRect as drawRectSvg,
|
|
18
|
+
} from '../../drawingSvg';
|
|
19
|
+
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
|
|
20
|
+
import { hideElementCursor } from '../../cursors/elementCursor';
|
|
21
|
+
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
|
|
22
|
+
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
|
|
23
|
+
import {
|
|
24
|
+
PublicToolProps,
|
|
25
|
+
ToolProps,
|
|
26
|
+
EventTypes,
|
|
27
|
+
SVGDrawingHelper,
|
|
28
|
+
} from '../../types';
|
|
29
|
+
import { RectangleROIThresholdAnnotation } from '../../types/ToolSpecificAnnotationTypes';
|
|
30
|
+
import { AnnotationModifiedEventDetail } from '../../types/EventTypes';
|
|
31
|
+
import RectangleROITool from '../annotation/RectangleROITool';
|
|
32
|
+
import { StyleSpecifier } from '../../types/AnnotationStyle';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This tool is exactly the RectangleROITool but only draws a rectangle on the image,
|
|
36
|
+
* and by using utility functions such as thresholdByRange and thresholdByROIStat it can be used to
|
|
37
|
+
* create a segmentation. This tool, however, does not calculate the statistics
|
|
38
|
+
* as RectangleROITool does.
|
|
39
|
+
*/
|
|
40
|
+
class RectangleROIThresholdTool extends RectangleROITool {
|
|
41
|
+
static toolName;
|
|
42
|
+
_throttledCalculateCachedStats: any;
|
|
43
|
+
editData: {
|
|
44
|
+
annotation: any;
|
|
45
|
+
viewportIdsToRender: string[];
|
|
46
|
+
handleIndex?: number;
|
|
47
|
+
newAnnotation?: boolean;
|
|
48
|
+
hasMoved?: boolean;
|
|
49
|
+
} | null;
|
|
50
|
+
isDrawing: boolean;
|
|
51
|
+
isHandleOutsideImage: boolean;
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
toolProps: PublicToolProps = {},
|
|
55
|
+
defaultToolProps: ToolProps = {
|
|
56
|
+
supportedInteractionTypes: ['Mouse', 'Touch'],
|
|
57
|
+
configuration: {
|
|
58
|
+
shadow: true,
|
|
59
|
+
preventHandleOutsideImage: false,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
) {
|
|
63
|
+
super(toolProps, defaultToolProps);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Based on the current position of the mouse and the enabledElement it creates
|
|
68
|
+
* the edit data for the tool.
|
|
69
|
+
*
|
|
70
|
+
* @param evt - EventTypes.NormalizedMouseEventType
|
|
71
|
+
* @returns The annotation object.
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
addNewAnnotation = (evt: EventTypes.InteractionEventType) => {
|
|
75
|
+
const eventDetail = evt.detail;
|
|
76
|
+
const { currentPoints, element } = eventDetail;
|
|
77
|
+
const worldPos = currentPoints.world;
|
|
78
|
+
|
|
79
|
+
const enabledElement = getEnabledElement(element);
|
|
80
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
81
|
+
|
|
82
|
+
this.isDrawing = true;
|
|
83
|
+
|
|
84
|
+
const camera = viewport.getCamera();
|
|
85
|
+
const { viewPlaneNormal, viewUp } = camera;
|
|
86
|
+
|
|
87
|
+
const targetId = this.getTargetId(viewport);
|
|
88
|
+
let referencedImageId, volumeId;
|
|
89
|
+
|
|
90
|
+
if (viewport instanceof StackViewport) {
|
|
91
|
+
referencedImageId = targetId.split('imageId:')[1];
|
|
92
|
+
} else {
|
|
93
|
+
volumeId = targetId.split('volumeId:')[1];
|
|
94
|
+
const imageVolume = cache.getVolume(volumeId);
|
|
95
|
+
referencedImageId = csUtils.getClosestImageId(
|
|
96
|
+
imageVolume,
|
|
97
|
+
worldPos,
|
|
98
|
+
viewPlaneNormal,
|
|
99
|
+
viewUp
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
|
|
104
|
+
// Todo: how not to store enabledElement on the annotation, segmentationModule needs the element to
|
|
105
|
+
// decide on the active segmentIndex, active segmentationIndex etc.
|
|
106
|
+
const annotation = {
|
|
107
|
+
highlighted: true,
|
|
108
|
+
invalidated: true,
|
|
109
|
+
metadata: {
|
|
110
|
+
viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
|
|
111
|
+
enabledElement,
|
|
112
|
+
viewUp: <Types.Point3>[...viewUp],
|
|
113
|
+
FrameOfReferenceUID,
|
|
114
|
+
referencedImageId,
|
|
115
|
+
toolName: this.getToolName(),
|
|
116
|
+
volumeId,
|
|
117
|
+
},
|
|
118
|
+
data: {
|
|
119
|
+
label: '',
|
|
120
|
+
handles: {
|
|
121
|
+
// No need a textBox
|
|
122
|
+
textBox: {
|
|
123
|
+
hasMoved: false,
|
|
124
|
+
worldPosition: null,
|
|
125
|
+
worldBoundingBox: null,
|
|
126
|
+
},
|
|
127
|
+
points: [
|
|
128
|
+
<Types.Point3>[...worldPos],
|
|
129
|
+
<Types.Point3>[...worldPos],
|
|
130
|
+
<Types.Point3>[...worldPos],
|
|
131
|
+
<Types.Point3>[...worldPos],
|
|
132
|
+
],
|
|
133
|
+
activeHandleIndex: null,
|
|
134
|
+
},
|
|
135
|
+
segmentationId: null,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
addAnnotation(annotation, element);
|
|
140
|
+
|
|
141
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(
|
|
142
|
+
element,
|
|
143
|
+
this.getToolName()
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
this.editData = {
|
|
147
|
+
annotation,
|
|
148
|
+
viewportIdsToRender,
|
|
149
|
+
handleIndex: 3,
|
|
150
|
+
newAnnotation: true,
|
|
151
|
+
hasMoved: false,
|
|
152
|
+
};
|
|
153
|
+
this._activateDraw(element);
|
|
154
|
+
|
|
155
|
+
hideElementCursor(element);
|
|
156
|
+
|
|
157
|
+
evt.preventDefault();
|
|
158
|
+
|
|
159
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
160
|
+
|
|
161
|
+
return annotation;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* it is used to draw the RectangleROI Threshold annotation in each
|
|
166
|
+
* request animation frame.
|
|
167
|
+
*
|
|
168
|
+
* @param enabledElement - The Cornerstone's enabledElement.
|
|
169
|
+
* @param svgDrawingHelper - The svgDrawingHelper providing the context for drawing.
|
|
170
|
+
*/
|
|
171
|
+
renderAnnotation = (
|
|
172
|
+
enabledElement: Types.IEnabledElement,
|
|
173
|
+
svgDrawingHelper: SVGDrawingHelper
|
|
174
|
+
): boolean => {
|
|
175
|
+
let renderStatus = false;
|
|
176
|
+
const { viewport, renderingEngineId } = enabledElement;
|
|
177
|
+
const { element } = viewport;
|
|
178
|
+
let annotations = getAnnotations(this.getToolName(), element);
|
|
179
|
+
|
|
180
|
+
if (!annotations?.length) {
|
|
181
|
+
return renderStatus;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
annotations = this.filterInteractableAnnotationsForElement(
|
|
185
|
+
element,
|
|
186
|
+
annotations
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
if (!annotations?.length) {
|
|
190
|
+
return renderStatus;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const styleSpecifier: StyleSpecifier = {
|
|
194
|
+
toolGroupId: this.toolGroupId,
|
|
195
|
+
toolName: this.getToolName(),
|
|
196
|
+
viewportId: enabledElement.viewport.id,
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
200
|
+
const annotation = annotations[i] as RectangleROIThresholdAnnotation;
|
|
201
|
+
const { annotationUID, data } = annotation;
|
|
202
|
+
const { points, activeHandleIndex } = data.handles;
|
|
203
|
+
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
|
|
204
|
+
|
|
205
|
+
styleSpecifier.annotationUID = annotationUID;
|
|
206
|
+
|
|
207
|
+
const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
|
|
208
|
+
const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
|
|
209
|
+
const color = this.getStyle('color', styleSpecifier, annotation);
|
|
210
|
+
|
|
211
|
+
// If rendering engine has been destroyed while rendering
|
|
212
|
+
if (!viewport.getRenderingEngine()) {
|
|
213
|
+
console.warn('Rendering Engine has been destroyed');
|
|
214
|
+
return renderStatus;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Todo: This is not correct way to add the event trigger,
|
|
218
|
+
// this will trigger on all mouse hover too. Problem is that we don't
|
|
219
|
+
// have a cached stats mechanism for this tool yet?
|
|
220
|
+
const eventType = Events.ANNOTATION_MODIFIED;
|
|
221
|
+
|
|
222
|
+
const eventDetail: AnnotationModifiedEventDetail = {
|
|
223
|
+
annotation,
|
|
224
|
+
viewportId: viewport.id,
|
|
225
|
+
renderingEngineId,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
triggerEvent(eventTarget, eventType, eventDetail);
|
|
229
|
+
|
|
230
|
+
let activeHandleCanvasCoords;
|
|
231
|
+
|
|
232
|
+
if (!isAnnotationVisible(annotationUID)) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (
|
|
237
|
+
!isAnnotationLocked(annotation) &&
|
|
238
|
+
!this.editData &&
|
|
239
|
+
activeHandleIndex !== null
|
|
240
|
+
) {
|
|
241
|
+
// Not locked or creating and hovering over handle, so render handle.
|
|
242
|
+
activeHandleCanvasCoords = [canvasCoordinates[activeHandleIndex]];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (activeHandleCanvasCoords) {
|
|
246
|
+
const handleGroupUID = '0';
|
|
247
|
+
|
|
248
|
+
drawHandlesSvg(
|
|
249
|
+
svgDrawingHelper,
|
|
250
|
+
annotationUID,
|
|
251
|
+
handleGroupUID,
|
|
252
|
+
activeHandleCanvasCoords,
|
|
253
|
+
{
|
|
254
|
+
color,
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const rectangleUID = '0';
|
|
260
|
+
drawRectSvg(
|
|
261
|
+
svgDrawingHelper,
|
|
262
|
+
annotationUID,
|
|
263
|
+
rectangleUID,
|
|
264
|
+
canvasCoordinates[0],
|
|
265
|
+
canvasCoordinates[3],
|
|
266
|
+
{
|
|
267
|
+
color,
|
|
268
|
+
lineDash,
|
|
269
|
+
lineWidth,
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
renderStatus = true;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return renderStatus;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
RectangleROIThresholdTool.toolName = 'RectangleROIThreshold';
|
|
281
|
+
export default RectangleROIThresholdTool;
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { cache, getEnabledElement, StackViewport } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
|
|
4
|
+
import { BaseTool } from '../base';
|
|
5
|
+
import {
|
|
6
|
+
PublicToolProps,
|
|
7
|
+
ToolProps,
|
|
8
|
+
EventTypes,
|
|
9
|
+
SVGDrawingHelper,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
import { fillInsideRectangle } from './strategies/fillRectangle';
|
|
12
|
+
import { eraseInsideRectangle } from './strategies/eraseRectangle';
|
|
13
|
+
import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
|
|
14
|
+
|
|
15
|
+
import { Events } from '../../enums';
|
|
16
|
+
import { drawRect as drawRectSvg } from '../../drawingSvg';
|
|
17
|
+
import {
|
|
18
|
+
resetElementCursor,
|
|
19
|
+
hideElementCursor,
|
|
20
|
+
} from '../../cursors/elementCursor';
|
|
21
|
+
|
|
22
|
+
import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
|
|
23
|
+
import {
|
|
24
|
+
config as segmentationConfig,
|
|
25
|
+
segmentLocking,
|
|
26
|
+
segmentIndex as segmentIndexController,
|
|
27
|
+
activeSegmentation,
|
|
28
|
+
} from '../../stateManagement/segmentation';
|
|
29
|
+
|
|
30
|
+
import { getSegmentation } from '../../stateManagement/segmentation/segmentationState';
|
|
31
|
+
import { LabelmapSegmentationData } from '../../types/LabelmapTypes';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Tool for manipulating segmentation data by drawing a rectangle. It acts on the
|
|
35
|
+
* active Segmentation on the viewport (enabled element) and requires an active
|
|
36
|
+
* segmentation to be already present. By default it will use the activeSegmentIndex
|
|
37
|
+
* for the segmentation to modify. You can use SegmentationModule to set the active
|
|
38
|
+
* segmentation and segmentIndex.
|
|
39
|
+
*/
|
|
40
|
+
class RectangleScissorsTool extends BaseTool {
|
|
41
|
+
static toolName;
|
|
42
|
+
_throttledCalculateCachedStats: any;
|
|
43
|
+
editData: {
|
|
44
|
+
annotation: any;
|
|
45
|
+
segmentationId: string;
|
|
46
|
+
segmentation: any;
|
|
47
|
+
segmentIndex: number;
|
|
48
|
+
segmentsLocked: number[];
|
|
49
|
+
segmentColor: [number, number, number, number];
|
|
50
|
+
viewportIdsToRender: string[];
|
|
51
|
+
handleIndex?: number;
|
|
52
|
+
movingTextBox: boolean;
|
|
53
|
+
newAnnotation?: boolean;
|
|
54
|
+
hasMoved?: boolean;
|
|
55
|
+
} | null;
|
|
56
|
+
isDrawing: boolean;
|
|
57
|
+
isHandleOutsideImage: boolean;
|
|
58
|
+
|
|
59
|
+
constructor(
|
|
60
|
+
toolProps: PublicToolProps = {},
|
|
61
|
+
defaultToolProps: ToolProps = {
|
|
62
|
+
supportedInteractionTypes: ['Mouse', 'Touch'],
|
|
63
|
+
configuration: {
|
|
64
|
+
strategies: {
|
|
65
|
+
FILL_INSIDE: fillInsideRectangle,
|
|
66
|
+
ERASE_INSIDE: eraseInsideRectangle,
|
|
67
|
+
},
|
|
68
|
+
defaultStrategy: 'FILL_INSIDE',
|
|
69
|
+
activeStrategy: 'FILL_INSIDE',
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
) {
|
|
73
|
+
super(toolProps, defaultToolProps);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Based on the current position of the mouse and the enabledElement, it
|
|
78
|
+
* finds the active segmentation info and use it for the current tool.
|
|
79
|
+
*
|
|
80
|
+
* @param evt - EventTypes.NormalizedMouseEventType
|
|
81
|
+
* @returns The annotation object.
|
|
82
|
+
*
|
|
83
|
+
*/
|
|
84
|
+
preMouseDownCallback = (evt: EventTypes.InteractionEventType): boolean => {
|
|
85
|
+
const eventDetail = evt.detail;
|
|
86
|
+
const { currentPoints, element } = eventDetail;
|
|
87
|
+
const worldPos = currentPoints.world;
|
|
88
|
+
|
|
89
|
+
const enabledElement = getEnabledElement(element);
|
|
90
|
+
const { viewport, renderingEngine } = enabledElement;
|
|
91
|
+
|
|
92
|
+
this.isDrawing = true;
|
|
93
|
+
|
|
94
|
+
const camera = viewport.getCamera();
|
|
95
|
+
const { viewPlaneNormal, viewUp } = camera;
|
|
96
|
+
const toolGroupId = this.toolGroupId;
|
|
97
|
+
|
|
98
|
+
const activeSegmentationRepresentation =
|
|
99
|
+
activeSegmentation.getActiveSegmentationRepresentation(toolGroupId);
|
|
100
|
+
if (!activeSegmentationRepresentation) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
'No active segmentation detected, create one before using scissors tool'
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const { segmentationRepresentationUID, segmentationId, type } =
|
|
107
|
+
activeSegmentationRepresentation;
|
|
108
|
+
const segmentIndex =
|
|
109
|
+
segmentIndexController.getActiveSegmentIndex(segmentationId);
|
|
110
|
+
const segmentsLocked = segmentLocking.getLockedSegments(segmentationId);
|
|
111
|
+
|
|
112
|
+
const segmentColor = segmentationConfig.color.getColorForSegmentIndex(
|
|
113
|
+
toolGroupId,
|
|
114
|
+
segmentationRepresentationUID,
|
|
115
|
+
segmentIndex
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const { representationData } = getSegmentation(segmentationId);
|
|
119
|
+
|
|
120
|
+
// Todo: are we going to support contour editing with rectangle scissors?
|
|
121
|
+
const { volumeId } = representationData[type] as LabelmapSegmentationData;
|
|
122
|
+
const segmentation = cache.getVolume(volumeId);
|
|
123
|
+
|
|
124
|
+
// Todo: Used for drawing the svg only, we might not need it at all
|
|
125
|
+
const annotation = {
|
|
126
|
+
highlighted: true,
|
|
127
|
+
invalidated: true,
|
|
128
|
+
metadata: {
|
|
129
|
+
viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
|
|
130
|
+
viewUp: <Types.Point3>[...viewUp],
|
|
131
|
+
FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
|
|
132
|
+
referencedImageId: '',
|
|
133
|
+
toolName: this.getToolName(),
|
|
134
|
+
segmentColor,
|
|
135
|
+
},
|
|
136
|
+
data: {
|
|
137
|
+
handles: {
|
|
138
|
+
points: [
|
|
139
|
+
<Types.Point3>[...worldPos],
|
|
140
|
+
<Types.Point3>[...worldPos],
|
|
141
|
+
<Types.Point3>[...worldPos],
|
|
142
|
+
<Types.Point3>[...worldPos],
|
|
143
|
+
],
|
|
144
|
+
activeHandleIndex: null,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const viewportIdsToRender = getViewportIdsWithToolToRender(
|
|
150
|
+
element,
|
|
151
|
+
this.getToolName()
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
this.editData = {
|
|
155
|
+
annotation,
|
|
156
|
+
segmentation,
|
|
157
|
+
segmentIndex,
|
|
158
|
+
segmentsLocked,
|
|
159
|
+
segmentColor,
|
|
160
|
+
segmentationId,
|
|
161
|
+
viewportIdsToRender,
|
|
162
|
+
handleIndex: 3,
|
|
163
|
+
movingTextBox: false,
|
|
164
|
+
newAnnotation: true,
|
|
165
|
+
hasMoved: false,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
this._activateDraw(element);
|
|
169
|
+
|
|
170
|
+
hideElementCursor(element);
|
|
171
|
+
|
|
172
|
+
evt.preventDefault();
|
|
173
|
+
|
|
174
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
175
|
+
|
|
176
|
+
return true;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
_dragCallback = (evt: EventTypes.InteractionEventType) => {
|
|
180
|
+
this.isDrawing = true;
|
|
181
|
+
|
|
182
|
+
const eventDetail = evt.detail;
|
|
183
|
+
const { element } = eventDetail;
|
|
184
|
+
|
|
185
|
+
const { annotation, viewportIdsToRender, handleIndex } = this.editData;
|
|
186
|
+
const { data } = annotation;
|
|
187
|
+
|
|
188
|
+
// Moving handle.
|
|
189
|
+
const { currentPoints } = eventDetail;
|
|
190
|
+
const enabledElement = getEnabledElement(element);
|
|
191
|
+
const { worldToCanvas, canvasToWorld } = enabledElement.viewport;
|
|
192
|
+
const worldPos = currentPoints.world;
|
|
193
|
+
|
|
194
|
+
const { points } = data.handles;
|
|
195
|
+
|
|
196
|
+
// Move this handle.
|
|
197
|
+
points[handleIndex] = [...worldPos];
|
|
198
|
+
|
|
199
|
+
let bottomLeftCanvas;
|
|
200
|
+
let bottomRightCanvas;
|
|
201
|
+
let topLeftCanvas;
|
|
202
|
+
let topRightCanvas;
|
|
203
|
+
|
|
204
|
+
let bottomLeftWorld;
|
|
205
|
+
let bottomRightWorld;
|
|
206
|
+
let topLeftWorld;
|
|
207
|
+
let topRightWorld;
|
|
208
|
+
|
|
209
|
+
switch (handleIndex) {
|
|
210
|
+
case 0:
|
|
211
|
+
case 3:
|
|
212
|
+
// Moving bottomLeft or topRight
|
|
213
|
+
|
|
214
|
+
bottomLeftCanvas = worldToCanvas(points[0]);
|
|
215
|
+
topRightCanvas = worldToCanvas(points[3]);
|
|
216
|
+
|
|
217
|
+
bottomRightCanvas = [topRightCanvas[0], bottomLeftCanvas[1]];
|
|
218
|
+
topLeftCanvas = [bottomLeftCanvas[0], topRightCanvas[1]];
|
|
219
|
+
|
|
220
|
+
bottomRightWorld = canvasToWorld(bottomRightCanvas);
|
|
221
|
+
topLeftWorld = canvasToWorld(topLeftCanvas);
|
|
222
|
+
|
|
223
|
+
points[1] = bottomRightWorld;
|
|
224
|
+
points[2] = topLeftWorld;
|
|
225
|
+
|
|
226
|
+
break;
|
|
227
|
+
case 1:
|
|
228
|
+
case 2:
|
|
229
|
+
// Moving bottomRight or topLeft
|
|
230
|
+
bottomRightCanvas = worldToCanvas(points[1]);
|
|
231
|
+
topLeftCanvas = worldToCanvas(points[2]);
|
|
232
|
+
|
|
233
|
+
bottomLeftCanvas = <Types.Point2>[
|
|
234
|
+
topLeftCanvas[0],
|
|
235
|
+
bottomRightCanvas[1],
|
|
236
|
+
];
|
|
237
|
+
topRightCanvas = <Types.Point2>[bottomRightCanvas[0], topLeftCanvas[1]];
|
|
238
|
+
|
|
239
|
+
bottomLeftWorld = canvasToWorld(bottomLeftCanvas);
|
|
240
|
+
topRightWorld = canvasToWorld(topRightCanvas);
|
|
241
|
+
|
|
242
|
+
points[0] = bottomLeftWorld;
|
|
243
|
+
points[3] = topRightWorld;
|
|
244
|
+
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
annotation.invalidated = true;
|
|
248
|
+
|
|
249
|
+
this.editData.hasMoved = true;
|
|
250
|
+
|
|
251
|
+
const { renderingEngine } = enabledElement;
|
|
252
|
+
|
|
253
|
+
triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
_endCallback = (evt: EventTypes.InteractionEventType) => {
|
|
257
|
+
const eventDetail = evt.detail;
|
|
258
|
+
const { element } = eventDetail;
|
|
259
|
+
|
|
260
|
+
const {
|
|
261
|
+
annotation,
|
|
262
|
+
newAnnotation,
|
|
263
|
+
hasMoved,
|
|
264
|
+
segmentation,
|
|
265
|
+
segmentationId,
|
|
266
|
+
segmentIndex,
|
|
267
|
+
segmentsLocked,
|
|
268
|
+
} = this.editData;
|
|
269
|
+
const { data } = annotation;
|
|
270
|
+
|
|
271
|
+
if (newAnnotation && !hasMoved) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
data.handles.activeHandleIndex = null;
|
|
276
|
+
|
|
277
|
+
this._deactivateDraw(element);
|
|
278
|
+
|
|
279
|
+
resetElementCursor(element);
|
|
280
|
+
|
|
281
|
+
const enabledElement = getEnabledElement(element);
|
|
282
|
+
const { viewport } = enabledElement;
|
|
283
|
+
|
|
284
|
+
this.editData = null;
|
|
285
|
+
this.isDrawing = false;
|
|
286
|
+
|
|
287
|
+
if (viewport instanceof StackViewport) {
|
|
288
|
+
throw new Error('Not implemented yet');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const operationData = {
|
|
292
|
+
points: data.handles.points,
|
|
293
|
+
volume: segmentation,
|
|
294
|
+
segmentationId,
|
|
295
|
+
segmentIndex,
|
|
296
|
+
segmentsLocked,
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
this.applyActiveStrategy(enabledElement, operationData);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Add event handlers for the modify event loop, and prevent default event propagation.
|
|
304
|
+
*/
|
|
305
|
+
_activateDraw = (element) => {
|
|
306
|
+
element.addEventListener(Events.MOUSE_UP, this._endCallback);
|
|
307
|
+
element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
|
|
308
|
+
element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
|
|
309
|
+
|
|
310
|
+
element.addEventListener(Events.TOUCH_END, this._endCallback);
|
|
311
|
+
element.addEventListener(Events.TOUCH_DRAG, this._dragCallback);
|
|
312
|
+
element.addEventListener(Events.TOUCH_TAP, this._endCallback);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Add event handlers for the modify event loop, and prevent default event prapogation.
|
|
317
|
+
*/
|
|
318
|
+
_deactivateDraw = (element) => {
|
|
319
|
+
element.removeEventListener(Events.MOUSE_UP, this._endCallback);
|
|
320
|
+
element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
|
|
321
|
+
element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
|
|
322
|
+
element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
|
|
323
|
+
|
|
324
|
+
element.removeEventListener(Events.TOUCH_END, this._endCallback);
|
|
325
|
+
element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* it is used to draw the rectangleScissor annotation in each
|
|
330
|
+
* request animation frame. Note that the annotation are disappeared
|
|
331
|
+
* after the segmentation modification.
|
|
332
|
+
*
|
|
333
|
+
* @param enabledElement - The Cornerstone's enabledElement.
|
|
334
|
+
* @param svgDrawingHelper - The svgDrawingHelper providing the context for drawing.
|
|
335
|
+
*/
|
|
336
|
+
renderAnnotation = (
|
|
337
|
+
enabledElement: Types.IEnabledElement,
|
|
338
|
+
svgDrawingHelper: SVGDrawingHelper
|
|
339
|
+
): boolean => {
|
|
340
|
+
let renderStatus = false;
|
|
341
|
+
if (!this.editData) {
|
|
342
|
+
return renderStatus;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const { viewport } = enabledElement;
|
|
346
|
+
const { annotation } = this.editData;
|
|
347
|
+
|
|
348
|
+
// Todo: rectangle color based on segment index
|
|
349
|
+
const toolMetadata = annotation.metadata;
|
|
350
|
+
const annotationUID = annotation.annotationUID;
|
|
351
|
+
|
|
352
|
+
const data = annotation.data;
|
|
353
|
+
const { points } = data.handles;
|
|
354
|
+
const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p));
|
|
355
|
+
const color = `rgb(${toolMetadata.segmentColor.slice(0, 3)})`;
|
|
356
|
+
|
|
357
|
+
// If rendering engine has been destroyed while rendering
|
|
358
|
+
if (!viewport.getRenderingEngine()) {
|
|
359
|
+
console.warn('Rendering Engine has been destroyed');
|
|
360
|
+
return renderStatus;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const rectangleUID = '0';
|
|
364
|
+
drawRectSvg(
|
|
365
|
+
svgDrawingHelper,
|
|
366
|
+
annotationUID,
|
|
367
|
+
rectangleUID,
|
|
368
|
+
canvasCoordinates[0],
|
|
369
|
+
canvasCoordinates[3],
|
|
370
|
+
{
|
|
371
|
+
color,
|
|
372
|
+
}
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
renderStatus = true;
|
|
376
|
+
|
|
377
|
+
return renderStatus;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
RectangleScissorsTool.toolName = 'RectangleScissor';
|
|
382
|
+
export default RectangleScissorsTool;
|