@cornerstonejs/tools 0.56.2 → 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/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,407 @@
|
|
|
1
|
+
import type { Types } from '@cornerstonejs/core';
|
|
2
|
+
import {
|
|
3
|
+
drawHandles as drawHandlesSvg,
|
|
4
|
+
drawPolyline as drawPolylineSvg,
|
|
5
|
+
} from '../../../drawingSvg';
|
|
6
|
+
import { polyline } from '../../../utilities/math';
|
|
7
|
+
import { findOpenUShapedContourVectorToPeakOnRender } from './findOpenUShapedContourVectorToPeak';
|
|
8
|
+
import { PlanarFreehandROIAnnotation } from '../../../types/ToolSpecificAnnotationTypes';
|
|
9
|
+
import { StyleSpecifier } from '../../../types/AnnotationStyle';
|
|
10
|
+
import { SVGDrawingHelper } from '../../../types';
|
|
11
|
+
|
|
12
|
+
const { pointsAreWithinCloseContourProximity } = polyline;
|
|
13
|
+
|
|
14
|
+
type PlanarFreehandROIRenderOptions = {
|
|
15
|
+
color?: string;
|
|
16
|
+
width?: number;
|
|
17
|
+
connectFirstToLast?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function _getRenderingOptions(
|
|
21
|
+
enabledElement: Types.IEnabledElement,
|
|
22
|
+
annotation: PlanarFreehandROIAnnotation
|
|
23
|
+
): PlanarFreehandROIRenderOptions {
|
|
24
|
+
const styleSpecifier: StyleSpecifier = {
|
|
25
|
+
toolGroupId: this.toolGroupId,
|
|
26
|
+
toolName: this.getToolName(),
|
|
27
|
+
viewportId: enabledElement.viewport.id,
|
|
28
|
+
annotationUID: annotation.annotationUID,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
|
|
32
|
+
const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
|
|
33
|
+
const color = this.getStyle('color', styleSpecifier, annotation);
|
|
34
|
+
|
|
35
|
+
const isOpenContour = annotation.data.isOpenContour;
|
|
36
|
+
|
|
37
|
+
const options = {
|
|
38
|
+
color: color === undefined ? undefined : <string>color,
|
|
39
|
+
width: lineWidth === undefined ? undefined : <number>lineWidth,
|
|
40
|
+
lineDash: lineDash === undefined ? undefined : <number[]>lineDash,
|
|
41
|
+
connectLastToFirst: !isOpenContour,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return options;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Renders a `PlanarFreehandROIAnnotation` that is not currently being drawn or edited.
|
|
49
|
+
*/
|
|
50
|
+
function renderContour(
|
|
51
|
+
enabledElement: Types.IEnabledElement,
|
|
52
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
53
|
+
annotation: PlanarFreehandROIAnnotation
|
|
54
|
+
): void {
|
|
55
|
+
// prevent drawing or further calculation in case viewport data is not ready yet
|
|
56
|
+
if (!enabledElement?.viewport?.getImageData()) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Check if the contour is an open contour
|
|
60
|
+
if (annotation.data.isOpenContour) {
|
|
61
|
+
// If its an open contour, check i its a U-shaped contour
|
|
62
|
+
if (annotation.data.isOpenUShapeContour) {
|
|
63
|
+
calculateUShapeContourVectorToPeakIfNotPresent(
|
|
64
|
+
enabledElement,
|
|
65
|
+
annotation
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
this.renderOpenUShapedContour(
|
|
69
|
+
enabledElement,
|
|
70
|
+
svgDrawingHelper,
|
|
71
|
+
annotation
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
// If not a U-shaped contour, render standard open contour.
|
|
75
|
+
this.renderOpenContour(enabledElement, svgDrawingHelper, annotation);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
this.renderClosedContour(enabledElement, svgDrawingHelper, annotation);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* If the open U-shaped contour does not have a peak.
|
|
84
|
+
*/
|
|
85
|
+
function calculateUShapeContourVectorToPeakIfNotPresent(
|
|
86
|
+
enabledElement: Types.IEnabledElement,
|
|
87
|
+
annotation: PlanarFreehandROIAnnotation
|
|
88
|
+
): void {
|
|
89
|
+
if (!annotation.data.openUShapeContourVectorToPeak) {
|
|
90
|
+
// Annotation just been set to be an open U-shaped contour.
|
|
91
|
+
// calculate its peak vector here.
|
|
92
|
+
annotation.data.openUShapeContourVectorToPeak =
|
|
93
|
+
findOpenUShapedContourVectorToPeakOnRender(enabledElement, annotation);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Renders an closed `PlanarFreehandROIAnnotation` annotation.
|
|
99
|
+
*/
|
|
100
|
+
function renderClosedContour(
|
|
101
|
+
enabledElement: Types.IEnabledElement,
|
|
102
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
103
|
+
annotation: PlanarFreehandROIAnnotation
|
|
104
|
+
): void {
|
|
105
|
+
const { viewport } = enabledElement;
|
|
106
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
107
|
+
|
|
108
|
+
// Its unfortunate that we have to do this for each annotation,
|
|
109
|
+
// Even if its unchanged. In the future we could cache the canvas points per
|
|
110
|
+
// element on the tool? That feels very weird also as we'd need to manage
|
|
111
|
+
// it/clean them up. Its a pre-optimisation for now and we can tackle it if it
|
|
112
|
+
// becomes a problem.
|
|
113
|
+
const canvasPoints = annotation.data.polyline.map((worldPos) =>
|
|
114
|
+
viewport.worldToCanvas(worldPos)
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const polylineUID = '1';
|
|
118
|
+
|
|
119
|
+
drawPolylineSvg(
|
|
120
|
+
svgDrawingHelper,
|
|
121
|
+
annotation.annotationUID,
|
|
122
|
+
polylineUID,
|
|
123
|
+
canvasPoints,
|
|
124
|
+
options
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Renders an open `PlanarFreehandROIAnnotation` annotation.
|
|
130
|
+
*/
|
|
131
|
+
function renderOpenContour(
|
|
132
|
+
enabledElement: Types.IEnabledElement,
|
|
133
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
134
|
+
annotation: PlanarFreehandROIAnnotation
|
|
135
|
+
): void {
|
|
136
|
+
const { viewport } = enabledElement;
|
|
137
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
138
|
+
|
|
139
|
+
const canvasPoints = annotation.data.polyline.map((worldPos) =>
|
|
140
|
+
viewport.worldToCanvas(worldPos)
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const polylineUID = '1';
|
|
144
|
+
|
|
145
|
+
drawPolylineSvg(
|
|
146
|
+
svgDrawingHelper,
|
|
147
|
+
annotation.annotationUID,
|
|
148
|
+
polylineUID,
|
|
149
|
+
canvasPoints,
|
|
150
|
+
options
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const activeHandleIndex = annotation.data.handles.activeHandleIndex;
|
|
154
|
+
|
|
155
|
+
if (this.configuration.alwaysRenderOpenContourHandles?.enabled === true) {
|
|
156
|
+
const radius = this.configuration.alwaysRenderOpenContourHandles.radius;
|
|
157
|
+
|
|
158
|
+
// Draw highlighted points
|
|
159
|
+
const handleGroupUID = '0';
|
|
160
|
+
|
|
161
|
+
// We already mapped all the points, so don't do the mapping again.
|
|
162
|
+
// The activeHandleIndex can only be one of two points.
|
|
163
|
+
const handlePoints = [
|
|
164
|
+
canvasPoints[0],
|
|
165
|
+
canvasPoints[canvasPoints.length - 1],
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
// Don't render a hovered handle, as this will be rendered larger in
|
|
169
|
+
// the next block.
|
|
170
|
+
if (activeHandleIndex === 0) {
|
|
171
|
+
handlePoints.shift();
|
|
172
|
+
} else if (activeHandleIndex === 1) {
|
|
173
|
+
handlePoints.pop();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
drawHandlesSvg(
|
|
177
|
+
svgDrawingHelper,
|
|
178
|
+
annotation.annotationUID,
|
|
179
|
+
handleGroupUID,
|
|
180
|
+
handlePoints,
|
|
181
|
+
{
|
|
182
|
+
color: options.color,
|
|
183
|
+
handleRadius: radius,
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (activeHandleIndex !== null) {
|
|
189
|
+
// Draw highlighted points
|
|
190
|
+
const handleGroupUID = '1';
|
|
191
|
+
|
|
192
|
+
// We already mapped all the points, so don't do the mapping again.
|
|
193
|
+
// The activeHandleIndex can only be one of two points.
|
|
194
|
+
const indexOfCanvasPoints =
|
|
195
|
+
activeHandleIndex === 0 ? 0 : canvasPoints.length - 1;
|
|
196
|
+
|
|
197
|
+
const handlePoint = canvasPoints[indexOfCanvasPoints];
|
|
198
|
+
|
|
199
|
+
drawHandlesSvg(
|
|
200
|
+
svgDrawingHelper,
|
|
201
|
+
annotation.annotationUID,
|
|
202
|
+
handleGroupUID,
|
|
203
|
+
[handlePoint],
|
|
204
|
+
{ color: options.color }
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function renderOpenUShapedContour(
|
|
210
|
+
enabledElement: Types.IEnabledElement,
|
|
211
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
212
|
+
annotation: PlanarFreehandROIAnnotation
|
|
213
|
+
): void {
|
|
214
|
+
const { viewport } = enabledElement;
|
|
215
|
+
const { polyline, openUShapeContourVectorToPeak } = annotation.data;
|
|
216
|
+
|
|
217
|
+
this.renderOpenContour(enabledElement, svgDrawingHelper, annotation);
|
|
218
|
+
|
|
219
|
+
// prevent rendering u shape in case openUShapeContourVectorToPeak is not set yet
|
|
220
|
+
if (!openUShapeContourVectorToPeak) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const firstCanvasPoint = viewport.worldToCanvas(polyline[0]);
|
|
225
|
+
const lastCanvasPoint = viewport.worldToCanvas(polyline[polyline.length - 1]);
|
|
226
|
+
|
|
227
|
+
const openUShapeContourVectorToPeakCanvas = [
|
|
228
|
+
viewport.worldToCanvas(openUShapeContourVectorToPeak[0]),
|
|
229
|
+
viewport.worldToCanvas(openUShapeContourVectorToPeak[1]),
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
233
|
+
|
|
234
|
+
// Join first and last points
|
|
235
|
+
drawPolylineSvg(
|
|
236
|
+
svgDrawingHelper,
|
|
237
|
+
annotation.annotationUID,
|
|
238
|
+
'first-to-last',
|
|
239
|
+
[firstCanvasPoint, lastCanvasPoint],
|
|
240
|
+
{
|
|
241
|
+
color: options.color,
|
|
242
|
+
width: options.width,
|
|
243
|
+
connectLastToFirst: false,
|
|
244
|
+
lineDash: '2,2',
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
// Render midpoint to open contour surface line
|
|
249
|
+
drawPolylineSvg(
|
|
250
|
+
svgDrawingHelper,
|
|
251
|
+
annotation.annotationUID,
|
|
252
|
+
'midpoint-to-open-contour',
|
|
253
|
+
[
|
|
254
|
+
openUShapeContourVectorToPeakCanvas[0],
|
|
255
|
+
openUShapeContourVectorToPeakCanvas[1],
|
|
256
|
+
],
|
|
257
|
+
{
|
|
258
|
+
color: options.color,
|
|
259
|
+
width: options.width,
|
|
260
|
+
connectLastToFirst: false,
|
|
261
|
+
lineDash: '2,2',
|
|
262
|
+
}
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Renders a new `PlanarFreehandROIAnnotation` annotation during
|
|
268
|
+
* creation/drawing.
|
|
269
|
+
*/
|
|
270
|
+
function renderContourBeingDrawn(
|
|
271
|
+
enabledElement: Types.IEnabledElement,
|
|
272
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
273
|
+
annotation: PlanarFreehandROIAnnotation
|
|
274
|
+
): void {
|
|
275
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
276
|
+
|
|
277
|
+
const { allowOpenContours } = this.configuration;
|
|
278
|
+
const { canvasPoints } = this.drawData;
|
|
279
|
+
|
|
280
|
+
// Override rendering whilst drawing the contour, we don't know if its open
|
|
281
|
+
// or closed yet
|
|
282
|
+
options.connectLastToFirst = false;
|
|
283
|
+
|
|
284
|
+
drawPolylineSvg(
|
|
285
|
+
svgDrawingHelper,
|
|
286
|
+
annotation.annotationUID,
|
|
287
|
+
'1',
|
|
288
|
+
canvasPoints,
|
|
289
|
+
options
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
if (allowOpenContours) {
|
|
293
|
+
const firstPoint = canvasPoints[0];
|
|
294
|
+
const lastPoint = canvasPoints[canvasPoints.length - 1];
|
|
295
|
+
|
|
296
|
+
// Check if start and end are within close proximity
|
|
297
|
+
if (
|
|
298
|
+
pointsAreWithinCloseContourProximity(
|
|
299
|
+
firstPoint,
|
|
300
|
+
lastPoint,
|
|
301
|
+
this.configuration.closeContourProximity
|
|
302
|
+
)
|
|
303
|
+
) {
|
|
304
|
+
// Preview join last points
|
|
305
|
+
drawPolylineSvg(
|
|
306
|
+
svgDrawingHelper,
|
|
307
|
+
annotation.annotationUID,
|
|
308
|
+
'2',
|
|
309
|
+
[lastPoint, firstPoint],
|
|
310
|
+
options
|
|
311
|
+
);
|
|
312
|
+
} else {
|
|
313
|
+
// Draw start point
|
|
314
|
+
const handleGroupUID = '0';
|
|
315
|
+
|
|
316
|
+
drawHandlesSvg(
|
|
317
|
+
svgDrawingHelper,
|
|
318
|
+
annotation.annotationUID,
|
|
319
|
+
handleGroupUID,
|
|
320
|
+
[firstPoint],
|
|
321
|
+
{ color: options.color, handleRadius: 2 }
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Renders a closed `PlanarFreehandROIAnnotation` being edited.
|
|
329
|
+
*/
|
|
330
|
+
function renderClosedContourBeingEdited(
|
|
331
|
+
enabledElement,
|
|
332
|
+
svgDrawingHelper,
|
|
333
|
+
annotation
|
|
334
|
+
): void {
|
|
335
|
+
const { fusedCanvasPoints } = this.editData;
|
|
336
|
+
|
|
337
|
+
if (fusedCanvasPoints === undefined) {
|
|
338
|
+
// No edit to render yet, render closed contour.
|
|
339
|
+
this.renderClosedContour(enabledElement, svgDrawingHelper, annotation);
|
|
340
|
+
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
345
|
+
|
|
346
|
+
const polylineUIDToRender = 'preview-1';
|
|
347
|
+
|
|
348
|
+
drawPolylineSvg(
|
|
349
|
+
svgDrawingHelper,
|
|
350
|
+
annotation.annotationUID,
|
|
351
|
+
polylineUIDToRender,
|
|
352
|
+
fusedCanvasPoints,
|
|
353
|
+
options
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Renders an open `PlanarFreehandROIAnnotation` being edited.
|
|
359
|
+
*/
|
|
360
|
+
function renderOpenContourBeingEdited(
|
|
361
|
+
enabledElement: Types.IEnabledElement,
|
|
362
|
+
svgDrawingHelper: SVGDrawingHelper,
|
|
363
|
+
annotation: PlanarFreehandROIAnnotation
|
|
364
|
+
): void {
|
|
365
|
+
const { fusedCanvasPoints } = this.editData;
|
|
366
|
+
|
|
367
|
+
if (fusedCanvasPoints === undefined) {
|
|
368
|
+
// No edit to render yet, render closed contour.
|
|
369
|
+
this.renderOpenContour(enabledElement, svgDrawingHelper, annotation);
|
|
370
|
+
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const options = this._getRenderingOptions(enabledElement, annotation);
|
|
375
|
+
|
|
376
|
+
const polylineUIDToRender = 'preview-1';
|
|
377
|
+
|
|
378
|
+
drawPolylineSvg(
|
|
379
|
+
svgDrawingHelper,
|
|
380
|
+
annotation.annotationUID,
|
|
381
|
+
polylineUIDToRender,
|
|
382
|
+
fusedCanvasPoints,
|
|
383
|
+
options
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Registers the render methods of various contour states to the tool instance.
|
|
389
|
+
*/
|
|
390
|
+
function registerRenderMethods(toolInstance) {
|
|
391
|
+
toolInstance.renderContour = renderContour.bind(toolInstance);
|
|
392
|
+
toolInstance.renderClosedContour = renderClosedContour.bind(toolInstance);
|
|
393
|
+
toolInstance.renderOpenContour = renderOpenContour.bind(toolInstance);
|
|
394
|
+
toolInstance.renderOpenUShapedContour =
|
|
395
|
+
renderOpenUShapedContour.bind(toolInstance);
|
|
396
|
+
|
|
397
|
+
toolInstance.renderContourBeingDrawn =
|
|
398
|
+
renderContourBeingDrawn.bind(toolInstance);
|
|
399
|
+
|
|
400
|
+
toolInstance.renderClosedContourBeingEdited =
|
|
401
|
+
renderClosedContourBeingEdited.bind(toolInstance);
|
|
402
|
+
toolInstance.renderOpenContourBeingEdited =
|
|
403
|
+
renderOpenContourBeingEdited.bind(toolInstance);
|
|
404
|
+
toolInstance._getRenderingOptions = _getRenderingOptions.bind(toolInstance);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export default registerRenderMethods;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
utilities,
|
|
3
|
+
getEnabledElement,
|
|
4
|
+
VolumeViewport,
|
|
5
|
+
StackViewport,
|
|
6
|
+
cache,
|
|
7
|
+
} from '@cornerstonejs/core';
|
|
8
|
+
import type { Types } from '@cornerstonejs/core';
|
|
9
|
+
|
|
10
|
+
import { vec4 } from 'gl-matrix';
|
|
11
|
+
|
|
12
|
+
import BaseTool from './BaseTool';
|
|
13
|
+
import { getAnnotationManager } from '../../stateManagement/annotation/annotationState';
|
|
14
|
+
import { Annotation, Annotations, SVGDrawingHelper } from '../../types';
|
|
15
|
+
import triggerAnnotationRender from '../../utilities/triggerAnnotationRender';
|
|
16
|
+
import filterAnnotationsForDisplay from '../../utilities/planar/filterAnnotationsForDisplay';
|
|
17
|
+
import { getStyleProperty } from '../../stateManagement/annotation/config/helpers';
|
|
18
|
+
import { getState } from '../../stateManagement/annotation/config';
|
|
19
|
+
import { StyleSpecifier } from '../../types/AnnotationStyle';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Abstract class for tools which create and display annotations on the
|
|
23
|
+
* cornerstone3D canvas. In addition, it provides a base class for segmentation
|
|
24
|
+
* tools that require drawing an annotation before running the segmentation strategy
|
|
25
|
+
* for instance threshold segmentation based on an area and a threshold.
|
|
26
|
+
* Annotation tools make use of drawing utilities to draw SVG elements on the viewport.
|
|
27
|
+
*
|
|
28
|
+
* To create a new annotation tool, derive from this class and implement the
|
|
29
|
+
* abstract methods.
|
|
30
|
+
*/
|
|
31
|
+
abstract class AnnotationDisplayTool extends BaseTool {
|
|
32
|
+
static toolName;
|
|
33
|
+
// ===================================================================
|
|
34
|
+
// Abstract Methods - Must be implemented.
|
|
35
|
+
// ===================================================================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @abstract renderAnnotation it used to draw the tool's annotation in each
|
|
39
|
+
* request animation frame
|
|
40
|
+
*
|
|
41
|
+
* @param enabledElement - The Cornerstone's enabledElement.
|
|
42
|
+
* @param svgDrawingHelper - The svgDrawingHelper providing the context for drawing.
|
|
43
|
+
*/
|
|
44
|
+
abstract renderAnnotation(
|
|
45
|
+
enabledElement: Types.IEnabledElement,
|
|
46
|
+
svgDrawingHelper: SVGDrawingHelper
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @virtual Given the element and annotations which is an array of annotation, it
|
|
51
|
+
* filters the annotations array to only include the annotation based on the viewportType.
|
|
52
|
+
* If the viewport is StackViewport, it filters based on the current imageId of the viewport,
|
|
53
|
+
* if the viewport is volumeViewport, it only returns those that are within the
|
|
54
|
+
* same slice as the current rendered slice in the volume viewport.
|
|
55
|
+
* imageId as the enabledElement.
|
|
56
|
+
* @param element - The HTML element
|
|
57
|
+
* @param annotations - The annotations to filter (array of annotation)
|
|
58
|
+
* @returns The filtered annotations
|
|
59
|
+
*/
|
|
60
|
+
filterInteractableAnnotationsForElement(
|
|
61
|
+
element: HTMLDivElement,
|
|
62
|
+
annotations: Annotations
|
|
63
|
+
): Annotations | undefined {
|
|
64
|
+
if (!annotations || !annotations.length) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const enabledElement = getEnabledElement(element);
|
|
69
|
+
const { viewport } = enabledElement;
|
|
70
|
+
|
|
71
|
+
return filterAnnotationsForDisplay(viewport, annotations);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* On Image Calibration, take all the annotation from the AnnotationState manager,
|
|
76
|
+
* and invalidate them to force them to be re-rendered and their stats to be recalculated.
|
|
77
|
+
* Then use the old and new imageData (non-calibrated and calibrated) to calculate the
|
|
78
|
+
* new position for the annotations in the space of the new imageData.
|
|
79
|
+
*
|
|
80
|
+
* @param evt - The calibration event
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
public onImageSpacingCalibrated = (
|
|
84
|
+
evt: Types.EventTypes.ImageSpacingCalibratedEvent
|
|
85
|
+
) => {
|
|
86
|
+
const {
|
|
87
|
+
element,
|
|
88
|
+
rowScale,
|
|
89
|
+
columnScale,
|
|
90
|
+
imageId,
|
|
91
|
+
imageData: calibratedImageData,
|
|
92
|
+
worldToIndex: noneCalibratedWorldToIndex,
|
|
93
|
+
} = evt.detail;
|
|
94
|
+
|
|
95
|
+
const { viewport } = getEnabledElement(element);
|
|
96
|
+
|
|
97
|
+
if (viewport instanceof VolumeViewport) {
|
|
98
|
+
throw new Error('Cannot calibrate a volume viewport');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const calibratedIndexToWorld = calibratedImageData.getIndexToWorld();
|
|
102
|
+
|
|
103
|
+
const imageURI = utilities.imageIdToURI(imageId);
|
|
104
|
+
const stateManager = getAnnotationManager();
|
|
105
|
+
const framesOfReference = stateManager.getFramesOfReference();
|
|
106
|
+
|
|
107
|
+
// For each frame Of Reference
|
|
108
|
+
framesOfReference.forEach((frameOfReference) => {
|
|
109
|
+
const frameOfReferenceSpecificAnnotations =
|
|
110
|
+
stateManager.getAnnotations(frameOfReference);
|
|
111
|
+
|
|
112
|
+
const toolSpecificAnnotations =
|
|
113
|
+
frameOfReferenceSpecificAnnotations[this.getToolName()];
|
|
114
|
+
|
|
115
|
+
if (!toolSpecificAnnotations || !toolSpecificAnnotations.length) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// for this specific tool
|
|
120
|
+
toolSpecificAnnotations.forEach((annotation) => {
|
|
121
|
+
// if the annotation is drawn on the same imageId
|
|
122
|
+
const referencedImageURI = utilities.imageIdToURI(
|
|
123
|
+
annotation.metadata.referencedImageId
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (referencedImageURI === imageURI) {
|
|
127
|
+
// make them invalid since the image has been calibrated so that
|
|
128
|
+
// we can update the cachedStats and also rendering
|
|
129
|
+
annotation.invalidated = true;
|
|
130
|
+
annotation.data.cachedStats = {};
|
|
131
|
+
|
|
132
|
+
// Update annotation points to the new calibrated points. Basically,
|
|
133
|
+
// using the worldToIndex function we get the index on the non-calibrated
|
|
134
|
+
// image and then using the calibratedIndexToWorld function we get the
|
|
135
|
+
// corresponding point on the calibrated image world.
|
|
136
|
+
annotation.data.handles.points = annotation.data.handles.points.map(
|
|
137
|
+
(point) => {
|
|
138
|
+
const p = vec4.fromValues(...(point as Types.Point3), 1);
|
|
139
|
+
const pCalibrated = vec4.fromValues(0, 0, 0, 1);
|
|
140
|
+
const nonCalibratedIndexVec4 = vec4.create();
|
|
141
|
+
vec4.transformMat4(
|
|
142
|
+
nonCalibratedIndexVec4,
|
|
143
|
+
p,
|
|
144
|
+
noneCalibratedWorldToIndex
|
|
145
|
+
);
|
|
146
|
+
const calibratedIndex = [
|
|
147
|
+
columnScale * nonCalibratedIndexVec4[0],
|
|
148
|
+
rowScale * nonCalibratedIndexVec4[1],
|
|
149
|
+
nonCalibratedIndexVec4[2],
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
vec4.transformMat4(
|
|
153
|
+
pCalibrated,
|
|
154
|
+
vec4.fromValues(
|
|
155
|
+
calibratedIndex[0],
|
|
156
|
+
calibratedIndex[1],
|
|
157
|
+
calibratedIndex[2],
|
|
158
|
+
1
|
|
159
|
+
),
|
|
160
|
+
calibratedIndexToWorld
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return pCalibrated.slice(0, 3) as Types.Point3;
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
triggerAnnotationRender(element);
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
protected getReferencedImageId(
|
|
174
|
+
viewport: Types.IStackViewport | Types.IVolumeViewport,
|
|
175
|
+
worldPos: Types.Point3,
|
|
176
|
+
viewPlaneNormal: Types.Point3,
|
|
177
|
+
viewUp: Types.Point3
|
|
178
|
+
): string {
|
|
179
|
+
const targetId = this.getTargetId(viewport);
|
|
180
|
+
|
|
181
|
+
let referencedImageId;
|
|
182
|
+
|
|
183
|
+
if (viewport instanceof StackViewport) {
|
|
184
|
+
referencedImageId = targetId.split('imageId:')[1];
|
|
185
|
+
} else {
|
|
186
|
+
const volumeId = targetId.split('volumeId:')[1];
|
|
187
|
+
const imageVolume = cache.getVolume(volumeId);
|
|
188
|
+
|
|
189
|
+
referencedImageId = utilities.getClosestImageId(
|
|
190
|
+
imageVolume,
|
|
191
|
+
worldPos,
|
|
192
|
+
viewPlaneNormal,
|
|
193
|
+
viewUp
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return referencedImageId;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* It takes the property (color, lineDash, etc.) and based on the state of the
|
|
202
|
+
* annotation (selected, highlighted etc.) it returns the appropriate value
|
|
203
|
+
* based on the central toolStyle settings for each level of specification.
|
|
204
|
+
* @param property - The name of the style property to get.
|
|
205
|
+
* @param styleSpecifier - An object containing the specifications such as viewportId,
|
|
206
|
+
* toolGroupId, toolName and annotationUID which are used to get the style if the level of specificity is
|
|
207
|
+
* met (hierarchy is checked from most specific to least specific which is
|
|
208
|
+
* annotationLevel -> viewportLevel -> toolGroupLevel -> default.
|
|
209
|
+
* @param annotation - The annotation for the tool that is
|
|
210
|
+
* currently active.
|
|
211
|
+
* @returns The value of the property.
|
|
212
|
+
*/
|
|
213
|
+
public getStyle(
|
|
214
|
+
property: string,
|
|
215
|
+
specifications: StyleSpecifier,
|
|
216
|
+
annotation?: Annotation
|
|
217
|
+
): unknown {
|
|
218
|
+
return getStyleProperty(
|
|
219
|
+
property,
|
|
220
|
+
specifications,
|
|
221
|
+
getState(annotation),
|
|
222
|
+
this.mode
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
AnnotationDisplayTool.toolName = 'AnnotationDisplayTool';
|
|
228
|
+
export default AnnotationDisplayTool;
|