@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.
Files changed (360) hide show
  1. package/dist/cjs/tools/CrosshairsTool.d.ts +1 -0
  2. package/dist/cjs/tools/CrosshairsTool.js +4 -1
  3. package/dist/cjs/tools/CrosshairsTool.js.map +1 -1
  4. package/dist/esm/tools/CrosshairsTool.d.ts +1 -0
  5. package/dist/esm/tools/CrosshairsTool.js +4 -1
  6. package/dist/esm/tools/CrosshairsTool.js.map +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/dist/umd/index.js.map +1 -1
  9. package/package.json +5 -4
  10. package/src/constants/COLOR_LUT.ts +262 -0
  11. package/src/constants/index.ts +3 -0
  12. package/src/cursors/ImageMouseCursor.ts +39 -0
  13. package/src/cursors/MouseCursor.ts +114 -0
  14. package/src/cursors/SVGCursorDescriptor.ts +462 -0
  15. package/src/cursors/SVGMouseCursor.ts +145 -0
  16. package/src/cursors/elementCursor.ts +69 -0
  17. package/src/cursors/index.ts +24 -0
  18. package/src/cursors/setCursorForElement.ts +33 -0
  19. package/src/drawingSvg/_getHash.ts +9 -0
  20. package/src/drawingSvg/_setAttributesIfNecessary.ts +13 -0
  21. package/src/drawingSvg/_setNewAttributesIfValid.ts +10 -0
  22. package/src/drawingSvg/clearByToolType.ts +26 -0
  23. package/src/drawingSvg/draw.ts +16 -0
  24. package/src/drawingSvg/drawArrow.ts +82 -0
  25. package/src/drawingSvg/drawCircle.ts +62 -0
  26. package/src/drawingSvg/drawEllipse.ts +71 -0
  27. package/src/drawingSvg/drawHandles.ts +87 -0
  28. package/src/drawingSvg/drawLine.ts +70 -0
  29. package/src/drawingSvg/drawLink.ts +76 -0
  30. package/src/drawingSvg/drawLinkedTextBox.ts +64 -0
  31. package/src/drawingSvg/drawPolyline.ts +80 -0
  32. package/src/drawingSvg/drawRect.ts +70 -0
  33. package/src/drawingSvg/drawTextBox.ts +213 -0
  34. package/src/drawingSvg/getSvgDrawingHelper.ts +98 -0
  35. package/src/drawingSvg/index.ts +23 -0
  36. package/src/enums/AnnotationStyleStates.ts +22 -0
  37. package/src/enums/Events.ts +242 -0
  38. package/src/enums/SegmentationRepresentations.ts +12 -0
  39. package/src/enums/ToolBindings.ts +37 -0
  40. package/src/enums/ToolModes.ts +31 -0
  41. package/src/enums/Touch.ts +8 -0
  42. package/src/enums/index.js +16 -0
  43. package/src/eventDispatchers/annotationModifiedEventDispatcher.ts +41 -0
  44. package/src/eventDispatchers/cameraModifiedEventDispatcher.ts +41 -0
  45. package/src/eventDispatchers/imageRenderedEventDispatcher.ts +37 -0
  46. package/src/eventDispatchers/imageSpacingCalibratedEventDispatcher.ts +50 -0
  47. package/src/eventDispatchers/index.js +15 -0
  48. package/src/eventDispatchers/keyboardEventHandlers/index.js +4 -0
  49. package/src/eventDispatchers/keyboardEventHandlers/keyDown.ts +29 -0
  50. package/src/eventDispatchers/keyboardEventHandlers/keyUp.ts +33 -0
  51. package/src/eventDispatchers/keyboardToolEventDispatcher.ts +28 -0
  52. package/src/eventDispatchers/mouseEventHandlers/index.js +19 -0
  53. package/src/eventDispatchers/mouseEventHandlers/mouseClick.ts +13 -0
  54. package/src/eventDispatchers/mouseEventHandlers/mouseDoubleClick.ts +13 -0
  55. package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +196 -0
  56. package/src/eventDispatchers/mouseEventHandlers/mouseDownActivate.ts +35 -0
  57. package/src/eventDispatchers/mouseEventHandlers/mouseDrag.ts +25 -0
  58. package/src/eventDispatchers/mouseEventHandlers/mouseMove.ts +70 -0
  59. package/src/eventDispatchers/mouseEventHandlers/mouseUp.ts +9 -0
  60. package/src/eventDispatchers/mouseEventHandlers/mouseWheel.ts +13 -0
  61. package/src/eventDispatchers/mouseToolEventDispatcher.ts +64 -0
  62. package/src/eventDispatchers/shared/customCallbackHandler.ts +73 -0
  63. package/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +58 -0
  64. package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +61 -0
  65. package/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +64 -0
  66. package/src/eventDispatchers/shared/getMouseModifier.ts +30 -0
  67. package/src/eventDispatchers/shared/getToolsWithModesForMouseEvent.ts +56 -0
  68. package/src/eventDispatchers/shared/getToolsWithModesForTouchEvent.ts +54 -0
  69. package/src/eventDispatchers/touchEventHandlers/index.js +15 -0
  70. package/src/eventDispatchers/touchEventHandlers/touchDrag.ts +23 -0
  71. package/src/eventDispatchers/touchEventHandlers/touchEnd.ts +9 -0
  72. package/src/eventDispatchers/touchEventHandlers/touchPress.ts +13 -0
  73. package/src/eventDispatchers/touchEventHandlers/touchStart.ts +174 -0
  74. package/src/eventDispatchers/touchEventHandlers/touchStartActivate.ts +36 -0
  75. package/src/eventDispatchers/touchEventHandlers/touchTap.ts +9 -0
  76. package/src/eventDispatchers/touchToolEventDispatcher.ts +51 -0
  77. package/src/eventListeners/annotations/annotationModifiedListener.ts +22 -0
  78. package/src/eventListeners/annotations/annotationSelectionListener.ts +29 -0
  79. package/src/eventListeners/annotations/index.ts +4 -0
  80. package/src/eventListeners/index.ts +28 -0
  81. package/src/eventListeners/keyboard/index.ts +16 -0
  82. package/src/eventListeners/keyboard/keyDownListener.ts +99 -0
  83. package/src/eventListeners/mouse/getMouseEventPoints.ts +66 -0
  84. package/src/eventListeners/mouse/index.ts +55 -0
  85. package/src/eventListeners/mouse/mouseDoubleClickListener.ts +55 -0
  86. package/src/eventListeners/mouse/mouseDownListener.ts +519 -0
  87. package/src/eventListeners/mouse/mouseMoveListener.ts +33 -0
  88. package/src/eventListeners/segmentation/index.ts +11 -0
  89. package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +61 -0
  90. package/src/eventListeners/segmentation/segmentationModifiedEventListener.ts +32 -0
  91. package/src/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.ts +15 -0
  92. package/src/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.ts +16 -0
  93. package/src/eventListeners/touch/getTouchEventPoints.ts +75 -0
  94. package/src/eventListeners/touch/index.ts +37 -0
  95. package/src/eventListeners/touch/preventGhostClick.js +72 -0
  96. package/src/eventListeners/touch/touchStartListener.ts +499 -0
  97. package/src/eventListeners/wheel/index.ts +27 -0
  98. package/src/eventListeners/wheel/normalizeWheel.ts +69 -0
  99. package/src/eventListeners/wheel/wheelListener.ts +51 -0
  100. package/src/index.ts +133 -0
  101. package/src/init.ts +187 -0
  102. package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +399 -0
  103. package/src/stateManagement/annotation/annotationLocking.ts +178 -0
  104. package/src/stateManagement/annotation/annotationSelection.ts +163 -0
  105. package/src/stateManagement/annotation/annotationState.ts +180 -0
  106. package/src/stateManagement/annotation/annotationVisibility.ts +156 -0
  107. package/src/stateManagement/annotation/config/ToolStyle.ts +265 -0
  108. package/src/stateManagement/annotation/config/getFont.ts +36 -0
  109. package/src/stateManagement/annotation/config/getState.ts +26 -0
  110. package/src/stateManagement/annotation/config/helpers.ts +55 -0
  111. package/src/stateManagement/annotation/config/index.ts +5 -0
  112. package/src/stateManagement/annotation/helpers/state.ts +83 -0
  113. package/src/stateManagement/annotation/index.ts +15 -0
  114. package/src/stateManagement/index.js +40 -0
  115. package/src/stateManagement/segmentation/SegmentationStateManager.ts +491 -0
  116. package/src/stateManagement/segmentation/activeSegmentation.ts +60 -0
  117. package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +77 -0
  118. package/src/stateManagement/segmentation/addSegmentations.ts +27 -0
  119. package/src/stateManagement/segmentation/config/index.ts +29 -0
  120. package/src/stateManagement/segmentation/config/segmentationColor.ts +132 -0
  121. package/src/stateManagement/segmentation/config/segmentationConfig.ts +195 -0
  122. package/src/stateManagement/segmentation/config/segmentationVisibility.ts +171 -0
  123. package/src/stateManagement/segmentation/helpers/index.ts +3 -0
  124. package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +35 -0
  125. package/src/stateManagement/segmentation/helpers/validateSegmentationInput.ts +41 -0
  126. package/src/stateManagement/segmentation/index.ts +22 -0
  127. package/src/stateManagement/segmentation/removeSegmentationsFromToolGroup.ts +85 -0
  128. package/src/stateManagement/segmentation/segmentIndex.ts +38 -0
  129. package/src/stateManagement/segmentation/segmentLocking.ts +72 -0
  130. package/src/stateManagement/segmentation/segmentationState.ts +429 -0
  131. package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +157 -0
  132. package/src/store/SynchronizerManager/Synchronizer.ts +344 -0
  133. package/src/store/SynchronizerManager/createSynchronizer.ts +41 -0
  134. package/src/store/SynchronizerManager/destroy.ts +14 -0
  135. package/src/store/SynchronizerManager/destroySynchronizer.ts +25 -0
  136. package/src/store/SynchronizerManager/getAllSynchronizers.ts +12 -0
  137. package/src/store/SynchronizerManager/getSynchronizer.ts +13 -0
  138. package/src/store/SynchronizerManager/getSynchronizersForViewport.ts +44 -0
  139. package/src/store/SynchronizerManager/index.js +15 -0
  140. package/src/store/ToolGroupManager/ToolGroup.ts +679 -0
  141. package/src/store/ToolGroupManager/createToolGroup.ts +33 -0
  142. package/src/store/ToolGroupManager/destroy.ts +24 -0
  143. package/src/store/ToolGroupManager/destroyToolGroup.ts +26 -0
  144. package/src/store/ToolGroupManager/getAllToolGroups.ts +12 -0
  145. package/src/store/ToolGroupManager/getToolGroup.ts +14 -0
  146. package/src/store/ToolGroupManager/getToolGroupForViewport.ts +44 -0
  147. package/src/store/ToolGroupManager/getToolGroupsWithToolName.ts +33 -0
  148. package/src/store/ToolGroupManager/index.ts +17 -0
  149. package/src/store/addEnabledElement.ts +137 -0
  150. package/src/store/addTool.ts +56 -0
  151. package/src/store/cancelActiveManipulations.ts +30 -0
  152. package/src/store/filterMoveableAnnotationTools.ts +61 -0
  153. package/src/store/filterToolsWithAnnotationsForElement.ts +51 -0
  154. package/src/store/filterToolsWithMoveableHandles.ts +51 -0
  155. package/src/store/index.ts +29 -0
  156. package/src/store/removeEnabledElement.ts +132 -0
  157. package/src/store/state.ts +57 -0
  158. package/src/store/svgNodeCache.ts +7 -0
  159. package/src/synchronizers/callbacks/areViewportsCoplanar .ts +12 -0
  160. package/src/synchronizers/callbacks/cameraSyncCallback.ts +33 -0
  161. package/src/synchronizers/callbacks/stackImageSyncCallback.ts +157 -0
  162. package/src/synchronizers/callbacks/voiSyncCallback.ts +51 -0
  163. package/src/synchronizers/callbacks/zoomPanSyncCallback.ts +43 -0
  164. package/src/synchronizers/index.ts +11 -0
  165. package/src/synchronizers/synchronizers/createCameraPositionSynchronizer.ts +25 -0
  166. package/src/synchronizers/synchronizers/createStackImageSynchronizer.ts +25 -0
  167. package/src/synchronizers/synchronizers/createVOISynchronizer.ts +24 -0
  168. package/src/synchronizers/synchronizers/createZoomPanSynchronizer.ts +25 -0
  169. package/src/synchronizers/synchronizers/index.ts +11 -0
  170. package/src/tools/CrosshairsTool.ts +2693 -0
  171. package/src/tools/MIPJumpToClickTool.ts +99 -0
  172. package/src/tools/MagnifyTool.ts +319 -0
  173. package/src/tools/PanTool.ts +58 -0
  174. package/src/tools/PlanarRotateTool.ts +77 -0
  175. package/src/tools/ReferenceCursors.ts +466 -0
  176. package/src/tools/ReferenceLinesTool.ts +279 -0
  177. package/src/tools/ScaleOverlayTool.ts +685 -0
  178. package/src/tools/StackScrollTool.ts +97 -0
  179. package/src/tools/StackScrollToolMouseWheelTool.ts +58 -0
  180. package/src/tools/TrackballRotateTool.ts +141 -0
  181. package/src/tools/VolumeRotateMouseWheelTool.ts +86 -0
  182. package/src/tools/WindowLevelTool.ts +260 -0
  183. package/src/tools/ZoomTool.ts +293 -0
  184. package/src/tools/annotation/AngleTool.ts +835 -0
  185. package/src/tools/annotation/ArrowAnnotateTool.ts +820 -0
  186. package/src/tools/annotation/BidirectionalTool.ts +1350 -0
  187. package/src/tools/annotation/CircleROITool.ts +1070 -0
  188. package/src/tools/annotation/CobbAngleTool.ts +815 -0
  189. package/src/tools/annotation/DragProbeTool.ts +213 -0
  190. package/src/tools/annotation/EllipticalROITool.ts +1223 -0
  191. package/src/tools/annotation/LengthTool.ts +861 -0
  192. package/src/tools/annotation/PlanarFreehandROITool.ts +636 -0
  193. package/src/tools/annotation/ProbeTool.ts +681 -0
  194. package/src/tools/annotation/RectangleROITool.ts +1028 -0
  195. package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +488 -0
  196. package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +462 -0
  197. package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +331 -0
  198. package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +74 -0
  199. package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +612 -0
  200. package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +74 -0
  201. package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +407 -0
  202. package/src/tools/base/AnnotationDisplayTool.ts +228 -0
  203. package/src/tools/base/AnnotationTool.ts +307 -0
  204. package/src/tools/base/BaseTool.ts +215 -0
  205. package/src/tools/base/index.ts +4 -0
  206. package/src/tools/displayTools/Contour/addContourToElement.ts +135 -0
  207. package/src/tools/displayTools/Contour/contourDisplay.ts +252 -0
  208. package/src/tools/displayTools/Contour/index.ts +3 -0
  209. package/src/tools/displayTools/Contour/removeContourFromElement.ts +35 -0
  210. package/src/tools/displayTools/Labelmap/addLabelmapToElement.ts +57 -0
  211. package/src/tools/displayTools/Labelmap/index.ts +4 -0
  212. package/src/tools/displayTools/Labelmap/labelmapConfig.ts +37 -0
  213. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +461 -0
  214. package/src/tools/displayTools/Labelmap/removeLabelmapFromElement.ts +27 -0
  215. package/src/tools/displayTools/Labelmap/validateRepresentationData.ts +30 -0
  216. package/src/tools/displayTools/SegmentationDisplayTool.ts +198 -0
  217. package/src/tools/index.ts +84 -0
  218. package/src/tools/segmentation/BrushTool.ts +474 -0
  219. package/src/tools/segmentation/CircleScissorsTool.ts +365 -0
  220. package/src/tools/segmentation/PaintFillTool.ts +370 -0
  221. package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +471 -0
  222. package/src/tools/segmentation/RectangleROIThresholdTool.ts +281 -0
  223. package/src/tools/segmentation/RectangleScissorsTool.ts +382 -0
  224. package/src/tools/segmentation/SphereScissorsTool.ts +368 -0
  225. package/src/tools/segmentation/strategies/eraseCircle.ts +30 -0
  226. package/src/tools/segmentation/strategies/eraseRectangle.ts +81 -0
  227. package/src/tools/segmentation/strategies/eraseSphere.ts +27 -0
  228. package/src/tools/segmentation/strategies/fillCircle.ts +185 -0
  229. package/src/tools/segmentation/strategies/fillRectangle.ts +110 -0
  230. package/src/tools/segmentation/strategies/fillSphere.ts +88 -0
  231. package/src/tools/segmentation/strategies/index.ts +9 -0
  232. package/src/types/AnnotationGroupSelector.ts +7 -0
  233. package/src/types/AnnotationStyle.ts +42 -0
  234. package/src/types/AnnotationTypes.ts +109 -0
  235. package/src/types/BoundsIJK.ts +5 -0
  236. package/src/types/CINETypes.ts +32 -0
  237. package/src/types/ContourTypes.ts +26 -0
  238. package/src/types/CursorTypes.ts +12 -0
  239. package/src/types/EventTypes.ts +657 -0
  240. package/src/types/FloodFillTypes.ts +19 -0
  241. package/src/types/IAnnotationManager.ts +89 -0
  242. package/src/types/IDistance.ts +16 -0
  243. package/src/types/IPoints.ts +18 -0
  244. package/src/types/ISetToolModeOptions.ts +29 -0
  245. package/src/types/ISynchronizerEventHandler.ts +11 -0
  246. package/src/types/IToolClassReference.ts +5 -0
  247. package/src/types/IToolGroup.ts +72 -0
  248. package/src/types/ITouchPoints.ts +14 -0
  249. package/src/types/InteractionTypes.ts +6 -0
  250. package/src/types/InternalToolTypes.ts +19 -0
  251. package/src/types/JumpToSliceOptions.ts +7 -0
  252. package/src/types/LabelmapTypes.ts +41 -0
  253. package/src/types/PlanarBoundingBox.ts +8 -0
  254. package/src/types/SVGDrawingHelper.ts +10 -0
  255. package/src/types/ScrollOptions.ts +9 -0
  256. package/src/types/SegmentationStateTypes.ts +248 -0
  257. package/src/types/ToolHandle.ts +26 -0
  258. package/src/types/ToolProps.ts +16 -0
  259. package/src/types/ToolSpecificAnnotationTypes.ts +311 -0
  260. package/src/types/index.ts +115 -0
  261. package/src/utilities/boundingBox/extend2DBoundingBoxInViewAxis.ts +29 -0
  262. package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +57 -0
  263. package/src/utilities/boundingBox/index.ts +4 -0
  264. package/src/utilities/calibrateImageSpacing.ts +46 -0
  265. package/src/utilities/cine/events.ts +9 -0
  266. package/src/utilities/cine/index.ts +5 -0
  267. package/src/utilities/cine/playClip.ts +435 -0
  268. package/src/utilities/cine/state.ts +18 -0
  269. package/src/utilities/clip.js +30 -0
  270. package/src/utilities/debounce.js +217 -0
  271. package/src/utilities/drawing/getTextBoxCoordsCanvas.ts +45 -0
  272. package/src/utilities/drawing/index.ts +3 -0
  273. package/src/utilities/dynamicVolume/getDataInTime.ts +110 -0
  274. package/src/utilities/dynamicVolume/index.ts +2 -0
  275. package/src/utilities/getAnnotationNearPoint.ts +130 -0
  276. package/src/utilities/getModalityUnit.ts +11 -0
  277. package/src/utilities/getToolsWithModesForElement.ts +52 -0
  278. package/src/utilities/index.ts +68 -0
  279. package/src/utilities/isObject.js +29 -0
  280. package/src/utilities/math/angle/angleBetweenLines.ts +29 -0
  281. package/src/utilities/math/circle/_types.ts +6 -0
  282. package/src/utilities/math/circle/getCanvasCircleCorners.ts +23 -0
  283. package/src/utilities/math/circle/getCanvasCircleRadius.ts +16 -0
  284. package/src/utilities/math/circle/index.ts +4 -0
  285. package/src/utilities/math/ellipse/getCanvasEllipseCorners.ts +26 -0
  286. package/src/utilities/math/ellipse/index.ts +4 -0
  287. package/src/utilities/math/ellipse/pointInEllipse.ts +38 -0
  288. package/src/utilities/math/ellipse/pointInEllipsoidWithConstraint.ts +35 -0
  289. package/src/utilities/math/index.ts +8 -0
  290. package/src/utilities/math/line/distanceToPoint.ts +24 -0
  291. package/src/utilities/math/line/distanceToPointSquared.ts +44 -0
  292. package/src/utilities/math/line/index.ts +5 -0
  293. package/src/utilities/math/line/intersectLine.ts +92 -0
  294. package/src/utilities/math/midPoint.ts +24 -0
  295. package/src/utilities/math/point/distanceToPoint.ts +22 -0
  296. package/src/utilities/math/point/index.ts +3 -0
  297. package/src/utilities/math/polyline/addCanvasPointsToArray.ts +62 -0
  298. package/src/utilities/math/polyline/calculateAreaOfPoints.ts +23 -0
  299. package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +182 -0
  300. package/src/utilities/math/polyline/getSubPixelSpacingAndXYDirections.ts +99 -0
  301. package/src/utilities/math/polyline/index.ts +19 -0
  302. package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +36 -0
  303. package/src/utilities/math/polyline/pointCanProjectOnLine.ts +57 -0
  304. package/src/utilities/math/polyline/pointsAreWithinCloseContourProximity.ts +15 -0
  305. package/src/utilities/math/rectangle/distanceToPoint.ts +82 -0
  306. package/src/utilities/math/rectangle/index.ts +3 -0
  307. package/src/utilities/math/sphere/index.ts +3 -0
  308. package/src/utilities/math/sphere/pointInSphere.ts +31 -0
  309. package/src/utilities/math/vec2/findClosestPoint.ts +40 -0
  310. package/src/utilities/math/vec2/index.ts +4 -0
  311. package/src/utilities/math/vec2/liangBarksyClip.ts +84 -0
  312. package/src/utilities/orientation/getOrientationStringLPS.ts +52 -0
  313. package/src/utilities/orientation/index.ts +4 -0
  314. package/src/utilities/orientation/invertOrientationStringLPS.ts +21 -0
  315. package/src/utilities/planar/filterAnnotationsForDisplay.ts +68 -0
  316. package/src/utilities/planar/filterAnnotationsWithinSlice.ts +85 -0
  317. package/src/utilities/planar/getPointInLineOfSightWithCriteria.ts +104 -0
  318. package/src/utilities/planar/getWorldWidthAndHeightFromCorners.ts +51 -0
  319. package/src/utilities/planar/getWorldWidthAndHeightFromTwoPoints.ts +51 -0
  320. package/src/utilities/planar/index.ts +18 -0
  321. package/src/utilities/planarFreehandROITool/index.ts +7 -0
  322. package/src/utilities/planarFreehandROITool/interpolateAnnotation.ts +87 -0
  323. package/src/utilities/planarFreehandROITool/interpolatePoints.ts +214 -0
  324. package/src/utilities/planarFreehandROITool/interpolation/algorithms/bspline.ts +55 -0
  325. package/src/utilities/planarFreehandROITool/interpolation/interpolateSegmentPoints.ts +90 -0
  326. package/src/utilities/pointInShapeCallback.ts +138 -0
  327. package/src/utilities/pointInSurroundingSphereCallback.ts +188 -0
  328. package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +76 -0
  329. package/src/utilities/rectangleROITool/index.ts +3 -0
  330. package/src/utilities/scroll.ts +62 -0
  331. package/src/utilities/segmentation/brushSizeForToolGroup.ts +72 -0
  332. package/src/utilities/segmentation/brushThresholdForToolGroup.ts +65 -0
  333. package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +74 -0
  334. package/src/utilities/segmentation/createMergedLabelmapForIndex.ts +65 -0
  335. package/src/utilities/segmentation/floodFill.ts +194 -0
  336. package/src/utilities/segmentation/getDefaultRepresentationConfig.ts +20 -0
  337. package/src/utilities/segmentation/index.ts +33 -0
  338. package/src/utilities/segmentation/isValidRepresentationConfig.ts +22 -0
  339. package/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +91 -0
  340. package/src/utilities/segmentation/thresholdSegmentationByRange.ts +129 -0
  341. package/src/utilities/segmentation/thresholdVolumeByRange.ts +150 -0
  342. package/src/utilities/segmentation/triggerSegmentationRender.ts +206 -0
  343. package/src/utilities/segmentation/utilities.ts +116 -0
  344. package/src/utilities/stackPrefetch/index.ts +8 -0
  345. package/src/utilities/stackPrefetch/stackPrefetch.ts +405 -0
  346. package/src/utilities/stackPrefetch/state.ts +17 -0
  347. package/src/utilities/throttle.js +69 -0
  348. package/src/utilities/touch/index.ts +246 -0
  349. package/src/utilities/triggerAnnotationRender.ts +237 -0
  350. package/src/utilities/triggerAnnotationRenderForViewportIds.ts +18 -0
  351. package/src/utilities/viewport/index.ts +5 -0
  352. package/src/utilities/viewport/isViewportPreScaled.ts +24 -0
  353. package/src/utilities/viewport/jumpToSlice.ts +73 -0
  354. package/src/utilities/viewport/jumpToWorld.ts +58 -0
  355. package/src/utilities/viewportFilters/filterViewportsWithFrameOfReferenceUID.ts +28 -0
  356. package/src/utilities/viewportFilters/filterViewportsWithParallelNormals.ts +26 -0
  357. package/src/utilities/viewportFilters/filterViewportsWithSameOrientation.ts +15 -0
  358. package/src/utilities/viewportFilters/filterViewportsWithToolEnabled.ts +72 -0
  359. package/src/utilities/viewportFilters/getViewportIdsWithToolToRender.ts +45 -0
  360. package/src/utilities/viewportFilters/index.ts +11 -0
