@cornerstonejs/tools 0.56.2 → 0.56.4

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 (352) hide show
  1. package/package.json +5 -4
  2. package/src/constants/COLOR_LUT.ts +262 -0
  3. package/src/constants/index.ts +3 -0
  4. package/src/cursors/ImageMouseCursor.ts +39 -0
  5. package/src/cursors/MouseCursor.ts +114 -0
  6. package/src/cursors/SVGCursorDescriptor.ts +462 -0
  7. package/src/cursors/SVGMouseCursor.ts +145 -0
  8. package/src/cursors/elementCursor.ts +69 -0
  9. package/src/cursors/index.ts +24 -0
  10. package/src/cursors/setCursorForElement.ts +33 -0
  11. package/src/drawingSvg/_getHash.ts +9 -0
  12. package/src/drawingSvg/_setAttributesIfNecessary.ts +13 -0
  13. package/src/drawingSvg/_setNewAttributesIfValid.ts +10 -0
  14. package/src/drawingSvg/clearByToolType.ts +26 -0
  15. package/src/drawingSvg/draw.ts +16 -0
  16. package/src/drawingSvg/drawArrow.ts +82 -0
  17. package/src/drawingSvg/drawCircle.ts +62 -0
  18. package/src/drawingSvg/drawEllipse.ts +71 -0
  19. package/src/drawingSvg/drawHandles.ts +87 -0
  20. package/src/drawingSvg/drawLine.ts +70 -0
  21. package/src/drawingSvg/drawLink.ts +76 -0
  22. package/src/drawingSvg/drawLinkedTextBox.ts +64 -0
  23. package/src/drawingSvg/drawPolyline.ts +80 -0
  24. package/src/drawingSvg/drawRect.ts +70 -0
  25. package/src/drawingSvg/drawTextBox.ts +213 -0
  26. package/src/drawingSvg/getSvgDrawingHelper.ts +98 -0
  27. package/src/drawingSvg/index.ts +23 -0
  28. package/src/enums/AnnotationStyleStates.ts +22 -0
  29. package/src/enums/Events.ts +242 -0
  30. package/src/enums/SegmentationRepresentations.ts +12 -0
  31. package/src/enums/ToolBindings.ts +37 -0
  32. package/src/enums/ToolModes.ts +31 -0
  33. package/src/enums/Touch.ts +8 -0
  34. package/src/enums/index.js +16 -0
  35. package/src/eventDispatchers/annotationModifiedEventDispatcher.ts +41 -0
  36. package/src/eventDispatchers/cameraModifiedEventDispatcher.ts +41 -0
  37. package/src/eventDispatchers/imageRenderedEventDispatcher.ts +37 -0
  38. package/src/eventDispatchers/imageSpacingCalibratedEventDispatcher.ts +50 -0
  39. package/src/eventDispatchers/index.js +15 -0
  40. package/src/eventDispatchers/keyboardEventHandlers/index.js +4 -0
  41. package/src/eventDispatchers/keyboardEventHandlers/keyDown.ts +29 -0
  42. package/src/eventDispatchers/keyboardEventHandlers/keyUp.ts +33 -0
  43. package/src/eventDispatchers/keyboardToolEventDispatcher.ts +28 -0
  44. package/src/eventDispatchers/mouseEventHandlers/index.js +19 -0
  45. package/src/eventDispatchers/mouseEventHandlers/mouseClick.ts +13 -0
  46. package/src/eventDispatchers/mouseEventHandlers/mouseDoubleClick.ts +13 -0
  47. package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +196 -0
  48. package/src/eventDispatchers/mouseEventHandlers/mouseDownActivate.ts +35 -0
  49. package/src/eventDispatchers/mouseEventHandlers/mouseDrag.ts +25 -0
  50. package/src/eventDispatchers/mouseEventHandlers/mouseMove.ts +70 -0
  51. package/src/eventDispatchers/mouseEventHandlers/mouseUp.ts +9 -0
  52. package/src/eventDispatchers/mouseEventHandlers/mouseWheel.ts +13 -0
  53. package/src/eventDispatchers/mouseToolEventDispatcher.ts +64 -0
  54. package/src/eventDispatchers/shared/customCallbackHandler.ts +73 -0
  55. package/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +58 -0
  56. package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +61 -0
  57. package/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +64 -0
  58. package/src/eventDispatchers/shared/getMouseModifier.ts +30 -0
  59. package/src/eventDispatchers/shared/getToolsWithModesForMouseEvent.ts +56 -0
  60. package/src/eventDispatchers/shared/getToolsWithModesForTouchEvent.ts +54 -0
  61. package/src/eventDispatchers/touchEventHandlers/index.js +15 -0
  62. package/src/eventDispatchers/touchEventHandlers/touchDrag.ts +23 -0
  63. package/src/eventDispatchers/touchEventHandlers/touchEnd.ts +9 -0
  64. package/src/eventDispatchers/touchEventHandlers/touchPress.ts +13 -0
  65. package/src/eventDispatchers/touchEventHandlers/touchStart.ts +174 -0
  66. package/src/eventDispatchers/touchEventHandlers/touchStartActivate.ts +36 -0
  67. package/src/eventDispatchers/touchEventHandlers/touchTap.ts +9 -0
  68. package/src/eventDispatchers/touchToolEventDispatcher.ts +51 -0
  69. package/src/eventListeners/annotations/annotationModifiedListener.ts +22 -0
  70. package/src/eventListeners/annotations/annotationSelectionListener.ts +29 -0
  71. package/src/eventListeners/annotations/index.ts +4 -0
  72. package/src/eventListeners/index.ts +28 -0
  73. package/src/eventListeners/keyboard/index.ts +16 -0
  74. package/src/eventListeners/keyboard/keyDownListener.ts +99 -0
  75. package/src/eventListeners/mouse/getMouseEventPoints.ts +66 -0
  76. package/src/eventListeners/mouse/index.ts +55 -0
  77. package/src/eventListeners/mouse/mouseDoubleClickListener.ts +55 -0
  78. package/src/eventListeners/mouse/mouseDownListener.ts +519 -0
  79. package/src/eventListeners/mouse/mouseMoveListener.ts +33 -0
  80. package/src/eventListeners/segmentation/index.ts +11 -0
  81. package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +61 -0
  82. package/src/eventListeners/segmentation/segmentationModifiedEventListener.ts +32 -0
  83. package/src/eventListeners/segmentation/segmentationRepresentationModifiedEventListener.ts +15 -0
  84. package/src/eventListeners/segmentation/segmentationRepresentationRemovedEventListener.ts +16 -0
  85. package/src/eventListeners/touch/getTouchEventPoints.ts +75 -0
  86. package/src/eventListeners/touch/index.ts +37 -0
  87. package/src/eventListeners/touch/preventGhostClick.js +72 -0
  88. package/src/eventListeners/touch/touchStartListener.ts +499 -0
  89. package/src/eventListeners/wheel/index.ts +27 -0
  90. package/src/eventListeners/wheel/normalizeWheel.ts +69 -0
  91. package/src/eventListeners/wheel/wheelListener.ts +51 -0
  92. package/src/index.ts +133 -0
  93. package/src/init.ts +187 -0
  94. package/src/stateManagement/annotation/FrameOfReferenceSpecificAnnotationManager.ts +399 -0
  95. package/src/stateManagement/annotation/annotationLocking.ts +178 -0
  96. package/src/stateManagement/annotation/annotationSelection.ts +163 -0
  97. package/src/stateManagement/annotation/annotationState.ts +180 -0
  98. package/src/stateManagement/annotation/annotationVisibility.ts +156 -0
  99. package/src/stateManagement/annotation/config/ToolStyle.ts +265 -0
  100. package/src/stateManagement/annotation/config/getFont.ts +36 -0
  101. package/src/stateManagement/annotation/config/getState.ts +26 -0
  102. package/src/stateManagement/annotation/config/helpers.ts +55 -0
  103. package/src/stateManagement/annotation/config/index.ts +5 -0
  104. package/src/stateManagement/annotation/helpers/state.ts +83 -0
  105. package/src/stateManagement/annotation/index.ts +15 -0
  106. package/src/stateManagement/index.js +40 -0
  107. package/src/stateManagement/segmentation/SegmentationStateManager.ts +491 -0
  108. package/src/stateManagement/segmentation/activeSegmentation.ts +60 -0
  109. package/src/stateManagement/segmentation/addSegmentationRepresentations.ts +77 -0
  110. package/src/stateManagement/segmentation/addSegmentations.ts +27 -0
  111. package/src/stateManagement/segmentation/config/index.ts +29 -0
  112. package/src/stateManagement/segmentation/config/segmentationColor.ts +132 -0
  113. package/src/stateManagement/segmentation/config/segmentationConfig.ts +195 -0
  114. package/src/stateManagement/segmentation/config/segmentationVisibility.ts +171 -0
  115. package/src/stateManagement/segmentation/helpers/index.ts +3 -0
  116. package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +35 -0
  117. package/src/stateManagement/segmentation/helpers/validateSegmentationInput.ts +41 -0
  118. package/src/stateManagement/segmentation/index.ts +22 -0
  119. package/src/stateManagement/segmentation/removeSegmentationsFromToolGroup.ts +85 -0
  120. package/src/stateManagement/segmentation/segmentIndex.ts +38 -0
  121. package/src/stateManagement/segmentation/segmentLocking.ts +72 -0
  122. package/src/stateManagement/segmentation/segmentationState.ts +429 -0
  123. package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +157 -0
  124. package/src/store/SynchronizerManager/Synchronizer.ts +344 -0
  125. package/src/store/SynchronizerManager/createSynchronizer.ts +41 -0
  126. package/src/store/SynchronizerManager/destroy.ts +14 -0
  127. package/src/store/SynchronizerManager/destroySynchronizer.ts +25 -0
  128. package/src/store/SynchronizerManager/getAllSynchronizers.ts +12 -0
  129. package/src/store/SynchronizerManager/getSynchronizer.ts +13 -0
  130. package/src/store/SynchronizerManager/getSynchronizersForViewport.ts +44 -0
  131. package/src/store/SynchronizerManager/index.js +15 -0
  132. package/src/store/ToolGroupManager/ToolGroup.ts +679 -0
  133. package/src/store/ToolGroupManager/createToolGroup.ts +33 -0
  134. package/src/store/ToolGroupManager/destroy.ts +24 -0
  135. package/src/store/ToolGroupManager/destroyToolGroup.ts +26 -0
  136. package/src/store/ToolGroupManager/getAllToolGroups.ts +12 -0
  137. package/src/store/ToolGroupManager/getToolGroup.ts +14 -0
  138. package/src/store/ToolGroupManager/getToolGroupForViewport.ts +44 -0
  139. package/src/store/ToolGroupManager/getToolGroupsWithToolName.ts +33 -0
  140. package/src/store/ToolGroupManager/index.ts +17 -0
  141. package/src/store/addEnabledElement.ts +137 -0
  142. package/src/store/addTool.ts +56 -0
  143. package/src/store/cancelActiveManipulations.ts +30 -0
  144. package/src/store/filterMoveableAnnotationTools.ts +61 -0
  145. package/src/store/filterToolsWithAnnotationsForElement.ts +51 -0
  146. package/src/store/filterToolsWithMoveableHandles.ts +51 -0
  147. package/src/store/index.ts +29 -0
  148. package/src/store/removeEnabledElement.ts +132 -0
  149. package/src/store/state.ts +57 -0
  150. package/src/store/svgNodeCache.ts +7 -0
  151. package/src/synchronizers/callbacks/areViewportsCoplanar .ts +12 -0
  152. package/src/synchronizers/callbacks/cameraSyncCallback.ts +33 -0
  153. package/src/synchronizers/callbacks/stackImageSyncCallback.ts +157 -0
  154. package/src/synchronizers/callbacks/voiSyncCallback.ts +51 -0
  155. package/src/synchronizers/callbacks/zoomPanSyncCallback.ts +43 -0
  156. package/src/synchronizers/index.ts +11 -0
  157. package/src/synchronizers/synchronizers/createCameraPositionSynchronizer.ts +25 -0
  158. package/src/synchronizers/synchronizers/createStackImageSynchronizer.ts +25 -0
  159. package/src/synchronizers/synchronizers/createVOISynchronizer.ts +24 -0
  160. package/src/synchronizers/synchronizers/createZoomPanSynchronizer.ts +25 -0
  161. package/src/synchronizers/synchronizers/index.ts +11 -0
  162. package/src/tools/CrosshairsTool.ts +2693 -0
  163. package/src/tools/MIPJumpToClickTool.ts +99 -0
  164. package/src/tools/MagnifyTool.ts +319 -0
  165. package/src/tools/PanTool.ts +58 -0
  166. package/src/tools/PlanarRotateTool.ts +77 -0
  167. package/src/tools/ReferenceCursors.ts +466 -0
  168. package/src/tools/ReferenceLinesTool.ts +279 -0
  169. package/src/tools/ScaleOverlayTool.ts +685 -0
  170. package/src/tools/StackScrollTool.ts +97 -0
  171. package/src/tools/StackScrollToolMouseWheelTool.ts +58 -0
  172. package/src/tools/TrackballRotateTool.ts +141 -0
  173. package/src/tools/VolumeRotateMouseWheelTool.ts +86 -0
  174. package/src/tools/WindowLevelTool.ts +260 -0
  175. package/src/tools/ZoomTool.ts +293 -0
  176. package/src/tools/annotation/AngleTool.ts +835 -0
  177. package/src/tools/annotation/ArrowAnnotateTool.ts +820 -0
  178. package/src/tools/annotation/BidirectionalTool.ts +1350 -0
  179. package/src/tools/annotation/CircleROITool.ts +1070 -0
  180. package/src/tools/annotation/CobbAngleTool.ts +815 -0
  181. package/src/tools/annotation/DragProbeTool.ts +213 -0
  182. package/src/tools/annotation/EllipticalROITool.ts +1223 -0
  183. package/src/tools/annotation/LengthTool.ts +861 -0
  184. package/src/tools/annotation/PlanarFreehandROITool.ts +636 -0
  185. package/src/tools/annotation/ProbeTool.ts +681 -0
  186. package/src/tools/annotation/RectangleROITool.ts +1028 -0
  187. package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +488 -0
  188. package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +462 -0
  189. package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +331 -0
  190. package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +74 -0
  191. package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +612 -0
  192. package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +74 -0
  193. package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +407 -0
  194. package/src/tools/base/AnnotationDisplayTool.ts +228 -0
  195. package/src/tools/base/AnnotationTool.ts +307 -0
  196. package/src/tools/base/BaseTool.ts +215 -0
  197. package/src/tools/base/index.ts +4 -0
  198. package/src/tools/displayTools/Contour/addContourToElement.ts +135 -0
  199. package/src/tools/displayTools/Contour/contourDisplay.ts +252 -0
  200. package/src/tools/displayTools/Contour/index.ts +3 -0
  201. package/src/tools/displayTools/Contour/removeContourFromElement.ts +35 -0
  202. package/src/tools/displayTools/Labelmap/addLabelmapToElement.ts +57 -0
  203. package/src/tools/displayTools/Labelmap/index.ts +4 -0
  204. package/src/tools/displayTools/Labelmap/labelmapConfig.ts +37 -0
  205. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +461 -0
  206. package/src/tools/displayTools/Labelmap/removeLabelmapFromElement.ts +27 -0
  207. package/src/tools/displayTools/Labelmap/validateRepresentationData.ts +30 -0
  208. package/src/tools/displayTools/SegmentationDisplayTool.ts +198 -0
  209. package/src/tools/index.ts +84 -0
  210. package/src/tools/segmentation/BrushTool.ts +474 -0
  211. package/src/tools/segmentation/CircleScissorsTool.ts +365 -0
  212. package/src/tools/segmentation/PaintFillTool.ts +370 -0
  213. package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +471 -0
  214. package/src/tools/segmentation/RectangleROIThresholdTool.ts +281 -0
  215. package/src/tools/segmentation/RectangleScissorsTool.ts +382 -0
  216. package/src/tools/segmentation/SphereScissorsTool.ts +368 -0
  217. package/src/tools/segmentation/strategies/eraseCircle.ts +30 -0
  218. package/src/tools/segmentation/strategies/eraseRectangle.ts +81 -0
  219. package/src/tools/segmentation/strategies/eraseSphere.ts +27 -0
  220. package/src/tools/segmentation/strategies/fillCircle.ts +185 -0
  221. package/src/tools/segmentation/strategies/fillRectangle.ts +110 -0
  222. package/src/tools/segmentation/strategies/fillSphere.ts +88 -0
  223. package/src/tools/segmentation/strategies/index.ts +9 -0
  224. package/src/types/AnnotationGroupSelector.ts +7 -0
  225. package/src/types/AnnotationStyle.ts +42 -0
  226. package/src/types/AnnotationTypes.ts +109 -0
  227. package/src/types/BoundsIJK.ts +5 -0
  228. package/src/types/CINETypes.ts +32 -0
  229. package/src/types/ContourTypes.ts +26 -0
  230. package/src/types/CursorTypes.ts +12 -0
  231. package/src/types/EventTypes.ts +657 -0
  232. package/src/types/FloodFillTypes.ts +19 -0
  233. package/src/types/IAnnotationManager.ts +89 -0
  234. package/src/types/IDistance.ts +16 -0
  235. package/src/types/IPoints.ts +18 -0
  236. package/src/types/ISetToolModeOptions.ts +29 -0
  237. package/src/types/ISynchronizerEventHandler.ts +11 -0
  238. package/src/types/IToolClassReference.ts +5 -0
  239. package/src/types/IToolGroup.ts +72 -0
  240. package/src/types/ITouchPoints.ts +14 -0
  241. package/src/types/InteractionTypes.ts +6 -0
  242. package/src/types/InternalToolTypes.ts +19 -0
  243. package/src/types/JumpToSliceOptions.ts +7 -0
  244. package/src/types/LabelmapTypes.ts +41 -0
  245. package/src/types/PlanarBoundingBox.ts +8 -0
  246. package/src/types/SVGDrawingHelper.ts +10 -0
  247. package/src/types/ScrollOptions.ts +9 -0
  248. package/src/types/SegmentationStateTypes.ts +248 -0
  249. package/src/types/ToolHandle.ts +26 -0
  250. package/src/types/ToolProps.ts +16 -0
  251. package/src/types/ToolSpecificAnnotationTypes.ts +311 -0
  252. package/src/types/index.ts +115 -0
  253. package/src/utilities/boundingBox/extend2DBoundingBoxInViewAxis.ts +29 -0
  254. package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +57 -0
  255. package/src/utilities/boundingBox/index.ts +4 -0
  256. package/src/utilities/calibrateImageSpacing.ts +46 -0
  257. package/src/utilities/cine/events.ts +9 -0
  258. package/src/utilities/cine/index.ts +5 -0
  259. package/src/utilities/cine/playClip.ts +435 -0
  260. package/src/utilities/cine/state.ts +18 -0
  261. package/src/utilities/clip.js +30 -0
  262. package/src/utilities/debounce.js +217 -0
  263. package/src/utilities/drawing/getTextBoxCoordsCanvas.ts +45 -0
  264. package/src/utilities/drawing/index.ts +3 -0
  265. package/src/utilities/dynamicVolume/getDataInTime.ts +110 -0
  266. package/src/utilities/dynamicVolume/index.ts +2 -0
  267. package/src/utilities/getAnnotationNearPoint.ts +130 -0
  268. package/src/utilities/getModalityUnit.ts +11 -0
  269. package/src/utilities/getToolsWithModesForElement.ts +52 -0
  270. package/src/utilities/index.ts +68 -0
  271. package/src/utilities/isObject.js +29 -0
  272. package/src/utilities/math/angle/angleBetweenLines.ts +29 -0
  273. package/src/utilities/math/circle/_types.ts +6 -0
  274. package/src/utilities/math/circle/getCanvasCircleCorners.ts +23 -0
  275. package/src/utilities/math/circle/getCanvasCircleRadius.ts +16 -0
  276. package/src/utilities/math/circle/index.ts +4 -0
  277. package/src/utilities/math/ellipse/getCanvasEllipseCorners.ts +26 -0
  278. package/src/utilities/math/ellipse/index.ts +4 -0
  279. package/src/utilities/math/ellipse/pointInEllipse.ts +38 -0
  280. package/src/utilities/math/ellipse/pointInEllipsoidWithConstraint.ts +35 -0
  281. package/src/utilities/math/index.ts +8 -0
  282. package/src/utilities/math/line/distanceToPoint.ts +24 -0
  283. package/src/utilities/math/line/distanceToPointSquared.ts +44 -0
  284. package/src/utilities/math/line/index.ts +5 -0
  285. package/src/utilities/math/line/intersectLine.ts +92 -0
  286. package/src/utilities/math/midPoint.ts +24 -0
  287. package/src/utilities/math/point/distanceToPoint.ts +22 -0
  288. package/src/utilities/math/point/index.ts +3 -0
  289. package/src/utilities/math/polyline/addCanvasPointsToArray.ts +62 -0
  290. package/src/utilities/math/polyline/calculateAreaOfPoints.ts +23 -0
  291. package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +182 -0
  292. package/src/utilities/math/polyline/getSubPixelSpacingAndXYDirections.ts +99 -0
  293. package/src/utilities/math/polyline/index.ts +19 -0
  294. package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +36 -0
  295. package/src/utilities/math/polyline/pointCanProjectOnLine.ts +57 -0
  296. package/src/utilities/math/polyline/pointsAreWithinCloseContourProximity.ts +15 -0
  297. package/src/utilities/math/rectangle/distanceToPoint.ts +82 -0
  298. package/src/utilities/math/rectangle/index.ts +3 -0
  299. package/src/utilities/math/sphere/index.ts +3 -0
  300. package/src/utilities/math/sphere/pointInSphere.ts +31 -0
  301. package/src/utilities/math/vec2/findClosestPoint.ts +40 -0
  302. package/src/utilities/math/vec2/index.ts +4 -0
  303. package/src/utilities/math/vec2/liangBarksyClip.ts +84 -0
  304. package/src/utilities/orientation/getOrientationStringLPS.ts +52 -0
  305. package/src/utilities/orientation/index.ts +4 -0
  306. package/src/utilities/orientation/invertOrientationStringLPS.ts +21 -0
  307. package/src/utilities/planar/filterAnnotationsForDisplay.ts +68 -0
  308. package/src/utilities/planar/filterAnnotationsWithinSlice.ts +85 -0
  309. package/src/utilities/planar/getPointInLineOfSightWithCriteria.ts +104 -0
  310. package/src/utilities/planar/getWorldWidthAndHeightFromCorners.ts +51 -0
  311. package/src/utilities/planar/getWorldWidthAndHeightFromTwoPoints.ts +51 -0
  312. package/src/utilities/planar/index.ts +18 -0
  313. package/src/utilities/planarFreehandROITool/index.ts +7 -0
  314. package/src/utilities/planarFreehandROITool/interpolateAnnotation.ts +87 -0
  315. package/src/utilities/planarFreehandROITool/interpolatePoints.ts +214 -0
  316. package/src/utilities/planarFreehandROITool/interpolation/algorithms/bspline.ts +55 -0
  317. package/src/utilities/planarFreehandROITool/interpolation/interpolateSegmentPoints.ts +90 -0
  318. package/src/utilities/pointInShapeCallback.ts +138 -0
  319. package/src/utilities/pointInSurroundingSphereCallback.ts +188 -0
  320. package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +76 -0
  321. package/src/utilities/rectangleROITool/index.ts +3 -0
  322. package/src/utilities/scroll.ts +62 -0
  323. package/src/utilities/segmentation/brushSizeForToolGroup.ts +72 -0
  324. package/src/utilities/segmentation/brushThresholdForToolGroup.ts +65 -0
  325. package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +74 -0
  326. package/src/utilities/segmentation/createMergedLabelmapForIndex.ts +65 -0
  327. package/src/utilities/segmentation/floodFill.ts +194 -0
  328. package/src/utilities/segmentation/getDefaultRepresentationConfig.ts +20 -0
  329. package/src/utilities/segmentation/index.ts +33 -0
  330. package/src/utilities/segmentation/isValidRepresentationConfig.ts +22 -0
  331. package/src/utilities/segmentation/rectangleROIThresholdVolumeByRange.ts +91 -0
  332. package/src/utilities/segmentation/thresholdSegmentationByRange.ts +129 -0
  333. package/src/utilities/segmentation/thresholdVolumeByRange.ts +150 -0
  334. package/src/utilities/segmentation/triggerSegmentationRender.ts +206 -0
  335. package/src/utilities/segmentation/utilities.ts +116 -0
  336. package/src/utilities/stackPrefetch/index.ts +8 -0
  337. package/src/utilities/stackPrefetch/stackPrefetch.ts +405 -0
  338. package/src/utilities/stackPrefetch/state.ts +17 -0
  339. package/src/utilities/throttle.js +69 -0
  340. package/src/utilities/touch/index.ts +246 -0
  341. package/src/utilities/triggerAnnotationRender.ts +237 -0
  342. package/src/utilities/triggerAnnotationRenderForViewportIds.ts +18 -0
  343. package/src/utilities/viewport/index.ts +5 -0
  344. package/src/utilities/viewport/isViewportPreScaled.ts +24 -0
  345. package/src/utilities/viewport/jumpToSlice.ts +73 -0
  346. package/src/utilities/viewport/jumpToWorld.ts +58 -0
  347. package/src/utilities/viewportFilters/filterViewportsWithFrameOfReferenceUID.ts +28 -0
  348. package/src/utilities/viewportFilters/filterViewportsWithParallelNormals.ts +26 -0
  349. package/src/utilities/viewportFilters/filterViewportsWithSameOrientation.ts +15 -0
  350. package/src/utilities/viewportFilters/filterViewportsWithToolEnabled.ts +72 -0
  351. package/src/utilities/viewportFilters/getViewportIdsWithToolToRender.ts +45 -0
  352. package/src/utilities/viewportFilters/index.ts +11 -0
