@cornerstonejs/tools 0.56.1 → 0.56.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tools/CrosshairsTool.d.ts +1 -0
- package/dist/cjs/tools/CrosshairsTool.js +4 -1
- package/dist/cjs/tools/CrosshairsTool.js.map +1 -1
- package/dist/esm/tools/CrosshairsTool.d.ts +1 -0
- package/dist/esm/tools/CrosshairsTool.js +4 -1
- package/dist/esm/tools/CrosshairsTool.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- 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,679 @@
|
|
|
1
|
+
import { MouseBindings, ToolModes } from '../../enums';
|
|
2
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
3
|
+
import get from 'lodash.get';
|
|
4
|
+
import {
|
|
5
|
+
getRenderingEngine,
|
|
6
|
+
getRenderingEngines,
|
|
7
|
+
getEnabledElementByIds,
|
|
8
|
+
Settings,
|
|
9
|
+
utilities as csUtils,
|
|
10
|
+
} from '@cornerstonejs/core';
|
|
11
|
+
import type { Types } from '@cornerstonejs/core';
|
|
12
|
+
import { state } from '../index';
|
|
13
|
+
import {
|
|
14
|
+
IToolBinding,
|
|
15
|
+
IToolClassReference,
|
|
16
|
+
IToolGroup,
|
|
17
|
+
SetToolBindingsType,
|
|
18
|
+
ToolOptionsType,
|
|
19
|
+
} from '../../types';
|
|
20
|
+
|
|
21
|
+
import { MouseCursor, SVGMouseCursor } from '../../cursors';
|
|
22
|
+
import { initElementCursor } from '../../cursors/elementCursor';
|
|
23
|
+
|
|
24
|
+
const { Active, Passive, Enabled, Disabled } = ToolModes;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* ToolGroup class which is a container for tools and their modes and states.
|
|
28
|
+
* In Cornerstone3DTools, you need to create a tool group in order to use the
|
|
29
|
+
* tools. ToolGroup is a way to share tool configuration, state (enabled, disabled, etc.)
|
|
30
|
+
* across a set of viewports. Tools can set to be activated, enabled or disabled
|
|
31
|
+
* in a toolGroup. You should not directly instantiate a ToolGroup. You need to use
|
|
32
|
+
* ToolGroupManager helpers to create a new toolGroup or get a reference to an existing toolGroup.
|
|
33
|
+
*
|
|
34
|
+
* ```js
|
|
35
|
+
* const toolGroup = csTools.ToolGroupManager.createToolGroup('toolGroupId')
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export default class ToolGroup implements IToolGroup {
|
|
39
|
+
id: string;
|
|
40
|
+
viewportsInfo = [];
|
|
41
|
+
toolOptions = {};
|
|
42
|
+
_toolInstances = {};
|
|
43
|
+
|
|
44
|
+
constructor(id: string) {
|
|
45
|
+
this.id = id;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the viewport IDs of all the viewports in the current viewport
|
|
50
|
+
* @returns An array of viewport IDs.
|
|
51
|
+
*/
|
|
52
|
+
getViewportIds(): string[] {
|
|
53
|
+
return this.viewportsInfo.map(({ viewportId }) => viewportId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the toolGroup viewports info which is an array of {viewportId, renderingEngineId}
|
|
58
|
+
*/
|
|
59
|
+
getViewportsInfo(): Array<Types.IViewportId> {
|
|
60
|
+
return this.viewportsInfo.slice();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the tool instance for a given tool name in the toolGroup
|
|
65
|
+
* @param toolName - The name of the tool.
|
|
66
|
+
* @returns A tool instance.
|
|
67
|
+
*/
|
|
68
|
+
public getToolInstance(toolInstanceName: string) {
|
|
69
|
+
const toolInstance = this._toolInstances[toolInstanceName];
|
|
70
|
+
if (!toolInstance) {
|
|
71
|
+
console.warn(
|
|
72
|
+
`'${toolInstanceName}' is not registered with this toolGroup.`
|
|
73
|
+
);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return toolInstance;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Add a tool to the tool group with the given tool name and tool configuration.
|
|
81
|
+
* Note that adding a tool to a tool group will not automatically set the tool
|
|
82
|
+
* to be active. You must call setToolActive or setToolPassive and other methods
|
|
83
|
+
* to set the tool to be active or passive or in other states.
|
|
84
|
+
*
|
|
85
|
+
* @param toolName - string
|
|
86
|
+
* @param configuration - Tool configuration objects
|
|
87
|
+
*/
|
|
88
|
+
addTool(toolName: string, configuration = {}): void {
|
|
89
|
+
const toolDefinition = state.tools[toolName];
|
|
90
|
+
const hasToolName = typeof toolName !== 'undefined' && toolName !== '';
|
|
91
|
+
const localToolInstance = this.toolOptions[toolName];
|
|
92
|
+
|
|
93
|
+
if (!hasToolName) {
|
|
94
|
+
console.warn(
|
|
95
|
+
'Tool with configuration did not produce a toolName: ',
|
|
96
|
+
configuration
|
|
97
|
+
);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!toolDefinition) {
|
|
102
|
+
console.warn(
|
|
103
|
+
`'${toolName}' is not registered with the library. You need to use cornerstoneTools.addTool to register it.`
|
|
104
|
+
);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (localToolInstance) {
|
|
109
|
+
console.warn(
|
|
110
|
+
`'${toolName}' is already registered for ToolGroup ${this.id}.`
|
|
111
|
+
);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Should these be renamed higher up, so we don't have to alias?
|
|
116
|
+
// Wrap in try-catch so 3rd party tools don't explode?
|
|
117
|
+
const { toolClass: ToolClass } = toolDefinition;
|
|
118
|
+
|
|
119
|
+
const toolProps = {
|
|
120
|
+
name: toolName,
|
|
121
|
+
toolGroupId: this.id,
|
|
122
|
+
configuration,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const instantiatedTool = new ToolClass(toolProps);
|
|
126
|
+
|
|
127
|
+
// API instead of directly exposing schema?
|
|
128
|
+
// Maybe not here, but feels like a "must" for any method outside of the ToolGroup itself
|
|
129
|
+
this._toolInstances[toolName] = instantiatedTool;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public addToolInstance(
|
|
133
|
+
toolName: string,
|
|
134
|
+
parentClassName: string,
|
|
135
|
+
configuration = {}
|
|
136
|
+
): void {
|
|
137
|
+
let ToolClassToUse = state.tools[toolName]
|
|
138
|
+
?.toolClass as IToolClassReference;
|
|
139
|
+
|
|
140
|
+
if (!ToolClassToUse) {
|
|
141
|
+
// get parent class constructor
|
|
142
|
+
const ParentClass = state.tools[parentClassName]
|
|
143
|
+
.toolClass as IToolClassReference;
|
|
144
|
+
|
|
145
|
+
// Todo: could not find a way to make this work with typescript
|
|
146
|
+
// @ts-ignore
|
|
147
|
+
class ToolInstance extends ParentClass {}
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
ToolInstance.toolName = toolName;
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
ToolClassToUse = ToolInstance;
|
|
152
|
+
|
|
153
|
+
state.tools[toolName] = {
|
|
154
|
+
toolClass: ToolInstance as IToolClassReference,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// add the tool to the toolGroup
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
this.addTool(ToolClassToUse.toolName, configuration);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// class InstanceTool extends parentClass;
|
|
164
|
+
// InstanceTool.constructor.toolName = name;
|
|
165
|
+
// addTool(InstanceTool,configuration)
|
|
166
|
+
/**
|
|
167
|
+
* Add a viewport to the ToolGroup. It accepts viewportId and optional
|
|
168
|
+
* renderingEngineId parameter. If renderingEngineId is not provided,
|
|
169
|
+
* it checks if cornerstone-core has more than one renderingEngine; If so,
|
|
170
|
+
* it will throw an error. If cornerstone-core has only one renderingEngine,
|
|
171
|
+
* it will use that renderingEngine.
|
|
172
|
+
*
|
|
173
|
+
* @param viewportId - The unique identifier for the viewport.
|
|
174
|
+
* @param renderingEngineId - The rendering engine to use.
|
|
175
|
+
*/
|
|
176
|
+
public addViewport(viewportId: string, renderingEngineId?: string): void {
|
|
177
|
+
const renderingEngines = getRenderingEngines();
|
|
178
|
+
|
|
179
|
+
if (!renderingEngineId && renderingEngines.length > 1) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
'You must specify a renderingEngineId when there are multiple rendering engines.'
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const renderingEngineUIDToUse = renderingEngineId || renderingEngines[0].id;
|
|
186
|
+
|
|
187
|
+
// Don't overwrite if it already exists
|
|
188
|
+
if (
|
|
189
|
+
!this.viewportsInfo.some(({ viewportId: vpId }) => vpId === viewportId)
|
|
190
|
+
) {
|
|
191
|
+
this.viewportsInfo.push({
|
|
192
|
+
viewportId,
|
|
193
|
+
renderingEngineId: renderingEngineUIDToUse,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Handle the newly added viewport's mouse cursor
|
|
198
|
+
const toolName = this.getActivePrimaryMouseButtonTool();
|
|
199
|
+
|
|
200
|
+
const runtimeSettings = Settings.getRuntimeSettings();
|
|
201
|
+
if (runtimeSettings.get('useCursors')) {
|
|
202
|
+
this.setViewportsCursorByToolName(toolName);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Removes viewport from the toolGroup. If only renderingEngineId is defined
|
|
208
|
+
* it removes all the viewports with the same renderingEngineId, if viewportId
|
|
209
|
+
* is also provided, it will remove that specific viewport from the ToolGroup.
|
|
210
|
+
*
|
|
211
|
+
* @param renderingEngineId - renderingEngine id
|
|
212
|
+
* @param viewportId - viewport id
|
|
213
|
+
*/
|
|
214
|
+
public removeViewports(renderingEngineId: string, viewportId?: string): void {
|
|
215
|
+
const indices = [];
|
|
216
|
+
|
|
217
|
+
this.viewportsInfo.forEach((vpInfo, index) => {
|
|
218
|
+
let match = false;
|
|
219
|
+
if (vpInfo.renderingEngineId === renderingEngineId) {
|
|
220
|
+
match = true;
|
|
221
|
+
|
|
222
|
+
if (viewportId && vpInfo.viewportId !== viewportId) {
|
|
223
|
+
match = false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (match) {
|
|
227
|
+
indices.push(index);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
if (indices.length) {
|
|
232
|
+
// Note: Traverse the array backwards, such that when we remove items we
|
|
233
|
+
// do not immediately mess up our loop indicies.
|
|
234
|
+
for (let i = indices.length - 1; i >= 0; i--) {
|
|
235
|
+
this.viewportsInfo.splice(indices[i], 1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public setActiveStrategy(toolName: string, strategyName: string) {
|
|
241
|
+
const toolInstance = this._toolInstances[toolName];
|
|
242
|
+
|
|
243
|
+
if (toolInstance === undefined) {
|
|
244
|
+
console.warn(
|
|
245
|
+
`Tool ${toolName} not added to toolGroup, can't set tool configuration.`
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
toolInstance.setActiveStrategy(strategyName);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
setToolMode(
|
|
255
|
+
toolName: string,
|
|
256
|
+
mode: ToolModes,
|
|
257
|
+
options = {} as SetToolBindingsType
|
|
258
|
+
): void {
|
|
259
|
+
if (!toolName) {
|
|
260
|
+
console.warn('setToolMode: toolName must be defined');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (mode === ToolModes.Active) {
|
|
265
|
+
this.setToolActive(toolName, options);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (mode === ToolModes.Passive) {
|
|
270
|
+
this.setToolPassive(toolName);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (mode === ToolModes.Enabled) {
|
|
275
|
+
this.setToolEnabled(toolName);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (mode === ToolModes.Disabled) {
|
|
280
|
+
this.setToolDisabled(toolName);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
console.warn('setToolMode: mode must be defined');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Set the tool mode on the toolGroup to be Active. This means the tool
|
|
289
|
+
* can be actively used by the defined bindings (e.g., Mouse primary click)
|
|
290
|
+
*
|
|
291
|
+
* - Can be actively used by mouse/touch events mapped to its `ToolBinding`s.
|
|
292
|
+
* - Can add data if an annotation tool.
|
|
293
|
+
* - Can be passively interacted by grabbing a tool or its handles.
|
|
294
|
+
* - Renders data if the tool has a `renderAnnotation` method.
|
|
295
|
+
*
|
|
296
|
+
* @param toolName - tool name
|
|
297
|
+
* @param toolBindingsOptions - tool bindings
|
|
298
|
+
*/
|
|
299
|
+
public setToolActive(
|
|
300
|
+
toolName: string,
|
|
301
|
+
toolBindingsOptions = {} as SetToolBindingsType
|
|
302
|
+
): void {
|
|
303
|
+
const toolInstance = this._toolInstances[toolName];
|
|
304
|
+
|
|
305
|
+
if (toolInstance === undefined) {
|
|
306
|
+
console.warn(
|
|
307
|
+
`Tool ${toolName} not added to toolGroup, can't set tool mode.`
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (!toolInstance) {
|
|
314
|
+
console.warn(
|
|
315
|
+
`'${toolName}' instance ${toolInstance} is not registered with this toolGroup, can't set tool mode.`
|
|
316
|
+
);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const prevBindings: IToolBinding[] = this.toolOptions[toolName]
|
|
321
|
+
? this.toolOptions[toolName].bindings
|
|
322
|
+
: [];
|
|
323
|
+
|
|
324
|
+
const newBindings = toolBindingsOptions.bindings
|
|
325
|
+
? toolBindingsOptions.bindings
|
|
326
|
+
: [];
|
|
327
|
+
|
|
328
|
+
// combine the new bindings with the previous bindings to avoid duplicates
|
|
329
|
+
// it allows duplicated mouse buttons as long as they don't have same
|
|
330
|
+
// modifier keys.
|
|
331
|
+
const bindingsToUse = [...prevBindings, ...newBindings].reduce(
|
|
332
|
+
(unique, binding) => {
|
|
333
|
+
const TouchBinding = binding.numTouchPoints !== undefined;
|
|
334
|
+
const MouseBinding = binding.mouseButton !== undefined;
|
|
335
|
+
|
|
336
|
+
if (
|
|
337
|
+
!unique.some((obj) => hasSameBinding(obj, binding)) &&
|
|
338
|
+
(TouchBinding || MouseBinding)
|
|
339
|
+
) {
|
|
340
|
+
unique.push(binding);
|
|
341
|
+
}
|
|
342
|
+
return unique;
|
|
343
|
+
},
|
|
344
|
+
[]
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// We should not override the bindings if they are already set
|
|
348
|
+
const toolOptions: ToolOptionsType = {
|
|
349
|
+
bindings: bindingsToUse,
|
|
350
|
+
mode: Active,
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
this.toolOptions[toolName] = toolOptions;
|
|
354
|
+
this._toolInstances[toolName].mode = Active;
|
|
355
|
+
|
|
356
|
+
// reset the mouse cursor if tool has left click binding
|
|
357
|
+
const runtimeSettings = Settings.getRuntimeSettings();
|
|
358
|
+
const useCursor = runtimeSettings.get('useCursors');
|
|
359
|
+
|
|
360
|
+
if (this._hasMousePrimaryButtonBinding(toolBindingsOptions) && useCursor) {
|
|
361
|
+
this.setViewportsCursorByToolName(toolName);
|
|
362
|
+
} else {
|
|
363
|
+
// reset to default cursor only if there is no other tool with primary binding
|
|
364
|
+
const activeToolIdentifier = this.getActivePrimaryMouseButtonTool();
|
|
365
|
+
if (!activeToolIdentifier && useCursor) {
|
|
366
|
+
const cursor = MouseCursor.getDefinedCursor('default');
|
|
367
|
+
this._setCursorForViewports(cursor);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (typeof toolInstance.onSetToolActive === 'function') {
|
|
372
|
+
toolInstance.onSetToolActive();
|
|
373
|
+
}
|
|
374
|
+
this._renderViewports();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Set the tool mode on the toolGroup to be Passive.
|
|
379
|
+
*
|
|
380
|
+
* - Can be passively interacted by grabbing a tool or its handles.
|
|
381
|
+
* - Renders data if the tool has a `renderAnnotation` method.
|
|
382
|
+
*
|
|
383
|
+
* @param toolName - tool name
|
|
384
|
+
*/
|
|
385
|
+
public setToolPassive(toolName: string): void {
|
|
386
|
+
const toolInstance = this._toolInstances[toolName];
|
|
387
|
+
|
|
388
|
+
if (toolInstance === undefined) {
|
|
389
|
+
console.warn(
|
|
390
|
+
`Tool ${toolName} not added to toolGroup, can't set tool mode.`
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// We should only remove the primary button bindings and keep
|
|
397
|
+
// the other ones (Zoom on right click)
|
|
398
|
+
const prevToolOptions = this.getToolOptions(toolName);
|
|
399
|
+
const toolOptions = Object.assign(
|
|
400
|
+
{
|
|
401
|
+
bindings: prevToolOptions ? prevToolOptions.bindings : [],
|
|
402
|
+
},
|
|
403
|
+
prevToolOptions,
|
|
404
|
+
{
|
|
405
|
+
mode: Passive,
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
// Remove the primary button bindings without modifiers, if they exist
|
|
410
|
+
toolOptions.bindings = toolOptions.bindings.filter(
|
|
411
|
+
(binding) =>
|
|
412
|
+
binding.mouseButton !== MouseBindings.Primary || binding.modifierKey
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// If there are other bindings, set the tool to be active
|
|
416
|
+
let mode = Passive;
|
|
417
|
+
if (toolOptions.bindings.length !== 0) {
|
|
418
|
+
mode = Active;
|
|
419
|
+
toolOptions.mode = mode;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
this.toolOptions[toolName] = toolOptions;
|
|
423
|
+
toolInstance.mode = mode;
|
|
424
|
+
|
|
425
|
+
if (typeof toolInstance.onSetToolPassive === 'function') {
|
|
426
|
+
toolInstance.onSetToolPassive();
|
|
427
|
+
}
|
|
428
|
+
this._renderViewports();
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Set the tool mode on the toolGroup to be Enabled.
|
|
433
|
+
*
|
|
434
|
+
* - Renders data if the tool has a `renderAnnotation` method..
|
|
435
|
+
*
|
|
436
|
+
* @param toolName - tool name
|
|
437
|
+
*/
|
|
438
|
+
public setToolEnabled(toolName: string): void {
|
|
439
|
+
const toolInstance = this._toolInstances[toolName];
|
|
440
|
+
|
|
441
|
+
if (toolInstance === undefined) {
|
|
442
|
+
console.warn(
|
|
443
|
+
`Tool ${toolName} not added to toolGroup, can't set tool mode.`
|
|
444
|
+
);
|
|
445
|
+
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const toolOptions = {
|
|
450
|
+
bindings: [],
|
|
451
|
+
mode: Enabled,
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
this.toolOptions[toolName] = toolOptions;
|
|
455
|
+
toolInstance.mode = Enabled;
|
|
456
|
+
|
|
457
|
+
if (typeof toolInstance.onSetToolEnabled === 'function') {
|
|
458
|
+
toolInstance.onSetToolEnabled();
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
this._renderViewports();
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Set the tool mode on the toolGroup to be Disabled.
|
|
466
|
+
*
|
|
467
|
+
* - Annotation does not render.
|
|
468
|
+
*
|
|
469
|
+
* @param toolName - tool name
|
|
470
|
+
*/
|
|
471
|
+
public setToolDisabled(toolName: string): void {
|
|
472
|
+
const toolInstance = this._toolInstances[toolName];
|
|
473
|
+
|
|
474
|
+
if (toolInstance === undefined) {
|
|
475
|
+
console.warn(
|
|
476
|
+
`Tool ${toolName} not added to toolGroup, can't set tool mode.`
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
const toolOptions = {
|
|
483
|
+
bindings: [],
|
|
484
|
+
mode: Disabled,
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
this.toolOptions[toolName] = toolOptions;
|
|
488
|
+
toolInstance.mode = Disabled;
|
|
489
|
+
|
|
490
|
+
if (typeof toolInstance.onSetToolDisabled === 'function') {
|
|
491
|
+
toolInstance.onSetToolDisabled();
|
|
492
|
+
}
|
|
493
|
+
this._renderViewports();
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Get the options for a given tool
|
|
498
|
+
* @param toolName - The name of the tool.
|
|
499
|
+
* @returns the tool options
|
|
500
|
+
*/
|
|
501
|
+
public getToolOptions(toolName: string): ToolOptionsType {
|
|
502
|
+
const toolOptionsForTool = this.toolOptions[toolName];
|
|
503
|
+
|
|
504
|
+
if (toolOptionsForTool === undefined) {
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
return toolOptionsForTool;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Find the name of the tool that is Active and has a primary button binding
|
|
513
|
+
* (Mouse primary click)
|
|
514
|
+
*
|
|
515
|
+
* @returns The name of the tool
|
|
516
|
+
*/
|
|
517
|
+
public getActivePrimaryMouseButtonTool(): string {
|
|
518
|
+
return Object.keys(this.toolOptions).find((toolName) => {
|
|
519
|
+
const toolOptions = this.toolOptions[toolName];
|
|
520
|
+
return (
|
|
521
|
+
toolOptions.mode === Active &&
|
|
522
|
+
this._hasMousePrimaryButtonBinding(toolOptions)
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
public setViewportsCursorByToolName(
|
|
528
|
+
toolName: string,
|
|
529
|
+
strategyName?: string
|
|
530
|
+
): void {
|
|
531
|
+
const cursor = this._getCursor(toolName, strategyName);
|
|
532
|
+
|
|
533
|
+
this._setCursorForViewports(cursor);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
private _getCursor(toolName: string, strategyName?: string): MouseCursor {
|
|
537
|
+
let cursorName;
|
|
538
|
+
let cursor;
|
|
539
|
+
|
|
540
|
+
if (strategyName) {
|
|
541
|
+
// Try combinations with strategyName first:
|
|
542
|
+
// Try with toolName and toolInstanceName first.
|
|
543
|
+
cursorName = `${toolName}.${strategyName}`;
|
|
544
|
+
|
|
545
|
+
cursor = SVGMouseCursor.getDefinedCursor(cursorName, true);
|
|
546
|
+
|
|
547
|
+
if (cursor) {
|
|
548
|
+
return cursor;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// Try with toolName and toolInstanceName first.
|
|
553
|
+
cursorName = `${toolName}`;
|
|
554
|
+
|
|
555
|
+
cursor = SVGMouseCursor.getDefinedCursor(cursorName, true);
|
|
556
|
+
|
|
557
|
+
if (cursor) {
|
|
558
|
+
return cursor;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Try with just toolName.
|
|
562
|
+
cursorName = toolName;
|
|
563
|
+
|
|
564
|
+
cursor = SVGMouseCursor.getDefinedCursor(cursorName, true);
|
|
565
|
+
|
|
566
|
+
if (cursor) {
|
|
567
|
+
return cursor;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
return MouseCursor.getDefinedCursor('default');
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
_setCursorForViewports(cursor: MouseCursor): void {
|
|
574
|
+
this.viewportsInfo.forEach(({ renderingEngineId, viewportId }) => {
|
|
575
|
+
const enabledElement = getEnabledElementByIds(
|
|
576
|
+
viewportId,
|
|
577
|
+
renderingEngineId
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
if (!enabledElement) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const { viewport } = enabledElement;
|
|
585
|
+
initElementCursor(viewport.element, cursor);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Set a configuration of a tool by the given toolName.
|
|
591
|
+
* Use overwrite as true in case you want to overwrite any existing configuration (be careful, depending on config change it might break the annotation flow).
|
|
592
|
+
*/
|
|
593
|
+
public setToolConfiguration(
|
|
594
|
+
toolName: string,
|
|
595
|
+
configuration: Record<any, any>,
|
|
596
|
+
overwrite?: boolean
|
|
597
|
+
): boolean {
|
|
598
|
+
if (this._toolInstances[toolName] === undefined) {
|
|
599
|
+
console.warn(
|
|
600
|
+
`Tool ${toolName} not present, can't set tool configuration.`
|
|
601
|
+
);
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
let _configuration;
|
|
606
|
+
|
|
607
|
+
if (overwrite) {
|
|
608
|
+
_configuration = configuration;
|
|
609
|
+
} else {
|
|
610
|
+
_configuration = csUtils.deepMerge(
|
|
611
|
+
this._toolInstances[toolName].configuration,
|
|
612
|
+
configuration
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
this._toolInstances[toolName].configuration = _configuration;
|
|
617
|
+
|
|
618
|
+
this._renderViewports();
|
|
619
|
+
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Get the configuration of tool. It returns only the config for the given path (in case exists).
|
|
625
|
+
* ConfigurationPath is the the path of the property to get separated by '.'.
|
|
626
|
+
*
|
|
627
|
+
* @example
|
|
628
|
+
* getToolConfiguration('LengthTool', 'firstLevel.secondLevel')
|
|
629
|
+
* // get from LengthTool instance the configuration value as being LengthToolInstance[configuration][firstLevel][secondLevel]
|
|
630
|
+
*/
|
|
631
|
+
getToolConfiguration(toolName: string, configurationPath: string): any {
|
|
632
|
+
if (this._toolInstances[toolName] === undefined) {
|
|
633
|
+
console.warn(
|
|
634
|
+
`Tool ${toolName} not present, can't set tool configuration.`
|
|
635
|
+
);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const _configuration = get(
|
|
640
|
+
this._toolInstances[toolName].configuration,
|
|
641
|
+
configurationPath
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
return cloneDeep(_configuration);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Check if the tool binding is set to be primary mouse button.
|
|
649
|
+
* @param toolOptions - The options for the tool mode.
|
|
650
|
+
* @returns A boolean value.
|
|
651
|
+
*/
|
|
652
|
+
private _hasMousePrimaryButtonBinding(toolOptions) {
|
|
653
|
+
return toolOptions?.bindings?.some(
|
|
654
|
+
(binding) =>
|
|
655
|
+
binding.mouseButton === MouseBindings.Primary &&
|
|
656
|
+
binding.modifierKey === undefined
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* It re-renders the viewports in the toolGroup
|
|
662
|
+
*/
|
|
663
|
+
private _renderViewports(): void {
|
|
664
|
+
this.viewportsInfo.forEach(({ renderingEngineId, viewportId }) => {
|
|
665
|
+
getRenderingEngine(renderingEngineId).renderViewport(viewportId);
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function hasSameBinding(
|
|
671
|
+
binding1: IToolBinding,
|
|
672
|
+
binding2: IToolBinding
|
|
673
|
+
): boolean {
|
|
674
|
+
if (binding1.mouseButton !== binding2.mouseButton) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return binding1.modifierKey === binding2.modifierKey;
|
|
679
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { state } from '../index';
|
|
2
|
+
import ToolGroup from './ToolGroup';
|
|
3
|
+
import { IToolGroup } from '../../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a new tool group with the given name. ToolGroups are the new way
|
|
7
|
+
* in Cornerstone3DTools to share tool configuration, state (enabled, disabled, etc.)
|
|
8
|
+
* across a set of viewports.
|
|
9
|
+
*
|
|
10
|
+
* @param toolGroupId - The unique ID of the tool group.
|
|
11
|
+
* @returns A reference to the tool group that was created.
|
|
12
|
+
*/
|
|
13
|
+
function createToolGroup(toolGroupId: string): IToolGroup | undefined {
|
|
14
|
+
// Exit early if ID conflict
|
|
15
|
+
const toolGroupWithIdExists = state.toolGroups.some(
|
|
16
|
+
(tg) => tg.id === toolGroupId
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (toolGroupWithIdExists) {
|
|
20
|
+
console.warn(`'${toolGroupId}' already exists.`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const toolGroup = new ToolGroup(toolGroupId);
|
|
25
|
+
|
|
26
|
+
// Update state
|
|
27
|
+
state.toolGroups.push(toolGroup);
|
|
28
|
+
|
|
29
|
+
// Return reference
|
|
30
|
+
return toolGroup;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default createToolGroup;
|