@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,194 @@
1
+ import type {
2
+ FloodFillResult,
3
+ FloodFillGetter,
4
+ FloodFillOptions,
5
+ } from '../../types';
6
+ import { Types } from '@cornerstonejs/core';
7
+
8
+ /**
9
+ * floodFill.js - Taken from MIT OSS lib - https://github.com/tuzz/n-dimensional-flood-fill
10
+ * Refactored to ES6.
11
+ *
12
+ * @param {function} getter The getter to the elements of your data structure,
13
+ * e.g. getter(x,y) for a 2D interprettation of your structure.
14
+ * @param {number[]} seed The seed for your fill. The dimensionality is infered
15
+ * by the number of dimensions of the seed.
16
+ * @param {function} [options.onFlood] An optional callback to execute when each pixel is flooded.
17
+ * e.g. onFlood(x,y).
18
+ * @param {function} [options.onBoundary] An optional callback to execute whenever a boundary is reached.
19
+ * a boundary could be another segmentIndex, or the edge of your
20
+ * data structure (i.e. when your getter returns undefined).
21
+ * @param {function} [options.equals] An optional equality method for your datastructure.
22
+ * Default is simply value1 = value2.
23
+ * @param {boolean} [options.diagonals] Whether you allow flooding through diagonals. Defaults to false.
24
+ *
25
+ * @returns {Object}
26
+ */
27
+ function floodFill(
28
+ getter: FloodFillGetter,
29
+ seed: Types.Point2 | Types.Point3,
30
+ options: FloodFillOptions = {}
31
+ ): FloodFillResult {
32
+ const onFlood = options.onFlood;
33
+ const onBoundary = options.onBoundary;
34
+ const equals = options.equals || defaultEquals;
35
+ const diagonals = options.diagonals || false;
36
+ const startNode = get(seed);
37
+ const permutations = prunedPermutations();
38
+ const stack = [];
39
+ const flooded = [];
40
+ const visits = {};
41
+ const bounds = {};
42
+
43
+ stack.push({ currentArgs: seed });
44
+
45
+ while (stack.length > 0) {
46
+ flood(stack.pop());
47
+ }
48
+
49
+ return {
50
+ flooded,
51
+ boundaries: boundaries(),
52
+ };
53
+
54
+ function flood(job) {
55
+ const getArgs = job.currentArgs;
56
+ const prevArgs = job.previousArgs;
57
+
58
+ if (visited(getArgs)) {
59
+ return;
60
+ }
61
+ markAsVisited(getArgs);
62
+
63
+ if (member(getArgs)) {
64
+ markAsFlooded(getArgs);
65
+ pushAdjacent(getArgs);
66
+ } else {
67
+ markAsBoundary(prevArgs);
68
+ }
69
+ }
70
+
71
+ function visited(key) {
72
+ return visits[key] === true;
73
+ }
74
+
75
+ function markAsVisited(key) {
76
+ visits[key] = true;
77
+ }
78
+
79
+ function member(getArgs) {
80
+ const node = safely(get, [getArgs]);
81
+
82
+ return safely(equals, [node, startNode]);
83
+ }
84
+
85
+ function markAsFlooded(getArgs) {
86
+ flooded.push(getArgs);
87
+ if (onFlood) {
88
+ //@ts-ignore
89
+ onFlood(...getArgs);
90
+ }
91
+ }
92
+
93
+ function markAsBoundary(prevArgs) {
94
+ bounds[prevArgs] = prevArgs;
95
+ if (onBoundary) {
96
+ //@ts-ignore
97
+ onBoundary(...prevArgs);
98
+ }
99
+ }
100
+
101
+ function pushAdjacent(getArgs) {
102
+ for (let i = 0; i < permutations.length; i += 1) {
103
+ const perm = permutations[i];
104
+ const nextArgs = getArgs.slice(0);
105
+
106
+ for (let j = 0; j < getArgs.length; j += 1) {
107
+ nextArgs[j] += perm[j];
108
+ }
109
+
110
+ stack.push({
111
+ currentArgs: nextArgs,
112
+ previousArgs: getArgs,
113
+ });
114
+ }
115
+ }
116
+
117
+ function get(getArgs) {
118
+ //@ts-ignore
119
+ return getter(...getArgs);
120
+ }
121
+
122
+ function safely(f, args) {
123
+ try {
124
+ return f(...args);
125
+ } catch (error) {
126
+ return;
127
+ }
128
+ }
129
+
130
+ function prunedPermutations() {
131
+ const permutations = permute(seed.length);
132
+
133
+ return permutations.filter(function (perm) {
134
+ const count = countNonZeroes(perm);
135
+
136
+ return count !== 0 && (count === 1 || diagonals);
137
+ });
138
+ }
139
+
140
+ function permute(length) {
141
+ const perms = [];
142
+
143
+ const permutation = function (string) {
144
+ return string.split('').map(function (c) {
145
+ return parseInt(c, 10) - 1;
146
+ });
147
+ };
148
+
149
+ for (let i = 0; i < Math.pow(3, length); i += 1) {
150
+ const string = lpad(i.toString(3), '0', length);
151
+
152
+ perms.push(permutation(string));
153
+ }
154
+
155
+ return perms;
156
+ }
157
+
158
+ function boundaries() {
159
+ const array = [];
160
+
161
+ for (const key in bounds) {
162
+ if (bounds[key] !== undefined) {
163
+ array.unshift(bounds[key]);
164
+ }
165
+ }
166
+
167
+ return array;
168
+ }
169
+ }
170
+
171
+ function defaultEquals(a, b) {
172
+ return a === b;
173
+ }
174
+
175
+ function countNonZeroes(array) {
176
+ let count = 0;
177
+
178
+ for (let i = 0; i < array.length; i += 1) {
179
+ if (array[i] !== 0) {
180
+ count += 1;
181
+ }
182
+ }
183
+
184
+ return count;
185
+ }
186
+
187
+ function lpad(string, character, length) {
188
+ const array = new Array(length + 1);
189
+ const pad = array.join(character);
190
+
191
+ return (pad + string).slice(-length);
192
+ }
193
+
194
+ export default floodFill;
@@ -0,0 +1,20 @@
1
+ import getDefaultLabelmapConfig from '../../tools/displayTools/Labelmap/labelmapConfig';
2
+ import SegmentationRepresentation from '../../enums/SegmentationRepresentations';
3
+ import { Segmentation } from '../../types/SegmentationStateTypes';
4
+
5
+ /**
6
+ * It returns a configuration object for the given representation type.
7
+ * @param representationType - The type of segmentation representation
8
+ * @returns A representation configuration object.
9
+ */
10
+ export default function getDefaultRepresentationConfig(
11
+ segmentation: Segmentation
12
+ ) {
13
+ const { type: representationType } = segmentation;
14
+ switch (representationType) {
15
+ case SegmentationRepresentation.Labelmap:
16
+ return getDefaultLabelmapConfig();
17
+ default:
18
+ throw new Error(`Unknown representation type: ${representationType}`);
19
+ }
20
+ }
@@ -0,0 +1,33 @@
1
+ import thresholdVolumeByRange from './thresholdVolumeByRange';
2
+ import rectangleROIThresholdVolumeByRange from './rectangleROIThresholdVolumeByRange';
3
+ import createMergedLabelmapForIndex from './createMergedLabelmapForIndex';
4
+ import isValidRepresentationConfig from './isValidRepresentationConfig';
5
+ import getDefaultRepresentationConfig from './getDefaultRepresentationConfig';
6
+ import createLabelmapVolumeForViewport from './createLabelmapVolumeForViewport';
7
+ import { triggerSegmentationRender } from './triggerSegmentationRender';
8
+ import floodFill from './floodFill';
9
+ import {
10
+ getBrushSizeForToolGroup,
11
+ setBrushSizeForToolGroup,
12
+ } from './brushSizeForToolGroup';
13
+ import {
14
+ getBrushThresholdForToolGroup,
15
+ setBrushThresholdForToolGroup,
16
+ } from './brushThresholdForToolGroup';
17
+ import thresholdSegmentationByRange from './thresholdSegmentationByRange';
18
+
19
+ export {
20
+ thresholdVolumeByRange,
21
+ createMergedLabelmapForIndex,
22
+ isValidRepresentationConfig,
23
+ getDefaultRepresentationConfig,
24
+ createLabelmapVolumeForViewport,
25
+ rectangleROIThresholdVolumeByRange,
26
+ triggerSegmentationRender,
27
+ floodFill,
28
+ getBrushSizeForToolGroup,
29
+ setBrushSizeForToolGroup,
30
+ getBrushThresholdForToolGroup,
31
+ setBrushThresholdForToolGroup,
32
+ thresholdSegmentationByRange,
33
+ };
@@ -0,0 +1,22 @@
1
+ import { isValidLabelmapConfig } from '../../tools/displayTools/Labelmap/labelmapConfig';
2
+ import SegmentationRepresentation from '../../enums/SegmentationRepresentations';
3
+ import { RepresentationConfig } from '../../types/SegmentationStateTypes';
4
+
5
+ /**
6
+ * Given a representation type and a configuration, return true if the
7
+ * configuration is valid for that representation type
8
+ * @param representationType - The type of segmentation representation
9
+ * @param config - RepresentationConfig
10
+ * @returns A boolean value.
11
+ */
12
+ export default function isValidRepresentationConfig(
13
+ representationType: string,
14
+ config: RepresentationConfig
15
+ ): boolean {
16
+ switch (representationType) {
17
+ case SegmentationRepresentation.Labelmap:
18
+ return isValidLabelmapConfig(config);
19
+ default:
20
+ throw new Error(`Unknown representation type: ${representationType}`);
21
+ }
22
+ }
@@ -0,0 +1,91 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { state } from '../../stateManagement/annotation';
3
+ import {
4
+ RectangleROIStartEndThresholdTool,
5
+ RectangleROIThresholdTool,
6
+ } from '../../tools';
7
+
8
+ import thresholdVolumeByRange from './thresholdVolumeByRange';
9
+ import getBoundsIJKFromRectangleAnnotations from '../rectangleROITool/getBoundsIJKFromRectangleAnnotations';
10
+ import { ThresholdInformation } from './utilities';
11
+
12
+ export type ThresholdOptions = {
13
+ numSlicesToProject?: number; // number of slices to project before and after current slice
14
+ overwrite: boolean;
15
+ overlapType?: number; // type of the voxel overlap
16
+ };
17
+
18
+ export type AnnotationForThresholding = {
19
+ data: {
20
+ handles: {
21
+ points: Types.Point3[];
22
+ };
23
+ cachedStats?: {
24
+ projectionPoints?: Types.Point3[][];
25
+ };
26
+ };
27
+ };
28
+
29
+ /**
30
+ * It uses the provided rectangleROI annotations (either RectangleROIThreshold, or
31
+ * RectangleROIStartEndThreshold) to compute an ROI that is the intersection of
32
+ * all the annotations. Then it uses the rectangleROIThreshold utility to threshold
33
+ * the volume.
34
+ * @param annotationUIDs - rectangleROI annotationsUIDs to use for ROI
35
+ * @param segmentationVolume - the segmentation volume
36
+ * @param thresholdVolumeInformation - object array containing the volume data and range threshold values
37
+ * @param options - options for thresholding
38
+ * @returns
39
+ */
40
+ function rectangleROIThresholdVolumeByRange(
41
+ annotationUIDs: string[],
42
+ segmentationVolume: Types.IImageVolume,
43
+ thresholdVolumeInformation: ThresholdInformation[],
44
+ options: ThresholdOptions
45
+ ): Types.IImageVolume {
46
+ const annotations = annotationUIDs.map((annotationUID) => {
47
+ return state.getAnnotation(annotationUID);
48
+ });
49
+
50
+ _validateAnnotations(annotations);
51
+
52
+ let boundsIJK;
53
+ for (let i = 0; i < thresholdVolumeInformation.length; i++) {
54
+ // make sure that the boundsIJK are generated by the correct volume
55
+ const volumeSize =
56
+ thresholdVolumeInformation[i].volume.getScalarData().length;
57
+ if (volumeSize === segmentationVolume.getScalarData().length || i === 0) {
58
+ boundsIJK = getBoundsIJKFromRectangleAnnotations(
59
+ annotations,
60
+ thresholdVolumeInformation[i].volume,
61
+ options
62
+ );
63
+ }
64
+ }
65
+
66
+ const outputSegmentationVolume = thresholdVolumeByRange(
67
+ segmentationVolume,
68
+ thresholdVolumeInformation,
69
+ { ...options, boundsIJK }
70
+ );
71
+
72
+ return outputSegmentationVolume;
73
+ }
74
+
75
+ function _validateAnnotations(annotations) {
76
+ const validToolNames = [
77
+ RectangleROIThresholdTool.toolName,
78
+ RectangleROIStartEndThresholdTool.toolName,
79
+ ];
80
+
81
+ for (const annotation of annotations) {
82
+ const name = annotation.metadata.toolName;
83
+ if (!validToolNames.includes(name)) {
84
+ throw new Error(
85
+ 'rectangleROIThresholdVolumeByRange only supports RectangleROIThreshold and RectangleROIStartEndThreshold annotations'
86
+ );
87
+ }
88
+ }
89
+ }
90
+
91
+ export default rectangleROIThresholdVolumeByRange;
@@ -0,0 +1,129 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import { pointInShapeCallback } from '../../utilities';
3
+ import { triggerSegmentationDataModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
4
+ import {
5
+ getVoxelOverlap,
6
+ processVolumes,
7
+ ThresholdInformation,
8
+ } from './utilities';
9
+
10
+ /**
11
+ * It thresholds a segmentation volume based on a set of threshold values with
12
+ * respect to a list of volumes and respective threshold ranges.
13
+ * @param segmentationVolume - the segmentation volume to be modified
14
+ * @param segmentationIndex - the index of the segmentation to modify
15
+ * @param thresholdVolumeInformation - array of objects containing volume data
16
+ * and a range (lower and upper values) to threshold
17
+ * @param overlapType - indicates if the user requires all voxels pass
18
+ * (overlapType = 1) or any voxel pass (overlapType = 0)
19
+ * @returns
20
+ */
21
+ function thresholdSegmentationByRange(
22
+ segmentationVolume: Types.IImageVolume,
23
+ segmentationIndex: number,
24
+ thresholdVolumeInformation: ThresholdInformation[],
25
+ overlapType: number
26
+ ): Types.IImageVolume {
27
+ const scalarData = segmentationVolume.getScalarData();
28
+
29
+ // prepare a list of volume information objects for callback functions
30
+ const { baseVolumeIdx, volumeInfoList } = processVolumes(
31
+ segmentationVolume,
32
+ thresholdVolumeInformation
33
+ );
34
+
35
+ /**
36
+ * This function will test all overlaps between a voxel in base volume
37
+ * (the reference for segmentation volume creation) and voxels in other
38
+ * volumes.
39
+ * If the segmentation volume and the image volume are the same size,
40
+ * checks if the scalar data at each point is within the threshold values.
41
+ * If the segmentation volume and the image volume are different sizes,
42
+ * checks the voxel overlap
43
+ */
44
+ volumeInfoList.forEach((volumeInfo) => {
45
+ const { volumeSize } = volumeInfo;
46
+
47
+ if (volumeSize === scalarData.length) {
48
+ _handleSameSizeVolume(scalarData, segmentationIndex, volumeInfo);
49
+ } else {
50
+ _handleDifferentSizeVolume(
51
+ scalarData,
52
+ segmentationIndex,
53
+ volumeInfo,
54
+ volumeInfoList,
55
+ baseVolumeIdx,
56
+ overlapType
57
+ );
58
+ }
59
+ });
60
+
61
+ triggerSegmentationDataModified(segmentationVolume.volumeId);
62
+
63
+ return segmentationVolume;
64
+ }
65
+
66
+ function _handleDifferentSizeVolume(
67
+ scalarData: Types.VolumeScalarData,
68
+ segmentationIndex: number,
69
+ volumeInfo: any,
70
+ volumeInfoList: any,
71
+ baseVolumeIdx: number,
72
+ overlapType: number
73
+ ) {
74
+ const { imageData, lower, upper, dimensions } = volumeInfo;
75
+
76
+ let total, overlaps, range;
77
+
78
+ for (let i = 0; i < scalarData.length; i++) {
79
+ if (scalarData[i] === segmentationIndex) {
80
+ const overlapBounds = getVoxelOverlap(
81
+ imageData,
82
+ dimensions,
83
+ volumeInfoList[baseVolumeIdx].spacing,
84
+ volumeInfoList[baseVolumeIdx].imageData.getPoint(i)
85
+ );
86
+
87
+ const callbackOverlap = ({ value }) => {
88
+ total = total + 1;
89
+ if (value >= range.lower && value <= range.upper) {
90
+ overlaps = overlaps + 1;
91
+ }
92
+ };
93
+
94
+ total = 0;
95
+ overlaps = 0;
96
+ range = { lower, upper };
97
+ let overlapTest = false;
98
+
99
+ // check all voxel overlaps
100
+ pointInShapeCallback(
101
+ imageData,
102
+ () => true,
103
+ callbackOverlap,
104
+ overlapBounds
105
+ );
106
+
107
+ overlapTest = overlapType === 0 ? overlaps > 0 : overlaps === total;
108
+ scalarData[i] = overlapTest ? segmentationIndex : 0;
109
+ }
110
+ }
111
+ return { total, range, overlaps };
112
+ }
113
+
114
+ function _handleSameSizeVolume(
115
+ scalarData: Types.VolumeScalarData,
116
+ segmentationIndex: number,
117
+ volumeInfo: any
118
+ ) {
119
+ const { referenceValues, lower, upper } = volumeInfo;
120
+
121
+ for (let i = 0; i < scalarData.length; i++) {
122
+ if (scalarData[i] === segmentationIndex) {
123
+ const value = referenceValues[i];
124
+ scalarData[i] = value >= lower && value <= upper ? segmentationIndex : 0;
125
+ }
126
+ }
127
+ }
128
+
129
+ export default thresholdSegmentationByRange;
@@ -0,0 +1,150 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import { pointInShapeCallback } from '../../utilities';
3
+ import { triggerSegmentationDataModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
4
+ import { BoundsIJK } from '../../types';
5
+ import {
6
+ getVoxelOverlap,
7
+ processVolumes,
8
+ ThresholdInformation,
9
+ } from './utilities';
10
+
11
+ export type ThresholdRangeOptions = {
12
+ overwrite: boolean;
13
+ boundsIJK: BoundsIJK;
14
+ overlapType?: number;
15
+ };
16
+
17
+ /**
18
+ * It thresholds a segmentation volume based on a set of threshold values with
19
+ * respect to a list of volumes and respective threshold ranges.
20
+ * @param segmentationVolume - the segmentation volume to be modified
21
+ * @param thresholdVolumeInformation - array of objects containing volume data
22
+ * and a range (lower and upper values) to threshold
23
+ * @param options - the options for thresholding
24
+ * As there is a chance the volumes might have different dimensions and spacing,
25
+ * could be the case of no 1 to 1 mapping. So we need to work with the idea of
26
+ * voxel overlaps (1 to many mappings). We consider all intersections valid, to
27
+ * avoid the complexity to calculate a minimum voxel intersection percentage.
28
+ * This function, given a voxel center and spacing, calculates the overlap of
29
+ * the voxel with another volume and range check the voxels in the overlap.
30
+ * Three situations can occur: all voxels pass the range check, some voxels pass
31
+ * or none voxels pass. The overlapType parameter indicates if the user requires
32
+ * all voxels pass (overlapType = 1) or any voxel pass (overlapType = 0)
33
+ *
34
+ * @returns segmented volume
35
+ */
36
+ function thresholdVolumeByRange(
37
+ segmentationVolume: Types.IImageVolume,
38
+ thresholdVolumeInformation: ThresholdInformation[],
39
+ options: ThresholdRangeOptions
40
+ ): Types.IImageVolume {
41
+ const { imageData: segmentationImageData } = segmentationVolume;
42
+ const scalarData = segmentationVolume.getScalarData();
43
+
44
+ const { overwrite, boundsIJK } = options;
45
+ const overlapType = options?.overlapType || 0;
46
+
47
+ // set the segmentation to all zeros
48
+ if (overwrite) {
49
+ for (let i = 0; i < scalarData.length; i++) {
50
+ scalarData[i] = 0;
51
+ }
52
+ }
53
+
54
+ const { baseVolumeIdx, volumeInfoList } = processVolumes(
55
+ segmentationVolume,
56
+ thresholdVolumeInformation
57
+ );
58
+
59
+ // global variables used in callbackOverlap function
60
+ let overlaps, total, range;
61
+
62
+ const testOverlapRange = (volumeInfo, voxelSpacing, voxelCenter) => {
63
+ /**
64
+ * This callback function will test all overlaps between a voxel in base
65
+ * volume (the reference for segmentation volume creation) and voxels in other
66
+ * volumes.
67
+ */
68
+ const callbackOverlap = ({ value }) => {
69
+ total = total + 1;
70
+ if (value >= range.lower && value <= range.upper) {
71
+ overlaps = overlaps + 1;
72
+ }
73
+ };
74
+
75
+ const { imageData, dimensions, lower, upper } = volumeInfo;
76
+
77
+ const overlapBounds = getVoxelOverlap(
78
+ imageData,
79
+ dimensions,
80
+ voxelSpacing,
81
+ voxelCenter
82
+ );
83
+
84
+ // reset global variables and setting the range check
85
+ total = 0;
86
+ overlaps = 0;
87
+ range = { lower, upper };
88
+
89
+ let overlapTest = false;
90
+
91
+ // check all voxel overlaps
92
+ pointInShapeCallback(imageData, () => true, callbackOverlap, overlapBounds);
93
+
94
+ if (overlapType === 0) {
95
+ overlapTest = overlaps > 0; // any voxel overlap is accepted
96
+ } else if (overlapType == 1) {
97
+ overlapTest = overlaps === total; // require all voxel overlaps
98
+ }
99
+ return overlapTest;
100
+ };
101
+
102
+ // range checks a voxel in a volume with same dimension as the segmentation
103
+ const testRange = (volumeInfo, pointIJK) => {
104
+ const { imageData, referenceValues, lower, upper } = volumeInfo;
105
+ const offset = imageData.computeOffsetIndex(pointIJK);
106
+
107
+ const value = referenceValues[offset];
108
+ if (value <= lower || value >= upper) {
109
+ return false;
110
+ } else {
111
+ return true;
112
+ }
113
+ };
114
+
115
+ /**
116
+ * This callback function will test all overlaps between a voxel in base
117
+ * volume (the reference for segmentation volume creation) and voxels in other
118
+ * volumes.
119
+ */
120
+ const callback = ({ index, pointIJK, pointLPS }) => {
121
+ let insert = volumeInfoList.length > 0;
122
+ for (let i = 0; i < volumeInfoList.length; i++) {
123
+ // if volume has the same size as segmentation volume, just range check
124
+ if (volumeInfoList[i].volumeSize === scalarData.length) {
125
+ insert = testRange(volumeInfoList[i], pointIJK);
126
+ } else {
127
+ // if not, need to calculate overlaps
128
+ insert = testOverlapRange(
129
+ volumeInfoList[i],
130
+ volumeInfoList[baseVolumeIdx].spacing,
131
+ pointLPS
132
+ );
133
+ }
134
+ if (!insert) {
135
+ break;
136
+ }
137
+ }
138
+
139
+ // Todo: make the segmentIndex a parameter
140
+ if (insert) scalarData[index] = 1;
141
+ };
142
+
143
+ pointInShapeCallback(segmentationImageData, () => true, callback, boundsIJK);
144
+
145
+ triggerSegmentationDataModified(segmentationVolume.volumeId);
146
+
147
+ return segmentationVolume;
148
+ }
149
+
150
+ export default thresholdVolumeByRange;