@@ -0,0 +1,265 @@
1
+ import {
2
+ StyleConfig,
3
+ ToolStyleConfig,
4
+ StyleSpecifier,
5
+ AnnotationStyle,
6
+ } from '../../../types/AnnotationStyle';
7
+
8
+ /**
9
+ * This class handles the configuration of the tool style. You can use it to set
10
+ * the style of a tool at various levels (annotation, viewport, toolGroup, global).
11
+ *
12
+ * The hierarchy of the configuration is as follows (each level falls back to the
13
+ * next level if not specified):
14
+ *
15
+ * 1) Annotation-level styles (with annotationUID)
16
+ * 2) Viewport-level tool styles
17
+ * - Per-tool: Length on the viewport with viewportId
18
+ * - Global: All tools on the viewport with viewportId
19
+ * 3) ToolGroup tool styles
20
+ * - Per-tool: Angle on toolGroupId in all viewports of the toolGroup
21
+ * - Global: All tools in the toolGroupId for all viewports
22
+ * 4) Default level:
23
+ * - Per-tool: Length styles
24
+ * - Global: Opinionated styles by CornerstoneJS
25
+ */
26
+ class ToolStyle {
27
+ config: StyleConfig;
28
+
29
+ constructor() {
30
+ const defaultConfig = {
31
+ color: 'rgb(255, 255, 0)',
32
+ colorHighlighted: 'rgb(0, 255, 0)',
33
+ colorSelected: 'rgb(0, 220, 0)',
34
+ colorLocked: 'rgb(255, 255, 0)',
35
+ lineWidth: '1',
36
+ lineDash: '',
37
+ shadow: true,
38
+ textBoxFontFamily: 'Helvetica Neue, Helvetica, Arial, sans-serif',
39
+ textBoxFontSize: '14px',
40
+ textBoxColor: 'rgb(255, 255, 0)',
41
+ textBoxColorHighlighted: 'rgb(0, 255, 0)',
42
+ textBoxColorSelected: 'rgb(0, 255, 0)',
43
+ textBoxColorLocked: 'rgb(255, 255, 0)',
44
+ textBoxBackground: '',
45
+ textBoxLinkLineWidth: '1',
46
+ textBoxLinkLineDash: '2,3',
47
+ textBoxShadow: true,
48
+ };
49
+
50
+ this._initializeConfig(defaultConfig);
51
+ }
52
+
53
+ /**
54
+ * It returns the annotation-specific tool styles for the annotation with the given UID
55
+ * @param annotationUID - The unique identifier of the annotation.
56
+ * @returns The annotation tool styles for the annotation with the given UID.
57
+ */
58
+ getAnnotationToolStyles(annotationUID: string): AnnotationStyle {
59
+ return this.config.annotations && this.config.annotations[annotationUID];
60
+ }
61
+
62
+ /**
63
+ * It returns the styles for a given viewport. It includes tool-specific and
64
+ * global styles (all tools in the viewport)
65
+ * @param viewportId - The id of the viewport
66
+ * @returns The viewport tool styles for the given viewport id.
67
+ */
68
+ getViewportToolStyles(viewportId: string): ToolStyleConfig {
69
+ return this.config.viewports && this.config.viewports[viewportId];
70
+ }
71
+
72
+ /**
73
+ * It returns the tool style for the given toolGroup. It includes tool-specific and
74
+ * global styles (all tools in the toolGroup)
75
+ * @param toolGroupId - The id of the toolGroup.
76
+ * @returns The tool styles for the tool group with the given id.
77
+ */
78
+ getToolGroupToolStyles(toolGroupId: string): ToolStyleConfig {
79
+ return this.config.toolGroups && this.config.toolGroups[toolGroupId];
80
+ }
81
+
82
+ /**
83
+ * It returns the default tool styles from the config file. It includes tool-specific and
84
+ * global styles (all tools in all tooLGroups)
85
+ * @returns The default tool styles.
86
+ */
87
+ getDefaultToolStyles(): ToolStyleConfig {
88
+ return this.config.default;
89
+ }
90
+
91
+ /**
92
+ * It takes an annotationUID and a style object and sets the styles at
93
+ * the annotationLevel (highest priority in the hierarchy). The styles is an
94
+ * object with key value pairs.
95
+ * @param annotationUID - string - The unique identifier for the annotation.
96
+ * @param styles - ToolStyles
97
+ */
98
+ setAnnotationStyles(annotationUID: string, styles: AnnotationStyle) {
99
+ let annotationSpecificStyles = this.config.annotations;
100
+
101
+ if (!annotationSpecificStyles) {
102
+ this.config = {
103
+ ...this.config,
104
+ annotations: {},
105
+ };
106
+
107
+ annotationSpecificStyles = this.config.annotations;
108
+ }
109
+
110
+ annotationSpecificStyles[annotationUID] = styles;
111
+ }
112
+
113
+ /**
114
+ * It takes a viewportId and a ToolStyles object, and adds the ToolStyles object
115
+ * at the viewport level (second highest priority in the hierarchy after the annotation level).
116
+ * @param viewportId - The id of the viewport
117
+ * @param styles - style object including tool-specific and/or global styles (All tools in the viewport)
118
+ */
119
+ setViewportToolStyles(viewportId: string, styles: ToolStyleConfig) {
120
+ let viewportSpecificStyles = this.config.viewports;
121
+
122
+ if (!viewportSpecificStyles) {
123
+ this.config = {
124
+ ...this.config,
125
+ viewports: {},
126
+ };
127
+
128
+ viewportSpecificStyles = this.config.viewports;
129
+ }
130
+
131
+ viewportSpecificStyles[viewportId] = styles;
132
+ }
133
+
134
+ /**
135
+ * It takes a toolGroupId and a ToolStyles object, and it adds the ToolStyles object
136
+ * at the toolGroup level (third highest priority in the hierarchy after the viewport level).
137
+ * @param toolGroupId - The id of the toolGroup
138
+ * @param styles - style object including tool-specific (in all viewports of the toolGroup) and/or
139
+ * global styles (All tools in the toolGroup for all viewports)
140
+ */
141
+ setToolGroupToolStyles(toolGroupId: string, styles: ToolStyleConfig) {
142
+ let toolGroupSpecificStyles = this.config.toolGroups;
143
+
144
+ if (!toolGroupSpecificStyles) {
145
+ this.config = {
146
+ ...this.config,
147
+ toolGroups: {},
148
+ };
149
+
150
+ toolGroupSpecificStyles = this.config.toolGroups;
151
+ }
152
+
153
+ toolGroupSpecificStyles[toolGroupId] = styles;
154
+ }
155
+
156
+ /**
157
+ * Sets the default tool styles for the editor. It overrides the default styles for all tools.
158
+ * @param styles - style object including tool-specific (a tool in all toolGroups) and/or
159
+ * global styles (All tools in all tooLGroups)
160
+ */
161
+ setDefaultToolStyles(styles: ToolStyleConfig) {
162
+ this.config.default = styles;
163
+ }
164
+
165
+ /**
166
+ * It returns the value for a given style key, based on the provided specifications.
167
+ * It starts by looking at the annotation-specific styles, then at the viewport-specific styles,
168
+ * then at the toolGroup-specific styles, and finally at the default styles.
169
+ * @param styleKey - The key of the style.
170
+ * @param styleSpecifier - An object containing the specifications such as viewportId,
171
+ * toolGroupId, toolName and annotationUID which are used to get the style if the level of specificity is
172
+ * met
173
+ * @returns The value for the given style key.
174
+ */
175
+ getStyleProperty(toolStyle: string, specifications: StyleSpecifier) {
176
+ const { annotationUID, viewportId, toolGroupId, toolName } = specifications;
177
+
178
+ return this._getToolStyle(
179
+ toolStyle,
180
+ annotationUID,
181
+ viewportId,
182
+ toolGroupId,
183
+ toolName
184
+ );
185
+ }
186
+
187
+ private _getToolStyle(
188
+ property: string,
189
+ annotationUID: string,
190
+ viewportId: string,
191
+ toolGroupId: string,
192
+ toolName: string
193
+ ) {
194
+ if (annotationUID) {
195
+ const styles = this.getAnnotationToolStyles(annotationUID);
196
+
197
+ if (styles) {
198
+ // check first in the toolSpecific styles
199
+ if (styles[property]) {
200
+ return styles[property];
201
+ }
202
+ }
203
+ }
204
+
205
+ if (viewportId) {
206
+ const styles = this.getViewportToolStyles(viewportId);
207
+
208
+ if (styles) {
209
+ // check if we have the viewportId specific style
210
+ // check first in the toolSpecific styles
211
+ if (styles[toolName] && styles[toolName][property]) {
212
+ return styles[toolName][property];
213
+ }
214
+
215
+ // check if we have the style in the viewport specific global viewportSpecificStyles
216
+ if (styles.global && styles.global[property]) {
217
+ return styles.global[property];
218
+ }
219
+ }
220
+ }
221
+
222
+ if (toolGroupId) {
223
+ const styles = this.getToolGroupToolStyles(toolGroupId);
224
+
225
+ if (styles) {
226
+ // check first in the toolSpecific styles
227
+ if (styles[toolName] && styles[toolName][property]) {
228
+ return styles[toolName][property];
229
+ }
230
+
231
+ // check if we have the style in the toolGroup specific global styles
232
+ if (styles.global && styles.global[property]) {
233
+ return styles.global[property];
234
+ }
235
+ }
236
+ }
237
+
238
+ const globalStyles = this.getDefaultToolStyles();
239
+
240
+ if (globalStyles[toolName] && globalStyles[toolName][property]) {
241
+ return globalStyles[toolName][property];
242
+ }
243
+
244
+ if (globalStyles.global && globalStyles.global[property]) {
245
+ return globalStyles.global[property];
246
+ }
247
+ }
248
+
249
+ private _initializeConfig(config) {
250
+ const toolStyles = {};
251
+ for (const name in config) {
252
+ toolStyles[name] = config[name];
253
+ }
254
+
255
+ this.config = {
256
+ default: {
257
+ global: toolStyles as AnnotationStyle,
258
+ },
259
+ };
260
+ }
261
+ }
262
+
263
+ const toolStyle = new ToolStyle();
264
+
265
+ export default toolStyle;
@@ -0,0 +1,36 @@
1
+ import { ToolModes, AnnotationStyleStates } from '../../../enums';
2
+ import { getStyleProperty } from './helpers';
3
+ import { StyleSpecifier } from '../../../types/AnnotationStyle';
4
+
5
+ /**
6
+ * getFont - Returns a font string of the form "{fontSize}px fontName" used by `canvas`.
7
+ * @param styleSpecifier - An object containing the specifications such as viewportId,
8
+ * toolGroupId, toolName and annotationUID which are used to get the style if the level of specificity is
9
+ * met (hierarchy is checked from most specific to least specific which is
10
+ * annotationLevel -> viewportLevel -> toolGroupLevel -> default.
11
+ * @param state - An optional state to determine the final property name
12
+ * @param mode - An optional mode to determine the final property name
13
+ * @returns The font string.
14
+ */
15
+ function getFont(
16
+ styleSpecifier: StyleSpecifier,
17
+ state?: AnnotationStyleStates,
18
+ mode?: ToolModes
19
+ ): string {
20
+ const fontSize = getStyleProperty(
21
+ 'textBoxFontSize',
22
+ styleSpecifier,
23
+ state,
24
+ mode
25
+ );
26
+ const fontFamily = getStyleProperty(
27
+ 'textBoxFontFamily',
28
+ styleSpecifier,
29
+ state,
30
+ mode
31
+ );
32
+
33
+ return `${fontSize}px ${fontFamily}`;
34
+ }
35
+
36
+ export default getFont;
@@ -0,0 +1,26 @@
1
+ import { Annotation } from '../../../types';
2
+ import { isAnnotationLocked } from '../annotationLocking';
3
+ import { isAnnotationSelected } from '../annotationSelection';
4
+ import { AnnotationStyleStates } from '../../../enums';
5
+
6
+ /**
7
+ * Given a Annotation object, return the annotationStyle State that it
8
+ * should be in based on its data
9
+ * @param annotation - The annotation that we want to style.
10
+ * @returns The state of the annotation whether it is Default, Highlighted, Locked, or Selected.
11
+ */
12
+ function getState(annotation?: Annotation): AnnotationStyleStates {
13
+ if (annotation) {
14
+ if (annotation.data && annotation.highlighted)
15
+ return AnnotationStyleStates.Highlighted;
16
+ if (isAnnotationSelected(annotation.annotationUID))
17
+ return AnnotationStyleStates.Selected;
18
+
19
+ // Todo: make annotation lock api not to rely on the annotation itself
20
+ if (isAnnotationLocked(annotation)) return AnnotationStyleStates.Locked;
21
+ }
22
+
23
+ return AnnotationStyleStates.Default;
24
+ }
25
+
26
+ export default getState;
@@ -0,0 +1,55 @@
1
+ import { StyleSpecifier } from '../../../types/AnnotationStyle';
2
+ import { ToolModes, AnnotationStyleStates } from '../../../enums';
3
+ import toolStyle from './ToolStyle';
4
+
5
+ /**
6
+ * Build a list of hierarchal property names in ascending order of priority
7
+ * @param property - The base property name -- e.g., 'color'
8
+ * @param state - An optional state to determine the final property name
9
+ * @param mode - An optional mode to determine the final property name
10
+ * @returns A list of property names
11
+ */
12
+ function getHierarchalPropertyStyles(
13
+ property: string,
14
+ state?: AnnotationStyleStates,
15
+ mode?: ToolModes
16
+ ): string[] {
17
+ const list = [`${property}`];
18
+ if (state) list.push(`${list[0]}${state}`);
19
+ if (mode) list.push(`${list[list.length - 1]}${mode}`);
20
+ return list;
21
+ }
22
+
23
+ /**
24
+ * Get the value of a style property from the ToolStyle config
25
+ * @param property - The name of the property to get.
26
+ * @param styleSpecifier - An object containing the specifications such as viewportId,
27
+ * toolGroupId, toolName and annotationUID which are used to get the style if the level of specificity is
28
+ * met (hierarchy is checked from most specific to least specific which is
29
+ * annotationLevel -> viewportLevel -> toolGroupLevel -> default.
30
+ * @param state - The state of the tool (Default, Locked etc.)
31
+ * @param mode - The current tool mode. (Active, Passive etc.)
32
+ * @returns The value of the property.
33
+ */
34
+ function getStyleProperty(
35
+ property: string,
36
+ styleSpecifier: StyleSpecifier,
37
+ state?: AnnotationStyleStates,
38
+ mode?: ToolModes
39
+ ): string {
40
+ // Hierarchal property styles is a list of property names with priority in ascending
41
+ // order like: ['color', 'colorSelected', 'colorSelectedActive'], if in the toolStyle
42
+ // config, the `colorSelectedActive` property is defined, it will be used, otherwise
43
+ // the `colorSelected` property will be used, and if that is not defined, the `color`
44
+ // property will be used. This is done to ensure that the most specific property is used.
45
+ // Thus, we attempt resolving property names in reverse order
46
+ const alternatives = getHierarchalPropertyStyles(property, state, mode);
47
+ for (let i = alternatives.length - 1; i >= 0; --i) {
48
+ const style = toolStyle.getStyleProperty(alternatives[i], styleSpecifier);
49
+ if (style !== undefined) {
50
+ return style;
51
+ }
52
+ }
53
+ }
54
+
55
+ export { getStyleProperty };
@@ -0,0 +1,5 @@
1
+ import getState from './getState';
2
+ import getFont from './getFont';
3
+ import style from './ToolStyle';
4
+
5
+ export { getState, getFont, style };
@@ -0,0 +1,83 @@
1
+ import {
2
+ getEnabledElement,
3
+ triggerEvent,
4
+ eventTarget,
5
+ getEnabledElementByIds,
6
+ } from '@cornerstonejs/core';
7
+ import { Events } from '../../../enums';
8
+ import { Annotation } from '../../../types/AnnotationTypes';
9
+ import { getToolGroupsWithToolName } from '../../../store/ToolGroupManager';
10
+ import { AnnotationAddedEventDetail } from '../../../types/EventTypes';
11
+
12
+ /**
13
+ * It triggers an event for the element when an annotation is added
14
+ * @param annotation - Annotation - The annotation that was added.
15
+ * @param element - The element that the annotation was added to.
16
+ */
17
+ function triggerAnnotationAddedForElement(
18
+ annotation: Annotation,
19
+ element: HTMLDivElement
20
+ ) {
21
+ const enabledElement = getEnabledElement(element);
22
+ const { renderingEngine, viewportId } = enabledElement;
23
+
24
+ const eventType = Events.ANNOTATION_ADDED;
25
+
26
+ const eventDetail: AnnotationAddedEventDetail = {
27
+ annotation,
28
+ viewportId,
29
+ renderingEngineId: renderingEngine.id,
30
+ };
31
+
32
+ triggerEvent(eventTarget, eventType, eventDetail);
33
+ }
34
+
35
+ /**
36
+ * If the annotation has a FrameOfReferenceUID, it triggers the ANNOTATION_ADDED
37
+ * event for all the viewports that has the same FrameOfReferenceUID.
38
+ * @param annotation - Annotation - The annotation that was added
39
+ */
40
+ function triggerAnnotationAddedForFOR(annotation: Annotation) {
41
+ const { toolName } = annotation.metadata;
42
+
43
+ const toolGroups = getToolGroupsWithToolName(toolName);
44
+
45
+ if (!toolGroups.length) {
46
+ return;
47
+ }
48
+
49
+ // Find the viewports in the toolGroups who has the same FrameOfReferenceUID
50
+ const viewportsToRender = [];
51
+
52
+ toolGroups.forEach((toolGroup) => {
53
+ toolGroup.viewportsInfo.forEach((viewportInfo) => {
54
+ const { renderingEngineId, viewportId } = viewportInfo;
55
+ const { FrameOfReferenceUID } = getEnabledElementByIds(
56
+ viewportId,
57
+ renderingEngineId
58
+ );
59
+
60
+ if (annotation.metadata.FrameOfReferenceUID === FrameOfReferenceUID) {
61
+ viewportsToRender.push(viewportInfo);
62
+ }
63
+ });
64
+ });
65
+
66
+ if (!viewportsToRender.length) {
67
+ return;
68
+ }
69
+
70
+ const eventType = Events.ANNOTATION_ADDED;
71
+
72
+ viewportsToRender.forEach(({ renderingEngineId, viewportId }) => {
73
+ const eventDetail: AnnotationAddedEventDetail = {
74
+ annotation,
75
+ viewportId,
76
+ renderingEngineId,
77
+ };
78
+
79
+ triggerEvent(eventTarget, eventType, eventDetail);
80
+ });
81
+ }
82
+
83
+ export { triggerAnnotationAddedForElement, triggerAnnotationAddedForFOR };
@@ -0,0 +1,15 @@
1
+ import * as config from './config';
2
+ import * as locking from './annotationLocking';
3
+ import * as selection from './annotationSelection';
4
+ import * as state from './annotationState';
5
+ import * as visibility from './annotationVisibility';
6
+ import FrameOfReferenceSpecificAnnotationManager from './FrameOfReferenceSpecificAnnotationManager';
7
+
8
+ export {
9
+ config,
10
+ locking,
11
+ selection,
12
+ state,
13
+ visibility,
14
+ FrameOfReferenceSpecificAnnotationManager,
15
+ };
@@ -0,0 +1,40 @@
1
+ import FrameOfReferenceSpecificAnnotationManager, {
2
+ defaultFrameOfReferenceSpecificAnnotationManager,
3
+ } from './annotation/FrameOfReferenceSpecificAnnotationManager';
4
+ import * as annotationLocking from './annotation/annotationLocking';
5
+ import * as annotationSelection from './annotation/annotationSelection';
6
+
7
+ import {
8
+ getAnnotations,
9
+ addAnnotation,
10
+ removeAnnotation,
11
+ getAnnotation,
12
+ getNumberOfAnnotations,
13
+ setAnnotationManager,
14
+ getAnnotationManager,
15
+ resetAnnotationManager,
16
+ } from './annotation/annotationState';
17
+
18
+ import {
19
+ addSegmentationRepresentations,
20
+ removeSegmentationsFromToolGroup,
21
+ } from './segmentation';
22
+
23
+ export {
24
+ // annotations
25
+ FrameOfReferenceSpecificAnnotationManager,
26
+ defaultFrameOfReferenceSpecificAnnotationManager,
27
+ annotationLocking,
28
+ annotationSelection,
29
+ getAnnotations,
30
+ addAnnotation,
31
+ getNumberOfAnnotations,
32
+ removeAnnotation,
33
+ getAnnotation,
34
+ setAnnotationManager,
35
+ getAnnotationManager,
36
+ resetAnnotationManager,
37
+ // segmentations
38
+ addSegmentationRepresentations,
39
+ removeSegmentationsFromToolGroup,
40
+ };