@cornerstonejs/tools 0.56.1 → 0.56.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tools/CrosshairsTool.d.ts +1 -0
- package/dist/cjs/tools/CrosshairsTool.js +4 -1
- package/dist/cjs/tools/CrosshairsTool.js.map +1 -1
- package/dist/esm/tools/CrosshairsTool.d.ts +1 -0
- package/dist/esm/tools/CrosshairsTool.js +4 -1
- package/dist/esm/tools/CrosshairsTool.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +5 -4
- package/src/constants/COLOR_LUT.ts +262 -0
- package/src/constants/index.ts +3 -0
- package/src/cursors/ImageMouseCursor.ts +39 -0
- package/src/cursors/MouseCursor.ts +114 -0
- package/src/cursors/SVGCursorDescriptor.ts +462 -0
- package/src/cursors/SVGMouseCursor.ts +145 -0
- package/src/cursors/elementCursor.ts +69 -0
- package/src/cursors/index.ts +24 -0
- package/src/cursors/setCursorForElement.ts +33 -0
- package/src/drawingSvg/_getHash.ts +9 -0
- package/src/drawingSvg/_setAttributesIfNecessary.ts +13 -0
- package/src/drawingSvg/_setNewAttributesIfValid.ts +10 -0
- package/src/drawingSvg/clearByToolType.ts +26 -0
- package/src/drawingSvg/draw.ts +16 -0
- package/src/drawingSvg/drawArrow.ts +82 -0
- package/src/drawingSvg/drawCircle.ts +62 -0
- package/src/drawingSvg/drawEllipse.ts +71 -0
- package/src/drawingSvg/drawHandles.ts +87 -0
- package/src/drawingSvg/drawLine.ts +70 -0
- package/src/drawingSvg/drawLink.ts +76 -0
- package/src/drawingSvg/drawLinkedTextBox.ts +64 -0
- package/src/drawingSvg/drawPolyline.ts +80 -0
- package/src/drawingSvg/drawRect.ts +70 -0
- package/src/drawingSvg/drawTextBox.ts +213 -0
- package/src/drawingSvg/getSvgDrawingHelper.ts +98 -0
- package/src/drawingSvg/index.ts +23 -0
- package/src/enums/AnnotationStyleStates.ts +22 -0
- package/src/enums/Events.ts +242 -0
- package/src/enums/SegmentationRepresentations.ts +12 -0
- package/src/enums/ToolBindings.ts +37 -0
- package/src/enums/ToolModes.ts +31 -0
- package/src/enums/Touch.ts +8 -0
- package/src/enums/index.js +16 -0
- package/src/eventDispatchers/annotationModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/cameraModifiedEventDispatcher.ts +41 -0
- package/src/eventDispatchers/imageRenderedEventDispatcher.ts +37 -0
- package/src/eventDispatchers/imageSpacingCalibratedEventDispatcher.ts +50 -0
- package/src/eventDispatchers/index.js +15 -0
- package/src/eventDispatchers/keyboardEventHandlers/index.js +4 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyDown.ts +29 -0
- package/src/eventDispatchers/keyboardEventHandlers/keyUp.ts +33 -0
- package/src/eventDispatchers/keyboardToolEventDispatcher.ts +28 -0
- package/src/eventDispatchers/mouseEventHandlers/index.js +19 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDoubleClick.ts +13 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +196 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDownActivate.ts +35 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseDrag.ts +25 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseMove.ts +70 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseUp.ts +9 -0
- package/src/eventDispatchers/mouseEventHandlers/mouseWheel.ts +13 -0
- package/src/eventDispatchers/mouseToolEventDispatcher.ts +64 -0
- package/src/eventDispatchers/shared/customCallbackHandler.ts +73 -0
- package/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +58 -0
- package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +61 -0
- package/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +64 -0
- package/src/eventDispatchers/shared/getMouseModifier.ts +30 -0
- package/src/eventDispatchers/shared/getToolsWithModesForMouseEvent.ts +56 -0
- package/src/eventDispatchers/shared/getToolsWithModesForTouchEvent.ts +54 -0
- package/src/eventDispatchers/touchEventHandlers/index.js +15 -0
- package/src/eventDispatchers/touchEventHandlers/touchDrag.ts +23 -0
- package/src/eventDispatchers/touchEventHandlers/touchEnd.ts +9 -0
- package/src/eventDispatchers/touchEventHandlers/touchPress.ts +13 -0
- package/src/eventDispatchers/touchEventHandlers/touchStart.ts +174 -0
- package/src/eventDispatchers/touchEventHandlers/touchStartActivate.ts +36 -0
- package/src/eventDispatchers/touchEventHandlers/touchTap.ts +9 -0
- package/src/eventDispatchers/touchToolEventDispatcher.ts +51 -0
- package/src/eventListeners/annotations/annotationModifiedListener.ts +22 -0
- package/src/eventListeners/annotations/annotationSelectionListener.ts +29 -0
- package/src/eventListeners/annotations/index.ts +4 -0
- package/src/eventListeners/index.ts +28 -0
- package/src/eventListeners/keyboard/index.ts +16 -0
- package/src/eventListeners/keyboard/keyDownListener.ts +99 -0
- package/src/eventListeners/mouse/getMouseEventPoints.ts +66 -0
- package/src/eventListeners/mouse/index.ts +55 -0
- package/src/eventListeners/mouse/mouseDoubleClickListener.ts +55 -0
- package/src/eventListeners/mouse/mouseDownListener.ts +519 -0
- package/src/eventListeners/mouse/mouseMoveListener.ts +33 -0
- package/src/eventListeners/segmentation/index.ts +11 -0
- package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +61 -0
- package/src/eventListeners/segmentation/segmentationModifiedEventListener.ts +32 -0
- package/src/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.ts +15 -0
- package/src/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.ts +16 -0
- package/src/eventListeners/touch/getTouchEventPoints.ts +75 -0
- package/src/eventListeners/touch/index.ts +37 -0
- package/src/eventListeners/touch/preventGhostClick.js +72 -0
- package/src/eventListeners/touch/touchStartListener.ts +499 -0
- package/src/eventListeners/wheel/index.ts +27 -0
- package/src/eventListeners/wheel/normalizeWheel.ts +69 -0
- package/src/eventListeners/wheel/wheelListener.ts +51 -0
- package/src/index.ts +133 -0
- package/src/init.ts +187 -0
- package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +399 -0
- package/src/stateManagement/annotation/annotationLocking.ts +178 -0
- package/src/stateManagement/annotation/annotationSelection.ts +163 -0
- package/src/stateManagement/annotation/annotationState.ts +180 -0
- package/src/stateManagement/annotation/annotationVisibility.ts +156 -0
- package/src/stateManagement/annotation/config/ToolStyle.ts +265 -0
- package/src/stateManagement/annotation/config/getFont.ts +36 -0
- package/src/stateManagement/annotation/config/getState.ts +26 -0
- package/src/stateManagement/annotation/config/helpers.ts +55 -0
- package/src/stateManagement/annotation/config/index.ts +5 -0
- package/src/stateManagement/annotation/helpers/state.ts +83 -0
- package/src/stateManagement/annotation/index.ts +15 -0
- package/src/stateManagement/index.js +40 -0
- package/src/stateManagement/segmentation/SegmentationStateManager.ts +491 -0
- package/src/stateManagement/segmentation/activeSegmentation.ts +60 -0
- package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +77 -0
- package/src/stateManagement/segmentation/addSegmentations.ts +27 -0
- package/src/stateManagement/segmentation/config/index.ts +29 -0
- package/src/stateManagement/segmentation/config/segmentationColor.ts +132 -0
- package/src/stateManagement/segmentation/config/segmentationConfig.ts +195 -0
- package/src/stateManagement/segmentation/config/segmentationVisibility.ts +171 -0
- package/src/stateManagement/segmentation/helpers/index.ts +3 -0
- package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +35 -0
- package/src/stateManagement/segmentation/helpers/validateSegmentationInput.ts +41 -0
- package/src/stateManagement/segmentation/index.ts +22 -0
- package/src/stateManagement/segmentation/removeSegmentationsFromToolGroup.ts +85 -0
- package/src/stateManagement/segmentation/segmentIndex.ts +38 -0
- package/src/stateManagement/segmentation/segmentLocking.ts +72 -0
- package/src/stateManagement/segmentation/segmentationState.ts +429 -0
- package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +157 -0
- package/src/store/SynchronizerManager/Synchronizer.ts +344 -0
- package/src/store/SynchronizerManager/createSynchronizer.ts +41 -0
- package/src/store/SynchronizerManager/destroy.ts +14 -0
- package/src/store/SynchronizerManager/destroySynchronizer.ts +25 -0
- package/src/store/SynchronizerManager/getAllSynchronizers.ts +12 -0
- package/src/store/SynchronizerManager/getSynchronizer.ts +13 -0
- package/src/store/SynchronizerManager/getSynchronizersForViewport.ts +44 -0
- package/src/store/SynchronizerManager/index.js +15 -0
- package/src/store/ToolGroupManager/ToolGroup.ts +679 -0
- package/src/store/ToolGroupManager/createToolGroup.ts +33 -0
- package/src/store/ToolGroupManager/destroy.ts +24 -0
- package/src/store/ToolGroupManager/destroyToolGroup.ts +26 -0
- package/src/store/ToolGroupManager/getAllToolGroups.ts +12 -0
- package/src/store/ToolGroupManager/getToolGroup.ts +14 -0
- package/src/store/ToolGroupManager/getToolGroupForViewport.ts +44 -0
- package/src/store/ToolGroupManager/getToolGroupsWithToolName.ts +33 -0
- package/src/store/ToolGroupManager/index.ts +17 -0
- package/src/store/addEnabledElement.ts +137 -0
- package/src/store/addTool.ts +56 -0
- package/src/store/cancelActiveManipulations.ts +30 -0
- package/src/store/filterMoveableAnnotationTools.ts +61 -0
- package/src/store/filterToolsWithAnnotationsForElement.ts +51 -0
- package/src/store/filterToolsWithMoveableHandles.ts +51 -0
- package/src/store/index.ts +29 -0
- package/src/store/removeEnabledElement.ts +132 -0
- package/src/store/state.ts +57 -0
- package/src/store/svgNodeCache.ts +7 -0
- package/src/synchronizers/callbacks/areViewportsCoplanar .ts +12 -0
- package/src/synchronizers/callbacks/cameraSyncCallback.ts +33 -0
- package/src/synchronizers/callbacks/stackImageSyncCallback.ts +157 -0
- package/src/synchronizers/callbacks/voiSyncCallback.ts +51 -0
- package/src/synchronizers/callbacks/zoomPanSyncCallback.ts +43 -0
- package/src/synchronizers/index.ts +11 -0
- package/src/synchronizers/synchronizers/createCameraPositionSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createStackImageSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/createVOISynchronizer.ts +24 -0
- package/src/synchronizers/synchronizers/createZoomPanSynchronizer.ts +25 -0
- package/src/synchronizers/synchronizers/index.ts +11 -0
- package/src/tools/CrosshairsTool.ts +2693 -0
- package/src/tools/MIPJumpToClickTool.ts +99 -0
- package/src/tools/MagnifyTool.ts +319 -0
- package/src/tools/PanTool.ts +58 -0
- package/src/tools/PlanarRotateTool.ts +77 -0
- package/src/tools/ReferenceCursors.ts +466 -0
- package/src/tools/ReferenceLinesTool.ts +279 -0
- package/src/tools/ScaleOverlayTool.ts +685 -0
- package/src/tools/StackScrollTool.ts +97 -0
- package/src/tools/StackScrollToolMouseWheelTool.ts +58 -0
- package/src/tools/TrackballRotateTool.ts +141 -0
- package/src/tools/VolumeRotateMouseWheelTool.ts +86 -0
- package/src/tools/WindowLevelTool.ts +260 -0
- package/src/tools/ZoomTool.ts +293 -0
- package/src/tools/annotation/AngleTool.ts +835 -0
- package/src/tools/annotation/ArrowAnnotateTool.ts +820 -0
- package/src/tools/annotation/BidirectionalTool.ts +1350 -0
- package/src/tools/annotation/CircleROITool.ts +1070 -0
- package/src/tools/annotation/CobbAngleTool.ts +815 -0
- package/src/tools/annotation/DragProbeTool.ts +213 -0
- package/src/tools/annotation/EllipticalROITool.ts +1223 -0
- package/src/tools/annotation/LengthTool.ts +861 -0
- package/src/tools/annotation/PlanarFreehandROITool.ts +636 -0
- package/src/tools/annotation/ProbeTool.ts +681 -0
- package/src/tools/annotation/RectangleROITool.ts +1028 -0
- package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +488 -0
- package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +462 -0
- package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +331 -0
- package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +612 -0
- package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +74 -0
- package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +407 -0
- package/src/tools/base/AnnotationDisplayTool.ts +228 -0
- package/src/tools/base/AnnotationTool.ts +307 -0
- package/src/tools/base/BaseTool.ts +215 -0
- package/src/tools/base/index.ts +4 -0
- package/src/tools/displayTools/Contour/addContourToElement.ts +135 -0
- package/src/tools/displayTools/Contour/contourDisplay.ts +252 -0
- package/src/tools/displayTools/Contour/index.ts +3 -0
- package/src/tools/displayTools/Contour/removeContourFromElement.ts +35 -0
- package/src/tools/displayTools/Labelmap/addLabelmapToElement.ts +57 -0
- package/src/tools/displayTools/Labelmap/index.ts +4 -0
- package/src/tools/displayTools/Labelmap/labelmapConfig.ts +37 -0
- package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +461 -0
- package/src/tools/displayTools/Labelmap/removeLabelmapFromElement.ts +27 -0
- package/src/tools/displayTools/Labelmap/validateRepresentationData.ts +30 -0
- package/src/tools/displayTools/SegmentationDisplayTool.ts +198 -0
- package/src/tools/index.ts +84 -0
- package/src/tools/segmentation/BrushTool.ts +474 -0
- package/src/tools/segmentation/CircleScissorsTool.ts +365 -0
- package/src/tools/segmentation/PaintFillTool.ts +370 -0
- package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +471 -0
- package/src/tools/segmentation/RectangleROIThresholdTool.ts +281 -0
- package/src/tools/segmentation/RectangleScissorsTool.ts +382 -0
- package/src/tools/segmentation/SphereScissorsTool.ts +368 -0
- package/src/tools/segmentation/strategies/eraseCircle.ts +30 -0
- package/src/tools/segmentation/strategies/eraseRectangle.ts +81 -0
- package/src/tools/segmentation/strategies/eraseSphere.ts +27 -0
- package/src/tools/segmentation/strategies/fillCircle.ts +185 -0
- package/src/tools/segmentation/strategies/fillRectangle.ts +110 -0
- package/src/tools/segmentation/strategies/fillSphere.ts +88 -0
- package/src/tools/segmentation/strategies/index.ts +9 -0
- package/src/types/AnnotationGroupSelector.ts +7 -0
- package/src/types/AnnotationStyle.ts +42 -0
- package/src/types/AnnotationTypes.ts +109 -0
- package/src/types/BoundsIJK.ts +5 -0
- package/src/types/CINETypes.ts +32 -0
- package/src/types/ContourTypes.ts +26 -0
- package/src/types/CursorTypes.ts +12 -0
- package/src/types/EventTypes.ts +657 -0
- package/src/types/FloodFillTypes.ts +19 -0
- package/src/types/IAnnotationManager.ts +89 -0
- package/src/types/IDistance.ts +16 -0
- package/src/types/IPoints.ts +18 -0
- package/src/types/ISetToolModeOptions.ts +29 -0
- package/src/types/ISynchronizerEventHandler.ts +11 -0
- package/src/types/IToolClassReference.ts +5 -0
- package/src/types/IToolGroup.ts +72 -0
- package/src/types/ITouchPoints.ts +14 -0
- package/src/types/InteractionTypes.ts +6 -0
- package/src/types/InternalToolTypes.ts +19 -0
- package/src/types/JumpToSliceOptions.ts +7 -0
- package/src/types/LabelmapTypes.ts +41 -0
- package/src/types/PlanarBoundingBox.ts +8 -0
- package/src/types/SVGDrawingHelper.ts +10 -0
- package/src/types/ScrollOptions.ts +9 -0
- package/src/types/SegmentationStateTypes.ts +248 -0
- package/src/types/ToolHandle.ts +26 -0
- package/src/types/ToolProps.ts +16 -0
- package/src/types/ToolSpecificAnnotationTypes.ts +311 -0
- package/src/types/index.ts +115 -0
- package/src/utilities/boundingBox/extend2DBoundingBoxInViewAxis.ts +29 -0
- package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +57 -0
- package/src/utilities/boundingBox/index.ts +4 -0
- package/src/utilities/calibrateImageSpacing.ts +46 -0
- package/src/utilities/cine/events.ts +9 -0
- package/src/utilities/cine/index.ts +5 -0
- package/src/utilities/cine/playClip.ts +435 -0
- package/src/utilities/cine/state.ts +18 -0
- package/src/utilities/clip.js +30 -0
- package/src/utilities/debounce.js +217 -0
- package/src/utilities/drawing/getTextBoxCoordsCanvas.ts +45 -0
- package/src/utilities/drawing/index.ts +3 -0
- package/src/utilities/dynamicVolume/getDataInTime.ts +110 -0
- package/src/utilities/dynamicVolume/index.ts +2 -0
- package/src/utilities/getAnnotationNearPoint.ts +130 -0
- package/src/utilities/getModalityUnit.ts +11 -0
- package/src/utilities/getToolsWithModesForElement.ts +52 -0
- package/src/utilities/index.ts +68 -0
- package/src/utilities/isObject.js +29 -0
- package/src/utilities/math/angle/angleBetweenLines.ts +29 -0
- package/src/utilities/math/circle/_types.ts +6 -0
- package/src/utilities/math/circle/getCanvasCircleCorners.ts +23 -0
- package/src/utilities/math/circle/getCanvasCircleRadius.ts +16 -0
- package/src/utilities/math/circle/index.ts +4 -0
- package/src/utilities/math/ellipse/getCanvasEllipseCorners.ts +26 -0
- package/src/utilities/math/ellipse/index.ts +4 -0
- package/src/utilities/math/ellipse/pointInEllipse.ts +38 -0
- package/src/utilities/math/ellipse/pointInEllipsoidWithConstraint.ts +35 -0
- package/src/utilities/math/index.ts +8 -0
- package/src/utilities/math/line/distanceToPoint.ts +24 -0
- package/src/utilities/math/line/distanceToPointSquared.ts +44 -0
- package/src/utilities/math/line/index.ts +5 -0
- package/src/utilities/math/line/intersectLine.ts +92 -0
- package/src/utilities/math/midPoint.ts +24 -0
- package/src/utilities/math/point/distanceToPoint.ts +22 -0
- package/src/utilities/math/point/index.ts +3 -0
- package/src/utilities/math/polyline/addCanvasPointsToArray.ts +62 -0
- package/src/utilities/math/polyline/calculateAreaOfPoints.ts +23 -0
- package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +182 -0
- package/src/utilities/math/polyline/getSubPixelSpacingAndXYDirections.ts +99 -0
- package/src/utilities/math/polyline/index.ts +19 -0
- package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +36 -0
- package/src/utilities/math/polyline/pointCanProjectOnLine.ts +57 -0
- package/src/utilities/math/polyline/pointsAreWithinCloseContourProximity.ts +15 -0
- package/src/utilities/math/rectangle/distanceToPoint.ts +82 -0
- package/src/utilities/math/rectangle/index.ts +3 -0
- package/src/utilities/math/sphere/index.ts +3 -0
- package/src/utilities/math/sphere/pointInSphere.ts +31 -0
- package/src/utilities/math/vec2/findClosestPoint.ts +40 -0
- package/src/utilities/math/vec2/index.ts +4 -0
- package/src/utilities/math/vec2/liangBarksyClip.ts +84 -0
- package/src/utilities/orientation/getOrientationStringLPS.ts +52 -0
- package/src/utilities/orientation/index.ts +4 -0
- package/src/utilities/orientation/invertOrientationStringLPS.ts +21 -0
- package/src/utilities/planar/filterAnnotationsForDisplay.ts +68 -0
- package/src/utilities/planar/filterAnnotationsWithinSlice.ts +85 -0
- package/src/utilities/planar/getPointInLineOfSightWithCriteria.ts +104 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromCorners.ts +51 -0
- package/src/utilities/planar/getWorldWidthAndHeightFromTwoPoints.ts +51 -0
- package/src/utilities/planar/index.ts +18 -0
- package/src/utilities/planarFreehandROITool/index.ts +7 -0
- package/src/utilities/planarFreehandROITool/interpolateAnnotation.ts +87 -0
- package/src/utilities/planarFreehandROITool/interpolatePoints.ts +214 -0
- package/src/utilities/planarFreehandROITool/interpolation/algorithms/bspline.ts +55 -0
- package/src/utilities/planarFreehandROITool/interpolation/interpolateSegmentPoints.ts +90 -0
- package/src/utilities/pointInShapeCallback.ts +138 -0
- package/src/utilities/pointInSurroundingSphereCallback.ts +188 -0
- package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +76 -0
- package/src/utilities/rectangleROITool/index.ts +3 -0
- package/src/utilities/scroll.ts +62 -0
- package/src/utilities/segmentation/brushSizeForToolGroup.ts +72 -0
- package/src/utilities/segmentation/brushThresholdForToolGroup.ts +65 -0
- package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +74 -0
- package/src/utilities/segmentation/createMergedLabelmapForIndex.ts +65 -0
- package/src/utilities/segmentation/floodFill.ts +194 -0
- package/src/utilities/segmentation/getDefaultRepresentationConfig.ts +20 -0
- package/src/utilities/segmentation/index.ts +33 -0
- package/src/utilities/segmentation/isValidRepresentationConfig.ts +22 -0
- package/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +91 -0
- package/src/utilities/segmentation/thresholdSegmentationByRange.ts +129 -0
- package/src/utilities/segmentation/thresholdVolumeByRange.ts +150 -0
- package/src/utilities/segmentation/triggerSegmentationRender.ts +206 -0
- package/src/utilities/segmentation/utilities.ts +116 -0
- package/src/utilities/stackPrefetch/index.ts +8 -0
- package/src/utilities/stackPrefetch/stackPrefetch.ts +405 -0
- package/src/utilities/stackPrefetch/state.ts +17 -0
- package/src/utilities/throttle.js +69 -0
- package/src/utilities/touch/index.ts +246 -0
- package/src/utilities/triggerAnnotationRender.ts +237 -0
- package/src/utilities/triggerAnnotationRenderForViewportIds.ts +18 -0
- package/src/utilities/viewport/index.ts +5 -0
- package/src/utilities/viewport/isViewportPreScaled.ts +24 -0
- package/src/utilities/viewport/jumpToSlice.ts +73 -0
- package/src/utilities/viewport/jumpToWorld.ts +58 -0
- package/src/utilities/viewportFilters/filterViewportsWithFrameOfReferenceUID.ts +28 -0
- package/src/utilities/viewportFilters/filterViewportsWithParallelNormals.ts +26 -0
- package/src/utilities/viewportFilters/filterViewportsWithSameOrientation.ts +15 -0
- package/src/utilities/viewportFilters/filterViewportsWithToolEnabled.ts +72 -0
- package/src/utilities/viewportFilters/getViewportIdsWithToolToRender.ts +45 -0
- package/src/utilities/viewportFilters/index.ts +11 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import cloneDeep from 'lodash.clonedeep';
|
|
2
|
+
import {
|
|
3
|
+
Annotation,
|
|
4
|
+
Annotations,
|
|
5
|
+
AnnotationState,
|
|
6
|
+
GroupSpecificAnnotations,
|
|
7
|
+
} from '../../types/AnnotationTypes';
|
|
8
|
+
|
|
9
|
+
import { AnnotationGroupSelector, IAnnotationManager } from '../../types';
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
Enums,
|
|
13
|
+
eventTarget,
|
|
14
|
+
getEnabledElement,
|
|
15
|
+
Types,
|
|
16
|
+
utilities,
|
|
17
|
+
} from '@cornerstonejs/core';
|
|
18
|
+
|
|
19
|
+
import { checkAndDefineIsLockedProperty } from './annotationLocking';
|
|
20
|
+
import { checkAndDefineIsVisibleProperty } from './annotationVisibility';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is the default annotation manager. It stores annotations by default
|
|
24
|
+
* based on the FrameOfReferenceUID. However, it is possible to override the
|
|
25
|
+
* getAnnotationStateKey function to store annotations based on any other
|
|
26
|
+
* property of the element. When you write your custom annotation manager, you
|
|
27
|
+
* can use the setAnnotationManager function to set your custom annotation.
|
|
28
|
+
*
|
|
29
|
+
* Note that this class is a singleton and should not be instantiated directly.
|
|
30
|
+
* To get the stored annotations information you can use ToolState helpers.
|
|
31
|
+
*/
|
|
32
|
+
class FrameOfReferenceSpecificAnnotationManager implements IAnnotationManager {
|
|
33
|
+
private annotations: AnnotationState;
|
|
34
|
+
public readonly uid: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param uid - The uid of the state manager. If omitted it is autogenerated.
|
|
38
|
+
*/
|
|
39
|
+
constructor(uid?: string) {
|
|
40
|
+
if (!uid) {
|
|
41
|
+
uid = utilities.uuidv4();
|
|
42
|
+
}
|
|
43
|
+
this.annotations = {};
|
|
44
|
+
this.uid = uid;
|
|
45
|
+
|
|
46
|
+
// Listen to the IMAGE_VOLUME_MODIFIED event to invalidate data.
|
|
47
|
+
eventTarget.addEventListener(
|
|
48
|
+
Enums.Events.IMAGE_VOLUME_MODIFIED,
|
|
49
|
+
this._imageVolumeModifiedHandler
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Default annotation manager works with FrameOfReferenceUID as the key. The
|
|
55
|
+
* manager adds them under the FrameOfReferenceUID for the element being
|
|
56
|
+
* annotated.
|
|
57
|
+
*
|
|
58
|
+
* @param annotationGroupSelector - element or a string that is provided
|
|
59
|
+
* to the annotation manager to get the key.
|
|
60
|
+
* @returns - The annotation state key for the element.
|
|
61
|
+
*/
|
|
62
|
+
getGroupKey = (annotationGroupSelector: AnnotationGroupSelector): string => {
|
|
63
|
+
if (typeof annotationGroupSelector === 'string') {
|
|
64
|
+
return annotationGroupSelector;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const element = annotationGroupSelector;
|
|
68
|
+
const enabledElement = getEnabledElement(element);
|
|
69
|
+
|
|
70
|
+
if (!enabledElement) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
'Element not enabled, you must have an enabled element if you are not providing a FrameOfReferenceUID'
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return enabledElement.FrameOfReferenceUID;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* When a volume is modified we invalidate all of the `annotations` on the
|
|
81
|
+
* volume's `FrameOfReferenceUID`. This is mainly to update statistics calculations
|
|
82
|
+
* when an annotation is drawn whilst data is still loading.
|
|
83
|
+
*
|
|
84
|
+
* @param evt - The IMAGE_VOLUME_MODIFIED rendering event.
|
|
85
|
+
*/
|
|
86
|
+
_imageVolumeModifiedHandler = (
|
|
87
|
+
evt: Types.EventTypes.ImageVolumeModifiedEvent
|
|
88
|
+
) => {
|
|
89
|
+
const eventDetail = evt.detail;
|
|
90
|
+
const { FrameOfReferenceUID } = eventDetail;
|
|
91
|
+
|
|
92
|
+
const annotations = this.annotations;
|
|
93
|
+
const frameOfReferenceSpecificAnnotations =
|
|
94
|
+
annotations[FrameOfReferenceUID];
|
|
95
|
+
|
|
96
|
+
if (!frameOfReferenceSpecificAnnotations) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Object.keys(frameOfReferenceSpecificAnnotations).forEach((toolName) => {
|
|
101
|
+
const toolSpecificAnnotations =
|
|
102
|
+
frameOfReferenceSpecificAnnotations[toolName];
|
|
103
|
+
|
|
104
|
+
toolSpecificAnnotations.forEach((annotation) => {
|
|
105
|
+
const invalidated = annotation.invalidated;
|
|
106
|
+
|
|
107
|
+
if (invalidated !== undefined) {
|
|
108
|
+
annotation.invalidated = true;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns all the available frameOfReferences inside the state manager
|
|
116
|
+
* @returns - All the added frames of references inside the manager
|
|
117
|
+
*/
|
|
118
|
+
getFramesOfReference = (): Array<string> => {
|
|
119
|
+
return Object.keys(this.annotations);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Returns the annotations associated with the specified frameOfReference and tool, or
|
|
124
|
+
* all annotations for the group if the tool name is not provided.
|
|
125
|
+
*
|
|
126
|
+
* @param groupKey - The annotation group key to retrieve annotations for (in default manager it is FrameOfReferenceUID).
|
|
127
|
+
* @param toolName - Optional. The name of the tool to retrieve annotations for.
|
|
128
|
+
* @returns The annotations associated with the specified group (default FrameOfReferenceUID) and tool,
|
|
129
|
+
* or all annotations for the group (FrameOfReferenceUID) if the tool name is not provided.
|
|
130
|
+
*/
|
|
131
|
+
getAnnotations = (
|
|
132
|
+
groupKey: string,
|
|
133
|
+
toolName?: string
|
|
134
|
+
): GroupSpecificAnnotations | Annotations => {
|
|
135
|
+
const annotations = this.annotations;
|
|
136
|
+
|
|
137
|
+
if (!annotations[groupKey]) {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (toolName) {
|
|
142
|
+
return annotations[groupKey][toolName];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return annotations[groupKey];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Given the unique identified for the some `annotation`, returns the `annotation`
|
|
150
|
+
* from the `annotations`. Each `annotation` has a unique identifier.
|
|
151
|
+
*
|
|
152
|
+
* @param annotationUID - The unique identifier of the `annotation`.
|
|
153
|
+
* @returns The retrieved `annotation`.
|
|
154
|
+
*/
|
|
155
|
+
getAnnotation = (annotationUID: string): Annotation | undefined => {
|
|
156
|
+
const annotations = this.annotations;
|
|
157
|
+
|
|
158
|
+
for (const frameOfReferenceUID in annotations) {
|
|
159
|
+
const frameOfReferenceAnnotations = annotations[frameOfReferenceUID];
|
|
160
|
+
|
|
161
|
+
for (const toolName in frameOfReferenceAnnotations) {
|
|
162
|
+
const toolSpecificAnnotations = frameOfReferenceAnnotations[toolName];
|
|
163
|
+
|
|
164
|
+
for (const annotation of toolSpecificAnnotations) {
|
|
165
|
+
if (annotationUID === annotation.annotationUID) {
|
|
166
|
+
return annotation;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* A function that returns the number of annotations for a given tool in the
|
|
175
|
+
* specific group (default FrameOfReferenceUID) IF no groupKey (FrameOfReferenceUID) is provided,
|
|
176
|
+
* it will return the number of annotations for the tool in all groups (FrameOfReferenceUIDs)
|
|
177
|
+
*
|
|
178
|
+
* @param groupKey - The annotation group key to retrieve annotations for (in default manager it is FrameOfReferenceUID).
|
|
179
|
+
* @param toolName - The name of the tool to retrieve data for.
|
|
180
|
+
*
|
|
181
|
+
* @returns The number of annotations for a given tool in the state
|
|
182
|
+
*/
|
|
183
|
+
getNumberOfAnnotations = (groupKey: string, toolName?: string): number => {
|
|
184
|
+
const annotations = this.getAnnotations(groupKey, toolName);
|
|
185
|
+
|
|
186
|
+
if (!annotations.length) {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (toolName) {
|
|
191
|
+
return (annotations as Annotations).length;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let total = 0;
|
|
195
|
+
|
|
196
|
+
for (const toolName in annotations) {
|
|
197
|
+
total += annotations[toolName].length;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return total;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Adds an instance of `Annotation` to the `annotations`.
|
|
205
|
+
*
|
|
206
|
+
* @param annotation - The annotation to add.
|
|
207
|
+
* @param groupKey - The annotation group key to add the annotation to (in default manager it is FrameOfReferenceUID).
|
|
208
|
+
*/
|
|
209
|
+
addAnnotation = (annotation: Annotation, groupKey?: string): void => {
|
|
210
|
+
const { metadata } = annotation;
|
|
211
|
+
const { FrameOfReferenceUID, toolName } = metadata;
|
|
212
|
+
|
|
213
|
+
groupKey = groupKey || FrameOfReferenceUID;
|
|
214
|
+
|
|
215
|
+
const annotations = this.annotations;
|
|
216
|
+
|
|
217
|
+
let frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
218
|
+
|
|
219
|
+
if (!frameOfReferenceSpecificAnnotations) {
|
|
220
|
+
annotations[groupKey] = {};
|
|
221
|
+
|
|
222
|
+
frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let toolSpecificAnnotations = frameOfReferenceSpecificAnnotations[toolName];
|
|
226
|
+
|
|
227
|
+
if (!toolSpecificAnnotations) {
|
|
228
|
+
frameOfReferenceSpecificAnnotations[toolName] = [];
|
|
229
|
+
|
|
230
|
+
toolSpecificAnnotations = frameOfReferenceSpecificAnnotations[toolName];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
toolSpecificAnnotations.push(annotation);
|
|
234
|
+
checkAndDefineIsLockedProperty(annotation);
|
|
235
|
+
checkAndDefineIsVisibleProperty(annotation);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Given the unique identified for the some `annotation`, removes the `annotation`
|
|
240
|
+
* from the `annotations`.
|
|
241
|
+
*
|
|
242
|
+
* @param annotationUID - The unique identifier of the `annotation` to remove.
|
|
243
|
+
*/
|
|
244
|
+
removeAnnotation = (annotationUID: string): void => {
|
|
245
|
+
const { annotations } = this;
|
|
246
|
+
|
|
247
|
+
for (const groupKey in annotations) {
|
|
248
|
+
const groupAnnotations = annotations[groupKey];
|
|
249
|
+
|
|
250
|
+
for (const toolName in groupAnnotations) {
|
|
251
|
+
const toolAnnotations = groupAnnotations[toolName];
|
|
252
|
+
|
|
253
|
+
const index = toolAnnotations.findIndex(
|
|
254
|
+
(annotation) => annotation.annotationUID === annotationUID
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
if (index !== -1) {
|
|
258
|
+
toolAnnotations.splice(index, 1);
|
|
259
|
+
|
|
260
|
+
if (toolAnnotations.length === 0) {
|
|
261
|
+
delete groupAnnotations[toolName];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (Object.keys(groupAnnotations).length === 0) {
|
|
267
|
+
delete annotations[groupKey];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Removes all annotations associated with the specified group (FrameOfReferenceUID) and tool, or
|
|
274
|
+
* all annotations for the group (FrameOfReferenceUID) if the tool name is not provided.
|
|
275
|
+
*
|
|
276
|
+
* @param groupKey - The group key to remove annotations for (in default manager it is FrameOfReferenceUID).
|
|
277
|
+
* @param toolName - Optional. The name of the tool to remove annotations for.
|
|
278
|
+
*/
|
|
279
|
+
removeAnnotations = (groupKey: string, toolName?: string): void => {
|
|
280
|
+
const annotations = this.annotations;
|
|
281
|
+
if (annotations[groupKey]) {
|
|
282
|
+
if (toolName) {
|
|
283
|
+
delete annotations[groupKey][toolName];
|
|
284
|
+
} else {
|
|
285
|
+
delete annotations[groupKey];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Returns a section of the annotations. Useful for serialization.
|
|
292
|
+
* If both groupKey (default manager is FrameOfReferenceUID) and toolName are provided, returns the corresponding Annotations instance
|
|
293
|
+
* for that groupKey (FrameOfReferenceUID) and toolName.
|
|
294
|
+
* If only groupKey is provided, returns the corresponding FrameOfReferenceSpecificAnnotations instance
|
|
295
|
+
* for that groupKey.
|
|
296
|
+
* If neither groupKey nor toolName is provided, returns the entire AnnotationState object.
|
|
297
|
+
* @param groupKey - Optional. The group key (e.g. FrameOfReferenceUID) to retrieve annotations for.
|
|
298
|
+
* @param toolName - Optional. The name of the tool to retrieve annotations for.
|
|
299
|
+
* @returns A section of the annotations.
|
|
300
|
+
*/
|
|
301
|
+
saveAnnotations = (
|
|
302
|
+
groupKey?: string,
|
|
303
|
+
toolName?: string
|
|
304
|
+
): AnnotationState | GroupSpecificAnnotations | Annotations => {
|
|
305
|
+
const annotations = this.annotations;
|
|
306
|
+
|
|
307
|
+
if (groupKey && toolName) {
|
|
308
|
+
const frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
309
|
+
|
|
310
|
+
if (!frameOfReferenceSpecificAnnotations) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const toolSpecificAnnotations =
|
|
315
|
+
frameOfReferenceSpecificAnnotations[toolName];
|
|
316
|
+
|
|
317
|
+
return cloneDeep(toolSpecificAnnotations);
|
|
318
|
+
} else if (groupKey) {
|
|
319
|
+
const frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
320
|
+
|
|
321
|
+
return cloneDeep(frameOfReferenceSpecificAnnotations);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return cloneDeep(annotations);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Restores a section of the `annotations`. Useful for loading in serialized data.
|
|
329
|
+
*
|
|
330
|
+
* - If no arguments are given, the entire `AnnotationState` instance is restored.
|
|
331
|
+
* - If the `FrameOfReferenceUID` is given, the corresponding
|
|
332
|
+
* `FrameOfReferenceSpecificAnnotations` instance is restored.
|
|
333
|
+
* - If both the `FrameOfReferenceUID` and the `toolName` are are given, the
|
|
334
|
+
* corresponding `Annotations` instance is restored.
|
|
335
|
+
*
|
|
336
|
+
* @param groupKey - A filter string for restoring only the `annotations` of a specific frame of reference.
|
|
337
|
+
* @param toolName - A filter string for restoring `annotation` for a specific tool on a specific frame of reference.
|
|
338
|
+
*/
|
|
339
|
+
restoreAnnotations = (
|
|
340
|
+
state: AnnotationState | GroupSpecificAnnotations | Annotations,
|
|
341
|
+
groupKey?: string,
|
|
342
|
+
toolName?: string
|
|
343
|
+
): void => {
|
|
344
|
+
const annotations = this.annotations;
|
|
345
|
+
|
|
346
|
+
if (groupKey && toolName) {
|
|
347
|
+
// Set Annotations for FrameOfReferenceUID and toolName.
|
|
348
|
+
|
|
349
|
+
let frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
350
|
+
|
|
351
|
+
if (!frameOfReferenceSpecificAnnotations) {
|
|
352
|
+
annotations[groupKey] = {};
|
|
353
|
+
|
|
354
|
+
frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
frameOfReferenceSpecificAnnotations[toolName] = <Annotations>state;
|
|
358
|
+
} else if (groupKey) {
|
|
359
|
+
// Set FrameOfReferenceSpecificAnnotations for FrameOfReferenceUID.
|
|
360
|
+
|
|
361
|
+
annotations[groupKey] = <GroupSpecificAnnotations>state;
|
|
362
|
+
} else {
|
|
363
|
+
// Set entire annotations
|
|
364
|
+
this.annotations = <AnnotationState>cloneDeep(state);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* A function that returns the number of all annotations in the annotation state
|
|
370
|
+
*
|
|
371
|
+
* @returns The number of all annotations in the state
|
|
372
|
+
*/
|
|
373
|
+
getNumberOfAllAnnotations = (): number => {
|
|
374
|
+
let count = 0;
|
|
375
|
+
const annotations = this.annotations;
|
|
376
|
+
for (const groupKey in annotations) {
|
|
377
|
+
const frameOfReferenceSpecificAnnotations = annotations[groupKey];
|
|
378
|
+
for (const toolName in frameOfReferenceSpecificAnnotations) {
|
|
379
|
+
const toolSpecificAnnotations =
|
|
380
|
+
frameOfReferenceSpecificAnnotations[toolName];
|
|
381
|
+
count += toolSpecificAnnotations.length;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return count;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Removes all annotations in the annotation state.
|
|
389
|
+
*/
|
|
390
|
+
removeAllAnnotations = (): void => {
|
|
391
|
+
this.annotations = {};
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const defaultFrameOfReferenceSpecificAnnotationManager =
|
|
396
|
+
new FrameOfReferenceSpecificAnnotationManager('DEFAULT');
|
|
397
|
+
|
|
398
|
+
export { defaultFrameOfReferenceSpecificAnnotationManager };
|
|
399
|
+
export default FrameOfReferenceSpecificAnnotationManager;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { eventTarget, triggerEvent } from '@cornerstonejs/core';
|
|
2
|
+
import { Events } from '../../enums';
|
|
3
|
+
import { Annotation } from '../../types';
|
|
4
|
+
import { AnnotationLockChangeEventDetail } from '../../types/EventTypes';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Constants
|
|
8
|
+
*/
|
|
9
|
+
const globalLockedAnnotationsSet: Set<Annotation> = new Set();
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
* Interface (Public API)
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Set the "Locked" state of a given annotation instance.
|
|
17
|
+
*
|
|
18
|
+
* @triggers ANNOTATION_LOCK_CHANGE
|
|
19
|
+
*
|
|
20
|
+
* @param annotation - The annotation instance which will have
|
|
21
|
+
* its locked state changed. An event will only be triggered if the locked state
|
|
22
|
+
* of the given annotation instance changed.
|
|
23
|
+
* @param locked - A boolean value indicating if the instance should
|
|
24
|
+
* be locked (true) or not (false)
|
|
25
|
+
*/
|
|
26
|
+
function setAnnotationLocked(annotation: Annotation, locked = true): void {
|
|
27
|
+
const detail = makeEventDetail();
|
|
28
|
+
if (annotation) {
|
|
29
|
+
if (locked) {
|
|
30
|
+
lock(annotation, globalLockedAnnotationsSet, detail);
|
|
31
|
+
} else {
|
|
32
|
+
unlock(annotation, globalLockedAnnotationsSet, detail);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
publish(detail, globalLockedAnnotationsSet);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Clears all the locked annotation
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
function unlockAllAnnotations(): void {
|
|
43
|
+
const detail = makeEventDetail();
|
|
44
|
+
clearLockedAnnotationsSet(globalLockedAnnotationsSet, detail);
|
|
45
|
+
publish(detail, globalLockedAnnotationsSet);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns an array of all the annotation that is currently locked
|
|
50
|
+
* @returns An array of tool specific annotation objects.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
function getAnnotationsLocked(): Array<Annotation> {
|
|
54
|
+
return Array.from(globalLockedAnnotationsSet);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Given a Annotation object, return true if it is locked.
|
|
59
|
+
* @param annotation - Annotation
|
|
60
|
+
* @returns A boolean value.
|
|
61
|
+
*/
|
|
62
|
+
function isAnnotationLocked(annotation: Annotation): boolean {
|
|
63
|
+
return globalLockedAnnotationsSet.has(annotation);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get the number of locked annotation objects in the global set of locked annotation
|
|
68
|
+
* objects.
|
|
69
|
+
* @returns The number of locked annotation objects.
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
function getAnnotationsLockedCount(): number {
|
|
73
|
+
return globalLockedAnnotationsSet.size;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Properly initialize the isLocked on annotation, and set it as locked if
|
|
78
|
+
* isLocked is true.
|
|
79
|
+
* @param annotation - The annotation object to be checked.
|
|
80
|
+
*/
|
|
81
|
+
function checkAndDefineIsLockedProperty(annotation: Annotation): void {
|
|
82
|
+
if (annotation) {
|
|
83
|
+
const isLocked = !!annotation.isLocked;
|
|
84
|
+
if (shouldDefineIsLockedProperty(annotation)) {
|
|
85
|
+
Object.defineProperty(annotation, 'isLocked', {
|
|
86
|
+
configurable: false,
|
|
87
|
+
enumerable: true,
|
|
88
|
+
set: setIsLocked,
|
|
89
|
+
get: getIsLocked,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
setAnnotationLocked(annotation, isLocked);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* Private Helpers
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
function makeEventDetail(): AnnotationLockChangeEventDetail {
|
|
101
|
+
return Object.freeze({
|
|
102
|
+
added: [],
|
|
103
|
+
removed: [],
|
|
104
|
+
locked: [],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function lock(
|
|
109
|
+
annotation: Annotation,
|
|
110
|
+
lockedAnnotationsSet: Set<Annotation>,
|
|
111
|
+
detail: AnnotationLockChangeEventDetail
|
|
112
|
+
): void {
|
|
113
|
+
if (!lockedAnnotationsSet.has(annotation)) {
|
|
114
|
+
lockedAnnotationsSet.add(annotation);
|
|
115
|
+
detail.added.push(annotation);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function unlock(
|
|
120
|
+
annotation: Annotation,
|
|
121
|
+
lockedAnnotationsSet: Set<Annotation>,
|
|
122
|
+
detail: AnnotationLockChangeEventDetail
|
|
123
|
+
): void {
|
|
124
|
+
if (lockedAnnotationsSet.delete(annotation)) {
|
|
125
|
+
detail.removed.push(annotation);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function clearLockedAnnotationsSet(
|
|
130
|
+
lockedAnnotationsSet: Set<Annotation>,
|
|
131
|
+
detail: AnnotationLockChangeEventDetail
|
|
132
|
+
): void {
|
|
133
|
+
lockedAnnotationsSet.forEach((annotation) => {
|
|
134
|
+
unlock(annotation, lockedAnnotationsSet, detail);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function publish(
|
|
139
|
+
detail: AnnotationLockChangeEventDetail,
|
|
140
|
+
lockedAnnotationsSet: Set<Annotation>
|
|
141
|
+
) {
|
|
142
|
+
if (detail.added.length > 0 || detail.removed.length > 0) {
|
|
143
|
+
lockedAnnotationsSet.forEach((item) => void detail.locked.push(item));
|
|
144
|
+
triggerEvent(eventTarget, Events.ANNOTATION_LOCK_CHANGE, detail);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function shouldDefineIsLockedProperty(annotation: Annotation): boolean {
|
|
149
|
+
const descriptor = Object.getOwnPropertyDescriptor(annotation, 'isLocked');
|
|
150
|
+
if (descriptor) {
|
|
151
|
+
return (
|
|
152
|
+
descriptor.configurable &&
|
|
153
|
+
(descriptor.set !== setIsLocked || descriptor.get !== getIsLocked)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
return Object.isExtensible(annotation);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function setIsLocked(locked: boolean) {
|
|
160
|
+
setAnnotationLocked(this as Annotation, locked);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getIsLocked() {
|
|
164
|
+
return isAnnotationLocked(this as Annotation);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
* Exports
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
setAnnotationLocked,
|
|
173
|
+
getAnnotationsLocked,
|
|
174
|
+
getAnnotationsLockedCount,
|
|
175
|
+
unlockAllAnnotations,
|
|
176
|
+
isAnnotationLocked,
|
|
177
|
+
checkAndDefineIsLockedProperty,
|
|
178
|
+
};
|