@@ -0,0 +1,466 @@
1
+ import {
2
+ getEnabledElement,
3
+ StackViewport,
4
+ VolumeViewport,
5
+ utilities,
6
+ getEnabledElementByIds,
7
+ } from '@cornerstonejs/core';
8
+ import type { Types } from '@cornerstonejs/core';
9
+ import {
10
+ addAnnotation,
11
+ getAnnotations,
12
+ } from '../stateManagement/annotation/annotationState';
13
+ import { isAnnotationVisible } from '../stateManagement/annotation/annotationVisibility';
14
+ import { drawLine } from '../drawingSvg';
15
+ import { getViewportIdsWithToolToRender } from '../utilities/viewportFilters';
16
+ import {
17
+ EventTypes,
18
+ PublicToolProps,
19
+ ToolProps,
20
+ SVGDrawingHelper,
21
+ Annotation,
22
+ Annotations,
23
+ } from '../types';
24
+ import { ReferenceCursor } from '../types/ToolSpecificAnnotationTypes';
25
+
26
+ import triggerAnnotationRenderForViewportIds from '../utilities/triggerAnnotationRenderForViewportIds';
27
+ import { StyleSpecifier } from '../types/AnnotationStyle';
28
+ import { vec3 } from 'gl-matrix';
29
+ import AnnotationDisplayTool from './base/AnnotationDisplayTool';
30
+ import vtkMath from '@kitware/vtk.js/Common/Core/Math';
31
+ import {
32
+ hideElementCursor,
33
+ resetElementCursor,
34
+ } from '../cursors/elementCursor';
35
+ import { getToolGroup } from '../store/ToolGroupManager';
36
+
37
+ /**
38
+ * ReferenceCursors is a tool that will show your cursors position in all other elements in the toolGroup if they have a matching FrameOfReference relative to its position in world space.
39
+ * Also when positionSync is enabled, it will try to sync viewports so that the cursor can be displayed in the correct position in all viewports.
40
+ *
41
+ * Configuration:
42
+ * - positionSync: boolean, if true, it will try to sync viewports so that the cursor can be displayed in the correct position in all viewports.
43
+ * - disableCursor: boolean, if true, it will hide the cursor in all viewports. You need to disable and reactivate the tool for this to apply.
44
+ * - displayThreshold: number, if the distance of the cursor in a viewport is bigger than this threshold the cursor will not be displayed.
45
+ *
46
+ * Only uses Active and Disabled state
47
+ */
48
+ class ReferenceCursors extends AnnotationDisplayTool {
49
+ static toolName;
50
+ touchDragCallback: any;
51
+ mouseDragCallback: any;
52
+ _throttledCalculateCachedStats: any;
53
+ isDrawing = false;
54
+ isHandleOutsideImage = false;
55
+ _elementWithCursor: null | HTMLDivElement = null;
56
+ _currentCursorWorldPosition: null | Types.Point3 = null;
57
+ _currentCanvasPosition: null | Types.Point2 = null;
58
+ //need to keep track if this was enabled when tool was enabled because we need to know if we should reset cursors
59
+ _disableCursorEnabled = false;
60
+
61
+ constructor(
62
+ toolProps: PublicToolProps = {},
63
+ defaultToolProps: ToolProps = {
64
+ supportedInteractionTypes: ['Mouse', 'Touch'],
65
+ configuration: {
66
+ shadow: true,
67
+ preventHandleOutsideImage: false,
68
+ displayThreshold: 5,
69
+ positionSync: true,
70
+ disableCursor: false,
71
+ },
72
+ }
73
+ ) {
74
+ super(toolProps, defaultToolProps);
75
+ this._disableCursorEnabled = this.configuration.disableCursor;
76
+ }
77
+
78
+ /**
79
+ * Overwritten mouseMoveCallback since we want to keep track of the current mouse position and redraw on mouseMove
80
+ * @virtual Event handler for Cornerstone MOUSE_MOVE event.
81
+ *
82
+ *
83
+ * @param evt - The normalized mouse event
84
+ * @param filteredAnnotations - The annotations to check for hover interactions
85
+ * @returns True if the annotation needs to be re-drawn by the annotationRenderingEngine.
86
+ */
87
+ mouseMoveCallback = (evt: EventTypes.InteractionEventType): boolean => {
88
+ const { detail } = evt;
89
+ const { element, currentPoints } = detail;
90
+
91
+ //save current positions and current element the curser is hovering over
92
+ this._currentCursorWorldPosition = currentPoints.world;
93
+ this._currentCanvasPosition = currentPoints.canvas;
94
+ this._elementWithCursor = element;
95
+
96
+ const annotation = this.getActiveAnnotation(element);
97
+ if (annotation === null) {
98
+ this.createInitialAnnotation(currentPoints.world, element);
99
+ return false;
100
+ }
101
+ this.updateAnnotationPosition(element, annotation);
102
+ return false;
103
+ };
104
+
105
+ onSetToolActive(): void {
106
+ this._disableCursorEnabled = this.configuration.disableCursor;
107
+ if (!this._disableCursorEnabled) return;
108
+ const viewportIds = getToolGroup(this.toolGroupId).viewportsInfo;
109
+ if (!viewportIds) return;
110
+ const enabledElements = viewportIds.map((e) =>
111
+ getEnabledElementByIds(e.viewportId, e.renderingEngineId)
112
+ );
113
+
114
+ enabledElements.forEach((element) => {
115
+ if (element) hideElementCursor(element.viewport.element);
116
+ });
117
+ }
118
+ onSetToolDisabled(): void {
119
+ if (!this._disableCursorEnabled) return;
120
+ const viewportIds = getToolGroup(this.toolGroupId).viewportsInfo;
121
+ if (!viewportIds) return;
122
+ const enabledElements = viewportIds.map((e) =>
123
+ getEnabledElementByIds(e.viewportId, e.renderingEngineId)
124
+ );
125
+ enabledElements.forEach((element) => {
126
+ if (element) resetElementCursor(element.viewport.element);
127
+ });
128
+ }
129
+
130
+ createInitialAnnotation = (
131
+ worldPos: Types.Point3,
132
+ element: HTMLDivElement
133
+ ): void => {
134
+ const enabledElement = getEnabledElement(element);
135
+ if (!enabledElement) throw new Error('No enabled element found');
136
+ const { viewport, renderingEngine } = enabledElement;
137
+
138
+ this.isDrawing = true;
139
+
140
+ const camera = viewport.getCamera();
141
+ const { viewPlaneNormal, viewUp } = camera;
142
+ if (!viewPlaneNormal || !viewUp) throw new Error('Camera not found');
143
+
144
+ const referencedImageId = this.getReferencedImageId(
145
+ viewport,
146
+ worldPos,
147
+ viewPlaneNormal,
148
+ viewUp
149
+ );
150
+
151
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
152
+
153
+ const annotation = {
154
+ highlighted: true,
155
+ invalidated: true,
156
+ metadata: {
157
+ toolName: this.getToolName(),
158
+ viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
159
+ viewUp: <Types.Point3>[...viewUp],
160
+ FrameOfReferenceUID,
161
+ referencedImageId,
162
+ },
163
+ data: {
164
+ label: '',
165
+ handles: {
166
+ points: [[...worldPos]] as [Types.Point3],
167
+ activeHandleIndex: null,
168
+ textBox: {
169
+ hasMoved: false,
170
+ worldPosition: <Types.Point3>[0, 0, 0],
171
+ worldBoundingBox: {
172
+ topLeft: <Types.Point3>[0, 0, 0],
173
+ topRight: <Types.Point3>[0, 0, 0],
174
+ bottomLeft: <Types.Point3>[0, 0, 0],
175
+ bottomRight: <Types.Point3>[0, 0, 0],
176
+ },
177
+ },
178
+ },
179
+ },
180
+ };
181
+
182
+ const annotations = getAnnotations(this.getToolName(), element);
183
+
184
+ if (annotations.length > 0) return null;
185
+ const annotationId = addAnnotation(annotation, element);
186
+
187
+ if (annotationId === null) return;
188
+
189
+ const viewportIdsToRender = getViewportIdsWithToolToRender(
190
+ element,
191
+ this.getToolName(),
192
+ false
193
+ );
194
+
195
+ triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
196
+ };
197
+
198
+ getActiveAnnotation(element: HTMLDivElement): null | Annotation {
199
+ const annotations = getAnnotations(this.getToolName(), element);
200
+ if (!annotations.length) {
201
+ return null;
202
+ }
203
+ const targetAnnotation = annotations[0];
204
+ return targetAnnotation;
205
+ }
206
+
207
+ /**
208
+ * updates the position of the annotation to match the currently set world position
209
+ */
210
+ updateAnnotationPosition(
211
+ element: HTMLDivElement,
212
+ annotation: Annotation
213
+ ): void {
214
+ const worldPos = this._currentCursorWorldPosition;
215
+ if (!worldPos) return;
216
+ if (!annotation.data?.handles?.points) return;
217
+ annotation.data.handles.points = [[...worldPos]];
218
+ annotation.invalidated = true;
219
+
220
+ const viewportIdsToRender = getViewportIdsWithToolToRender(
221
+ element,
222
+ this.getToolName(),
223
+ false
224
+ );
225
+ const enabledElement = getEnabledElement(element);
226
+ if (!enabledElement) return;
227
+ const { renderingEngine } = enabledElement;
228
+ triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
229
+ }
230
+
231
+ //checks if we need to update the annotation position due to camera changes
232
+ onCameraModified = (evt: any): void => {
233
+ const eventDetail = evt.detail;
234
+ const { element, previousCamera, camera } = eventDetail;
235
+ const enabledElement = getEnabledElement(element);
236
+ const viewport = enabledElement.viewport as
237
+ | Types.IVolumeViewport
238
+ | Types.IStackViewport;
239
+
240
+ //only react to changes for element with cursor, otherwise would cause infinite loop
241
+ if (element !== this._elementWithCursor) return;
242
+ //check if camera moved along its normal
243
+ const oldFocalPoint = previousCamera.focalPoint;
244
+ const cameraNormal = camera.viewPlaneNormal;
245
+ const newFocalPoint = camera.focalPoint;
246
+
247
+ const deltaCameraFocalPoint: Types.Point3 = [0, 0, 0];
248
+ vtkMath.subtract(newFocalPoint, oldFocalPoint, deltaCameraFocalPoint);
249
+ //check if focal point changed
250
+ if (deltaCameraFocalPoint.reduce((a, b) => a + b, 0) === 0) return;
251
+ //if nomrmal is perpendicular to focal point change, then we are not moving along the normal
252
+ const dotProduct = vtkMath.dot(deltaCameraFocalPoint, cameraNormal);
253
+ //dot product is 0 -> perpendicular
254
+ if (Math.abs(dotProduct) < 1e-2) return;
255
+
256
+ //need to update the position of the annotation since camera changed
257
+ if (!this._currentCanvasPosition) return;
258
+
259
+ const newWorldPos = viewport.canvasToWorld(this._currentCanvasPosition);
260
+ this._currentCursorWorldPosition = newWorldPos;
261
+ this.updateAnnotationPosition(element, this.getActiveAnnotation(element));
262
+ };
263
+
264
+ //display annotation if current viewing plane has a max distance of "displayThreshold" from the annotation
265
+ filterInteractableAnnotationsForElement(
266
+ element: HTMLDivElement,
267
+ annotations: Annotations
268
+ ): Annotations {
269
+ //calculate distance of current viewport to annotation
270
+ if (!(annotations instanceof Array) || annotations.length === 0) return [];
271
+ const annotation = annotations[0];
272
+ const viewport = getEnabledElement(element)?.viewport;
273
+ if (!viewport) return [];
274
+ const camera = viewport.getCamera();
275
+ const { viewPlaneNormal, focalPoint } = camera;
276
+ if (!viewPlaneNormal || !focalPoint) return [];
277
+ const points = annotation.data?.handles?.points;
278
+ if (!(points instanceof Array) || points.length !== 1) return [];
279
+ const worldPos = points[0];
280
+ const plane = utilities.planar.planeEquation(viewPlaneNormal, focalPoint);
281
+ const distance = utilities.planar.planeDistanceToPoint(plane, worldPos);
282
+ return distance < this.configuration.displayThreshold ? [annotation] : [];
283
+ }
284
+
285
+ /**
286
+ * Draws the cursor representation on the enabledElement
287
+ * Checks if a stack change has happened and updates annotation in that case
288
+ *
289
+ * @param enabledElement - The Cornerstone's enabledElement.
290
+ * @param svgDrawingHelper - The svgDrawingHelper providing the context for drawing.
291
+ */
292
+ renderAnnotation = (
293
+ enabledElement: Types.IEnabledElement,
294
+ svgDrawingHelper: SVGDrawingHelper
295
+ ): boolean => {
296
+ let renderStatus = false;
297
+ const { viewport, FrameOfReferenceUID } = enabledElement;
298
+
299
+ const isElementWithCursor = this._elementWithCursor === viewport.element;
300
+
301
+ //update stack position if position sync is enabled
302
+ if (this.configuration.positionSync && !isElementWithCursor) {
303
+ this.updateViewportImage(viewport);
304
+ }
305
+
306
+ const { element } = viewport;
307
+
308
+ let annotations = getAnnotations(this.getToolName(), element);
309
+
310
+ if (!annotations?.length) {
311
+ return renderStatus;
312
+ }
313
+
314
+ //the viewport change from updateStackPosition might not be applied yet, so sometimes the annotation might not be immediately visible
315
+ annotations = this.filterInteractableAnnotationsForElement(
316
+ element,
317
+ annotations
318
+ ) as Annotations;
319
+
320
+ if (!annotations?.length) {
321
+ return renderStatus;
322
+ }
323
+
324
+ const styleSpecifier: StyleSpecifier = {
325
+ toolGroupId: this.toolGroupId,
326
+ toolName: this.getToolName(),
327
+ viewportId: enabledElement.viewport.id,
328
+ };
329
+
330
+ for (let i = 0; i < annotations.length; i++) {
331
+ const annotation = annotations[i] as ReferenceCursor;
332
+ const { annotationUID, data } = annotation;
333
+ const { handles } = data;
334
+ const { points } = handles;
335
+
336
+ if (!annotationUID) return renderStatus;
337
+ styleSpecifier.annotationUID = annotationUID;
338
+
339
+ const lineWidthBase = parseFloat(
340
+ this.getStyle('lineWidth', styleSpecifier, annotation) as string
341
+ );
342
+
343
+ const lineWidth =
344
+ typeof lineWidthBase === 'number' && isElementWithCursor
345
+ ? lineWidthBase
346
+ : lineWidthBase;
347
+ const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
348
+ const color = this.getStyle('color', styleSpecifier, annotation);
349
+
350
+ if (points[0].some((e) => isNaN(e))) return renderStatus;
351
+ const canvasCoordinates = points.map((p) =>
352
+ viewport.worldToCanvas(p)
353
+ ) as [Types.Point2];
354
+
355
+ // If rendering engine has been destroyed while rendering
356
+ if (!viewport.getRenderingEngine()) {
357
+ console.warn('Rendering Engine has been destroyed');
358
+ return renderStatus;
359
+ }
360
+
361
+ if (!isAnnotationVisible(annotationUID)) {
362
+ continue;
363
+ }
364
+
365
+ const crosshairUIDs = {
366
+ upper: 'upper',
367
+ right: 'right',
368
+ lower: 'lower',
369
+ left: 'left',
370
+ };
371
+ const [x, y] = canvasCoordinates[0];
372
+ const centerSpace = isElementWithCursor ? 20 : 7;
373
+ const lineLength = isElementWithCursor ? 5 : 7;
374
+ drawLine(
375
+ svgDrawingHelper,
376
+ annotationUID,
377
+ crosshairUIDs.upper,
378
+ [x, y - (centerSpace / 2 + lineLength)],
379
+ [x, y - centerSpace / 2],
380
+ { color, lineDash, lineWidth }
381
+ );
382
+ drawLine(
383
+ svgDrawingHelper,
384
+ annotationUID,
385
+ crosshairUIDs.lower,
386
+ [x, y + (centerSpace / 2 + lineLength)],
387
+ [x, y + centerSpace / 2],
388
+ { color, lineDash, lineWidth }
389
+ );
390
+ drawLine(
391
+ svgDrawingHelper,
392
+ annotationUID,
393
+ crosshairUIDs.right,
394
+ [x + (centerSpace / 2 + lineLength), y],
395
+ [x + centerSpace / 2, y],
396
+ { color, lineDash, lineWidth }
397
+ );
398
+ drawLine(
399
+ svgDrawingHelper,
400
+ annotationUID,
401
+ crosshairUIDs.left,
402
+ [x - (centerSpace / 2 + lineLength), y],
403
+ [x - centerSpace / 2, y],
404
+ { color, lineDash, lineWidth }
405
+ );
406
+ renderStatus = true;
407
+ }
408
+
409
+ return renderStatus;
410
+ };
411
+
412
+ updateViewportImage(
413
+ viewport: Types.IStackViewport | Types.IVolumeViewport
414
+ ): void {
415
+ const currentMousePosition = this._currentCursorWorldPosition;
416
+
417
+ if (!currentMousePosition || currentMousePosition.some((e) => isNaN(e)))
418
+ return;
419
+
420
+ if (viewport instanceof StackViewport) {
421
+ const closestIndex = utilities.getClosestStackImageIndexForPoint(
422
+ currentMousePosition,
423
+ viewport
424
+ );
425
+
426
+ if (closestIndex === null) return;
427
+ if (closestIndex !== viewport.getCurrentImageIdIndex())
428
+ viewport.setImageIdIndex(closestIndex);
429
+ } else if (viewport instanceof VolumeViewport) {
430
+ const { focalPoint, viewPlaneNormal } = viewport.getCamera();
431
+ if (!focalPoint || !viewPlaneNormal) return;
432
+ const plane = utilities.planar.planeEquation(viewPlaneNormal, focalPoint);
433
+ const currentDistance = utilities.planar.planeDistanceToPoint(
434
+ plane,
435
+ currentMousePosition,
436
+ true
437
+ );
438
+
439
+ if (Math.abs(currentDistance) < 0.5) return;
440
+ const normalizedViewPlane = vec3.normalize(
441
+ vec3.create(),
442
+ vec3.fromValues(...viewPlaneNormal)
443
+ );
444
+ const scaledPlaneNormal = vec3.scale(
445
+ vec3.create(),
446
+ normalizedViewPlane,
447
+ currentDistance
448
+ );
449
+ const newFocalPoint = vec3.add(
450
+ vec3.create(),
451
+ vec3.fromValues(...focalPoint),
452
+ scaledPlaneNormal
453
+ ) as Types.Point3;
454
+ //TODO: make check if new focal point is within bounds of volume
455
+ const isInBounds = true;
456
+ if (isInBounds) {
457
+ viewport.setCamera({ focalPoint: newFocalPoint });
458
+ const renderingEngine = viewport.getRenderingEngine();
459
+ if (renderingEngine) renderingEngine.renderViewport(viewport.id);
460
+ }
461
+ }
462
+ }
463
+ }
464
+
465
+ ReferenceCursors.toolName = 'ReferenceCursors';
466
+ export default ReferenceCursors;