@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,519 @@
|
|
|
1
|
+
import { getEnabledElement, triggerEvent } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
|
|
4
|
+
import Events from '../../enums/Events';
|
|
5
|
+
import mouseMoveListener from './mouseMoveListener';
|
|
6
|
+
import { EventTypes, IPoints } from '../../types';
|
|
7
|
+
import getMouseEventPoints from './getMouseEventPoints';
|
|
8
|
+
|
|
9
|
+
const { MOUSE_DOWN, MOUSE_DOWN_ACTIVATE, MOUSE_CLICK, MOUSE_UP, MOUSE_DRAG } =
|
|
10
|
+
Events;
|
|
11
|
+
|
|
12
|
+
// The amount of time in milliseconds within which a browser 'dblclick' event has to occur.
|
|
13
|
+
// Any mouse down, up, down and up sequence taking longer than this time is considered to
|
|
14
|
+
// NOT be a double click and any browser 'dblclick' event that subsequently occurs as a result
|
|
15
|
+
// of such a sequence will be ignored. It is best to set this to a value that is less
|
|
16
|
+
// than the system value for detecting a double click. Setting something too large
|
|
17
|
+
// might detect a double click that does not constitute a browser 'dblclick' and thus
|
|
18
|
+
// no mouse events for the sequence will get fired at all.
|
|
19
|
+
//
|
|
20
|
+
// TODO This module should detect and fire 'dblclick' events at its discretion and
|
|
21
|
+
// ignore all those generated by the browser.
|
|
22
|
+
//
|
|
23
|
+
const DOUBLE_CLICK_TOLERANCE_MS = 400;
|
|
24
|
+
|
|
25
|
+
// A drag (projected distance) during the double click timeout that is greater than this
|
|
26
|
+
// value will cancel the timeout and suppress any double click that might occur.
|
|
27
|
+
// This tolerance is particularly important on touch devices where some movement
|
|
28
|
+
// might occur between the two clicks.
|
|
29
|
+
//
|
|
30
|
+
// TODO revisit this value for touch devices
|
|
31
|
+
//
|
|
32
|
+
const DOUBLE_CLICK_DRAG_TOLERANCE = 3;
|
|
33
|
+
|
|
34
|
+
interface IMouseDownListenerState {
|
|
35
|
+
mouseButton: number;
|
|
36
|
+
element: HTMLDivElement;
|
|
37
|
+
renderingEngineId: string;
|
|
38
|
+
viewportId: string;
|
|
39
|
+
isClickEvent: boolean;
|
|
40
|
+
clickDelay: number;
|
|
41
|
+
preventClickTimeout: ReturnType<typeof setTimeout>;
|
|
42
|
+
startPoints: IPoints;
|
|
43
|
+
lastPoints: IPoints;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface IDoubleClickState {
|
|
47
|
+
doubleClickTimeout: ReturnType<typeof setTimeout>;
|
|
48
|
+
mouseDownEvent: MouseEvent;
|
|
49
|
+
mouseUpEvent: MouseEvent;
|
|
50
|
+
ignoreDoubleClick: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// STATE
|
|
54
|
+
const defaultState: IMouseDownListenerState = {
|
|
55
|
+
mouseButton: undefined,
|
|
56
|
+
//
|
|
57
|
+
element: null,
|
|
58
|
+
renderingEngineId: undefined,
|
|
59
|
+
viewportId: undefined,
|
|
60
|
+
//
|
|
61
|
+
isClickEvent: true,
|
|
62
|
+
clickDelay: 200,
|
|
63
|
+
preventClickTimeout: null,
|
|
64
|
+
startPoints: {
|
|
65
|
+
page: [0, 0],
|
|
66
|
+
client: [0, 0],
|
|
67
|
+
canvas: [0, 0],
|
|
68
|
+
world: [0, 0, 0],
|
|
69
|
+
},
|
|
70
|
+
lastPoints: {
|
|
71
|
+
page: [0, 0],
|
|
72
|
+
client: [0, 0],
|
|
73
|
+
canvas: [0, 0],
|
|
74
|
+
world: [0, 0, 0],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let state: IMouseDownListenerState = {
|
|
79
|
+
mouseButton: undefined,
|
|
80
|
+
//
|
|
81
|
+
renderingEngineId: undefined,
|
|
82
|
+
viewportId: undefined,
|
|
83
|
+
//
|
|
84
|
+
isClickEvent: true,
|
|
85
|
+
clickDelay: 200,
|
|
86
|
+
element: null,
|
|
87
|
+
preventClickTimeout: null,
|
|
88
|
+
startPoints: {
|
|
89
|
+
page: [0, 0],
|
|
90
|
+
client: [0, 0],
|
|
91
|
+
canvas: [0, 0],
|
|
92
|
+
world: [0, 0, 0],
|
|
93
|
+
},
|
|
94
|
+
lastPoints: {
|
|
95
|
+
page: [0, 0],
|
|
96
|
+
client: [0, 0],
|
|
97
|
+
canvas: [0, 0],
|
|
98
|
+
world: [0, 0, 0],
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const doubleClickState: IDoubleClickState = {
|
|
103
|
+
doubleClickTimeout: null,
|
|
104
|
+
mouseDownEvent: null,
|
|
105
|
+
mouseUpEvent: null,
|
|
106
|
+
ignoreDoubleClick: false,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Listens to mouse down events from the DOM and depending on interaction and further
|
|
111
|
+
* interaction can emit the following mouse events:
|
|
112
|
+
*
|
|
113
|
+
* - MOUSE_DOWN
|
|
114
|
+
* - MOUSE_DOWN_ACTIVATE
|
|
115
|
+
* - MOUSE_DRAG (move while down)
|
|
116
|
+
* - MOUSE_UP
|
|
117
|
+
* - MOUSE_CLICK
|
|
118
|
+
*
|
|
119
|
+
* The mouse down is NOT handled immediately. Instead, a timeout is started to
|
|
120
|
+
* determine if this mouse down is the first in a sequence that constitutes a
|
|
121
|
+
* double click.
|
|
122
|
+
*
|
|
123
|
+
* @param evt - The Mouse event.
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
function mouseDownListener(evt: MouseEvent) {
|
|
127
|
+
// Ignore any mouse down during the double click timeout because only
|
|
128
|
+
// the first mouse down has the potential of being handled.
|
|
129
|
+
if (doubleClickState.doubleClickTimeout) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
doubleClickState.doubleClickTimeout = setTimeout(
|
|
134
|
+
_doStateMouseDownAndUp,
|
|
135
|
+
DOUBLE_CLICK_TOLERANCE_MS
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// First mouse down of a potential double click. So save it and start
|
|
139
|
+
// a timeout to determine a double click.
|
|
140
|
+
doubleClickState.mouseDownEvent = evt;
|
|
141
|
+
doubleClickState.ignoreDoubleClick = false;
|
|
142
|
+
|
|
143
|
+
state.element = <HTMLDivElement>evt.currentTarget;
|
|
144
|
+
|
|
145
|
+
state.mouseButton = evt.button;
|
|
146
|
+
|
|
147
|
+
const enabledElement = getEnabledElement(state.element);
|
|
148
|
+
const { renderingEngineId, viewportId } = enabledElement;
|
|
149
|
+
|
|
150
|
+
state.renderingEngineId = renderingEngineId;
|
|
151
|
+
state.viewportId = viewportId;
|
|
152
|
+
|
|
153
|
+
state.preventClickTimeout = setTimeout(
|
|
154
|
+
_preventClickHandler,
|
|
155
|
+
state.clickDelay
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// Prevent CornerstoneToolsMouseMove while mouse is down
|
|
159
|
+
state.element.removeEventListener('mousemove', mouseMoveListener);
|
|
160
|
+
|
|
161
|
+
const startPoints = getMouseEventPoints(evt, state.element);
|
|
162
|
+
state.startPoints = _copyPoints(startPoints);
|
|
163
|
+
state.lastPoints = _copyPoints(startPoints);
|
|
164
|
+
|
|
165
|
+
document.addEventListener('mouseup', _onMouseUp);
|
|
166
|
+
document.addEventListener('mousemove', _onMouseDrag);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Does the actual mouse down logic if the double click timer has expired or
|
|
171
|
+
* a mouse drag has started.
|
|
172
|
+
* @param evt the mouse down event
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
function _doMouseDown(evt: MouseEvent) {
|
|
176
|
+
const deltaPoints = _getDeltaPoints(state.startPoints, state.startPoints);
|
|
177
|
+
|
|
178
|
+
const eventDetail: EventTypes.MouseDownEventDetail = {
|
|
179
|
+
event: evt,
|
|
180
|
+
eventName: MOUSE_DOWN,
|
|
181
|
+
element: state.element,
|
|
182
|
+
mouseButton: state.mouseButton,
|
|
183
|
+
renderingEngineId: state.renderingEngineId,
|
|
184
|
+
viewportId: state.viewportId,
|
|
185
|
+
camera: {},
|
|
186
|
+
startPoints: state.startPoints,
|
|
187
|
+
lastPoints: state.startPoints,
|
|
188
|
+
currentPoints: state.startPoints,
|
|
189
|
+
deltaPoints,
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
state.lastPoints = _copyPoints(eventDetail.lastPoints);
|
|
193
|
+
|
|
194
|
+
// by triggering MOUSE_DOWN it checks if this is toolSelection, handle modification etc.
|
|
195
|
+
// of already existing tools
|
|
196
|
+
const notConsumed = triggerEvent(
|
|
197
|
+
eventDetail.element,
|
|
198
|
+
MOUSE_DOWN,
|
|
199
|
+
eventDetail
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
// if no tools responded to this event and prevented its default behavior,
|
|
203
|
+
// create a new tool
|
|
204
|
+
if (notConsumed) {
|
|
205
|
+
triggerEvent(eventDetail.element, MOUSE_DOWN_ACTIVATE, eventDetail);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
*_onMouseDrag - Handle emission of drag events whilst the mouse is depressed.
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
* @param evt - The mouse event.
|
|
214
|
+
*/
|
|
215
|
+
function _onMouseDrag(evt: MouseEvent) {
|
|
216
|
+
const currentPoints = getMouseEventPoints(evt, state.element);
|
|
217
|
+
const lastPoints = _updateMouseEventsLastPoints(
|
|
218
|
+
state.element,
|
|
219
|
+
state.lastPoints
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const deltaPoints = _getDeltaPoints(currentPoints, lastPoints);
|
|
223
|
+
|
|
224
|
+
if (doubleClickState.doubleClickTimeout) {
|
|
225
|
+
if (_isDragPastDoubleClickTolerance(deltaPoints.canvas)) {
|
|
226
|
+
// Dragging past the tolerance means no double click should occur.
|
|
227
|
+
_doStateMouseDownAndUp();
|
|
228
|
+
} else {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const eventDetail: EventTypes.MouseDragEventDetail = {
|
|
234
|
+
event: evt,
|
|
235
|
+
eventName: MOUSE_DRAG,
|
|
236
|
+
mouseButton: state.mouseButton,
|
|
237
|
+
renderingEngineId: state.renderingEngineId,
|
|
238
|
+
viewportId: state.viewportId,
|
|
239
|
+
camera: {},
|
|
240
|
+
element: state.element,
|
|
241
|
+
startPoints: _copyPoints(state.startPoints),
|
|
242
|
+
lastPoints: _copyPoints(lastPoints),
|
|
243
|
+
currentPoints,
|
|
244
|
+
deltaPoints,
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
triggerEvent(state.element, MOUSE_DRAG, eventDetail);
|
|
248
|
+
|
|
249
|
+
// Update the last points
|
|
250
|
+
state.lastPoints = _copyPoints(currentPoints);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
*_onMouseUp - Handle emission of mouse up events, and re-enabling mouse move events.
|
|
255
|
+
*
|
|
256
|
+
* If the mouse up event occurs during a double click timeout, it is either the first or
|
|
257
|
+
* second mouse up of a potential double click sequence. If the first, then it
|
|
258
|
+
* is saved in case the double click timeout expires and a simple mouse down and
|
|
259
|
+
* up have to get executed. If the second, then the latest mouse down, up, down and
|
|
260
|
+
* up constitute a double click and the mouseDoubleClickListener needs to execute.
|
|
261
|
+
*
|
|
262
|
+
* If the mouse up event comes after the double click timeout, then it is simply
|
|
263
|
+
* handled as the up of a mouse down and up sequence.
|
|
264
|
+
*
|
|
265
|
+
* @private
|
|
266
|
+
* @param evt - The mouse event.
|
|
267
|
+
*/
|
|
268
|
+
function _onMouseUp(evt: MouseEvent): void {
|
|
269
|
+
// Cancel the timeout preventing the click event from triggering
|
|
270
|
+
clearTimeout(state.preventClickTimeout);
|
|
271
|
+
|
|
272
|
+
if (doubleClickState.doubleClickTimeout) {
|
|
273
|
+
// received a mouse up while waiting for a double click (via a timeout)
|
|
274
|
+
|
|
275
|
+
if (!doubleClickState.mouseUpEvent) {
|
|
276
|
+
// this is the first mouse up during the double click timeout; we'll need it later if the timeout expires
|
|
277
|
+
doubleClickState.mouseUpEvent = evt;
|
|
278
|
+
|
|
279
|
+
state.element.addEventListener('mousemove', _onMouseMove);
|
|
280
|
+
} else {
|
|
281
|
+
// this is the second mouse up of a double click!
|
|
282
|
+
_cleanUp();
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
// Handle the actual mouse up. Note that it may have occurred during the double click timeout or
|
|
286
|
+
// after it expired. In either case this block is being executed after the time out has expired
|
|
287
|
+
// or after a drag started.
|
|
288
|
+
|
|
289
|
+
const eventName = state.isClickEvent ? MOUSE_CLICK : MOUSE_UP;
|
|
290
|
+
|
|
291
|
+
const currentPoints = getMouseEventPoints(evt, state.element);
|
|
292
|
+
const deltaPoints = _getDeltaPoints(currentPoints, state.lastPoints);
|
|
293
|
+
const eventDetail:
|
|
294
|
+
| EventTypes.MouseUpEventDetail
|
|
295
|
+
| EventTypes.MouseClickEventType = {
|
|
296
|
+
event: evt,
|
|
297
|
+
eventName,
|
|
298
|
+
mouseButton: state.mouseButton,
|
|
299
|
+
element: state.element,
|
|
300
|
+
renderingEngineId: state.renderingEngineId,
|
|
301
|
+
viewportId: state.viewportId,
|
|
302
|
+
camera: {},
|
|
303
|
+
startPoints: _copyPoints(state.startPoints),
|
|
304
|
+
lastPoints: _copyPoints(state.lastPoints),
|
|
305
|
+
currentPoints,
|
|
306
|
+
deltaPoints,
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
triggerEvent(eventDetail.element, eventName, eventDetail);
|
|
310
|
+
|
|
311
|
+
_cleanUp();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Remove the drag as soon as we get the mouse up because either we have executed
|
|
315
|
+
// the mouse up logic, or we have not even handled the mouse down logic yet
|
|
316
|
+
// - either way no drag should/can occur.
|
|
317
|
+
document.removeEventListener('mousemove', _onMouseDrag);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Handles a mouse move on the state element after a mouse down AND up AND
|
|
322
|
+
* while the double click timeout is still running.
|
|
323
|
+
* @private
|
|
324
|
+
* @param evt - The mouse event.
|
|
325
|
+
*/
|
|
326
|
+
function _onMouseMove(evt: MouseEvent) {
|
|
327
|
+
const currentPoints = getMouseEventPoints(evt, state.element);
|
|
328
|
+
const lastPoints = _updateMouseEventsLastPoints(
|
|
329
|
+
state.element,
|
|
330
|
+
state.lastPoints
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
const deltaPoints = _getDeltaPoints(currentPoints, lastPoints);
|
|
334
|
+
|
|
335
|
+
if (!_isDragPastDoubleClickTolerance(deltaPoints.canvas)) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
_doStateMouseDownAndUp();
|
|
340
|
+
|
|
341
|
+
// Do the move again because during the timeout the global mouse move listener was removed.
|
|
342
|
+
// Now it is back.
|
|
343
|
+
mouseMoveListener(evt);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Determines if the given delta is past the double click, (projected) drag distance
|
|
348
|
+
* tolerance.
|
|
349
|
+
* @param delta the delta
|
|
350
|
+
* @returns true iff the delta is past the tolerance
|
|
351
|
+
*/
|
|
352
|
+
function _isDragPastDoubleClickTolerance(delta: Types.Point2): boolean {
|
|
353
|
+
return Math.abs(delta[0]) + Math.abs(delta[1]) > DOUBLE_CLICK_DRAG_TOLERANCE;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function _preventClickHandler() {
|
|
357
|
+
state.isClickEvent = false;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Do a mouse down and potential mouse up using each of the events in the double click state.
|
|
362
|
+
* The events were stored in the state during the timeout to determine a double click.
|
|
363
|
+
*
|
|
364
|
+
* This function should be invoked whenever it is determined that the latest
|
|
365
|
+
* sequence of mouse down(s) and up(s) is NOT a double click. Examples of this include
|
|
366
|
+
* - the expiration of the double click timeout
|
|
367
|
+
* - a mouse drag/move beyond the DOUBLE_CLICK_DRAG_TOLERANCE
|
|
368
|
+
*
|
|
369
|
+
* This function sets the doubleClickState.ignoreDoubleClick flag in case our timeout value
|
|
370
|
+
* or mouse move/drag tolerance is inaccurate and we do indeed get a double click event from
|
|
371
|
+
* the browser later. The flag will be cleared in the mouseDoubleClickIgnoreListener should a
|
|
372
|
+
* double click event get fired. If there is no eventual double click for the latest sequence,
|
|
373
|
+
* the flag spills into the next sequence where it will get cleared at the beginning of that next
|
|
374
|
+
* sequence in mouseDownListener. It is perfectly safe for the flag to be
|
|
375
|
+
* left true when no double click actually occurs because any future double click must start with
|
|
376
|
+
* a mouse down that is handled in this module.
|
|
377
|
+
*
|
|
378
|
+
* @private
|
|
379
|
+
*/
|
|
380
|
+
function _doStateMouseDownAndUp() {
|
|
381
|
+
doubleClickState.ignoreDoubleClick = true;
|
|
382
|
+
|
|
383
|
+
const mouseDownEvent = doubleClickState.mouseDownEvent;
|
|
384
|
+
const mouseUpEvent = doubleClickState.mouseUpEvent;
|
|
385
|
+
|
|
386
|
+
_clearDoubleClickTimeoutAndEvents();
|
|
387
|
+
|
|
388
|
+
_doMouseDown(mouseDownEvent);
|
|
389
|
+
|
|
390
|
+
if (mouseUpEvent) {
|
|
391
|
+
_onMouseUp(mouseUpEvent);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Clears the mouse events and double click timeout id in the double click state object.
|
|
397
|
+
* The timeout itself is also cleared so that no callback is invoked.
|
|
398
|
+
*/
|
|
399
|
+
function _clearDoubleClickTimeoutAndEvents() {
|
|
400
|
+
if (doubleClickState.doubleClickTimeout) {
|
|
401
|
+
clearTimeout(doubleClickState.doubleClickTimeout);
|
|
402
|
+
doubleClickState.doubleClickTimeout = null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
doubleClickState.mouseDownEvent = null;
|
|
406
|
+
doubleClickState.mouseUpEvent = null;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function _cleanUp() {
|
|
410
|
+
document.removeEventListener('mouseup', _onMouseUp);
|
|
411
|
+
state.element?.removeEventListener('mousemove', _onMouseMove);
|
|
412
|
+
|
|
413
|
+
// Restore our global mousemove listener
|
|
414
|
+
state.element?.addEventListener('mousemove', mouseMoveListener);
|
|
415
|
+
|
|
416
|
+
_clearDoubleClickTimeoutAndEvents();
|
|
417
|
+
|
|
418
|
+
state = JSON.parse(JSON.stringify(defaultState));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Copies a set of points.
|
|
423
|
+
* @param points - The `IPoints` instance to copy.
|
|
424
|
+
*
|
|
425
|
+
* @returns A copy of the points.
|
|
426
|
+
*/
|
|
427
|
+
function _copyPoints(points: IPoints): IPoints {
|
|
428
|
+
return JSON.parse(JSON.stringify(points));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Recalculates the last world coordinate, as the linear transform from client
|
|
433
|
+
* to world could be different if the camera was updated.
|
|
434
|
+
* @param element - The HTML element
|
|
435
|
+
* @param lastPoints - The last points
|
|
436
|
+
*/
|
|
437
|
+
function _updateMouseEventsLastPoints(
|
|
438
|
+
element: HTMLDivElement,
|
|
439
|
+
lastPoints: IPoints
|
|
440
|
+
): IPoints {
|
|
441
|
+
const { viewport } = getEnabledElement(element);
|
|
442
|
+
// Need to update the world point to be calculated from the current reference frame,
|
|
443
|
+
// Which might have changed since the last interaction.
|
|
444
|
+
const world = viewport.canvasToWorld(lastPoints.canvas);
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
page: lastPoints.page,
|
|
448
|
+
client: lastPoints.client,
|
|
449
|
+
canvas: lastPoints.canvas,
|
|
450
|
+
world,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Returns the difference between two `IPoints` instances.
|
|
456
|
+
* @param currentPoints - The current points.
|
|
457
|
+
* @param lastPoints -- The last points, to be subtracted from the `currentPoints`.
|
|
458
|
+
*
|
|
459
|
+
* @returns The difference in IPoints format
|
|
460
|
+
*/
|
|
461
|
+
function _getDeltaPoints(currentPoints: IPoints, lastPoints: IPoints): IPoints {
|
|
462
|
+
return {
|
|
463
|
+
page: _subtractPoints2D(currentPoints.page, lastPoints.page),
|
|
464
|
+
client: _subtractPoints2D(currentPoints.client, lastPoints.client),
|
|
465
|
+
canvas: _subtractPoints2D(currentPoints.canvas, lastPoints.canvas),
|
|
466
|
+
world: _subtractPoints3D(currentPoints.world, lastPoints.world),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* _subtractPoints - Subtracts `point1` from `point0`.
|
|
472
|
+
* @param point0 - The first point.
|
|
473
|
+
* @param point1 - The second point to subtract from the first.
|
|
474
|
+
*
|
|
475
|
+
* @returns The difference.
|
|
476
|
+
*/
|
|
477
|
+
function _subtractPoints2D(
|
|
478
|
+
point0: Types.Point2,
|
|
479
|
+
point1: Types.Point2
|
|
480
|
+
): Types.Point2 {
|
|
481
|
+
return [point0[0] - point1[0], point0[1] - point1[1]];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function _subtractPoints3D(
|
|
485
|
+
point0: Types.Point3,
|
|
486
|
+
point1: Types.Point3
|
|
487
|
+
): Types.Point3 {
|
|
488
|
+
return [point0[0] - point1[0], point0[1] - point1[1], point0[2] - point1[2]];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export function getMouseButton(): number {
|
|
492
|
+
return state.mouseButton;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Handles a dblclick event to determine if it should be ignored based on the
|
|
497
|
+
* double click state's ignoreDoubleClick flag. stopImmediatePropagation and
|
|
498
|
+
* preventDefault are used to ignore the event.
|
|
499
|
+
* @param evt browser dblclick event
|
|
500
|
+
*/
|
|
501
|
+
export function mouseDoubleClickIgnoreListener(evt: MouseEvent) {
|
|
502
|
+
if (doubleClickState.ignoreDoubleClick) {
|
|
503
|
+
doubleClickState.ignoreDoubleClick = false;
|
|
504
|
+
|
|
505
|
+
// Use stopImmediatePropagation to lessen the possibility that a third party 'dblclick'
|
|
506
|
+
// listener receives this event. However, there still is no guarantee
|
|
507
|
+
// that any third party listener has not already handled the event.
|
|
508
|
+
evt.stopImmediatePropagation();
|
|
509
|
+
evt.preventDefault();
|
|
510
|
+
} else {
|
|
511
|
+
// If the embedding application blocked the first mouse down and up
|
|
512
|
+
// of a double click sequence from reaching this module, then this module
|
|
513
|
+
// has handled the second mouse down and up and thus needs to clean them up.
|
|
514
|
+
// Doing a clean up here for the typical double click case is harmless.
|
|
515
|
+
_cleanUp();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export default mouseDownListener;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getEnabledElement, triggerEvent } from '@cornerstonejs/core';
|
|
2
|
+
import Events from '../../enums/Events';
|
|
3
|
+
import getMouseEventPoints from './getMouseEventPoints';
|
|
4
|
+
import { MouseMoveEventDetail } from '../../types/EventTypes';
|
|
5
|
+
|
|
6
|
+
const eventName = Events.MOUSE_MOVE;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Captures and normalizes the mouse move event. Emits as a cornerstoneTools3D
|
|
10
|
+
* mouse move event.
|
|
11
|
+
*
|
|
12
|
+
* @param evt - The mouse event.
|
|
13
|
+
*/
|
|
14
|
+
function mouseMoveListener(evt: MouseEvent) {
|
|
15
|
+
const element = <HTMLDivElement>evt.currentTarget;
|
|
16
|
+
const enabledElement = getEnabledElement(element);
|
|
17
|
+
const { renderingEngineId, viewportId } = enabledElement;
|
|
18
|
+
|
|
19
|
+
const currentPoints = getMouseEventPoints(evt);
|
|
20
|
+
const eventDetail: MouseMoveEventDetail = {
|
|
21
|
+
renderingEngineId,
|
|
22
|
+
viewportId,
|
|
23
|
+
camera: {},
|
|
24
|
+
element,
|
|
25
|
+
currentPoints,
|
|
26
|
+
eventName,
|
|
27
|
+
event: evt,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
triggerEvent(element, eventName, eventDetail);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default mouseMoveListener;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import segmentationRepresentationModifiedEventListener from './segmentationRepresentationModifiedEventListener';
|
|
2
|
+
import segmentationDataModifiedEventListener from './segmentationDataModifiedEventListener';
|
|
3
|
+
import segmentationRepresentationRemovedEventListener from './segmentationRepresentationRemovedEventListener';
|
|
4
|
+
import segmentationModifiedListener from './segmentationModifiedEventListener';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
segmentationRepresentationModifiedEventListener,
|
|
8
|
+
segmentationDataModifiedEventListener,
|
|
9
|
+
segmentationRepresentationRemovedEventListener,
|
|
10
|
+
segmentationModifiedListener,
|
|
11
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { cache } from '@cornerstonejs/core';
|
|
2
|
+
|
|
3
|
+
import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
|
|
4
|
+
import SegmentationRepresentations from '../../enums/SegmentationRepresentations';
|
|
5
|
+
import * as SegmentationState from '../../stateManagement/segmentation/segmentationState';
|
|
6
|
+
import { SegmentationDataModifiedEventType } from '../../types/EventTypes';
|
|
7
|
+
|
|
8
|
+
/** A callback function that is called when the segmentation data is modified which
|
|
9
|
+
* often is as a result of tool interactions e.g., scissors, eraser, etc.
|
|
10
|
+
*/
|
|
11
|
+
const onSegmentationDataModified = function (
|
|
12
|
+
evt: SegmentationDataModifiedEventType
|
|
13
|
+
): void {
|
|
14
|
+
const { segmentationId, modifiedSlicesToUse } = evt.detail;
|
|
15
|
+
|
|
16
|
+
const { representationData, type } =
|
|
17
|
+
SegmentationState.getSegmentation(segmentationId);
|
|
18
|
+
|
|
19
|
+
let toolGroupIds;
|
|
20
|
+
if (type === SegmentationRepresentations.Labelmap) {
|
|
21
|
+
// get the volume from cache, we need the openGLTexture to be updated to GPU
|
|
22
|
+
const segmentationVolume = cache.getVolume(
|
|
23
|
+
representationData[type].volumeId
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (!segmentationVolume) {
|
|
27
|
+
console.warn('segmentation not found in cache');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { imageData, vtkOpenGLTexture } = segmentationVolume;
|
|
32
|
+
|
|
33
|
+
// Update the texture for the volume in the GPU
|
|
34
|
+
let slicesToUpdate;
|
|
35
|
+
if (modifiedSlicesToUse && Array.isArray(modifiedSlicesToUse)) {
|
|
36
|
+
slicesToUpdate = modifiedSlicesToUse;
|
|
37
|
+
} else {
|
|
38
|
+
const numSlices = imageData.getDimensions()[2];
|
|
39
|
+
slicesToUpdate = [...Array(numSlices).keys()];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
slicesToUpdate.forEach((i) => {
|
|
43
|
+
vtkOpenGLTexture.setUpdatedFrame(i);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Trigger modified on the imageData to update the image
|
|
47
|
+
imageData.modified();
|
|
48
|
+
toolGroupIds =
|
|
49
|
+
SegmentationState.getToolGroupIdsWithSegmentation(segmentationId);
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`onSegmentationDataModified: representationType ${type} not supported yet`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
toolGroupIds.forEach((toolGroupId) => {
|
|
57
|
+
triggerSegmentationRender(toolGroupId);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default onSegmentationDataModified;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SegmentationModifiedEventType } from '../../types/EventTypes';
|
|
2
|
+
import {
|
|
3
|
+
getToolGroupIdsWithSegmentation,
|
|
4
|
+
getSegmentationRepresentations,
|
|
5
|
+
} from '../../stateManagement/segmentation/segmentationState';
|
|
6
|
+
import { triggerSegmentationRepresentationModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
|
|
7
|
+
|
|
8
|
+
/** A function that listens to the `segmentationModified` event and triggers
|
|
9
|
+
* the triggerSegmentationRepresentationModified on each toolGroup that
|
|
10
|
+
* has a representation of the given segmentationId.
|
|
11
|
+
*/
|
|
12
|
+
const segmentationModifiedListener = function (
|
|
13
|
+
evt: SegmentationModifiedEventType
|
|
14
|
+
): void {
|
|
15
|
+
const { segmentationId } = evt.detail;
|
|
16
|
+
|
|
17
|
+
const toolGroupIds = getToolGroupIdsWithSegmentation(segmentationId);
|
|
18
|
+
|
|
19
|
+
toolGroupIds.forEach((toolGroupId) => {
|
|
20
|
+
const segRepresentations = getSegmentationRepresentations(toolGroupId);
|
|
21
|
+
segRepresentations.forEach((representation) => {
|
|
22
|
+
if (representation.segmentationId === segmentationId) {
|
|
23
|
+
triggerSegmentationRepresentationModified(
|
|
24
|
+
toolGroupId,
|
|
25
|
+
representation.segmentationRepresentationUID
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default segmentationModifiedListener;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
|
|
2
|
+
import { SegmentationRepresentationModifiedEventType } from '../../types/EventTypes';
|
|
3
|
+
|
|
4
|
+
/** A function that listens to the `segmentationStateModified` event and triggers
|
|
5
|
+
* the `triggerSegmentationRender` function. This function is called when the
|
|
6
|
+
* segmentation state or config is modified.
|
|
7
|
+
*/
|
|
8
|
+
const segmentationRepresentationModifiedListener = function (
|
|
9
|
+
evt: SegmentationRepresentationModifiedEventType
|
|
10
|
+
): void {
|
|
11
|
+
const { toolGroupId } = evt.detail;
|
|
12
|
+
triggerSegmentationRender(toolGroupId);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default segmentationRepresentationModifiedListener;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
|
|
2
|
+
import { SegmentationRepresentationRemovedEventType } from '../../types/EventTypes';
|
|
3
|
+
|
|
4
|
+
/** A function that listens to the `segmentationRepresentationRemoved` event and triggers
|
|
5
|
+
* the `triggerSegmentationRender` function. This function is called when the
|
|
6
|
+
* segmentation state or config is modified.
|
|
7
|
+
*/
|
|
8
|
+
const segmentationRepresentationRemovedEventListener = function (
|
|
9
|
+
evt: SegmentationRepresentationRemovedEventType
|
|
10
|
+
): void {
|
|
11
|
+
const { toolGroupId, segmentationRepresentationUID } = evt.detail;
|
|
12
|
+
|
|
13
|
+
triggerSegmentationRender(toolGroupId);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default segmentationRepresentationRemovedEventListener;
|