@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,307 @@
|
|
|
1
|
+
import { getEnabledElement } from '@cornerstonejs/core';
|
|
2
|
+
import type { Types } from '@cornerstonejs/core';
|
|
3
|
+
|
|
4
|
+
import { vec2 } from 'gl-matrix';
|
|
5
|
+
|
|
6
|
+
import AnnotationDisplayTool from './AnnotationDisplayTool';
|
|
7
|
+
import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
|
|
8
|
+
import { isAnnotationVisible } from '../../stateManagement/annotation/annotationVisibility';
|
|
9
|
+
import {
|
|
10
|
+
Annotation,
|
|
11
|
+
Annotations,
|
|
12
|
+
EventTypes,
|
|
13
|
+
ToolHandle,
|
|
14
|
+
InteractionTypes,
|
|
15
|
+
} from '../../types';
|
|
16
|
+
import { StyleSpecifier } from '../../types/AnnotationStyle';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Abstract class for tools which create and display annotations on the
|
|
20
|
+
* cornerstone3D canvas. In addition, it provides a base class for segmentation
|
|
21
|
+
* tools that require drawing an annotation before running the segmentation strategy
|
|
22
|
+
* for instance threshold segmentation based on an area and a threshold.
|
|
23
|
+
* Annotation tools make use of drawing utilities to draw SVG elements on the viewport.
|
|
24
|
+
*
|
|
25
|
+
* To create a new annotation tool, derive from this class and implement the
|
|
26
|
+
* abstract methods.
|
|
27
|
+
*/
|
|
28
|
+
abstract class AnnotationTool extends AnnotationDisplayTool {
|
|
29
|
+
static toolName;
|
|
30
|
+
// ===================================================================
|
|
31
|
+
// Abstract Methods - Must be implemented.
|
|
32
|
+
// ===================================================================
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @abstract addNewAnnotation Creates a new annotation based on the clicked mouse position
|
|
36
|
+
*
|
|
37
|
+
* @param evt - The normalized mouse event
|
|
38
|
+
* @param interactionType - The interaction type used to add the annotation.
|
|
39
|
+
*/
|
|
40
|
+
abstract addNewAnnotation(
|
|
41
|
+
evt: EventTypes.InteractionEventType,
|
|
42
|
+
interactionType: InteractionTypes
|
|
43
|
+
): Annotation;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @abstract cancel Used to cancel the ongoing tool drawing and manipulation
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
abstract cancel(element: HTMLDivElement);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* handleSelectedCallback Custom callback for when a handle is selected.
|
|
53
|
+
*
|
|
54
|
+
* @param evt - The normalized mouse event
|
|
55
|
+
* @param annotation - The annotation selected.
|
|
56
|
+
* @param handle - The selected handle (either Types.Point3 in space for annotations, or TextBoxHandle object for text boxes).
|
|
57
|
+
* @param interactionType - The interaction type the handle was selected with.
|
|
58
|
+
*/
|
|
59
|
+
abstract handleSelectedCallback(
|
|
60
|
+
evt: EventTypes.InteractionEventType,
|
|
61
|
+
annotation: Annotation,
|
|
62
|
+
handle: ToolHandle,
|
|
63
|
+
interactionType: InteractionTypes
|
|
64
|
+
): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Custom callback for when an annotation is selected
|
|
68
|
+
*
|
|
69
|
+
* @param evt - The normalized mouse event
|
|
70
|
+
* @param annotation - The `Annotation` to check.
|
|
71
|
+
* @param interactionType - The interaction type used to select the tool.
|
|
72
|
+
*/
|
|
73
|
+
abstract toolSelectedCallback(
|
|
74
|
+
evt: EventTypes.InteractionEventType,
|
|
75
|
+
annotation: Annotation,
|
|
76
|
+
interactionType: InteractionTypes
|
|
77
|
+
): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if the provided canvas coordinate tool is near the annotation
|
|
81
|
+
*
|
|
82
|
+
* @param element - The HTML element
|
|
83
|
+
* @param annotation - The annotation to check
|
|
84
|
+
* @param canvasCoords - The canvas coordinate to check
|
|
85
|
+
* @param proximity - The minimum proximity to consider the point near
|
|
86
|
+
* @param interactionType - The interaction type used to select the tool.
|
|
87
|
+
*
|
|
88
|
+
* @returns boolean if the point is near.
|
|
89
|
+
*/
|
|
90
|
+
abstract isPointNearTool(
|
|
91
|
+
element: HTMLDivElement,
|
|
92
|
+
annotation: Annotation,
|
|
93
|
+
canvasCoords: Types.Point2,
|
|
94
|
+
proximity: number,
|
|
95
|
+
interactionType: string
|
|
96
|
+
): boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @virtual Event handler for Cornerstone MOUSE_MOVE event.
|
|
100
|
+
*
|
|
101
|
+
*
|
|
102
|
+
* @param evt - The normalized mouse event
|
|
103
|
+
* @param filteredAnnotations - The annotations to check for hover interactions
|
|
104
|
+
* @returns True if the annotation needs to be re-drawn by the annotationRenderingEngine.
|
|
105
|
+
*/
|
|
106
|
+
public mouseMoveCallback = (
|
|
107
|
+
evt: EventTypes.MouseMoveEventType,
|
|
108
|
+
filteredAnnotations?: Annotations
|
|
109
|
+
): boolean => {
|
|
110
|
+
if (!filteredAnnotations) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { element, currentPoints } = evt.detail;
|
|
115
|
+
const canvasCoords = currentPoints.canvas;
|
|
116
|
+
let annotationsNeedToBeRedrawn = false;
|
|
117
|
+
|
|
118
|
+
for (const annotation of filteredAnnotations) {
|
|
119
|
+
// Do not do anything if the annotation is locked or hidden.
|
|
120
|
+
if (
|
|
121
|
+
isAnnotationLocked(annotation) ||
|
|
122
|
+
!isAnnotationVisible(annotation.annotationUID)
|
|
123
|
+
) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const { data } = annotation;
|
|
128
|
+
const activateHandleIndex = data.handles
|
|
129
|
+
? data.handles.activeHandleIndex
|
|
130
|
+
: undefined;
|
|
131
|
+
|
|
132
|
+
// Perform tool specific imagePointNearToolOrHandle to determine if the mouse
|
|
133
|
+
// is near the tool or its handles or its textBox.
|
|
134
|
+
const near = this._imagePointNearToolOrHandle(
|
|
135
|
+
element,
|
|
136
|
+
annotation,
|
|
137
|
+
canvasCoords,
|
|
138
|
+
6 // Todo: This should come from the state
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const nearToolAndNotMarkedActive = near && !annotation.highlighted;
|
|
142
|
+
const notNearToolAndMarkedActive = !near && annotation.highlighted;
|
|
143
|
+
if (nearToolAndNotMarkedActive || notNearToolAndMarkedActive) {
|
|
144
|
+
annotation.highlighted = !annotation.highlighted;
|
|
145
|
+
annotationsNeedToBeRedrawn = true;
|
|
146
|
+
} else if (
|
|
147
|
+
data.handles &&
|
|
148
|
+
data.handles.activeHandleIndex !== activateHandleIndex
|
|
149
|
+
) {
|
|
150
|
+
// Active handle index has changed, re-render.
|
|
151
|
+
annotationsNeedToBeRedrawn = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return annotationsNeedToBeRedrawn;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* It checks if the mouse click is near TextBoxHandle or AnnotationHandle itself, and
|
|
160
|
+
* return either it. It prioritize TextBoxHandle over AnnotationHandle. If
|
|
161
|
+
* the mouse click is not near any of the handles, it does not return anything.
|
|
162
|
+
*
|
|
163
|
+
* @param element - The element that the tool is attached to.
|
|
164
|
+
* @param annotation - The annotation object associated with the annotation
|
|
165
|
+
* @param canvasCoords - The coordinates of the mouse click on canvas
|
|
166
|
+
* @param proximity - The distance from the mouse cursor to the point
|
|
167
|
+
* that is considered "near".
|
|
168
|
+
* @returns The handle that is closest to the cursor, or null if the cursor
|
|
169
|
+
* is not near any of the handles.
|
|
170
|
+
*/
|
|
171
|
+
getHandleNearImagePoint(
|
|
172
|
+
element: HTMLDivElement,
|
|
173
|
+
annotation: Annotation,
|
|
174
|
+
canvasCoords: Types.Point2,
|
|
175
|
+
proximity: number
|
|
176
|
+
): ToolHandle | undefined {
|
|
177
|
+
const enabledElement = getEnabledElement(element);
|
|
178
|
+
const { viewport } = enabledElement;
|
|
179
|
+
|
|
180
|
+
const { data } = annotation;
|
|
181
|
+
const { points, textBox } = data.handles;
|
|
182
|
+
const { worldBoundingBox } = textBox;
|
|
183
|
+
|
|
184
|
+
if (worldBoundingBox) {
|
|
185
|
+
const canvasBoundingBox = {
|
|
186
|
+
topLeft: viewport.worldToCanvas(worldBoundingBox.topLeft),
|
|
187
|
+
topRight: viewport.worldToCanvas(worldBoundingBox.topRight),
|
|
188
|
+
bottomLeft: viewport.worldToCanvas(worldBoundingBox.bottomLeft),
|
|
189
|
+
bottomRight: viewport.worldToCanvas(worldBoundingBox.bottomRight),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
if (
|
|
193
|
+
canvasCoords[0] >= canvasBoundingBox.topLeft[0] &&
|
|
194
|
+
canvasCoords[0] <= canvasBoundingBox.bottomRight[0] &&
|
|
195
|
+
canvasCoords[1] >= canvasBoundingBox.topLeft[1] &&
|
|
196
|
+
canvasCoords[1] <= canvasBoundingBox.bottomRight[1]
|
|
197
|
+
) {
|
|
198
|
+
data.handles.activeHandleIndex = null;
|
|
199
|
+
return textBox;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (let i = 0; i < points.length; i++) {
|
|
204
|
+
const point = points[i];
|
|
205
|
+
const annotationCanvasCoordinate = viewport.worldToCanvas(point);
|
|
206
|
+
|
|
207
|
+
const near =
|
|
208
|
+
vec2.distance(canvasCoords, annotationCanvasCoordinate) < proximity;
|
|
209
|
+
|
|
210
|
+
if (near === true) {
|
|
211
|
+
data.handles.activeHandleIndex = i;
|
|
212
|
+
return point;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
data.handles.activeHandleIndex = null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* It returns the style for the text box
|
|
221
|
+
* @param styleSpecifier - An object containing the specifications such as viewportId,
|
|
222
|
+
* toolGroupId, toolName and annotationUID which are used to get the style if the level of specificity is
|
|
223
|
+
* met (hierarchy is checked from most specific to least specific which is
|
|
224
|
+
* annotationLevel -> viewportLevel -> toolGroupLevel -> default.
|
|
225
|
+
* @param annotation - The annotation for the tool that is
|
|
226
|
+
* currently active.
|
|
227
|
+
* @returns An object of the style settings for the text box.
|
|
228
|
+
*/
|
|
229
|
+
public getLinkedTextBoxStyle(
|
|
230
|
+
specifications: StyleSpecifier,
|
|
231
|
+
annotation?: Annotation
|
|
232
|
+
): Record<string, unknown> {
|
|
233
|
+
// Todo: this function can be used to set different styles for different toolMode
|
|
234
|
+
// for the textBox.
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
fontFamily: this.getStyle(
|
|
238
|
+
'textBoxFontFamily',
|
|
239
|
+
specifications,
|
|
240
|
+
annotation
|
|
241
|
+
),
|
|
242
|
+
fontSize: this.getStyle('textBoxFontSize', specifications, annotation),
|
|
243
|
+
color: this.getStyle('textBoxColor', specifications, annotation),
|
|
244
|
+
shadow: this.getStyle('textBoxShadow', specifications, annotation),
|
|
245
|
+
background: this.getStyle(
|
|
246
|
+
'textBoxBackground',
|
|
247
|
+
specifications,
|
|
248
|
+
annotation
|
|
249
|
+
),
|
|
250
|
+
lineWidth: this.getStyle(
|
|
251
|
+
'textBoxLinkLineWidth',
|
|
252
|
+
specifications,
|
|
253
|
+
annotation
|
|
254
|
+
),
|
|
255
|
+
lineDash: this.getStyle(
|
|
256
|
+
'textBoxLinkLineDash',
|
|
257
|
+
specifications,
|
|
258
|
+
annotation
|
|
259
|
+
),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Returns true if the `canvasCoords` are near a handle or selectable part of the tool
|
|
265
|
+
*
|
|
266
|
+
* @param element - The HTML element
|
|
267
|
+
* @param annotation - The annotation to check
|
|
268
|
+
* @param canvasCoords - The canvas coordinates to check
|
|
269
|
+
* @param proximity - The proximity to consider
|
|
270
|
+
*
|
|
271
|
+
* @returns If the point is near.
|
|
272
|
+
*/
|
|
273
|
+
private _imagePointNearToolOrHandle(
|
|
274
|
+
element: HTMLDivElement,
|
|
275
|
+
annotation: Annotation,
|
|
276
|
+
canvasCoords: Types.Point2,
|
|
277
|
+
proximity: number
|
|
278
|
+
): boolean {
|
|
279
|
+
// Based on the tool instance type, check if the point is near the tool handles
|
|
280
|
+
const handleNearImagePoint = this.getHandleNearImagePoint(
|
|
281
|
+
element,
|
|
282
|
+
annotation,
|
|
283
|
+
canvasCoords,
|
|
284
|
+
proximity
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
if (handleNearImagePoint) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// If the point is not near the handles, check if the point is near the tool
|
|
292
|
+
const toolNewImagePoint = this.isPointNearTool(
|
|
293
|
+
element,
|
|
294
|
+
annotation,
|
|
295
|
+
canvasCoords,
|
|
296
|
+
proximity,
|
|
297
|
+
'mouse'
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
if (toolNewImagePoint) {
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
AnnotationTool.toolName = 'AnnotationTool';
|
|
307
|
+
export default AnnotationTool;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { StackViewport, VolumeViewport, utilities } from '@cornerstonejs/core';
|
|
2
|
+
import { Types } from '@cornerstonejs/core';
|
|
3
|
+
import { ToolModes } from '../../enums';
|
|
4
|
+
import { InteractionTypes, ToolProps, PublicToolProps } from '../../types';
|
|
5
|
+
|
|
6
|
+
export interface IBaseTool {
|
|
7
|
+
/** ToolGroup ID the tool instance belongs to */
|
|
8
|
+
toolGroupId: string;
|
|
9
|
+
/** Tool supported interaction types */
|
|
10
|
+
supportedInteractionTypes: InteractionTypes[];
|
|
11
|
+
/** Tool Mode : Active, Passive, Enabled, Disabled */
|
|
12
|
+
mode: ToolModes;
|
|
13
|
+
/** Tool Configuration */
|
|
14
|
+
configuration: {
|
|
15
|
+
preventHandleOutsideImage?: boolean;
|
|
16
|
+
strategies?: Record<string, any>;
|
|
17
|
+
defaultStrategy?: string;
|
|
18
|
+
activeStrategy?: string;
|
|
19
|
+
strategyOptions?: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Abstract base class from which all tools derive.
|
|
25
|
+
* Deals with cleanly merging custom and default configuration, and strategy
|
|
26
|
+
* application.
|
|
27
|
+
*/
|
|
28
|
+
abstract class BaseTool implements IBaseTool {
|
|
29
|
+
static toolName;
|
|
30
|
+
/** Supported Interaction Types - currently only Mouse */
|
|
31
|
+
public supportedInteractionTypes: InteractionTypes[];
|
|
32
|
+
public configuration: Record<string, any>;
|
|
33
|
+
/** ToolGroup ID the tool instance belongs to */
|
|
34
|
+
public toolGroupId: string;
|
|
35
|
+
/** Tool Mode - Active/Passive/Enabled/Disabled/ */
|
|
36
|
+
public mode: ToolModes;
|
|
37
|
+
|
|
38
|
+
constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps) {
|
|
39
|
+
const initialProps = utilities.deepMerge(defaultToolProps, toolProps);
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
configuration = {},
|
|
43
|
+
supportedInteractionTypes,
|
|
44
|
+
toolGroupId,
|
|
45
|
+
} = initialProps;
|
|
46
|
+
|
|
47
|
+
// If strategies are not initialized in the tool config
|
|
48
|
+
if (!configuration.strategies) {
|
|
49
|
+
configuration.strategies = {};
|
|
50
|
+
configuration.defaultStrategy = undefined;
|
|
51
|
+
configuration.activeStrategy = undefined;
|
|
52
|
+
configuration.strategyOptions = {};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.toolGroupId = toolGroupId;
|
|
56
|
+
this.supportedInteractionTypes = supportedInteractionTypes || [];
|
|
57
|
+
this.configuration = Object.assign({}, configuration);
|
|
58
|
+
this.mode = ToolModes.Disabled;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns the name of the tool
|
|
63
|
+
* @returns The name of the tool.
|
|
64
|
+
*/
|
|
65
|
+
public getToolName(): string {
|
|
66
|
+
// Since toolName is static we get it from the class constructor
|
|
67
|
+
return (<typeof BaseTool>this.constructor).toolName;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* It applies the active strategy to the enabled element.
|
|
72
|
+
* @param enabledElement - The element that is being operated on.
|
|
73
|
+
* @param operationData - The data that needs to be passed to the strategy.
|
|
74
|
+
* @returns The result of the strategy.
|
|
75
|
+
*/
|
|
76
|
+
public applyActiveStrategy(
|
|
77
|
+
enabledElement: Types.IEnabledElement,
|
|
78
|
+
operationData: unknown
|
|
79
|
+
): any {
|
|
80
|
+
const { strategies, activeStrategy } = this.configuration;
|
|
81
|
+
return strategies[activeStrategy].call(this, enabledElement, operationData);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* merges the new configuration with the tool configuration
|
|
86
|
+
* @param configuration - toolConfiguration
|
|
87
|
+
*/
|
|
88
|
+
public setConfiguration(newConfiguration: Record<string, any>): void {
|
|
89
|
+
this.configuration = utilities.deepMerge(
|
|
90
|
+
this.configuration,
|
|
91
|
+
newConfiguration
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Sets the active strategy for a tool. Strategies are
|
|
97
|
+
* multiple implementations of tool behavior that can be switched by tool
|
|
98
|
+
* configuration.
|
|
99
|
+
*
|
|
100
|
+
* @param strategyName - name of the strategy to be set as active
|
|
101
|
+
*/
|
|
102
|
+
public setActiveStrategy(strategyName: string): void {
|
|
103
|
+
this.setConfiguration({ activeStrategy: strategyName });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns the volumeId for the volume viewport. It will grabbed the volumeId
|
|
108
|
+
* from the volumeId if particularly specified in the tool configuration, or if
|
|
109
|
+
* not, the first actorUID in the viewport is returned as the volumeId. NOTE: for
|
|
110
|
+
* segmentations, actorUID is not necessarily the volumeId since the segmentation
|
|
111
|
+
* can have multiple representations, use segmentation helpers to get the volumeId
|
|
112
|
+
* based on the actorUID.
|
|
113
|
+
*
|
|
114
|
+
* @param viewport - Volume viewport
|
|
115
|
+
* @returns the volumeId for the viewport if specified in the tool configuration,
|
|
116
|
+
* or the first actorUID in the viewport if not.
|
|
117
|
+
*/
|
|
118
|
+
private getTargetVolumeId(viewport: Types.IViewport): string | undefined {
|
|
119
|
+
if (this.configuration.volumeId) {
|
|
120
|
+
return this.configuration.volumeId;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// If volume not specified, then return the actorUID for the
|
|
124
|
+
// default actor - first actor
|
|
125
|
+
const actorEntries = viewport.getActors();
|
|
126
|
+
|
|
127
|
+
if (!actorEntries) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// find the first image actor of instance type vtkVolume
|
|
132
|
+
return actorEntries.find(
|
|
133
|
+
(actorEntry) => actorEntry.actor.getClassName() === 'vtkVolume'
|
|
134
|
+
)?.uid;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get the image that is displayed for the targetId in the cachedStats
|
|
139
|
+
* which can be either imageId:<imageId> or volumeId:<volumeId>
|
|
140
|
+
*
|
|
141
|
+
* @param targetId - annotation targetId stored in the cached stats
|
|
142
|
+
* @param renderingEngine - The rendering engine
|
|
143
|
+
* @returns The image data for the target.
|
|
144
|
+
*/
|
|
145
|
+
protected getTargetIdImage(
|
|
146
|
+
targetId: string,
|
|
147
|
+
renderingEngine: Types.IRenderingEngine
|
|
148
|
+
): Types.IImageData | Types.CPUIImageData | Types.IImageVolume {
|
|
149
|
+
if (targetId.startsWith('imageId:')) {
|
|
150
|
+
const imageId = targetId.split('imageId:')[1];
|
|
151
|
+
const imageURI = utilities.imageIdToURI(imageId);
|
|
152
|
+
let viewports = utilities.getViewportsWithImageURI(
|
|
153
|
+
imageURI,
|
|
154
|
+
renderingEngine.id
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
if (!viewports || !viewports.length) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
viewports = viewports.filter((viewport) => {
|
|
162
|
+
return viewport.getCurrentImageId() === imageId;
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
if (!viewports || !viewports.length) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return viewports[0].getImageData();
|
|
170
|
+
} else if (targetId.startsWith('volumeId:')) {
|
|
171
|
+
const volumeId = targetId.split('volumeId:')[1];
|
|
172
|
+
const viewports = utilities.getViewportsWithVolumeId(
|
|
173
|
+
volumeId,
|
|
174
|
+
renderingEngine.id
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
if (!viewports || !viewports.length) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return viewports[0].getImageData();
|
|
182
|
+
} else {
|
|
183
|
+
throw new Error(
|
|
184
|
+
'getTargetIdImage: targetId must start with "imageId:" or "volumeId:"'
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get the target Id for the viewport which will be used to store the cached
|
|
191
|
+
* statistics scoped to that target in the annotations.
|
|
192
|
+
* For StackViewport, targetId is the viewportId, but for the volume viewport,
|
|
193
|
+
* the targetId will be grabbed from the volumeId if particularly specified
|
|
194
|
+
* in the tool configuration, or if not, the first actorUID in the viewport.
|
|
195
|
+
*
|
|
196
|
+
* @param viewport - viewport to get the targetId for
|
|
197
|
+
* @returns targetId
|
|
198
|
+
*/
|
|
199
|
+
protected getTargetId(viewport: Types.IViewport): string | undefined {
|
|
200
|
+
if (viewport instanceof StackViewport) {
|
|
201
|
+
return `imageId:${viewport.getCurrentImageId()}`;
|
|
202
|
+
} else if (viewport instanceof VolumeViewport) {
|
|
203
|
+
return `volumeId:${this.getTargetVolumeId(viewport)}`;
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(
|
|
206
|
+
'getTargetId: viewport must be a StackViewport or VolumeViewport'
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Note: this is a workaround since terser plugin does not support static blocks
|
|
213
|
+
// yet and we can't easily say static toolName = "BaseTool" in the class definition.
|
|
214
|
+
BaseTool.toolName = 'BaseTool';
|
|
215
|
+
export default BaseTool;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getEnabledElement, Types, Enums } from '@cornerstonejs/core';
|
|
2
|
+
import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
|
|
3
|
+
import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
|
|
4
|
+
import vtkPoints from '@kitware/vtk.js/Common/Core/Points';
|
|
5
|
+
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
|
|
6
|
+
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
|
|
7
|
+
|
|
8
|
+
// Todo: this seems to have performance issues when there are many contours
|
|
9
|
+
// Maybe we should not create one actor per contour, but rather one actor per
|
|
10
|
+
// contourSet?
|
|
11
|
+
function addContourToElement(
|
|
12
|
+
element: HTMLDivElement,
|
|
13
|
+
contour: Types.IContour,
|
|
14
|
+
actorUID: string
|
|
15
|
+
): void {
|
|
16
|
+
const enabledElement = getEnabledElement(element);
|
|
17
|
+
const { renderingEngine, viewport } = enabledElement;
|
|
18
|
+
const { id: viewportId } = viewport;
|
|
19
|
+
|
|
20
|
+
// Default to true since we are setting a new segmentation, however,
|
|
21
|
+
// in the event listener, we will make other segmentations visible/invisible
|
|
22
|
+
// based on the config
|
|
23
|
+
const visibility = true;
|
|
24
|
+
const immediateRender = false;
|
|
25
|
+
const suppressEvents = true;
|
|
26
|
+
|
|
27
|
+
const pointList = contour.getPoints();
|
|
28
|
+
const flatPoints = contour.getFlatPointsArray();
|
|
29
|
+
const color = contour.getColor();
|
|
30
|
+
const type = contour.getType();
|
|
31
|
+
|
|
32
|
+
const p = pointList.map((_, i) => i);
|
|
33
|
+
|
|
34
|
+
if (type === Enums.ContourType.CLOSED_PLANAR) {
|
|
35
|
+
p.push(0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const var1 = Float32Array.from(flatPoints);
|
|
39
|
+
const var2 = Uint32Array.from([p.length, ...p]);
|
|
40
|
+
|
|
41
|
+
const colorToUse = color.map((c) => c / 255);
|
|
42
|
+
|
|
43
|
+
const points = vtkPoints.newInstance();
|
|
44
|
+
points.setData(var1, 3);
|
|
45
|
+
|
|
46
|
+
const lines = vtkCellArray.newInstance();
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
lines.setData(var2, 3);
|
|
49
|
+
|
|
50
|
+
const polygon = vtkPolyData.newInstance();
|
|
51
|
+
polygon.setPoints(points);
|
|
52
|
+
polygon.setLines(lines);
|
|
53
|
+
|
|
54
|
+
const mapper1 = vtkMapper.newInstance();
|
|
55
|
+
mapper1.setInputData(polygon);
|
|
56
|
+
const actor1 = vtkActor.newInstance();
|
|
57
|
+
actor1.setMapper(mapper1);
|
|
58
|
+
actor1.getProperty().setLineWidth(4);
|
|
59
|
+
actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
|
|
60
|
+
|
|
61
|
+
viewport.addActor({ actor: actor1, uid: actorUID });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function addContourSetToElement(
|
|
65
|
+
element: HTMLDivElement,
|
|
66
|
+
contourSet: Types.IContourSet,
|
|
67
|
+
actorUID: string
|
|
68
|
+
): void {
|
|
69
|
+
const enabledElement = getEnabledElement(element);
|
|
70
|
+
const { renderingEngine, viewport } = enabledElement;
|
|
71
|
+
const { id: viewportId } = viewport;
|
|
72
|
+
|
|
73
|
+
// Default to true since we are setting a new segmentation, however,
|
|
74
|
+
// in the event listener, we will make other segmentations visible/invisible
|
|
75
|
+
// based on the config
|
|
76
|
+
const visibility = true;
|
|
77
|
+
const immediateRender = false;
|
|
78
|
+
const suppressEvents = true;
|
|
79
|
+
|
|
80
|
+
const actor1 = vtkActor.newInstance();
|
|
81
|
+
let color;
|
|
82
|
+
|
|
83
|
+
const pointArray = [];
|
|
84
|
+
|
|
85
|
+
const points = vtkPoints.newInstance();
|
|
86
|
+
const lines = vtkCellArray.newInstance();
|
|
87
|
+
|
|
88
|
+
// this variable will indicate the index of the first point in the current line
|
|
89
|
+
// so we can correctly generate the point index list to add in the cellArray
|
|
90
|
+
let pointIndex = 0;
|
|
91
|
+
contourSet.getContours().forEach((contour: Types.IContour) => {
|
|
92
|
+
const pointList = contour.getPoints();
|
|
93
|
+
const flatPoints = contour.getFlatPointsArray();
|
|
94
|
+
color = contour.getColor();
|
|
95
|
+
const type = contour.getType();
|
|
96
|
+
|
|
97
|
+
// creating a point index list that defines a line
|
|
98
|
+
const pointIndexes = pointList.map((_, i) => i + pointIndex);
|
|
99
|
+
|
|
100
|
+
// if close planar, add the first point index to the list
|
|
101
|
+
if (type === Enums.ContourType.CLOSED_PLANAR) {
|
|
102
|
+
pointIndexes.push(pointIndexes[0]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const linePoints = Float32Array.from(flatPoints);
|
|
106
|
+
// add the curent points into the point list
|
|
107
|
+
pointArray.push(...linePoints);
|
|
108
|
+
// add the point indexes into the cell array
|
|
109
|
+
lines.insertNextCell([...pointIndexes]);
|
|
110
|
+
// update the first point index
|
|
111
|
+
pointIndex = pointIndex + pointList.length;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// converts the pointArray into vtkPoints
|
|
115
|
+
points.setData(pointArray, 3);
|
|
116
|
+
|
|
117
|
+
// creates the polydata
|
|
118
|
+
const polygon = vtkPolyData.newInstance();
|
|
119
|
+
polygon.setPoints(points);
|
|
120
|
+
polygon.setLines(lines);
|
|
121
|
+
|
|
122
|
+
const mapper1 = vtkMapper.newInstance();
|
|
123
|
+
mapper1.setInputData(polygon);
|
|
124
|
+
actor1.setMapper(mapper1);
|
|
125
|
+
actor1.getProperty().setLineWidth(4);
|
|
126
|
+
|
|
127
|
+
// despite each contour can have its own color, we assign the last color to
|
|
128
|
+
// all contours
|
|
129
|
+
const colorToUse = color.map((c) => c / 255);
|
|
130
|
+
actor1.getProperty().setColor(colorToUse[0], colorToUse[1], colorToUse[2]);
|
|
131
|
+
|
|
132
|
+
viewport.addActor({ actor: actor1, uid: actorUID });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { addContourToElement, addContourSetToElement };
|