@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,246 @@
1
+ import { IDistance, IPoints, ITouchPoints } from '../../types';
2
+ import { Types } from '@cornerstonejs/core';
3
+
4
+ /**
5
+ * Returns the difference between multiple `IPoints` instances.
6
+ * @param currentPoints - The current points.
7
+ * @param lastPoints - The last points, to be subtracted from the `currentPoints`.
8
+ *
9
+ * @returns The difference in IPoints format
10
+ */
11
+ function getDeltaPoints(
12
+ currentPoints: IPoints[],
13
+ lastPoints: IPoints[]
14
+ ): IPoints {
15
+ const curr = getMeanPoints(currentPoints);
16
+ const last = getMeanPoints(lastPoints);
17
+ return {
18
+ page: _subtractPoints2D(curr.page, last.page),
19
+ client: _subtractPoints2D(curr.client, last.client),
20
+ canvas: _subtractPoints2D(curr.canvas, last.canvas),
21
+ world: _subtractPoints3D(curr.world, last.world),
22
+ };
23
+ }
24
+
25
+ /**
26
+ * Returns the distance between multiple `IPoints` instances.
27
+ * @param currentPoints - The current points.
28
+ * @param lastPoints - The last points, to be subtracted from the `currentPoints`.
29
+ *
30
+ * @returns The distance difference in IDistance format
31
+ */
32
+ function getDeltaDistance(
33
+ currentPoints: IPoints[],
34
+ lastPoints: IPoints[]
35
+ ): IDistance {
36
+ const curr = getMeanPoints(currentPoints);
37
+ const last = getMeanPoints(lastPoints);
38
+ return {
39
+ page: _getDistance2D(curr.page, last.page),
40
+ client: _getDistance2D(curr.client, last.client),
41
+ canvas: _getDistance2D(curr.canvas, last.canvas),
42
+ world: _getDistance3D(curr.world, last.world),
43
+ };
44
+ }
45
+
46
+ function getDeltaRotation(
47
+ currentPoints: ITouchPoints[],
48
+ lastPoints: ITouchPoints[]
49
+ ) {
50
+ // TODO
51
+ }
52
+
53
+ /**
54
+ * Returns the distance difference between multiple `IPoints` instances.
55
+ * @param currentPoints - The current points.
56
+ * @param lastPoints -- The last points.
57
+ *
58
+ * @returns The difference in IPoints format
59
+ */
60
+ function getDeltaDistanceBetweenIPoints(
61
+ currentPoints: IPoints[],
62
+ lastPoints: IPoints[]
63
+ ): IDistance {
64
+ const currentDistance = _getMeanDistanceBetweenAllIPoints(currentPoints);
65
+ const lastDistance = _getMeanDistanceBetweenAllIPoints(lastPoints);
66
+ const deltaDistance = {
67
+ page: currentDistance.page - lastDistance.page,
68
+ client: currentDistance.client - lastDistance.client,
69
+ canvas: currentDistance.canvas - lastDistance.canvas,
70
+ world: currentDistance.world - lastDistance.world,
71
+ };
72
+ return deltaDistance;
73
+ }
74
+
75
+ /**
76
+ * Copies a set of points.
77
+ * @param points - The `IPoints` instance to copy.
78
+ *
79
+ * @returns A copy of the points.
80
+ */
81
+ function copyPointsList(points: ITouchPoints[]): ITouchPoints[] {
82
+ return JSON.parse(JSON.stringify(points));
83
+ }
84
+
85
+ function copyPoints(points: ITouchPoints): ITouchPoints {
86
+ return JSON.parse(JSON.stringify(points));
87
+ }
88
+
89
+ function getMeanPoints(points: IPoints[]): IPoints {
90
+ return points.reduce(
91
+ (prev, curr) => {
92
+ return {
93
+ page: [
94
+ prev.page[0] + curr.page[0] / points.length,
95
+ prev.page[1] + curr.page[1] / points.length,
96
+ ],
97
+ client: [
98
+ prev.client[0] + curr.client[0] / points.length,
99
+ prev.client[1] + curr.client[1] / points.length,
100
+ ],
101
+ canvas: [
102
+ prev.canvas[0] + curr.canvas[0] / points.length,
103
+ prev.canvas[1] + curr.canvas[1] / points.length,
104
+ ],
105
+ world: [
106
+ prev.world[0] + curr.world[0] / points.length,
107
+ prev.world[1] + curr.world[1] / points.length,
108
+ prev.world[2] + curr.world[2] / points.length,
109
+ ],
110
+ };
111
+ },
112
+ {
113
+ page: [0, 0],
114
+ client: [0, 0],
115
+ canvas: [0, 0],
116
+ world: [0, 0, 0],
117
+ }
118
+ );
119
+ }
120
+
121
+ function getMeanTouchPoints(points: ITouchPoints[]): ITouchPoints {
122
+ return points.reduce(
123
+ (prev, curr) => {
124
+ return {
125
+ page: [
126
+ prev.page[0] + curr.page[0] / points.length,
127
+ prev.page[1] + curr.page[1] / points.length,
128
+ ],
129
+ client: [
130
+ prev.client[0] + curr.client[0] / points.length,
131
+ prev.client[1] + curr.client[1] / points.length,
132
+ ],
133
+ canvas: [
134
+ prev.canvas[0] + curr.canvas[0] / points.length,
135
+ prev.canvas[1] + curr.canvas[1] / points.length,
136
+ ],
137
+ world: [
138
+ prev.world[0] + curr.world[0] / points.length,
139
+ prev.world[1] + curr.world[1] / points.length,
140
+ prev.world[2] + curr.world[2] / points.length,
141
+ ],
142
+ touch: {
143
+ identifier: null,
144
+ radiusX: prev.touch.radiusX + curr.touch.radiusX / points.length,
145
+ radiusY: prev.touch.radiusY + curr.touch.radiusY / points.length,
146
+ force: prev.touch.force + curr.touch.force / points.length,
147
+ rotationAngle:
148
+ prev.touch.rotationAngle + curr.touch.rotationAngle / points.length,
149
+ },
150
+ };
151
+ },
152
+ {
153
+ page: [0, 0],
154
+ client: [0, 0],
155
+ canvas: [0, 0],
156
+ world: [0, 0, 0],
157
+ touch: {
158
+ identifier: null,
159
+ radiusX: 0,
160
+ radiusY: 0,
161
+ force: 0,
162
+ rotationAngle: 0,
163
+ },
164
+ }
165
+ );
166
+ }
167
+ /**
168
+ * _subtractPoints - Subtracts `point1` from `point0`.
169
+ * @param point0 - The first point.
170
+ * @param point1 - The second point to subtract from the first.
171
+ *
172
+ * @returns The difference.
173
+ */
174
+ function _subtractPoints2D(
175
+ point0: Types.Point2,
176
+ point1: Types.Point2
177
+ ): Types.Point2 {
178
+ return [point0[0] - point1[0], point0[1] - point1[1]];
179
+ }
180
+
181
+ function _subtractPoints3D(
182
+ point0: Types.Point3,
183
+ point1: Types.Point3
184
+ ): Types.Point3 {
185
+ return [point0[0] - point1[0], point0[1] - point1[1], point0[2] - point1[2]];
186
+ }
187
+
188
+ function _getMeanDistanceBetweenAllIPoints(points: IPoints[]): IDistance {
189
+ // get mean distance between all unordered pairs of points
190
+ const pairedDistance: IDistance[] = [];
191
+ for (let i = 0; i < points.length; i++) {
192
+ for (let j = 0; j < points.length; j++) {
193
+ if (i < j) {
194
+ pairedDistance.push({
195
+ page: _getDistance2D(points[i].page, points[j].page),
196
+ client: _getDistance2D(points[i].client, points[j].client),
197
+ canvas: _getDistance2D(points[i].canvas, points[j].canvas),
198
+ world: _getDistance3D(points[i].world, points[j].world),
199
+ });
200
+ }
201
+ }
202
+ }
203
+
204
+ // take the average distance
205
+ return pairedDistance.reduce(
206
+ (prev, curr) => {
207
+ return {
208
+ page: prev.page + curr.page / pairedDistance.length,
209
+ client: prev.client + curr.client / pairedDistance.length,
210
+ canvas: prev.canvas + curr.canvas / pairedDistance.length,
211
+ world: prev.world + curr.world / pairedDistance.length,
212
+ };
213
+ },
214
+ {
215
+ page: 0,
216
+ client: 0,
217
+ canvas: 0,
218
+ world: 0,
219
+ }
220
+ );
221
+ }
222
+
223
+ function _getDistance2D(point0: Types.Point2, point1: Types.Point2): number {
224
+ return Math.sqrt(
225
+ Math.pow(point0[0] - point1[0], 2) + Math.pow(point0[1] - point1[1], 2)
226
+ );
227
+ }
228
+
229
+ function _getDistance3D(point0: Types.Point3, point1: Types.Point3): number {
230
+ return Math.sqrt(
231
+ Math.pow(point0[0] - point1[0], 2) +
232
+ Math.pow(point0[1] - point1[1], 2) +
233
+ Math.pow(point0[2] - point1[2], 2)
234
+ );
235
+ }
236
+
237
+ export {
238
+ getMeanPoints,
239
+ getMeanTouchPoints,
240
+ copyPoints,
241
+ copyPointsList,
242
+ getDeltaDistanceBetweenIPoints,
243
+ getDeltaPoints,
244
+ getDeltaDistance,
245
+ getDeltaRotation,
246
+ };
@@ -0,0 +1,237 @@
1
+ import {
2
+ getEnabledElement,
3
+ triggerEvent,
4
+ getRenderingEngine,
5
+ } from '@cornerstonejs/core';
6
+ import { Events, ToolModes } from '../enums';
7
+ import { draw as drawSvg } from '../drawingSvg';
8
+ import getToolsWithModesForElement from './getToolsWithModesForElement';
9
+ import { AnnotationRenderedEventDetail } from '../types/EventTypes';
10
+ const { Active, Passive, Enabled } = ToolModes;
11
+
12
+ /**
13
+ * AnnotationRenderingEngine is a class that is responsible for rendering
14
+ * annotations defined in the renderAnnotation method of annotation tools on the page.
15
+ * It mimics the RenderingEngine in the Cornerstone Core. Here it uses requestAnimationFrame
16
+ * is used to render annotations by calling renderAnnotations() on each enabled tool. Note: This
17
+ * is a Singleton class and should not be instantiated directly. To trigger
18
+ * an annotation render for an HTML element containing a viewport you can use
19
+ *
20
+ * ```
21
+ * triggerAnnotationRender(element)
22
+ * ```
23
+ */
24
+ class AnnotationRenderingEngine {
25
+ public hasBeenDestroyed: boolean;
26
+ private _needsRender: Set<HTMLDivElement> = new Set();
27
+ private _animationFrameSet = false;
28
+ private _animationFrameHandle: number | null = null;
29
+ private _viewportElements: Map<string, HTMLDivElement>;
30
+
31
+ constructor() {
32
+ this._viewportElements = new Map();
33
+ }
34
+
35
+ /**
36
+ * Add the viewport's HTMLDivElement to the viewports for rendering. This method
37
+ * just informs the annotationRenderingEngine about the viewport and
38
+ * does not initiate a render.
39
+ * @param viewportId - Viewport Unique identifier
40
+ * @param element - HTMLDivElement
41
+ */
42
+ public addViewportElement(viewportId: string, element: HTMLDivElement) {
43
+ this._viewportElements.set(viewportId, element);
44
+ }
45
+
46
+ /**
47
+ * Remove the viewport's HTMLDivElement from subsequent annotation renders
48
+ * @param viewportId - Viewport Unique identifier
49
+ */
50
+ public removeViewportElement(viewportId: string, element: HTMLDivElement) {
51
+ this._viewportElements.delete(viewportId);
52
+
53
+ // delete element from needsRender if element exist
54
+ this._needsRender.delete(element);
55
+
56
+ // I don' think there is any disadvantage to canceling the animation frame
57
+ // and resetting the flags on viewport's element removal, since the removeVIewportElement
58
+ // might be as a result of reEnabling the element (in re-enable we disable first), hence the need to render the
59
+ // new one while removing the old one
60
+ this._reset();
61
+ }
62
+
63
+ /**
64
+ * It tells the AnnotationRenderingEngine to render the viewport element the next
65
+ * time it renders.
66
+ *
67
+ * @param element - The element to render.
68
+ */
69
+ public renderViewport(element: HTMLDivElement): void {
70
+ this._setViewportsToBeRenderedNextFrame([element]);
71
+ }
72
+
73
+ /**
74
+ * _throwIfDestroyed Throws an error if trying to interact with the `RenderingEngine`
75
+ * instance after its `destroy` method has been called.
76
+ */
77
+ private _throwIfDestroyed() {
78
+ if (this.hasBeenDestroyed) {
79
+ throw new Error(
80
+ 'this.destroy() has been manually called to free up memory, can not longer use this instance. Instead make a new one.'
81
+ );
82
+ }
83
+ }
84
+
85
+ private _renderFlaggedViewports = () => {
86
+ this._throwIfDestroyed();
87
+
88
+ const elements = Array.from(this._viewportElements.values());
89
+
90
+ for (let i = 0; i < elements.length; i++) {
91
+ const element = elements[i];
92
+ if (this._needsRender.has(element)) {
93
+ this._triggerRender(element);
94
+
95
+ // This viewport has been rendered, we can remove it from the set
96
+ this._needsRender.delete(element);
97
+
98
+ // If there is nothing left that is flagged for rendering, stop here
99
+ // and allow RAF to be called again
100
+ if (this._needsRender.size === 0) {
101
+ this._animationFrameSet = false;
102
+ this._animationFrameHandle = null;
103
+ return;
104
+ }
105
+ }
106
+ }
107
+ };
108
+
109
+ private _setAllViewportsToBeRenderedNextFrame() {
110
+ const elements = [...this._viewportElements.values()];
111
+
112
+ elements.forEach((element) => {
113
+ this._needsRender.add(element);
114
+ });
115
+
116
+ this._renderFlaggedViewports();
117
+ }
118
+
119
+ private _setViewportsToBeRenderedNextFrame(elements: HTMLDivElement[]) {
120
+ const elementsEnabled = [...this._viewportElements.values()];
121
+
122
+ // Add the viewports to the set of flagged viewports
123
+ elements.forEach((element) => {
124
+ // only enabledElement need to render
125
+ if (elementsEnabled.indexOf(element) !== -1) {
126
+ this._needsRender.add(element);
127
+ }
128
+ });
129
+
130
+ // Render any flagged viewports
131
+ this._render();
132
+ }
133
+
134
+ /**
135
+ * _render Sets up animation frame if necessary
136
+ */
137
+ private _render() {
138
+ // If we have viewports that need rendering and we have not already
139
+ // set the RAF callback to run on the next frame.
140
+ if (this._needsRender.size > 0 && this._animationFrameSet === false) {
141
+ this._animationFrameHandle = window.requestAnimationFrame(
142
+ this._renderFlaggedViewports
143
+ );
144
+
145
+ // Set the flag that we have already set up the next RAF call.
146
+ this._animationFrameSet = true;
147
+ }
148
+ }
149
+
150
+ _triggerRender(element) {
151
+ const enabledElement = getEnabledElement(element);
152
+
153
+ if (!enabledElement) {
154
+ console.warn('Element has been disabled');
155
+ return;
156
+ }
157
+
158
+ const renderingEngine = getRenderingEngine(
159
+ enabledElement.renderingEngineId
160
+ );
161
+ if (!renderingEngine) {
162
+ console.warn('rendering Engine has been destroyed');
163
+ return;
164
+ }
165
+
166
+ const enabledTools = getToolsWithModesForElement(element, [
167
+ Active,
168
+ Passive,
169
+ Enabled,
170
+ ]);
171
+
172
+ const { renderingEngineId, viewportId } = enabledElement;
173
+ const eventDetail: AnnotationRenderedEventDetail = {
174
+ element,
175
+ renderingEngineId,
176
+ viewportId,
177
+ };
178
+
179
+ // const enabledToolsWithAnnotations = enabledTools.filter((tool) => {
180
+ // const annotations = getAnnotations(tool.getToolName(), {FrameOfReferenceUID});
181
+ // return annotations && annotations.length;
182
+ // });
183
+
184
+ drawSvg(element, (svgDrawingHelper) => {
185
+ let anyRendered = false;
186
+ const handleDrawSvg = (tool) => {
187
+ if (tool.renderAnnotation) {
188
+ const rendered = tool.renderAnnotation(
189
+ enabledElement,
190
+ svgDrawingHelper
191
+ );
192
+ anyRendered = anyRendered || rendered;
193
+ }
194
+ };
195
+
196
+ /**
197
+ * We should be able to filter tools that don't have annotations, but
198
+ * currently some of tools have renderAnnotation method BUT
199
+ * don't keep annotation in the state, so if we do so, the tool will not be
200
+ * rendered.
201
+ */
202
+ enabledTools.forEach(handleDrawSvg);
203
+
204
+ if (anyRendered) {
205
+ triggerEvent(element, Events.ANNOTATION_RENDERED, { ...eventDetail });
206
+ }
207
+ });
208
+ }
209
+
210
+ /**
211
+ * _reset Resets the `RenderingEngine`
212
+ */
213
+ private _reset() {
214
+ window.cancelAnimationFrame(this._animationFrameHandle);
215
+
216
+ this._needsRender.clear();
217
+ this._animationFrameSet = false;
218
+ this._animationFrameHandle = null;
219
+
220
+ this._setAllViewportsToBeRenderedNextFrame();
221
+ }
222
+ }
223
+
224
+ const annotationRenderingEngine = new AnnotationRenderingEngine();
225
+
226
+ /**
227
+ * It triggers the rendering of the annotations for the given HTML element using
228
+ * the `AnnotationRenderingEngine`
229
+ * @param element - The element to render the annotation on.
230
+ */
231
+ function triggerAnnotationRender(element: HTMLDivElement): void {
232
+ annotationRenderingEngine.renderViewport(element);
233
+ }
234
+
235
+ export { annotationRenderingEngine, triggerAnnotationRender };
236
+
237
+ export default triggerAnnotationRender;
@@ -0,0 +1,18 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import triggerAnnotationRender from './triggerAnnotationRender';
3
+
4
+ export function triggerAnnotationRenderForViewportIds(
5
+ renderingEngine: Types.IRenderingEngine,
6
+ viewportIdsToRender: string[]
7
+ ): void {
8
+ if (!viewportIdsToRender.length) {
9
+ return;
10
+ }
11
+
12
+ viewportIdsToRender.forEach((viewportId) => {
13
+ const { element } = renderingEngine.getViewport(viewportId);
14
+ triggerAnnotationRender(element);
15
+ });
16
+ }
17
+
18
+ export default triggerAnnotationRenderForViewportIds;
@@ -0,0 +1,5 @@
1
+ import { isViewportPreScaled } from './isViewportPreScaled';
2
+ import jumpToSlice from './jumpToSlice';
3
+ import jumpToWorld from './jumpToWorld';
4
+
5
+ export { isViewportPreScaled, jumpToSlice, jumpToWorld };
@@ -0,0 +1,24 @@
1
+ import {
2
+ cache,
3
+ StackViewport,
4
+ Types,
5
+ BaseVolumeViewport,
6
+ } from '@cornerstonejs/core';
7
+
8
+ function isViewportPreScaled(
9
+ viewport: Types.IStackViewport | Types.IVolumeViewport,
10
+ targetId: string
11
+ ): boolean {
12
+ if (viewport instanceof BaseVolumeViewport) {
13
+ const volumeId = targetId.split('volumeId:')[1];
14
+ const volume = cache.getVolume(volumeId);
15
+ return volume.scaling && Object.keys(volume.scaling).length > 0;
16
+ } else if (viewport instanceof StackViewport) {
17
+ const { preScale } = viewport.getImageData();
18
+ return preScale.scaled;
19
+ } else {
20
+ throw new Error('Viewport is not a valid type');
21
+ }
22
+ }
23
+
24
+ export { isViewportPreScaled };
@@ -0,0 +1,73 @@
1
+ import {
2
+ getEnabledElement,
3
+ StackViewport,
4
+ VolumeViewport,
5
+ utilities as csUtils,
6
+ Types,
7
+ } from '@cornerstonejs/core';
8
+ import JumpToSliceOptions from '../../types/JumpToSliceOptions';
9
+ import clip from '../clip';
10
+ import scroll from '../scroll';
11
+
12
+ /**
13
+ * It uses the imageIndex in the Options to scroll to the slice that is intended.
14
+ * It works for both Stack and Volume viewports. In VolumeViewports, the imageIndex
15
+ * should be given with respect to the index in the 3D image in the view direction
16
+ * (i.e. the index of the slice in Axial, Sagittal, Coronal, or Oblique).
17
+ *
18
+ * @param element - the HTML Div element scrolling inside
19
+ * @param options - the options used for jumping to a slice
20
+ * @returns Promise that resolves to ImageIdIndex
21
+ */
22
+ async function jumpToSlice(
23
+ element: HTMLDivElement,
24
+ options = {} as JumpToSliceOptions
25
+ ): Promise<void> {
26
+ const { imageIndex, debounceLoading, volumeId } = options;
27
+ const enabledElement = getEnabledElement(element);
28
+
29
+ if (!enabledElement) {
30
+ throw new Error('Element has been disabled');
31
+ }
32
+
33
+ const { viewport } = enabledElement;
34
+
35
+ const { imageIndex: currentImageIndex, numberOfSlices } = _getImageSliceData(
36
+ viewport,
37
+ debounceLoading
38
+ );
39
+
40
+ const imageIndexToJump = _getImageIndexToJump(numberOfSlices, imageIndex);
41
+ const delta = imageIndexToJump - currentImageIndex;
42
+
43
+ scroll(viewport, { delta, debounceLoading, volumeId });
44
+ }
45
+
46
+ function _getImageSliceData(
47
+ viewport: Types.IStackViewport | Types.IVolumeViewport,
48
+ debounceLoading?: boolean
49
+ ): Types.ImageSliceData {
50
+ if (viewport instanceof StackViewport) {
51
+ return {
52
+ numberOfSlices: viewport.getImageIds().length,
53
+ imageIndex: debounceLoading
54
+ ? viewport.getTargetImageIdIndex()
55
+ : viewport.getCurrentImageIdIndex(),
56
+ };
57
+ } else if (viewport instanceof VolumeViewport) {
58
+ return csUtils.getImageSliceDataForVolumeViewport(viewport);
59
+ } else {
60
+ throw new Error('Unsupported viewport type');
61
+ }
62
+ }
63
+
64
+ function _getImageIndexToJump(
65
+ numberOfSlices: number,
66
+ imageIndex: number
67
+ ): number {
68
+ const lastSliceIndex = numberOfSlices - 1;
69
+
70
+ return clip(imageIndex, 0, lastSliceIndex);
71
+ }
72
+
73
+ export default jumpToSlice;
@@ -0,0 +1,58 @@
1
+ import { VolumeViewport } from '@cornerstonejs/core';
2
+ import type { Types } from '@cornerstonejs/core';
3
+
4
+ import { vec3 } from 'gl-matrix';
5
+
6
+ // Todo: merge this utility functionality with Crosshair _jump
7
+ /**
8
+ * Uses the viewport's current camera to jump to a specific world coordinate
9
+ * @param enabledElement - enabled element
10
+ * @param jumpWorld - location in the world to jump to
11
+ * @returns True if successful
12
+ */
13
+ export default function jumpToWorld(
14
+ viewport: Types.IVolumeViewport,
15
+ jumpWorld: Types.Point3
16
+ ): true | undefined {
17
+ // if not instance of volumeViewport, return
18
+ if (!(viewport instanceof VolumeViewport)) {
19
+ return;
20
+ }
21
+
22
+ const { focalPoint } = viewport.getCamera();
23
+
24
+ const delta: Types.Point3 = [0, 0, 0];
25
+ vec3.sub(delta, jumpWorld, focalPoint);
26
+
27
+ _applyShift(viewport, delta);
28
+
29
+ return true;
30
+ }
31
+
32
+ function _applyShift(viewport, delta) {
33
+ const camera = viewport.getCamera();
34
+ const normal = camera.viewPlaneNormal;
35
+
36
+ const dotProd = vec3.dot(delta, normal);
37
+ const projectedDelta = vec3.fromValues(normal[0], normal[1], normal[2]);
38
+
39
+ vec3.scale(projectedDelta, projectedDelta, dotProd);
40
+
41
+ if (
42
+ Math.abs(projectedDelta[0]) > 1e-3 ||
43
+ Math.abs(projectedDelta[1]) > 1e-3 ||
44
+ Math.abs(projectedDelta[2]) > 1e-3
45
+ ) {
46
+ const newFocalPoint: Types.Point3 = [0, 0, 0];
47
+ const newPosition: Types.Point3 = [0, 0, 0];
48
+
49
+ vec3.add(newFocalPoint, camera.focalPoint, projectedDelta);
50
+ vec3.add(newPosition, camera.position, projectedDelta);
51
+
52
+ viewport.setCamera({
53
+ focalPoint: newFocalPoint,
54
+ position: newPosition,
55
+ });
56
+ viewport.render();
57
+ }
58
+ }
@@ -0,0 +1,28 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+
3
+ /**
4
+ * Given an array of viewports, returns a list of viewports that are viewing a
5
+ * world space with the given `FrameOfReferenceUID`.
6
+ *
7
+ * @param viewports - An array of viewports.
8
+ * @param FrameOfReferenceUID - The UID defining a particular world space/Frame Of Reference.
9
+ *
10
+ * @returns A filtered array of viewports.
11
+ */
12
+ export default function filterViewportsWithFrameOfReferenceUID(
13
+ viewports: Array<Types.IStackViewport | Types.IVolumeViewport>,
14
+ FrameOfReferenceUID: string
15
+ ): Array<Types.IStackViewport | Types.IVolumeViewport> {
16
+ const numViewports = viewports.length;
17
+ const viewportsWithFrameOfReferenceUID = [];
18
+
19
+ for (let vp = 0; vp < numViewports; vp++) {
20
+ const viewport = viewports[vp];
21
+
22
+ if (viewport.getFrameOfReferenceUID() === FrameOfReferenceUID) {
23
+ viewportsWithFrameOfReferenceUID.push(viewport);
24
+ }
25
+ }
26
+
27
+ return viewportsWithFrameOfReferenceUID;
28
+ }