@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,685 @@
|
|
|
1
|
+
import AnnotationDisplayTool from './base/AnnotationDisplayTool';
|
|
2
|
+
import { vec3 } from 'gl-matrix';
|
|
3
|
+
import {
|
|
4
|
+
getEnabledElementByIds,
|
|
5
|
+
getRenderingEngines,
|
|
6
|
+
utilities as csUtils,
|
|
7
|
+
} from '@cornerstonejs/core';
|
|
8
|
+
import { ScaleOverlayAnnotation } from '../types/ToolSpecificAnnotationTypes';
|
|
9
|
+
import type { Types } from '@cornerstonejs/core';
|
|
10
|
+
import {
|
|
11
|
+
addAnnotation,
|
|
12
|
+
getAnnotations,
|
|
13
|
+
} from '../stateManagement/annotation/annotationState';
|
|
14
|
+
import {
|
|
15
|
+
drawLine as drawLineSvg,
|
|
16
|
+
drawTextBox as drawTextBoxSvg,
|
|
17
|
+
} from '../drawingSvg';
|
|
18
|
+
import {
|
|
19
|
+
EventTypes,
|
|
20
|
+
PublicToolProps,
|
|
21
|
+
ToolProps,
|
|
22
|
+
SVGDrawingHelper,
|
|
23
|
+
} from '../types';
|
|
24
|
+
import { StyleSpecifier } from '../types/AnnotationStyle';
|
|
25
|
+
import { getToolGroup } from '../store/ToolGroupManager';
|
|
26
|
+
|
|
27
|
+
const SCALEOVERLAYTOOL_ID = 'scaleoverlay-viewport';
|
|
28
|
+
const viewportsWithAnnotations = [];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @public
|
|
32
|
+
* @class ScaleOverlayTool
|
|
33
|
+
* @memberof Tools
|
|
34
|
+
*
|
|
35
|
+
* @classdesc Tool for displaying a scale overlay on the image.
|
|
36
|
+
* @extends Tools.Base.BaseTool
|
|
37
|
+
*/
|
|
38
|
+
class ScaleOverlayTool extends AnnotationDisplayTool {
|
|
39
|
+
static toolName;
|
|
40
|
+
|
|
41
|
+
public touchDragCallback: any;
|
|
42
|
+
public mouseDragCallback: any;
|
|
43
|
+
_throttledCalculateCachedStats: any;
|
|
44
|
+
editData: {
|
|
45
|
+
renderingEngine: any;
|
|
46
|
+
viewport: any;
|
|
47
|
+
annotation: ScaleOverlayAnnotation;
|
|
48
|
+
} | null = {} as any;
|
|
49
|
+
isDrawing: boolean;
|
|
50
|
+
isHandleOutsideImage: boolean;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
toolProps: PublicToolProps = {},
|
|
54
|
+
defaultToolProps: ToolProps = {
|
|
55
|
+
configuration: {
|
|
56
|
+
viewportId: '',
|
|
57
|
+
scaleLocation: 'bottom',
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
) {
|
|
61
|
+
super(toolProps, defaultToolProps);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_init = (): void => {
|
|
65
|
+
const renderingEngines = getRenderingEngines();
|
|
66
|
+
const renderingEngine = renderingEngines[0];
|
|
67
|
+
|
|
68
|
+
if (!renderingEngine) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// get viewports with tool enabled
|
|
73
|
+
const viewportIds = getToolGroup(this.toolGroupId).viewportsInfo;
|
|
74
|
+
|
|
75
|
+
if (!viewportIds) return;
|
|
76
|
+
|
|
77
|
+
// get enabled elements
|
|
78
|
+
const enabledElements = viewportIds.map((e) =>
|
|
79
|
+
getEnabledElementByIds(e.viewportId, e.renderingEngineId)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
let { viewport } = enabledElements[0];
|
|
83
|
+
const { FrameOfReferenceUID } = enabledElements[0];
|
|
84
|
+
|
|
85
|
+
// onCameraModified, configuration.viewportId is set to the active
|
|
86
|
+
// viewport Id, here we are setting the viewport variable to the
|
|
87
|
+
// viewport with the matching Id
|
|
88
|
+
if (this.configuration.viewportId) {
|
|
89
|
+
enabledElements.forEach((element) => {
|
|
90
|
+
if (element.viewport.id == this.configuration.viewportId) {
|
|
91
|
+
viewport = element.viewport;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!viewport) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { viewUp, viewPlaneNormal } = viewport.getCamera();
|
|
101
|
+
|
|
102
|
+
const viewportCanvasCornersInWorld =
|
|
103
|
+
csUtils.getViewportImageCornersInWorld(viewport);
|
|
104
|
+
|
|
105
|
+
let annotation = this.editData.annotation;
|
|
106
|
+
|
|
107
|
+
const annotations = getAnnotations(this.getToolName(), viewport.element);
|
|
108
|
+
|
|
109
|
+
// if annotations have been created, get the annotation for the
|
|
110
|
+
// current viewport Id
|
|
111
|
+
if (annotations.length) {
|
|
112
|
+
annotation = annotations.filter(
|
|
113
|
+
(thisAnnotation) => thisAnnotation.data.viewportId == viewport.id
|
|
114
|
+
)[0] as ScaleOverlayAnnotation;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// viewportsWithAnnotations stores which viewports have an annotation,
|
|
118
|
+
// if the viewport does not have an annotation, create a new one
|
|
119
|
+
if (!viewportsWithAnnotations.includes(viewport.id)) {
|
|
120
|
+
const newAnnotation: ScaleOverlayAnnotation = {
|
|
121
|
+
metadata: {
|
|
122
|
+
toolName: this.getToolName(),
|
|
123
|
+
viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
|
|
124
|
+
viewUp: <Types.Point3>[...viewUp],
|
|
125
|
+
FrameOfReferenceUID,
|
|
126
|
+
referencedImageId: null,
|
|
127
|
+
},
|
|
128
|
+
data: {
|
|
129
|
+
handles: {
|
|
130
|
+
points: viewportCanvasCornersInWorld,
|
|
131
|
+
},
|
|
132
|
+
viewportId: viewport.id,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
viewportsWithAnnotations.push(viewport.id);
|
|
137
|
+
|
|
138
|
+
addAnnotation(newAnnotation, viewport.element);
|
|
139
|
+
annotation = newAnnotation;
|
|
140
|
+
} else if (this.editData.annotation.data.viewportId == viewport.id) {
|
|
141
|
+
this.editData.annotation.data.handles.points =
|
|
142
|
+
viewportCanvasCornersInWorld;
|
|
143
|
+
this.editData.annotation.data.viewportId = viewport.id;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this.editData = {
|
|
147
|
+
viewport,
|
|
148
|
+
renderingEngine,
|
|
149
|
+
annotation,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
onSetToolEnabled = (): void => {
|
|
154
|
+
this._init();
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
onCameraModified = (evt: Types.EventTypes.CameraModifiedEvent): void => {
|
|
158
|
+
// If the camera is modified, we need to update the viewport
|
|
159
|
+
// that the camera was modified on
|
|
160
|
+
this.configuration.viewportId = evt.detail.viewportId;
|
|
161
|
+
this._init();
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Used to draw the scale annotation in each request animation
|
|
166
|
+
* frame.
|
|
167
|
+
*
|
|
168
|
+
* @param enabledElement - The Cornerstone's enabledElement.
|
|
169
|
+
* @param svgDrawingHelper - The svgDrawingHelper providing the context for drawing.
|
|
170
|
+
* @returns
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
renderAnnotation(
|
|
174
|
+
enabledElement: Types.IEnabledElement,
|
|
175
|
+
svgDrawingHelper: SVGDrawingHelper
|
|
176
|
+
) {
|
|
177
|
+
if (!this.editData.viewport) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const location = this.configuration.scaleLocation;
|
|
181
|
+
const { viewport } = enabledElement;
|
|
182
|
+
|
|
183
|
+
const annotations = getAnnotations(this.getToolName(), viewport.element);
|
|
184
|
+
const annotation = annotations.filter(
|
|
185
|
+
(thisAnnotation) => thisAnnotation.data.viewportId == viewport.id
|
|
186
|
+
)[0];
|
|
187
|
+
const canvas = enabledElement.viewport.canvas;
|
|
188
|
+
|
|
189
|
+
const renderStatus = false;
|
|
190
|
+
|
|
191
|
+
if (!viewport) {
|
|
192
|
+
return renderStatus;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const styleSpecifier: StyleSpecifier = {
|
|
196
|
+
toolGroupId: this.toolGroupId,
|
|
197
|
+
toolName: this.getToolName(),
|
|
198
|
+
viewportId: enabledElement.viewport.id,
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const canvasSize = {
|
|
202
|
+
width: canvas.width,
|
|
203
|
+
height: canvas.height,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const topLeft = annotation.data.handles.points[0];
|
|
207
|
+
const topRight = annotation.data.handles.points[1];
|
|
208
|
+
const bottomLeft = annotation.data.handles.points[2];
|
|
209
|
+
const bottomRight = annotation.data.handles.points[3];
|
|
210
|
+
|
|
211
|
+
const pointSet1 = [topLeft, bottomLeft, topRight, bottomRight];
|
|
212
|
+
|
|
213
|
+
const worldWidthViewport = vec3.distance(bottomLeft, bottomRight);
|
|
214
|
+
const worldHeightViewport = vec3.distance(topLeft, bottomLeft);
|
|
215
|
+
|
|
216
|
+
// hscaleBounds and vscaleBounds compute the max bound for scales on the image
|
|
217
|
+
const hscaleBounds = this.computeScaleBounds(
|
|
218
|
+
canvasSize,
|
|
219
|
+
0.05,
|
|
220
|
+
0.05,
|
|
221
|
+
location
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const vscaleBounds = this.computeScaleBounds(
|
|
225
|
+
canvasSize,
|
|
226
|
+
0.05,
|
|
227
|
+
0.05,
|
|
228
|
+
location
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
// Computes which scale size to use, ex: 100mm, 50mm
|
|
232
|
+
const scaleSize = this.computeScaleSize(
|
|
233
|
+
worldWidthViewport,
|
|
234
|
+
worldHeightViewport,
|
|
235
|
+
location
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Applies the scale with the predetermined size to the image in
|
|
239
|
+
// world coordinates, then converts them to canvas coordinates
|
|
240
|
+
const canvasCoordinates = this.computeWorldScaleCoordinates(
|
|
241
|
+
scaleSize,
|
|
242
|
+
location,
|
|
243
|
+
pointSet1
|
|
244
|
+
).map((world) => viewport.worldToCanvas(world));
|
|
245
|
+
|
|
246
|
+
// Uses the bounds and canvas size to center the scale
|
|
247
|
+
// based on the location
|
|
248
|
+
const scaleCanvasCoordinates = this.computeCanvasScaleCoordinates(
|
|
249
|
+
canvasSize,
|
|
250
|
+
canvasCoordinates,
|
|
251
|
+
vscaleBounds,
|
|
252
|
+
hscaleBounds,
|
|
253
|
+
location
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Computes the end scale ticks coordinates
|
|
257
|
+
const scaleTicks = this.computeEndScaleTicks(
|
|
258
|
+
scaleCanvasCoordinates,
|
|
259
|
+
location
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
const { annotationUID } = annotation;
|
|
263
|
+
|
|
264
|
+
styleSpecifier.annotationUID = annotationUID;
|
|
265
|
+
const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
|
|
266
|
+
const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
|
|
267
|
+
const color = this.getStyle('color', styleSpecifier, annotation);
|
|
268
|
+
const shadow = this.getStyle('shadow', styleSpecifier, annotation);
|
|
269
|
+
|
|
270
|
+
const scaleId = `${annotationUID}-scaleline`;
|
|
271
|
+
const scaleLineUID = '1';
|
|
272
|
+
drawLineSvg(
|
|
273
|
+
svgDrawingHelper,
|
|
274
|
+
annotationUID,
|
|
275
|
+
scaleLineUID,
|
|
276
|
+
scaleCanvasCoordinates[0],
|
|
277
|
+
scaleCanvasCoordinates[1],
|
|
278
|
+
{
|
|
279
|
+
color,
|
|
280
|
+
width: lineWidth,
|
|
281
|
+
lineDash,
|
|
282
|
+
shadow,
|
|
283
|
+
},
|
|
284
|
+
scaleId
|
|
285
|
+
);
|
|
286
|
+
const leftTickId = `${annotationUID}-left`;
|
|
287
|
+
const leftTickUID = '2';
|
|
288
|
+
|
|
289
|
+
drawLineSvg(
|
|
290
|
+
svgDrawingHelper,
|
|
291
|
+
annotationUID,
|
|
292
|
+
leftTickUID,
|
|
293
|
+
scaleTicks.endTick1[0] as Types.Point2,
|
|
294
|
+
scaleTicks.endTick1[1] as Types.Point2,
|
|
295
|
+
{
|
|
296
|
+
color,
|
|
297
|
+
width: lineWidth,
|
|
298
|
+
lineDash,
|
|
299
|
+
shadow,
|
|
300
|
+
},
|
|
301
|
+
leftTickId
|
|
302
|
+
);
|
|
303
|
+
const rightTickId = `${annotationUID}-right`;
|
|
304
|
+
const rightTickUID = '3';
|
|
305
|
+
|
|
306
|
+
drawLineSvg(
|
|
307
|
+
svgDrawingHelper,
|
|
308
|
+
annotationUID,
|
|
309
|
+
rightTickUID,
|
|
310
|
+
scaleTicks.endTick2[0] as Types.Point2,
|
|
311
|
+
scaleTicks.endTick2[1] as Types.Point2,
|
|
312
|
+
{
|
|
313
|
+
color,
|
|
314
|
+
width: lineWidth,
|
|
315
|
+
lineDash,
|
|
316
|
+
shadow,
|
|
317
|
+
},
|
|
318
|
+
rightTickId
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const locationTextOffest = {
|
|
322
|
+
bottom: [-10, -42],
|
|
323
|
+
top: [-12, -35],
|
|
324
|
+
left: [-40, -20],
|
|
325
|
+
right: [-50, -20],
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const textCanvasCoordinates = [
|
|
329
|
+
scaleCanvasCoordinates[0][0] + locationTextOffest[location][0],
|
|
330
|
+
scaleCanvasCoordinates[0][1] + locationTextOffest[location][1],
|
|
331
|
+
];
|
|
332
|
+
const textBoxLines = this._getTextLines(scaleSize);
|
|
333
|
+
|
|
334
|
+
const { tickIds, tickUIDs, tickCoordinates } = this.computeInnerScaleTicks(
|
|
335
|
+
scaleSize,
|
|
336
|
+
location,
|
|
337
|
+
annotationUID,
|
|
338
|
+
scaleTicks.endTick1,
|
|
339
|
+
scaleTicks.endTick2
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
// draws inner ticks for scale
|
|
343
|
+
for (let i = 0; i < tickUIDs.length; i++) {
|
|
344
|
+
drawLineSvg(
|
|
345
|
+
svgDrawingHelper,
|
|
346
|
+
annotationUID,
|
|
347
|
+
tickUIDs[i],
|
|
348
|
+
tickCoordinates[i][0],
|
|
349
|
+
tickCoordinates[i][1],
|
|
350
|
+
{
|
|
351
|
+
color,
|
|
352
|
+
width: lineWidth,
|
|
353
|
+
lineDash,
|
|
354
|
+
shadow,
|
|
355
|
+
},
|
|
356
|
+
tickIds[i]
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const textUID = 'text0';
|
|
361
|
+
drawTextBoxSvg(
|
|
362
|
+
svgDrawingHelper,
|
|
363
|
+
annotationUID,
|
|
364
|
+
textUID,
|
|
365
|
+
textBoxLines,
|
|
366
|
+
[textCanvasCoordinates[0], textCanvasCoordinates[1]],
|
|
367
|
+
{
|
|
368
|
+
fontFamily: 'Helvetica Neue, Helvetica, Arial, sans-serif',
|
|
369
|
+
fontSize: '14px',
|
|
370
|
+
lineDash: '2,3',
|
|
371
|
+
lineWidth: '1',
|
|
372
|
+
shadow: true,
|
|
373
|
+
color: color,
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
return renderStatus;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
_getTextLines(scaleSize: number): string[] | undefined {
|
|
381
|
+
let scaleSizeDisplayValue;
|
|
382
|
+
let scaleSizeUnits;
|
|
383
|
+
if (scaleSize >= 50) {
|
|
384
|
+
scaleSizeDisplayValue = scaleSize / 10; //convert to cm
|
|
385
|
+
scaleSizeUnits = ' cm';
|
|
386
|
+
} else {
|
|
387
|
+
scaleSizeDisplayValue = scaleSize; //convert to cm
|
|
388
|
+
scaleSizeUnits = ' mm';
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const textLines = [scaleSizeDisplayValue.toString().concat(scaleSizeUnits)];
|
|
392
|
+
|
|
393
|
+
return textLines;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
*
|
|
398
|
+
* @param worldWidthViewport
|
|
399
|
+
* @returns currentScaleSize
|
|
400
|
+
*/
|
|
401
|
+
computeScaleSize = (
|
|
402
|
+
worldWidthViewport: number,
|
|
403
|
+
worldHeightViewport: number,
|
|
404
|
+
location: any
|
|
405
|
+
) => {
|
|
406
|
+
const scaleSizes = [
|
|
407
|
+
16000, 8000, 4000, 2000, 1000, 500, 250, 100, 50, 25, 10, 5, 2,
|
|
408
|
+
];
|
|
409
|
+
let currentScaleSize;
|
|
410
|
+
if (location == 'top' || location == 'bottom') {
|
|
411
|
+
currentScaleSize = scaleSizes.filter(
|
|
412
|
+
(scaleSize) =>
|
|
413
|
+
scaleSize < worldWidthViewport * 0.6 &&
|
|
414
|
+
scaleSize > worldWidthViewport * 0.2
|
|
415
|
+
);
|
|
416
|
+
} else {
|
|
417
|
+
currentScaleSize = scaleSizes.filter(
|
|
418
|
+
(scaleSize) =>
|
|
419
|
+
scaleSize < worldHeightViewport * 0.6 &&
|
|
420
|
+
scaleSize > worldHeightViewport * 0.2
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return currentScaleSize[0];
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* calculates scale ticks for ends of the scale
|
|
429
|
+
* @param canvasCoordinates
|
|
430
|
+
* @returns leftTick, rightTick
|
|
431
|
+
*/
|
|
432
|
+
computeEndScaleTicks = (canvasCoordinates, location) => {
|
|
433
|
+
const locationTickOffset = {
|
|
434
|
+
bottom: [
|
|
435
|
+
[0, -10],
|
|
436
|
+
[0, -10],
|
|
437
|
+
],
|
|
438
|
+
top: [
|
|
439
|
+
[0, 10],
|
|
440
|
+
[0, 10],
|
|
441
|
+
],
|
|
442
|
+
left: [
|
|
443
|
+
[0, 0],
|
|
444
|
+
[10, 0],
|
|
445
|
+
],
|
|
446
|
+
right: [
|
|
447
|
+
[0, 0],
|
|
448
|
+
[-10, 0],
|
|
449
|
+
],
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const endTick1 = [
|
|
453
|
+
[
|
|
454
|
+
canvasCoordinates[1][0] + locationTickOffset[location][0][0],
|
|
455
|
+
canvasCoordinates[1][1] + locationTickOffset[location][0][0],
|
|
456
|
+
],
|
|
457
|
+
[
|
|
458
|
+
canvasCoordinates[1][0] + locationTickOffset[location][1][0],
|
|
459
|
+
canvasCoordinates[1][1] + locationTickOffset[location][1][1],
|
|
460
|
+
],
|
|
461
|
+
];
|
|
462
|
+
const endTick2 = [
|
|
463
|
+
[
|
|
464
|
+
canvasCoordinates[0][0] + locationTickOffset[location][0][0],
|
|
465
|
+
canvasCoordinates[0][1] + locationTickOffset[location][0][0],
|
|
466
|
+
],
|
|
467
|
+
[
|
|
468
|
+
canvasCoordinates[0][0] + locationTickOffset[location][1][0],
|
|
469
|
+
canvasCoordinates[0][1] + locationTickOffset[location][1][1],
|
|
470
|
+
],
|
|
471
|
+
];
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
endTick1: endTick1,
|
|
475
|
+
endTick2: endTick2,
|
|
476
|
+
};
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
computeInnerScaleTicks = (
|
|
480
|
+
scaleSize: number,
|
|
481
|
+
location: string,
|
|
482
|
+
annotationUID: string,
|
|
483
|
+
leftTick: any[][],
|
|
484
|
+
rightTick: any[][]
|
|
485
|
+
) => {
|
|
486
|
+
let canvasScaleSize;
|
|
487
|
+
if (location == 'bottom' || location == 'top') {
|
|
488
|
+
canvasScaleSize = rightTick[0][0] - leftTick[0][0];
|
|
489
|
+
} else if (location == 'left' || location == 'right') {
|
|
490
|
+
canvasScaleSize = rightTick[0][1] - leftTick[0][1];
|
|
491
|
+
}
|
|
492
|
+
const tickIds = [];
|
|
493
|
+
const tickUIDs = [];
|
|
494
|
+
const tickCoordinates = [];
|
|
495
|
+
let numberSmallTicks = scaleSize;
|
|
496
|
+
|
|
497
|
+
if (scaleSize >= 50) {
|
|
498
|
+
numberSmallTicks = scaleSize / 10;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const tickSpacing = canvasScaleSize / numberSmallTicks;
|
|
502
|
+
|
|
503
|
+
for (let i = 0; i < numberSmallTicks - 1; i++) {
|
|
504
|
+
const locationOffset = {
|
|
505
|
+
bottom: [
|
|
506
|
+
[tickSpacing * (i + 1), 0],
|
|
507
|
+
[tickSpacing * (i + 1), 5],
|
|
508
|
+
],
|
|
509
|
+
top: [
|
|
510
|
+
[tickSpacing * (i + 1), 0],
|
|
511
|
+
[tickSpacing * (i + 1), -5],
|
|
512
|
+
],
|
|
513
|
+
left: [
|
|
514
|
+
[0, tickSpacing * (i + 1)],
|
|
515
|
+
[-5, tickSpacing * (i + 1)],
|
|
516
|
+
],
|
|
517
|
+
right: [
|
|
518
|
+
[0, tickSpacing * (i + 1)],
|
|
519
|
+
[5, tickSpacing * (i + 1)],
|
|
520
|
+
],
|
|
521
|
+
};
|
|
522
|
+
tickIds.push(`${annotationUID}-tick${i}`);
|
|
523
|
+
tickUIDs.push(`tick${i}`);
|
|
524
|
+
if ((i + 1) % 5 == 0) {
|
|
525
|
+
tickCoordinates.push([
|
|
526
|
+
[
|
|
527
|
+
leftTick[0][0] + locationOffset[location][0][0],
|
|
528
|
+
leftTick[0][1] + locationOffset[location][0][1],
|
|
529
|
+
],
|
|
530
|
+
[
|
|
531
|
+
leftTick[1][0] + locationOffset[location][0][0],
|
|
532
|
+
leftTick[1][1] + locationOffset[location][0][1],
|
|
533
|
+
],
|
|
534
|
+
]);
|
|
535
|
+
} else {
|
|
536
|
+
tickCoordinates.push([
|
|
537
|
+
[
|
|
538
|
+
leftTick[0][0] + locationOffset[location][0][0],
|
|
539
|
+
leftTick[0][1] + locationOffset[location][0][1],
|
|
540
|
+
],
|
|
541
|
+
[
|
|
542
|
+
leftTick[1][0] + locationOffset[location][1][0],
|
|
543
|
+
leftTick[1][1] + locationOffset[location][1][1],
|
|
544
|
+
],
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return { tickIds, tickUIDs, tickCoordinates };
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
computeWorldScaleCoordinates = (scaleSize, location, pointSet) => {
|
|
553
|
+
let worldCoordinates;
|
|
554
|
+
let topBottomVec = vec3.subtract(vec3.create(), pointSet[0], pointSet[1]);
|
|
555
|
+
topBottomVec = vec3.normalize(vec3.create(), topBottomVec) as Types.Point3;
|
|
556
|
+
|
|
557
|
+
let topRightVec = vec3.subtract(vec3.create(), pointSet[2], pointSet[0]);
|
|
558
|
+
topRightVec = vec3.normalize(vec3.create(), topRightVec);
|
|
559
|
+
|
|
560
|
+
const midpointLocation = {
|
|
561
|
+
bottom: [pointSet[1], pointSet[2]],
|
|
562
|
+
top: [pointSet[0], pointSet[3]],
|
|
563
|
+
right: [pointSet[2], pointSet[3]],
|
|
564
|
+
left: [pointSet[0], pointSet[1]],
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const midpoint = vec3
|
|
568
|
+
.add(
|
|
569
|
+
vec3.create(),
|
|
570
|
+
midpointLocation[location][0],
|
|
571
|
+
midpointLocation[location][0]
|
|
572
|
+
)
|
|
573
|
+
.map((i) => i / 2) as Types.Point3;
|
|
574
|
+
|
|
575
|
+
const offset =
|
|
576
|
+
scaleSize /
|
|
577
|
+
2 /
|
|
578
|
+
Math.sqrt(
|
|
579
|
+
Math.pow(topBottomVec[0], 2) +
|
|
580
|
+
Math.pow(topBottomVec[1], 2) +
|
|
581
|
+
Math.pow(topBottomVec[2], 2)
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
if (location == 'top' || location == 'bottom') {
|
|
585
|
+
worldCoordinates = [
|
|
586
|
+
vec3.subtract(
|
|
587
|
+
vec3.create(),
|
|
588
|
+
midpoint,
|
|
589
|
+
topRightVec.map((i) => i * offset) as Types.Point3
|
|
590
|
+
),
|
|
591
|
+
vec3.add(
|
|
592
|
+
vec3.create(),
|
|
593
|
+
midpoint,
|
|
594
|
+
topRightVec.map((i) => i * offset) as Types.Point3
|
|
595
|
+
),
|
|
596
|
+
];
|
|
597
|
+
} else if (location == 'left' || location == 'right') {
|
|
598
|
+
worldCoordinates = [
|
|
599
|
+
vec3.add(
|
|
600
|
+
vec3.create(),
|
|
601
|
+
midpoint,
|
|
602
|
+
topBottomVec.map((i) => i * offset) as Types.Point3
|
|
603
|
+
),
|
|
604
|
+
vec3.subtract(
|
|
605
|
+
vec3.create(),
|
|
606
|
+
midpoint,
|
|
607
|
+
topBottomVec.map((i) => i * offset) as Types.Point3
|
|
608
|
+
),
|
|
609
|
+
];
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return worldCoordinates;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Computes the centered canvas coordinates for scale
|
|
617
|
+
* @param canvasSize
|
|
618
|
+
* @param canvasCoordinates
|
|
619
|
+
* @param vscaleBounds
|
|
620
|
+
* @returns scaleCanvasCoordinates
|
|
621
|
+
*/
|
|
622
|
+
computeCanvasScaleCoordinates = (
|
|
623
|
+
canvasSize,
|
|
624
|
+
canvasCoordinates,
|
|
625
|
+
vscaleBounds,
|
|
626
|
+
hscaleBounds,
|
|
627
|
+
location
|
|
628
|
+
) => {
|
|
629
|
+
let scaleCanvasCoordinates;
|
|
630
|
+
if (location == 'top' || location == 'bottom') {
|
|
631
|
+
const worldDistanceOnCanvas =
|
|
632
|
+
canvasCoordinates[0][0] - canvasCoordinates[1][0];
|
|
633
|
+
scaleCanvasCoordinates = [
|
|
634
|
+
[canvasSize.width / 2 - worldDistanceOnCanvas / 2, vscaleBounds.height],
|
|
635
|
+
[canvasSize.width / 2 + worldDistanceOnCanvas / 2, vscaleBounds.height],
|
|
636
|
+
];
|
|
637
|
+
} else if (location == 'left' || location == 'right') {
|
|
638
|
+
const worldDistanceOnCanvas =
|
|
639
|
+
canvasCoordinates[0][1] - canvasCoordinates[1][1];
|
|
640
|
+
scaleCanvasCoordinates = [
|
|
641
|
+
[hscaleBounds.width, canvasSize.height / 2 - worldDistanceOnCanvas / 2],
|
|
642
|
+
[hscaleBounds.width, canvasSize.height / 2 + worldDistanceOnCanvas / 2],
|
|
643
|
+
];
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
return scaleCanvasCoordinates;
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Computes the max bound for scales on the image
|
|
651
|
+
* @param {{width: number, height: number}} canvasSize
|
|
652
|
+
* @param {number} horizontalReduction
|
|
653
|
+
* @param {number} verticalReduction
|
|
654
|
+
* @returns {Object.<string, { x:number, y:number }>}
|
|
655
|
+
*/
|
|
656
|
+
computeScaleBounds = (
|
|
657
|
+
canvasSize,
|
|
658
|
+
horizontalReduction,
|
|
659
|
+
verticalReduction,
|
|
660
|
+
location
|
|
661
|
+
) => {
|
|
662
|
+
const hReduction = horizontalReduction * Math.min(1000, canvasSize.width);
|
|
663
|
+
const vReduction = verticalReduction * Math.min(1000, canvasSize.height);
|
|
664
|
+
const locationBounds = {
|
|
665
|
+
bottom: [-vReduction, -hReduction],
|
|
666
|
+
top: [vReduction, hReduction],
|
|
667
|
+
left: [vReduction, hReduction],
|
|
668
|
+
right: [-vReduction, -hReduction],
|
|
669
|
+
};
|
|
670
|
+
const canvasBounds = {
|
|
671
|
+
bottom: [canvasSize.height, canvasSize.width],
|
|
672
|
+
top: [0, canvasSize.width],
|
|
673
|
+
left: [canvasSize.height, 0],
|
|
674
|
+
right: [canvasSize.height, canvasSize.width],
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
return {
|
|
678
|
+
height: canvasBounds[location][0] + locationBounds[location][0],
|
|
679
|
+
width: canvasBounds[location][1] + locationBounds[location][1],
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
ScaleOverlayTool.toolName = 'ScaleOverlay';
|
|
685
|
+
export default ScaleOverlayTool;
|