@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,45 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Determine the coordinates that will place the textbox to the right of the
5
+ * annotation.
6
+ *
7
+ * @param annotationCanvasPoints - The canvas points of the annotation's handles.
8
+ * @returns - The coordinates for default placement of the textbox.
9
+ */
10
+ export default function getTextBoxCoordsCanvas(
11
+ annotationCanvasPoints: Array<Types.Point2>
12
+ ): Types.Point2 {
13
+ const corners = _determineCorners(annotationCanvasPoints);
14
+ const centerY = (corners.top[1] + corners.bottom[1]) / 2;
15
+ const textBoxCanvas = <Types.Point2>[corners.right[0], centerY];
16
+
17
+ return textBoxCanvas;
18
+ }
19
+
20
+ /**
21
+ * Determine the handles that have the min/max x and y values.
22
+ *
23
+ * @param canvasPoints - The canvas points of the annotation's handles.
24
+ * @returns - The top, left, bottom, and right handles.
25
+ */
26
+ function _determineCorners(canvasPoints: Array<Types.Point2>) {
27
+ const handlesLeftToRight = [canvasPoints[0], canvasPoints[1]].sort(_compareX);
28
+ const handlesTopToBottom = [canvasPoints[0], canvasPoints[1]].sort(_compareY);
29
+ const right = handlesLeftToRight[handlesLeftToRight.length - 1];
30
+ const top = handlesTopToBottom[0];
31
+ const bottom = handlesTopToBottom[handlesTopToBottom.length - 1];
32
+
33
+ return {
34
+ top,
35
+ bottom,
36
+ right,
37
+ };
38
+
39
+ function _compareX(a, b) {
40
+ return a[0] < b[0] ? -1 : 1;
41
+ }
42
+ function _compareY(a, b) {
43
+ return a[1] < b[1] ? -1 : 1;
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ import getTextBoxCoordsCanvas from './getTextBoxCoordsCanvas';
2
+
3
+ export { getTextBoxCoordsCanvas };
@@ -0,0 +1,110 @@
1
+ import { utilities, cache, Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Gets the scalar data for a series of time points for either a single
5
+ * coordinate or a segmentation mask, it will return the an array of scalar
6
+ * data for a single coordinate or an array of arrays for a segmentation.
7
+ *
8
+ * @param dynamicVolume: 4D volume to compute time point data from
9
+ * @param options: frameNumbers: which frames to use as timepoints, if left
10
+ * blank, gets data timepoints over all frames
11
+ * maskVolumeId: segmentationId to get timepoint data of
12
+ * imageCoordinate: world coordinate to get timepoint data of
13
+ * @returns
14
+ */
15
+ function getDataInTime(
16
+ dynamicVolume: Types.IDynamicImageVolume,
17
+ options: {
18
+ frameNumbers?;
19
+ maskVolumeId?;
20
+ imageCoordinate?;
21
+ }
22
+ ): number[] | number[][] {
23
+ let dataInTime;
24
+
25
+ // if frameNumbers is not provided, all frames are selected
26
+ const frames = options.frameNumbers || [
27
+ ...Array(dynamicVolume.numTimePoints).keys(),
28
+ ];
29
+
30
+ // You only need to provide either maskVolumeId OR imageCoordinate.
31
+ // Throws error if neither maskVolumeId or imageCoordinate is given,
32
+ // throws error if BOTH maskVolumeId and imageCoordinate is given
33
+ if (!options.maskVolumeId && !options.imageCoordinate) {
34
+ throw new Error('No ROI provided');
35
+ }
36
+
37
+ if (options.maskVolumeId && options.imageCoordinate) {
38
+ throw new Error('Please provide only one ROI');
39
+ }
40
+
41
+ if (options.maskVolumeId) {
42
+ const segmentationVolume = cache.getVolume(options.maskVolumeId);
43
+
44
+ // Get the index of every non-zero voxel in mask by mapping indexes to
45
+ // new array, then using the array to filter
46
+ const indexArray = segmentationVolume
47
+ .getScalarData()
48
+ .map((_, i) => i)
49
+ .filter((i) => segmentationVolume.getScalarData()[i] !== 0);
50
+ const dataInTime = _getTimePointDataMask(frames, indexArray, dynamicVolume);
51
+
52
+ return dataInTime;
53
+ }
54
+
55
+ if (options.imageCoordinate) {
56
+ const dataInTime = _getTimePointDataCoordinate(
57
+ frames,
58
+ options.imageCoordinate,
59
+ dynamicVolume
60
+ );
61
+
62
+ return dataInTime;
63
+ }
64
+
65
+ return dataInTime;
66
+ }
67
+
68
+ function _getTimePointDataCoordinate(frames, coordinate, volume) {
69
+ const { dimensions, imageData } = volume;
70
+ const index = imageData.worldToIndex(coordinate);
71
+
72
+ index[0] = Math.floor(index[0]);
73
+ index[1] = Math.floor(index[1]);
74
+ index[2] = Math.floor(index[2]);
75
+
76
+ if (!utilities.indexWithinDimensions(index, dimensions)) {
77
+ throw new Error('outside bounds');
78
+ }
79
+
80
+ // calculate offset for index
81
+ const yMultiple = dimensions[0];
82
+ const zMultiple = dimensions[0] * dimensions[1];
83
+ const allScalarData = volume.getScalarDataArrays();
84
+ const value = [];
85
+
86
+ for (let i = frames[0]; i < frames[0] + frames.length; i++) {
87
+ const activeScalarData = allScalarData[i];
88
+ const scalarIndex = index[2] * zMultiple + index[1] * yMultiple + index[0];
89
+ value.push(activeScalarData[scalarIndex]);
90
+ }
91
+
92
+ return value;
93
+ }
94
+
95
+ function _getTimePointDataMask(frames, indexArray, volume) {
96
+ const allScalarData = volume.getScalarDataArrays();
97
+ const value = [];
98
+
99
+ for (let i = 0; i < indexArray.length; i++) {
100
+ const indexValues = [];
101
+ for (let j = frames[0]; j < frames[0] + frames.length; j++) {
102
+ const activeScalarData = allScalarData[j];
103
+ indexValues.push(activeScalarData[indexArray[i]]);
104
+ }
105
+ value.push(indexValues);
106
+ }
107
+ return value;
108
+ }
109
+
110
+ export default getDataInTime;
@@ -0,0 +1,2 @@
1
+ import getDataInTime from './getDataInTime';
2
+ export { getDataInTime };
@@ -0,0 +1,130 @@
1
+ import { getEnabledElement } from '@cornerstonejs/core';
2
+ import type { Types } from '@cornerstonejs/core';
3
+
4
+ import { AnnotationTool, BaseTool } from '../tools';
5
+ import { Annotation } from '../types';
6
+ import { getAnnotations } from '../stateManagement/annotation/annotationState';
7
+ import * as ToolGroupManager from '../store/ToolGroupManager';
8
+
9
+ /**
10
+ * Get the annotation that is close to the provided canvas point, it will return
11
+ * the first annotation that is found.
12
+ *
13
+ * @param element - The element to search for an annotation on.
14
+ * @param canvasPoint - The canvasPoint on the page where the user clicked.
15
+ * @param proximity - The distance from the canvasPoint to the annotation.
16
+ * @returns The annotation for the element
17
+ */
18
+ function getAnnotationNearPoint(
19
+ element: HTMLDivElement,
20
+ canvasPoint: Types.Point2,
21
+ proximity = 5
22
+ ): Annotation | null {
23
+ // Todo: this function should return closest annotation, BUT, we are not using
24
+ // the function anywhere.
25
+ const enabledElement = getEnabledElement(element);
26
+ if (!enabledElement) {
27
+ throw new Error('getAnnotationNearPoint: enabledElement not found');
28
+ }
29
+
30
+ return getAnnotationNearPointOnEnabledElement(
31
+ enabledElement,
32
+ canvasPoint,
33
+ proximity
34
+ );
35
+ }
36
+
37
+ /**
38
+ * "Find the annotation near the point on the enabled element." it will return the
39
+ * first annotation that is found.
40
+ *
41
+ * @param enabledElement - The element that is currently active.
42
+ * @param point - The point to search near.
43
+ * @param proximity - The distance from the point that the annotation must
44
+ * be within.
45
+ * @returns A Annotation object.
46
+ */
47
+ function getAnnotationNearPointOnEnabledElement(
48
+ enabledElement: Types.IEnabledElement,
49
+ point: Types.Point2,
50
+ proximity: number
51
+ ): Annotation | null {
52
+ // Todo: this function should return closest annotation, BUT, we are not using
53
+ // the function anywhere.
54
+ const { renderingEngineId, viewportId } = enabledElement;
55
+ const toolGroup = ToolGroupManager.getToolGroupForViewport(
56
+ viewportId,
57
+ renderingEngineId
58
+ );
59
+
60
+ if (!toolGroup) {
61
+ return null;
62
+ }
63
+
64
+ const { _toolInstances: tools } = toolGroup;
65
+ for (const name in tools) {
66
+ const found = findAnnotationNearPointByTool(
67
+ tools[name],
68
+ enabledElement,
69
+ point,
70
+ proximity
71
+ );
72
+ if (found) {
73
+ return found;
74
+ }
75
+ }
76
+
77
+ return null;
78
+ }
79
+
80
+ /**
81
+ * For the provided toolClass, it will find the annotation that is near the point,
82
+ * it will return the first annotation that is found.
83
+ *
84
+ * @param tool - AnnotationTool
85
+ * @param enabledElement - The element that is currently active.
86
+ * @param point - The point in the image where the user clicked.
87
+ * @param proximity - The distance from the point that the tool must be
88
+ * within to be considered "near" the point.
89
+ * @returns The annotation object that is being returned is the annotation object that
90
+ * is being used in the tool.
91
+ */
92
+ function findAnnotationNearPointByTool(
93
+ tool: AnnotationTool,
94
+ enabledElement: Types.IEnabledElement,
95
+ point: Types.Point2,
96
+ proximity: number
97
+ ): Annotation | null {
98
+ // Todo: this function does not return closest annotation. It just returns
99
+ // the first annotation that is found in the proximity. BUT, we are not using
100
+ // the function anywhere.
101
+ const { viewport } = enabledElement;
102
+
103
+ const annotations = getAnnotations(
104
+ (tool.constructor as typeof BaseTool).toolName,
105
+ viewport?.element
106
+ );
107
+ const currentId = viewport?.getCurrentImageId?.();
108
+ if (annotations?.length) {
109
+ const { element } = enabledElement.viewport;
110
+ for (const annotation of annotations) {
111
+ const referencedImageId = annotation.metadata?.referencedImageId;
112
+ if (
113
+ (currentId && referencedImageId && currentId !== referencedImageId) ||
114
+ !tool.isPointNearTool
115
+ ) {
116
+ continue;
117
+ }
118
+
119
+ if (
120
+ tool.isPointNearTool(element, annotation, point, proximity, '') ||
121
+ tool.getHandleNearImagePoint(element, annotation, point, proximity)
122
+ ) {
123
+ return annotation;
124
+ }
125
+ }
126
+ }
127
+ return null;
128
+ }
129
+
130
+ export { getAnnotationNearPoint, getAnnotationNearPointOnEnabledElement };
@@ -0,0 +1,11 @@
1
+ function getModalityUnit(modality: string, isPreScaled: boolean): string {
2
+ if (modality === 'CT') {
3
+ return 'HU';
4
+ } else if (modality === 'PT' && isPreScaled === true) {
5
+ return 'SUV';
6
+ } else {
7
+ return '';
8
+ }
9
+ }
10
+
11
+ export { getModalityUnit };
@@ -0,0 +1,52 @@
1
+ import { ToolGroupManager } from '../store';
2
+ import { ToolModes } from '../enums';
3
+ import { getEnabledElement } from '@cornerstonejs/core';
4
+
5
+ type ModesFilter = Array<ToolModes>;
6
+
7
+ /**
8
+ * Finds the enabled element, and iterates over the tools inside its
9
+ * toolGroup. Returns the list of tool instances that are valid based
10
+ * on the provided tool mode.
11
+ *
12
+ * @param element Canvas element
13
+ * @param modesFilter tool modes: active, passive, enabled, disabled
14
+ * @returns enabled tool instances
15
+ */
16
+ export default function getToolsWithModesForElement(
17
+ element: HTMLDivElement,
18
+ modesFilter: ModesFilter
19
+ ) {
20
+ const enabledElement = getEnabledElement(element);
21
+ const { renderingEngineId, viewportId } = enabledElement;
22
+
23
+ const toolGroup = ToolGroupManager.getToolGroupForViewport(
24
+ viewportId,
25
+ renderingEngineId
26
+ );
27
+
28
+ if (!toolGroup) {
29
+ return [];
30
+ }
31
+
32
+ const enabledTools = [];
33
+
34
+ const toolGroupToolNames = Object.keys(toolGroup.toolOptions);
35
+
36
+ for (let j = 0; j < toolGroupToolNames.length; j++) {
37
+ const toolName = toolGroupToolNames[j];
38
+ const toolOptions = toolGroup.toolOptions[toolName];
39
+
40
+ /* filter out tools that don't have options */
41
+ if (!toolOptions) {
42
+ continue;
43
+ }
44
+
45
+ if (modesFilter.includes(toolOptions.mode)) {
46
+ const toolInstance = toolGroup.getToolInstance(toolName);
47
+ enabledTools.push(toolInstance);
48
+ }
49
+ }
50
+
51
+ return enabledTools;
52
+ }
@@ -0,0 +1,68 @@
1
+ import {
2
+ getAnnotationNearPoint,
3
+ getAnnotationNearPointOnEnabledElement,
4
+ } from './getAnnotationNearPoint';
5
+
6
+ // Lodash/common JS functionality
7
+ import debounce from './debounce';
8
+ import throttle from './throttle';
9
+ import isObject from './isObject';
10
+ import clip from './clip';
11
+ import calibrateImageSpacing from './calibrateImageSpacing';
12
+ import triggerAnnotationRenderForViewportIds from './triggerAnnotationRenderForViewportIds';
13
+ import triggerAnnotationRender from './triggerAnnotationRender';
14
+ import jumpToSlice from './viewport/jumpToSlice';
15
+
16
+ import pointInShapeCallback from './pointInShapeCallback';
17
+ import pointInSurroundingSphereCallback from './pointInSurroundingSphereCallback';
18
+ import scroll from './scroll';
19
+
20
+ // name spaces
21
+ import * as segmentation from './segmentation';
22
+ import * as drawing from './drawing';
23
+ import * as math from './math';
24
+ import * as planar from './planar';
25
+ import * as viewportFilters from './viewportFilters';
26
+ import * as orientation from './orientation';
27
+ import * as cine from './cine';
28
+ import * as boundingBox from './boundingBox';
29
+ import * as planarFreehandROITool from './planarFreehandROITool';
30
+ import * as rectangleROITool from './rectangleROITool';
31
+ import * as stackPrefetch from './stackPrefetch';
32
+ import * as viewport from './viewport';
33
+ import * as touch from './touch';
34
+ import * as dynamicVolume from './dynamicVolume';
35
+
36
+ // Events
37
+ import { triggerEvent } from '@cornerstonejs/core';
38
+
39
+ export {
40
+ math,
41
+ planar,
42
+ viewportFilters,
43
+ drawing,
44
+ debounce,
45
+ dynamicVolume,
46
+ throttle,
47
+ orientation,
48
+ isObject,
49
+ touch,
50
+ triggerEvent,
51
+ calibrateImageSpacing,
52
+ segmentation,
53
+ triggerAnnotationRenderForViewportIds,
54
+ triggerAnnotationRender,
55
+ pointInShapeCallback,
56
+ pointInSurroundingSphereCallback,
57
+ getAnnotationNearPoint,
58
+ getAnnotationNearPointOnEnabledElement,
59
+ jumpToSlice,
60
+ viewport,
61
+ cine,
62
+ clip,
63
+ boundingBox,
64
+ rectangleROITool,
65
+ planarFreehandROITool,
66
+ stackPrefetch,
67
+ scroll,
68
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Checks if `value` is the
3
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
4
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
5
+ *
6
+ * @since 0.1.0
7
+ * @param {*} value The value to check.
8
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
9
+ * @example
10
+ *
11
+ * isObject({})
12
+ * // => true
13
+ *
14
+ * isObject([1, 2, 3])
15
+ * // => true
16
+ *
17
+ * isObject(Function)
18
+ * // => true
19
+ *
20
+ * isObject(null)
21
+ * // => false
22
+ */
23
+ function isObject(value) {
24
+ const type = typeof value;
25
+
26
+ return value !== null && (type === 'object' || type === 'function');
27
+ }
28
+
29
+ export default isObject;
@@ -0,0 +1,29 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { vec3 } from 'gl-matrix';
3
+
4
+ type Line = [Types.Point3, Types.Point3];
5
+
6
+ /**
7
+ * It returns the angle between two lines in degrees.
8
+ * @param line1 - Line = [p1, p2]
9
+ * @param line2 - Line = [p3, p4]
10
+ * @returns The angle between two lines in degrees.
11
+ */
12
+ export default function angleBetweenLines(line1: Line, line2: Line): number {
13
+ const [p1, p2] = line1;
14
+ const [p3, p4] = line2;
15
+
16
+ const v1 = vec3.sub(vec3.create(), p2, p1);
17
+ const v2 = vec3.sub(vec3.create(), p3, p4);
18
+
19
+ const dot = vec3.dot(v1, v2);
20
+
21
+ const v1Length = vec3.length(v1);
22
+ const v2Length = vec3.length(v2);
23
+
24
+ const cos = dot / (v1Length * v2Length);
25
+
26
+ const radian = Math.acos(cos);
27
+
28
+ return (radian * 180) / Math.PI;
29
+ }
@@ -0,0 +1,6 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ export type canvasCoordinates = [
4
+ Types.Point2, // center
5
+ Types.Point2 // end
6
+ ];
@@ -0,0 +1,23 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { distanceToPoint } from '../point';
3
+ import { canvasCoordinates } from './_types';
4
+
5
+ /**
6
+ * It takes the canvas coordinates of the circle corners (wrapping square rectangle)
7
+ * and returns the top left and bottom right
8
+ * corners of it
9
+ *
10
+ * @param circleCanvasPoints - The coordinates of the circle in the canvas.
11
+ * @returns An array of two points.
12
+ */
13
+ export default function getCanvasCircleCorners(
14
+ circleCanvasPoints: canvasCoordinates
15
+ ): Array<Types.Point2> {
16
+ const [center, end] = circleCanvasPoints;
17
+ const radius = distanceToPoint(center, end);
18
+
19
+ const topLeft = <Types.Point2>[center[0] - radius, center[1] - radius];
20
+ const bottomRight = <Types.Point2>[center[0] + radius, center[1] + radius];
21
+
22
+ return [topLeft, bottomRight];
23
+ }
@@ -0,0 +1,16 @@
1
+ import { distanceToPoint } from '../point';
2
+ import { canvasCoordinates } from './_types';
3
+
4
+ /**
5
+ * It takes the canvas coordinates of the circle corners and returns the top left and bottom right
6
+ * corners of it
7
+ *
8
+ * @param circleCanvasPoints - The coordinates of the circle in the canvas.
9
+ * @returns An array of two points.
10
+ */
11
+ export default function getCanvasCircleRadius(
12
+ circleCanvasPoints: canvasCoordinates
13
+ ): number {
14
+ const [center, end] = circleCanvasPoints;
15
+ return distanceToPoint(center, end);
16
+ }
@@ -0,0 +1,4 @@
1
+ import getCanvasCircleRadius from './getCanvasCircleRadius';
2
+ import getCanvasCircleCorners from './getCanvasCircleCorners';
3
+
4
+ export { getCanvasCircleRadius, getCanvasCircleCorners };
@@ -0,0 +1,26 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ type canvasCoordinates = [
4
+ Types.Point2, // bottom
5
+ Types.Point2, // top
6
+ Types.Point2, // left
7
+ Types.Point2 // right
8
+ ];
9
+
10
+ /**
11
+ * It takes the canvas coordinates of the ellipse corners and returns the top left and bottom right
12
+ * corners of it
13
+ *
14
+ * @param ellipseCanvasPoints - The coordinates of the ellipse in the canvas.
15
+ * @returns An array of two points.
16
+ */
17
+ export default function getCanvasEllipseCorners(
18
+ ellipseCanvasPoints: canvasCoordinates
19
+ ): Array<Types.Point2> {
20
+ const [bottom, top, left, right] = ellipseCanvasPoints;
21
+
22
+ const topLeft = <Types.Point2>[left[0], top[1]];
23
+ const bottomRight = <Types.Point2>[right[0], bottom[1]];
24
+
25
+ return [topLeft, bottomRight];
26
+ }
@@ -0,0 +1,4 @@
1
+ import pointInEllipse from './pointInEllipse';
2
+ import getCanvasEllipseCorners from './getCanvasEllipseCorners';
3
+
4
+ export { pointInEllipse, getCanvasEllipseCorners };
@@ -0,0 +1,38 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ type Ellipse = {
4
+ center: Types.Point3;
5
+ xRadius: number;
6
+ yRadius: number;
7
+ zRadius: number;
8
+ };
9
+
10
+ /**
11
+ * Given an ellipse and a point, return true if the point is inside the ellipse
12
+ * @param ellipse - The ellipse object to check against.
13
+ * @param pointLPS - The point in LPS space to test.
14
+ * @returns A boolean value.
15
+ */
16
+ export default function pointInEllipse(
17
+ ellipse: Ellipse,
18
+ pointLPS: Types.Point3
19
+ ): boolean {
20
+ const { center: circleCenterWorld, xRadius, yRadius, zRadius } = ellipse;
21
+ const [x, y, z] = pointLPS;
22
+ const [x0, y0, z0] = circleCenterWorld;
23
+
24
+ let inside = 0;
25
+ if (xRadius !== 0) {
26
+ inside += ((x - x0) * (x - x0)) / (xRadius * xRadius);
27
+ }
28
+
29
+ if (yRadius !== 0) {
30
+ inside += ((y - y0) * (y - y0)) / (yRadius * yRadius);
31
+ }
32
+
33
+ if (zRadius !== 0) {
34
+ inside += ((z - z0) * (z - z0)) / (zRadius * zRadius);
35
+ }
36
+
37
+ return inside <= 1;
38
+ }
@@ -0,0 +1,35 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ type ellipsoid = {
4
+ center: [number, number, number];
5
+ width: number;
6
+ height: number;
7
+ depth: number;
8
+ };
9
+
10
+ /**
11
+ * Checks whether the point is inside the provided ellipse with constraint of a plane (viewPlane).
12
+ * @param ellipse - ellipse object including {center, width, height, depth}
13
+ * @param point - [x,y,z] of the point
14
+ * @param viewPlane - camera viewPlane
15
+ * @returns whether the point is inside the ellipse
16
+ */
17
+ export default function pointInEllipsoidWithConstraint(
18
+ ellipsoid: ellipsoid,
19
+ point: Types.Point3,
20
+ viewPlane: Types.Point3 // constraint
21
+ ) {
22
+ // Todo: This implementation should be used for oblique planes segmentation tools
23
+ // but still not a priority
24
+ // const { center, width, height, depth } = ellipsoid
25
+ // const [x, y, z] = point
26
+ // const [x0, y0, z0] = center
27
+ // const inside =
28
+ // ((x - x0) * (x - x0)) / (width * width) +
29
+ // ((y - y0) * (y - y0)) / (height * height) +
30
+ // ((z - z0) * (z - z0)) / (depth * depth) <=
31
+ // 1
32
+ // const onPlane =
33
+ // Math.abs(n1 * (x - x0) + n2 * (y - y0) + n3 * (z - z0)) <= 1e-3
34
+ // return inside
35
+ }
@@ -0,0 +1,8 @@
1
+ import * as vec2 from './vec2';
2
+ import * as ellipse from './ellipse';
3
+ import * as lineSegment from './line';
4
+ import * as rectangle from './rectangle';
5
+ import * as polyline from './polyline';
6
+ import * as point from './point';
7
+
8
+ export { vec2, ellipse, lineSegment, rectangle, polyline, point };
@@ -0,0 +1,24 @@
1
+ import distanceToPointSquared from './distanceToPointSquared';
2
+ import type { Types } from '@cornerstonejs/core';
3
+
4
+ /**
5
+ * Calculates the distance of a point to a line
6
+ *
7
+ * @param lineStart - x,y coordinates of the start of the line
8
+ * @param lineEnd - x,y coordinates of the end of the line
9
+ * @param point - x,y of the point
10
+ * @returns distance
11
+ */
12
+ export default function distanceToPoint(
13
+ lineStart: Types.Point2,
14
+ lineEnd: Types.Point2,
15
+ point: Types.Point2
16
+ ): number {
17
+ if (lineStart.length !== 2 || lineEnd.length !== 2 || point.length !== 2) {
18
+ throw Error(
19
+ 'lineStart, lineEnd, and point should have 2 elements of [x, y]'
20
+ );
21
+ }
22
+
23
+ return Math.sqrt(distanceToPointSquared(lineStart, lineEnd, point));
24
+ }