@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,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
triggerEvent,
|
|
3
|
+
eventTarget,
|
|
4
|
+
getRenderingEngine,
|
|
5
|
+
Enums,
|
|
6
|
+
Types,
|
|
7
|
+
} from '@cornerstonejs/core';
|
|
8
|
+
import { Events as csToolsEvents } from '../../enums';
|
|
9
|
+
import {
|
|
10
|
+
getToolGroup,
|
|
11
|
+
getToolGroupForViewport,
|
|
12
|
+
} from '../../store/ToolGroupManager';
|
|
13
|
+
|
|
14
|
+
import SegmentationDisplayTool from '../../tools/displayTools/SegmentationDisplayTool';
|
|
15
|
+
import { SegmentationRenderedEventDetail } from '../../types/EventTypes';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* SegmentationRenderingEngine is a class that is responsible for rendering
|
|
19
|
+
* segmentations for a toolGroup. It will call SegmentationDisplayTool to render the segmentation
|
|
20
|
+
* based on the segmentation data and their configurations. Note: This is a Singleton class
|
|
21
|
+
* and should not be instantiated directly. To trigger a render for all the
|
|
22
|
+
* segmentations of a tool group you can use.
|
|
23
|
+
*
|
|
24
|
+
* ```
|
|
25
|
+
* triggerSegmentationRender(toolGroupId)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class SegmentationRenderingEngine {
|
|
29
|
+
private _needsRender: Set<string> = new Set();
|
|
30
|
+
private _animationFrameSet = false;
|
|
31
|
+
private _animationFrameHandle: number | null = null;
|
|
32
|
+
public hasBeenDestroyed: boolean;
|
|
33
|
+
|
|
34
|
+
public removeToolGroup(toolGroupId) {
|
|
35
|
+
this._needsRender.delete(toolGroupId);
|
|
36
|
+
|
|
37
|
+
if (this._needsRender.size === 0) {
|
|
38
|
+
this._reset();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public renderToolGroupSegmentations(toolGroupId): void {
|
|
43
|
+
this._setToolGroupSegmentationToBeRenderedNextFrame([toolGroupId]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* _throwIfDestroyed Throws an error if trying to interact with the `RenderingEngine`
|
|
48
|
+
* instance after its `destroy` method has been called.
|
|
49
|
+
*/
|
|
50
|
+
private _throwIfDestroyed() {
|
|
51
|
+
if (this.hasBeenDestroyed) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
'this.destroy() has been manually called to free up memory, can not longer use this instance. Instead make a new one.'
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private _setToolGroupSegmentationToBeRenderedNextFrame(
|
|
59
|
+
toolGroupIds: string[]
|
|
60
|
+
) {
|
|
61
|
+
// Add the viewports to the set of flagged viewports
|
|
62
|
+
toolGroupIds.forEach((toolGroupId) => {
|
|
63
|
+
this._needsRender.add(toolGroupId);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Render any flagged viewports
|
|
67
|
+
this._render();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* _render Sets up animation frame if necessary
|
|
72
|
+
*/
|
|
73
|
+
private _render() {
|
|
74
|
+
// If we have viewports that need rendering and we have not already
|
|
75
|
+
// set the RAF callback to run on the next frame.
|
|
76
|
+
if (this._needsRender.size > 0 && this._animationFrameSet === false) {
|
|
77
|
+
this._animationFrameHandle = window.requestAnimationFrame(
|
|
78
|
+
this._renderFlaggedToolGroups
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Set the flag that we have already set up the next RAF call.
|
|
82
|
+
this._animationFrameSet = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private _renderFlaggedToolGroups = () => {
|
|
87
|
+
this._throwIfDestroyed();
|
|
88
|
+
|
|
89
|
+
// for each toolGroupId insides the _needsRender set, render the segmentation
|
|
90
|
+
const toolGroupIds = Array.from(this._needsRender.values());
|
|
91
|
+
|
|
92
|
+
for (const toolGroupId of toolGroupIds) {
|
|
93
|
+
this._triggerRender(toolGroupId);
|
|
94
|
+
|
|
95
|
+
// This viewport has been rendered, we can remove it from the set
|
|
96
|
+
this._needsRender.delete(toolGroupId);
|
|
97
|
+
|
|
98
|
+
// If there is nothing left that is flagged for rendering, stop here
|
|
99
|
+
// and allow RAF to be called again
|
|
100
|
+
if (this._needsRender.size === 0) {
|
|
101
|
+
this._animationFrameSet = false;
|
|
102
|
+
this._animationFrameHandle = null;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
_triggerRender(toolGroupId) {
|
|
108
|
+
const toolGroup = getToolGroup(toolGroupId);
|
|
109
|
+
|
|
110
|
+
if (!toolGroup) {
|
|
111
|
+
console.warn(`No tool group found with toolGroupId: ${toolGroupId}`);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const { viewportsInfo } = toolGroup;
|
|
116
|
+
const viewports = [];
|
|
117
|
+
|
|
118
|
+
viewportsInfo.forEach(({ viewportId, renderingEngineId }) => {
|
|
119
|
+
const renderingEngine = getRenderingEngine(renderingEngineId);
|
|
120
|
+
|
|
121
|
+
if (!renderingEngine) {
|
|
122
|
+
console.warn('rendering Engine has been destroyed');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
viewports.push(renderingEngine.getViewport(viewportId));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const segmentationDisplayToolInstance = toolGroup.getToolInstance(
|
|
130
|
+
SegmentationDisplayTool.toolName
|
|
131
|
+
) as SegmentationDisplayTool;
|
|
132
|
+
if (!segmentationDisplayToolInstance) {
|
|
133
|
+
console.warn('No segmentation tool found inside', toolGroupId);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function onSegmentationRender(evt: Types.EventTypes.ImageRenderedEvent) {
|
|
138
|
+
const { element, viewportId, renderingEngineId } = evt.detail;
|
|
139
|
+
|
|
140
|
+
element.removeEventListener(
|
|
141
|
+
Enums.Events.IMAGE_RENDERED,
|
|
142
|
+
onSegmentationRender as EventListener
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const toolGroup = getToolGroupForViewport(viewportId, renderingEngineId);
|
|
146
|
+
|
|
147
|
+
if (!toolGroup) {
|
|
148
|
+
console.warn('toolGroup has been destroyed');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const eventDetail: SegmentationRenderedEventDetail = {
|
|
153
|
+
toolGroupId: toolGroup.id,
|
|
154
|
+
viewportId,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
triggerEvent(eventTarget, csToolsEvents.SEGMENTATION_RENDERED, {
|
|
158
|
+
...eventDetail,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Todo: for other representations we probably need the drawSVG, but right now we are not using it
|
|
163
|
+
// drawSvg(element, (svgDrawingHelper) => {
|
|
164
|
+
// const handleDrawSvg = (tool) => {
|
|
165
|
+
// if (tool instanceof SegmentationDisplayTool && tool.renderAnnotation) {
|
|
166
|
+
// tool.renderAnnotation({ detail: eventDetail })
|
|
167
|
+
// triggerEvent(element, csToolsEvents.SEGMENTATION_RENDERED, { ...eventDetail })
|
|
168
|
+
// }
|
|
169
|
+
// }
|
|
170
|
+
// enabledTools.forEach(handleDrawSvg)
|
|
171
|
+
// })
|
|
172
|
+
|
|
173
|
+
viewports.forEach(({ element }) => {
|
|
174
|
+
element.addEventListener(
|
|
175
|
+
Enums.Events.IMAGE_RENDERED,
|
|
176
|
+
onSegmentationRender
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
segmentationDisplayToolInstance.renderSegmentation(toolGroupId);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* _reset Resets the `RenderingEngine`
|
|
185
|
+
*/
|
|
186
|
+
private _reset() {
|
|
187
|
+
window.cancelAnimationFrame(this._animationFrameHandle);
|
|
188
|
+
|
|
189
|
+
this._needsRender.clear();
|
|
190
|
+
this._animationFrameSet = false;
|
|
191
|
+
this._animationFrameHandle = null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const segmentationRenderingEngine = new SegmentationRenderingEngine();
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* It triggers a render for all the segmentations of the tool group with the given Id.
|
|
199
|
+
* @param toolGroupId - The Id of the tool group to render.
|
|
200
|
+
*/
|
|
201
|
+
function triggerSegmentationRender(toolGroupId: string): void {
|
|
202
|
+
segmentationRenderingEngine.renderToolGroupSegmentations(toolGroupId);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { segmentationRenderingEngine, triggerSegmentationRender };
|
|
206
|
+
export default triggerSegmentationRender;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Types } from '@cornerstonejs/core';
|
|
2
|
+
import { utilities as csUtils } from '@cornerstonejs/core';
|
|
3
|
+
import { getToolGroup } from '../../store/ToolGroupManager';
|
|
4
|
+
import BrushTool from '../../tools/segmentation/BrushTool';
|
|
5
|
+
import getBoundingBoxAroundShape from '../boundingBox/getBoundingBoxAroundShape';
|
|
6
|
+
|
|
7
|
+
export type ThresholdInformation = {
|
|
8
|
+
volume: Types.IImageVolume;
|
|
9
|
+
lower: number;
|
|
10
|
+
upper: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default function getBrushToolInstances(toolGroupId) {
|
|
14
|
+
const toolGroup = getToolGroup(toolGroupId);
|
|
15
|
+
|
|
16
|
+
if (toolGroup === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const toolInstances = toolGroup._toolInstances;
|
|
21
|
+
|
|
22
|
+
if (!Object.keys(toolInstances).length) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// For each tool that has BrushTool as base class, set the brush size.
|
|
27
|
+
const brushBasedToolInstances = Object.values(toolInstances).filter(
|
|
28
|
+
(toolInstance) => toolInstance instanceof BrushTool
|
|
29
|
+
) as BrushTool[];
|
|
30
|
+
|
|
31
|
+
return brushBasedToolInstances;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const equalsCheck = (a, b) => {
|
|
35
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Given the center of a voxel in world coordinates, calculate the voxel
|
|
40
|
+
* corners in world coords to calculate the voxel overlap in another volume
|
|
41
|
+
*/
|
|
42
|
+
export function getVoxelOverlap(
|
|
43
|
+
imageData,
|
|
44
|
+
dimensions,
|
|
45
|
+
voxelSpacing,
|
|
46
|
+
voxelCenter
|
|
47
|
+
) {
|
|
48
|
+
const voxelCornersWorld = [];
|
|
49
|
+
for (let i = 0; i < 2; i++) {
|
|
50
|
+
for (let j = 0; j < 2; j++) {
|
|
51
|
+
for (let k = 0; k < 2; k++) {
|
|
52
|
+
const point = voxelCenter;
|
|
53
|
+
point[0] = point[0] + ((i * 2 - 1) * voxelSpacing[0]) / 2;
|
|
54
|
+
point[1] = point[1] + ((j * 2 - 1) * voxelSpacing[1]) / 2;
|
|
55
|
+
point[2] = point[2] + ((k * 2 - 1) * voxelSpacing[2]) / 2;
|
|
56
|
+
voxelCornersWorld.push(point);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const voxelCornersIJK = voxelCornersWorld.map(
|
|
61
|
+
(world) => csUtils.transformWorldToIndex(imageData, world) as Types.Point3
|
|
62
|
+
);
|
|
63
|
+
const overlapBounds = getBoundingBoxAroundShape(voxelCornersIJK, dimensions);
|
|
64
|
+
|
|
65
|
+
return overlapBounds;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Prepare a list of volume information objects for callback functions
|
|
70
|
+
*/
|
|
71
|
+
export function processVolumes(
|
|
72
|
+
segmentationVolume: Types.IImageVolume,
|
|
73
|
+
thresholdVolumeInformation: ThresholdInformation[]
|
|
74
|
+
) {
|
|
75
|
+
const { spacing: segmentationSpacing, imageData: segmentationImageData } =
|
|
76
|
+
segmentationVolume;
|
|
77
|
+
const scalarData = segmentationVolume.getScalarData();
|
|
78
|
+
|
|
79
|
+
// prepare a list of volume information objects for callback functions
|
|
80
|
+
const volumeInfoList = [];
|
|
81
|
+
let baseVolumeIdx = 0;
|
|
82
|
+
for (let i = 0; i < thresholdVolumeInformation.length; i++) {
|
|
83
|
+
const { imageData, spacing, dimensions } =
|
|
84
|
+
thresholdVolumeInformation[i].volume;
|
|
85
|
+
|
|
86
|
+
const volumeSize =
|
|
87
|
+
thresholdVolumeInformation[i].volume.getScalarData().length;
|
|
88
|
+
// discover the index of the volume the segmentation data is based on
|
|
89
|
+
if (
|
|
90
|
+
volumeSize === scalarData.length &&
|
|
91
|
+
equalsCheck(spacing, segmentationSpacing)
|
|
92
|
+
) {
|
|
93
|
+
baseVolumeIdx = i;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// prepare information used in callback functions
|
|
97
|
+
const referenceValues = imageData.getPointData().getScalars().getData();
|
|
98
|
+
const lower = thresholdVolumeInformation[i].lower;
|
|
99
|
+
const upper = thresholdVolumeInformation[i].upper;
|
|
100
|
+
|
|
101
|
+
volumeInfoList.push({
|
|
102
|
+
imageData,
|
|
103
|
+
referenceValues,
|
|
104
|
+
lower,
|
|
105
|
+
upper,
|
|
106
|
+
spacing,
|
|
107
|
+
dimensions,
|
|
108
|
+
volumeSize,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
volumeInfoList,
|
|
114
|
+
baseVolumeIdx,
|
|
115
|
+
};
|
|
116
|
+
}
|