@cornerstonejs/tools 1.42.0 → 1.43.0

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 (333) hide show
  1. package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js +18 -5
  2. package/dist/cjs/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
  3. package/dist/cjs/index.d.ts +2 -2
  4. package/dist/cjs/index.js +2 -1
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/cjs/stateManagement/segmentation/activeSegmentation.d.ts +2 -1
  7. package/dist/cjs/stateManagement/segmentation/activeSegmentation.js +10 -1
  8. package/dist/cjs/stateManagement/segmentation/activeSegmentation.js.map +1 -1
  9. package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts +10 -0
  10. package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.js +65 -0
  11. package/dist/cjs/stateManagement/segmentation/convertStackToVolumeSegmentation.js.map +1 -0
  12. package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts +8 -0
  13. package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.js +92 -0
  14. package/dist/cjs/stateManagement/segmentation/convertVolumeToStackSegmentation.js.map +1 -0
  15. package/dist/cjs/stateManagement/segmentation/index.d.ts +3 -1
  16. package/dist/cjs/stateManagement/segmentation/index.js +5 -1
  17. package/dist/cjs/stateManagement/segmentation/index.js.map +1 -1
  18. package/dist/cjs/stateManagement/segmentation/segmentIndex.js +5 -0
  19. package/dist/cjs/stateManagement/segmentation/segmentIndex.js.map +1 -1
  20. package/dist/cjs/stateManagement/segmentation/segmentationState.d.ts +2 -1
  21. package/dist/cjs/stateManagement/segmentation/segmentationState.js +8 -1
  22. package/dist/cjs/stateManagement/segmentation/segmentationState.js.map +1 -1
  23. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +3 -0
  24. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  25. package/dist/cjs/tools/annotation/AngleTool.js +2 -2
  26. package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
  27. package/dist/cjs/tools/annotation/BidirectionalTool.js +2 -2
  28. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  29. package/dist/cjs/tools/annotation/CircleROITool.js +8 -8
  30. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  31. package/dist/cjs/tools/annotation/EllipticalROITool.js +7 -7
  32. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  33. package/dist/cjs/tools/annotation/LengthTool.js +2 -2
  34. package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
  35. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +5 -5
  36. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  37. package/dist/cjs/tools/annotation/ProbeTool.js +3 -3
  38. package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
  39. package/dist/cjs/tools/annotation/RectangleROITool.js +7 -7
  40. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  41. package/dist/cjs/tools/displayTools/Labelmap/labelmapConfig.js +2 -0
  42. package/dist/cjs/tools/displayTools/Labelmap/labelmapConfig.js.map +1 -1
  43. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +20 -4
  44. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  45. package/dist/cjs/tools/index.d.ts +2 -1
  46. package/dist/cjs/tools/index.js +3 -1
  47. package/dist/cjs/tools/index.js.map +1 -1
  48. package/dist/cjs/tools/segmentation/BrushTool.d.ts +1 -0
  49. package/dist/cjs/tools/segmentation/BrushTool.js +40 -19
  50. package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
  51. package/dist/cjs/tools/segmentation/CircleScissorsTool.js +5 -0
  52. package/dist/cjs/tools/segmentation/CircleScissorsTool.js.map +1 -1
  53. package/dist/cjs/tools/segmentation/RectangleScissorsTool.js +5 -0
  54. package/dist/cjs/tools/segmentation/RectangleScissorsTool.js.map +1 -1
  55. package/dist/cjs/tools/segmentation/SegmentSelectTool.d.ts +15 -0
  56. package/dist/cjs/tools/segmentation/SegmentSelectTool.js +105 -0
  57. package/dist/cjs/tools/segmentation/SegmentSelectTool.js.map +1 -0
  58. package/dist/cjs/tools/segmentation/SphereScissorsTool.js +5 -0
  59. package/dist/cjs/tools/segmentation/SphereScissorsTool.js.map +1 -1
  60. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.d.ts +2 -1
  61. package/dist/cjs/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  62. package/dist/cjs/tools/segmentation/strategies/fillCircle.js +12 -15
  63. package/dist/cjs/tools/segmentation/strategies/fillCircle.js.map +1 -1
  64. package/dist/cjs/tools/segmentation/strategies/fillRectangle.js +30 -3
  65. package/dist/cjs/tools/segmentation/strategies/fillRectangle.js.map +1 -1
  66. package/dist/cjs/tools/segmentation/strategies/fillSphere.js +3 -20
  67. package/dist/cjs/tools/segmentation/strategies/fillSphere.js.map +1 -1
  68. package/dist/cjs/tools/segmentation/strategies/utils/isWithinThreshold.d.ts +1 -1
  69. package/dist/cjs/tools/segmentation/strategies/utils/isWithinThreshold.js.map +1 -1
  70. package/dist/cjs/types/LabelmapTypes.d.ts +1 -0
  71. package/dist/cjs/utilities/boundingBox/getBoundingBoxAroundShape.d.ts +4 -2
  72. package/dist/cjs/utilities/boundingBox/getBoundingBoxAroundShape.js +45 -23
  73. package/dist/cjs/utilities/boundingBox/getBoundingBoxAroundShape.js.map +1 -1
  74. package/dist/cjs/utilities/boundingBox/index.d.ts +2 -2
  75. package/dist/cjs/utilities/boundingBox/index.js +5 -3
  76. package/dist/cjs/utilities/boundingBox/index.js.map +1 -1
  77. package/dist/cjs/utilities/getSphereBoundsInfo.d.ts +11 -0
  78. package/dist/cjs/utilities/getSphereBoundsInfo.js +45 -0
  79. package/dist/cjs/utilities/getSphereBoundsInfo.js.map +1 -0
  80. package/dist/cjs/utilities/index.d.ts +4 -3
  81. package/dist/cjs/utilities/index.js +8 -7
  82. package/dist/cjs/utilities/index.js.map +1 -1
  83. package/dist/cjs/utilities/pointInShapeCallback.d.ts +1 -1
  84. package/dist/cjs/utilities/pointInShapeCallback.js +1 -1
  85. package/dist/cjs/utilities/pointInShapeCallback.js.map +1 -1
  86. package/dist/cjs/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.js +2 -2
  87. package/dist/cjs/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.js.map +1 -1
  88. package/dist/cjs/utilities/rectangleROITool/index.d.ts +2 -1
  89. package/dist/cjs/utilities/rectangleROITool/index.js +3 -1
  90. package/dist/cjs/utilities/rectangleROITool/index.js.map +1 -1
  91. package/dist/cjs/utilities/rectangleROITool/isAxisAlignedRectangle.d.ts +2 -0
  92. package/dist/cjs/utilities/rectangleROITool/isAxisAlignedRectangle.js +26 -0
  93. package/dist/cjs/utilities/rectangleROITool/isAxisAlignedRectangle.js.map +1 -0
  94. package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.d.ts +2 -0
  95. package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.js +11 -0
  96. package/dist/cjs/utilities/segmentation/createImageIdReferenceMap.js.map +1 -0
  97. package/dist/cjs/utilities/segmentation/createLabelmapVolumeForViewport.js +1 -1
  98. package/dist/cjs/utilities/segmentation/createLabelmapVolumeForViewport.js.map +1 -1
  99. package/dist/cjs/utilities/segmentation/index.d.ts +3 -1
  100. package/dist/cjs/utilities/segmentation/index.js +5 -1
  101. package/dist/cjs/utilities/segmentation/index.js.map +1 -1
  102. package/dist/cjs/utilities/segmentation/invalidateBrushCursor.d.ts +1 -0
  103. package/dist/cjs/utilities/segmentation/invalidateBrushCursor.js +31 -0
  104. package/dist/cjs/utilities/segmentation/invalidateBrushCursor.js.map +1 -0
  105. package/dist/cjs/utilities/segmentation/thresholdSegmentationByRange.js.map +1 -1
  106. package/dist/cjs/utilities/segmentation/triggerSegmentationRender.js +8 -4
  107. package/dist/cjs/utilities/segmentation/triggerSegmentationRender.js.map +1 -1
  108. package/dist/cjs/utilities/segmentation/utilities.d.ts +1 -1
  109. package/dist/cjs/utilities/segmentation/utilities.js +2 -2
  110. package/dist/cjs/utilities/segmentation/utilities.js.map +1 -1
  111. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +2 -5
  112. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  113. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js +2 -1
  114. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
  115. package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js +18 -5
  116. package/dist/esm/eventListeners/segmentation/imageChangeEventListener.js.map +1 -1
  117. package/dist/esm/index.js +2 -2
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/stateManagement/segmentation/activeSegmentation.js +10 -2
  120. package/dist/esm/stateManagement/segmentation/activeSegmentation.js.map +1 -1
  121. package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.js +47 -0
  122. package/dist/esm/stateManagement/segmentation/convertStackToVolumeSegmentation.js.map +1 -0
  123. package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js +72 -0
  124. package/dist/esm/stateManagement/segmentation/convertVolumeToStackSegmentation.js.map +1 -0
  125. package/dist/esm/stateManagement/segmentation/index.js +3 -1
  126. package/dist/esm/stateManagement/segmentation/index.js.map +1 -1
  127. package/dist/esm/stateManagement/segmentation/segmentIndex.js +6 -1
  128. package/dist/esm/stateManagement/segmentation/segmentIndex.js.map +1 -1
  129. package/dist/esm/stateManagement/segmentation/segmentationState.js +7 -1
  130. package/dist/esm/stateManagement/segmentation/segmentationState.js.map +1 -1
  131. package/dist/esm/store/ToolGroupManager/ToolGroup.js +3 -0
  132. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  133. package/dist/esm/tools/annotation/AngleTool.js +1 -1
  134. package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
  135. package/dist/esm/tools/annotation/BidirectionalTool.js +1 -1
  136. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  137. package/dist/esm/tools/annotation/CircleROITool.js +1 -1
  138. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  139. package/dist/esm/tools/annotation/EllipticalROITool.js +1 -1
  140. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  141. package/dist/esm/tools/annotation/LengthTool.js +1 -1
  142. package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
  143. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +1 -1
  144. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  145. package/dist/esm/tools/annotation/ProbeTool.js +1 -1
  146. package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
  147. package/dist/esm/tools/annotation/RectangleROITool.js +1 -1
  148. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  149. package/dist/esm/tools/displayTools/Labelmap/labelmapConfig.js +2 -0
  150. package/dist/esm/tools/displayTools/Labelmap/labelmapConfig.js.map +1 -1
  151. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +21 -5
  152. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  153. package/dist/esm/tools/index.js +2 -1
  154. package/dist/esm/tools/index.js.map +1 -1
  155. package/dist/esm/tools/segmentation/BrushTool.js +39 -19
  156. package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
  157. package/dist/esm/tools/segmentation/CircleScissorsTool.js +5 -0
  158. package/dist/esm/tools/segmentation/CircleScissorsTool.js.map +1 -1
  159. package/dist/esm/tools/segmentation/RectangleScissorsTool.js +5 -0
  160. package/dist/esm/tools/segmentation/RectangleScissorsTool.js.map +1 -1
  161. package/dist/esm/tools/segmentation/SegmentSelectTool.js +100 -0
  162. package/dist/esm/tools/segmentation/SegmentSelectTool.js.map +1 -0
  163. package/dist/esm/tools/segmentation/SphereScissorsTool.js +5 -0
  164. package/dist/esm/tools/segmentation/SphereScissorsTool.js.map +1 -1
  165. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js.map +1 -1
  166. package/dist/esm/tools/segmentation/strategies/fillCircle.js +12 -15
  167. package/dist/esm/tools/segmentation/strategies/fillCircle.js.map +1 -1
  168. package/dist/esm/tools/segmentation/strategies/fillRectangle.js +32 -5
  169. package/dist/esm/tools/segmentation/strategies/fillRectangle.js.map +1 -1
  170. package/dist/esm/tools/segmentation/strategies/fillSphere.js +3 -20
  171. package/dist/esm/tools/segmentation/strategies/fillSphere.js.map +1 -1
  172. package/dist/esm/tools/segmentation/strategies/utils/isWithinThreshold.js.map +1 -1
  173. package/dist/esm/utilities/boundingBox/getBoundingBoxAroundShape.js +40 -23
  174. package/dist/esm/utilities/boundingBox/getBoundingBoxAroundShape.js.map +1 -1
  175. package/dist/esm/utilities/boundingBox/index.js +2 -2
  176. package/dist/esm/utilities/boundingBox/index.js.map +1 -1
  177. package/dist/esm/utilities/getSphereBoundsInfo.js +42 -0
  178. package/dist/esm/utilities/getSphereBoundsInfo.js.map +1 -0
  179. package/dist/esm/utilities/index.js +4 -3
  180. package/dist/esm/utilities/index.js.map +1 -1
  181. package/dist/esm/utilities/pointInShapeCallback.js +1 -1
  182. package/dist/esm/utilities/pointInShapeCallback.js.map +1 -1
  183. package/dist/esm/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.js +2 -2
  184. package/dist/esm/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.js.map +1 -1
  185. package/dist/esm/utilities/rectangleROITool/index.js +2 -1
  186. package/dist/esm/utilities/rectangleROITool/index.js.map +1 -1
  187. package/dist/esm/utilities/rectangleROITool/isAxisAlignedRectangle.js +23 -0
  188. package/dist/esm/utilities/rectangleROITool/isAxisAlignedRectangle.js.map +1 -0
  189. package/dist/esm/utilities/segmentation/createImageIdReferenceMap.js +8 -0
  190. package/dist/esm/utilities/segmentation/createImageIdReferenceMap.js.map +1 -0
  191. package/dist/esm/utilities/segmentation/createLabelmapVolumeForViewport.js +1 -1
  192. package/dist/esm/utilities/segmentation/createLabelmapVolumeForViewport.js.map +1 -1
  193. package/dist/esm/utilities/segmentation/index.js +3 -1
  194. package/dist/esm/utilities/segmentation/index.js.map +1 -1
  195. package/dist/esm/utilities/segmentation/invalidateBrushCursor.js +24 -0
  196. package/dist/esm/utilities/segmentation/invalidateBrushCursor.js.map +1 -0
  197. package/dist/esm/utilities/segmentation/thresholdSegmentationByRange.js.map +1 -1
  198. package/dist/esm/utilities/segmentation/triggerSegmentationRender.js +8 -4
  199. package/dist/esm/utilities/segmentation/triggerSegmentationRender.js.map +1 -1
  200. package/dist/esm/utilities/segmentation/utilities.js +2 -2
  201. package/dist/esm/utilities/segmentation/utilities.js.map +1 -1
  202. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +1 -1
  203. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -1
  204. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +2 -1
  205. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -1
  206. package/dist/types/eventListeners/segmentation/imageChangeEventListener.d.ts.map +1 -1
  207. package/dist/types/index.d.ts +2 -2
  208. package/dist/types/index.d.ts.map +1 -1
  209. package/dist/types/stateManagement/segmentation/activeSegmentation.d.ts +2 -1
  210. package/dist/types/stateManagement/segmentation/activeSegmentation.d.ts.map +1 -1
  211. package/dist/types/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts +11 -0
  212. package/dist/types/stateManagement/segmentation/convertStackToVolumeSegmentation.d.ts.map +1 -0
  213. package/dist/types/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts +9 -0
  214. package/dist/types/stateManagement/segmentation/convertVolumeToStackSegmentation.d.ts.map +1 -0
  215. package/dist/types/stateManagement/segmentation/index.d.ts +3 -1
  216. package/dist/types/stateManagement/segmentation/index.d.ts.map +1 -1
  217. package/dist/types/stateManagement/segmentation/segmentIndex.d.ts.map +1 -1
  218. package/dist/types/stateManagement/segmentation/segmentationState.d.ts +2 -1
  219. package/dist/types/stateManagement/segmentation/segmentationState.d.ts.map +1 -1
  220. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
  221. package/dist/types/tools/annotation/AngleTool.d.ts.map +1 -1
  222. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  223. package/dist/types/tools/displayTools/Labelmap/labelmapConfig.d.ts.map +1 -1
  224. package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts.map +1 -1
  225. package/dist/types/tools/index.d.ts +2 -1
  226. package/dist/types/tools/index.d.ts.map +1 -1
  227. package/dist/types/tools/segmentation/BrushTool.d.ts +1 -0
  228. package/dist/types/tools/segmentation/BrushTool.d.ts.map +1 -1
  229. package/dist/types/tools/segmentation/CircleScissorsTool.d.ts.map +1 -1
  230. package/dist/types/tools/segmentation/RectangleScissorsTool.d.ts.map +1 -1
  231. package/dist/types/tools/segmentation/SegmentSelectTool.d.ts +16 -0
  232. package/dist/types/tools/segmentation/SegmentSelectTool.d.ts.map +1 -0
  233. package/dist/types/tools/segmentation/SphereScissorsTool.d.ts.map +1 -1
  234. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts +2 -1
  235. package/dist/types/tools/segmentation/strategies/BrushStrategy.d.ts.map +1 -1
  236. package/dist/types/tools/segmentation/strategies/fillCircle.d.ts.map +1 -1
  237. package/dist/types/tools/segmentation/strategies/fillRectangle.d.ts.map +1 -1
  238. package/dist/types/tools/segmentation/strategies/fillSphere.d.ts.map +1 -1
  239. package/dist/types/tools/segmentation/strategies/utils/isWithinThreshold.d.ts +1 -1
  240. package/dist/types/tools/segmentation/strategies/utils/isWithinThreshold.d.ts.map +1 -1
  241. package/dist/types/types/LabelmapTypes.d.ts +1 -0
  242. package/dist/types/types/LabelmapTypes.d.ts.map +1 -1
  243. package/dist/types/utilities/boundingBox/getBoundingBoxAroundShape.d.ts +4 -2
  244. package/dist/types/utilities/boundingBox/getBoundingBoxAroundShape.d.ts.map +1 -1
  245. package/dist/types/utilities/boundingBox/index.d.ts +2 -2
  246. package/dist/types/utilities/boundingBox/index.d.ts.map +1 -1
  247. package/dist/types/utilities/getSphereBoundsInfo.d.ts +12 -0
  248. package/dist/types/utilities/getSphereBoundsInfo.d.ts.map +1 -0
  249. package/dist/types/utilities/index.d.ts +4 -3
  250. package/dist/types/utilities/index.d.ts.map +1 -1
  251. package/dist/types/utilities/pointInShapeCallback.d.ts +1 -1
  252. package/dist/types/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.d.ts.map +1 -1
  253. package/dist/types/utilities/rectangleROITool/index.d.ts +2 -1
  254. package/dist/types/utilities/rectangleROITool/index.d.ts.map +1 -1
  255. package/dist/types/utilities/rectangleROITool/isAxisAlignedRectangle.d.ts +3 -0
  256. package/dist/types/utilities/rectangleROITool/isAxisAlignedRectangle.d.ts.map +1 -0
  257. package/dist/types/utilities/segmentation/createImageIdReferenceMap.d.ts +3 -0
  258. package/dist/types/utilities/segmentation/createImageIdReferenceMap.d.ts.map +1 -0
  259. package/dist/types/utilities/segmentation/index.d.ts +3 -1
  260. package/dist/types/utilities/segmentation/index.d.ts.map +1 -1
  261. package/dist/types/utilities/segmentation/invalidateBrushCursor.d.ts +2 -0
  262. package/dist/types/utilities/segmentation/invalidateBrushCursor.d.ts.map +1 -0
  263. package/dist/types/utilities/segmentation/triggerSegmentationRender.d.ts.map +1 -1
  264. package/dist/types/utilities/segmentation/utilities.d.ts +1 -1
  265. package/dist/types/utilities/segmentation/utilities.d.ts.map +1 -1
  266. package/dist/types/utilities/stackPrefetch/stackPrefetchUtils.d.ts.map +1 -1
  267. package/dist/umd/index.js +1 -1
  268. package/dist/umd/index.js.map +1 -1
  269. package/package.json +4 -4
  270. package/src/eventListeners/segmentation/imageChangeEventListener.ts +42 -6
  271. package/src/index.ts +2 -0
  272. package/src/stateManagement/segmentation/activeSegmentation.ts +24 -1
  273. package/src/stateManagement/segmentation/convertStackToVolumeSegmentation.ts +98 -0
  274. package/src/stateManagement/segmentation/convertVolumeToStackSegmentation.ts +153 -0
  275. package/src/stateManagement/segmentation/index.ts +4 -0
  276. package/src/stateManagement/segmentation/segmentIndex.ts +15 -2
  277. package/src/stateManagement/segmentation/segmentationState.ts +17 -0
  278. package/src/store/ToolGroupManager/ToolGroup.ts +4 -0
  279. package/src/tools/annotation/AngleTool.ts +1 -2
  280. package/src/tools/annotation/BidirectionalTool.ts +1 -1
  281. package/src/tools/annotation/CircleROITool.ts +1 -1
  282. package/src/tools/annotation/EllipticalROITool.ts +1 -1
  283. package/src/tools/annotation/LengthTool.ts +1 -1
  284. package/src/tools/annotation/PlanarFreehandROITool.ts +1 -2
  285. package/src/tools/annotation/ProbeTool.ts +1 -1
  286. package/src/tools/annotation/RectangleROITool.ts +1 -1
  287. package/src/tools/displayTools/Labelmap/labelmapConfig.ts +2 -0
  288. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +39 -14
  289. package/src/tools/index.ts +2 -0
  290. package/src/tools/segmentation/BrushTool.ts +64 -33
  291. package/src/tools/segmentation/CircleScissorsTool.ts +9 -0
  292. package/src/tools/segmentation/RectangleScissorsTool.ts +10 -1
  293. package/src/tools/segmentation/SegmentSelectTool.ts +182 -0
  294. package/src/tools/segmentation/SphereScissorsTool.ts +9 -0
  295. package/src/tools/segmentation/strategies/BrushStrategy.ts +2 -1
  296. package/src/tools/segmentation/strategies/fillCircle.ts +19 -21
  297. package/src/tools/segmentation/strategies/fillRectangle.ts +51 -6
  298. package/src/tools/segmentation/strategies/fillSphere.ts +10 -38
  299. package/src/tools/segmentation/strategies/utils/isWithinThreshold.ts +1 -1
  300. package/src/types/LabelmapTypes.ts +7 -7
  301. package/src/utilities/boundingBox/getBoundingBoxAroundShape.ts +88 -37
  302. package/src/utilities/boundingBox/index.ts +11 -2
  303. package/src/utilities/{pointInSurroundingSphereCallback.ts → getSphereBoundsInfo.ts} +39 -82
  304. package/src/utilities/index.ts +6 -3
  305. package/src/utilities/math/ellipse/pointInEllipse.ts +1 -1
  306. package/src/utilities/pointInShapeCallback.ts +2 -2
  307. package/src/utilities/rectangleROITool/getBoundsIJKFromRectangleAnnotations.ts +5 -2
  308. package/src/utilities/rectangleROITool/index.ts +2 -1
  309. package/src/utilities/rectangleROITool/isAxisAlignedRectangle.ts +53 -0
  310. package/src/utilities/segmentation/createImageIdReferenceMap.ts +23 -0
  311. package/src/utilities/segmentation/createLabelmapVolumeForViewport.ts +1 -1
  312. package/src/utilities/segmentation/index.ts +4 -0
  313. package/src/utilities/segmentation/invalidateBrushCursor.ts +48 -0
  314. package/src/utilities/segmentation/thresholdSegmentationByRange.ts +2 -2
  315. package/src/utilities/segmentation/triggerSegmentationRender.ts +15 -10
  316. package/src/utilities/segmentation/utilities.ts +5 -2
  317. package/src/utilities/stackPrefetch/stackContextPrefetch.ts +1 -1
  318. package/src/utilities/stackPrefetch/stackPrefetchUtils.ts +5 -1
  319. package/dist/cjs/utilities/pointInSurroundingSphereCallback.d.ts +0 -4
  320. package/dist/cjs/utilities/pointInSurroundingSphereCallback.js +0 -70
  321. package/dist/cjs/utilities/pointInSurroundingSphereCallback.js.map +0 -1
  322. package/dist/cjs/utilities/roundNumber.d.ts +0 -2
  323. package/dist/cjs/utilities/roundNumber.js +0 -30
  324. package/dist/cjs/utilities/roundNumber.js.map +0 -1
  325. package/dist/esm/utilities/pointInSurroundingSphereCallback.js +0 -64
  326. package/dist/esm/utilities/pointInSurroundingSphereCallback.js.map +0 -1
  327. package/dist/esm/utilities/roundNumber.js +0 -28
  328. package/dist/esm/utilities/roundNumber.js.map +0 -1
  329. package/dist/types/utilities/pointInSurroundingSphereCallback.d.ts +0 -5
  330. package/dist/types/utilities/pointInSurroundingSphereCallback.d.ts.map +0 -1
  331. package/dist/types/utilities/roundNumber.d.ts +0 -3
  332. package/dist/types/utilities/roundNumber.d.ts.map +0 -1
  333. package/src/utilities/roundNumber.ts +0 -44
@@ -4,12 +4,12 @@ import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransf
4
4
  import {
5
5
  cache,
6
6
  getEnabledElementByIds,
7
+ StackViewport,
7
8
  Types,
8
- utilities,
9
+ VolumeViewport,
9
10
  } from '@cornerstonejs/core';
10
11
 
11
12
  import Representations from '../../../enums/SegmentationRepresentations';
12
- import * as SegmentationConfig from '../../../stateManagement/segmentation/config/segmentationConfig';
13
13
  import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
14
14
  import { getToolGroup } from '../../../store/ToolGroupManager';
15
15
  import type {
@@ -18,7 +18,6 @@ import type {
18
18
  LabelmapSegmentationData,
19
19
  } from '../../../types/LabelmapTypes';
20
20
  import {
21
- RepresentationPublicInput,
22
21
  SegmentationRepresentationConfig,
23
22
  ToolGroupSpecificRepresentation,
24
23
  } from '../../../types/SegmentationStateTypes';
@@ -131,11 +130,21 @@ async function render(
131
130
  } = representation;
132
131
 
133
132
  const segmentation = SegmentationState.getSegmentation(segmentationId);
133
+
134
+ if (!segmentation) {
135
+ console.warn('No segmentation found for segmentationId: ', segmentationId);
136
+ return;
137
+ }
138
+
134
139
  const labelmapData =
135
140
  segmentation.representationData[Representations.Labelmap];
136
141
 
137
142
  let actorEntry = viewport.getActor(segmentationRepresentationUID);
138
143
  if (isVolumeSegmentation(labelmapData)) {
144
+ if (viewport instanceof StackViewport) {
145
+ return;
146
+ }
147
+
139
148
  const { volumeId: labelmapUID } = labelmapData;
140
149
 
141
150
  const labelmap = cache.getVolume(labelmapUID);
@@ -159,6 +168,10 @@ async function render(
159
168
 
160
169
  actorEntry = viewport.getActor(segmentationRepresentationUID);
161
170
  } else {
171
+ if (viewport instanceof VolumeViewport) {
172
+ return;
173
+ }
174
+
162
175
  // stack segmentation
163
176
  const imageId = viewport.getCurrentImageId();
164
177
  const { imageIdReferenceMap } = labelmapData;
@@ -288,27 +301,39 @@ function _setLabelmapColorAndOpacity(
288
301
  }
289
302
  }
290
303
 
291
- const actor = actorEntry.actor as Types.Actor;
304
+ const actor = actorEntry.actor as Types.VolumeActor;
292
305
 
293
- // @ts-ignore
294
306
  actor.getProperty().setRGBTransferFunction(0, cfun);
295
307
 
296
308
  ofun.setClamping(false);
297
309
 
298
- // @ts-ignore
299
310
  actor.getProperty().setScalarOpacity(0, ofun);
300
- // @ts-ignore
301
311
  actor.getProperty().setInterpolationTypeToNearest();
312
+ actor.getProperty().setUseLabelOutline(renderOutline);
313
+
314
+ // @ts-ignore - fix type in vtk
315
+ actor.getProperty().setLabelOutlineOpacity(outlineOpacity);
302
316
 
303
- if (utilities.actorIsA(actorEntry, 'vtkVolume')) {
304
- // @ts-ignore
305
- actor.getProperty().setUseLabelOutline(renderOutline);
306
- // @ts-ignore
307
- actor.getProperty().setLabelOutlineOpacity(outlineOpacity);
308
- // @ts-ignore
309
- actor.getProperty().setLabelOutlineThickness(outlineWidth);
317
+ const { activeSegmentIndex } = SegmentationState.getSegmentation(
318
+ segmentationRepresentation.segmentationId
319
+ );
320
+
321
+ // create an array that contains all the segment indices and for the active
322
+ // segment index, use the activeSegmentOutlineWidthDelta, otherwise use the
323
+ // outlineWidth
324
+ // Pre-allocate the array with the required size to avoid dynamic resizing.
325
+ const outlineWidths = new Array(numColors - 1);
326
+
327
+ for (let i = 1; i < numColors; i++) {
328
+ // Start from 1 to skip the background segment index.
329
+ outlineWidths[i - 1] =
330
+ i === activeSegmentIndex
331
+ ? outlineWidth + toolGroupLabelmapConfig.activeSegmentOutlineWidthDelta
332
+ : outlineWidth;
310
333
  }
311
334
 
335
+ actor.getProperty().setLabelOutlineThickness(outlineWidths);
336
+
312
337
  // Set visibility based on whether actor visibility is specifically asked
313
338
  // to be turned on/off (on by default) AND whether is is in active but
314
339
  // we are rendering inactive labelmap
@@ -47,6 +47,7 @@ import RectangleROIStartEndThresholdTool from './segmentation/RectangleROIStartE
47
47
  import BrushTool from './segmentation/BrushTool';
48
48
  import PaintFillTool from './segmentation/PaintFillTool';
49
49
  import OrientationMarkerTool from './OrientationMarkerTool';
50
+ import SegmentSelectTool from './segmentation/SegmentSelectTool';
50
51
 
51
52
  export {
52
53
  // ~~ BASE
@@ -99,4 +100,5 @@ export {
99
100
  PaintFillTool,
100
101
  ScaleOverlayTool,
101
102
  OrientationMarkerTool,
103
+ SegmentSelectTool,
102
104
  };
@@ -171,7 +171,7 @@ class BrushTool extends BaseTool {
171
171
 
172
172
  createEditData(element) {
173
173
  const enabledElement = getEnabledElement(element);
174
- const { viewport, renderingEngine } = enabledElement;
174
+ const { viewport } = enabledElement;
175
175
 
176
176
  const toolGroupId = this.toolGroupId;
177
177
 
@@ -179,7 +179,7 @@ class BrushTool extends BaseTool {
179
179
  activeSegmentation.getActiveSegmentationRepresentation(toolGroupId);
180
180
  if (!activeSegmentationRepresentation) {
181
181
  throw new Error(
182
- 'No active segmentation detected, create one before using the brush tool'
182
+ 'No active segmentation detected, create a segmentation representation before using the brush tool'
183
183
  );
184
184
  }
185
185
 
@@ -198,8 +198,6 @@ class BrushTool extends BaseTool {
198
198
  const labelmapData =
199
199
  representationData[SegmentationRepresentations.Labelmap];
200
200
 
201
- const viewportIdsToRender = [viewport.id];
202
-
203
201
  if (isVolumeSegmentation(labelmapData)) {
204
202
  const { volumeId } = representationData[
205
203
  type
@@ -235,11 +233,9 @@ class BrushTool extends BaseTool {
235
233
  // and should throw an error or maybe simply just allow circle manipulation
236
234
  // and not sphere manipulation
237
235
  if (this.configuration.activeStrategy.includes('SPHERE')) {
238
- console.warn(
239
- 'Sphere manipulation is not supported for this stack of images yet'
236
+ throw new Error(
237
+ 'Sphere manipulation is not supported for stacks of image segmentations yet'
240
238
  );
241
- return;
242
-
243
239
  // Todo: add sphere (volumetric) manipulation support for stacks of images
244
240
  // we should basically check if the stack constructs a valid volume
245
241
  // meaning all the metadata is present and consistent
@@ -275,9 +271,11 @@ class BrushTool extends BaseTool {
275
271
  this._previewData.isDrag = false;
276
272
  this._previewData.timerStart = Date.now();
277
273
 
274
+ const hoverData = this._hoverData || this.createHoverData(element);
275
+
278
276
  triggerAnnotationRenderForViewportUIDs(
279
277
  renderingEngine,
280
- this._hoverData.viewportIdsToRender
278
+ hoverData.viewportIdsToRender
281
279
  );
282
280
 
283
281
  this.applyActiveStrategyCallback(
@@ -366,6 +364,40 @@ class BrushTool extends BaseTool {
366
364
  const camera = viewport.getCamera();
367
365
  const { viewPlaneNormal, viewUp } = camera;
368
366
 
367
+ const viewportIdsToRender = [viewport.id];
368
+
369
+ const {
370
+ segmentIndex,
371
+ segmentationId,
372
+ segmentationRepresentationUID,
373
+ segmentColor,
374
+ } = this.getActiveSegmentationData() || {};
375
+
376
+ // Center of circle in canvas Coordinates
377
+ const brushCursor = {
378
+ metadata: {
379
+ viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
380
+ viewUp: <Types.Point3>[...viewUp],
381
+ FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
382
+ referencedImageId: '',
383
+ toolName: this.getToolName(),
384
+ segmentColor,
385
+ },
386
+ data: {},
387
+ };
388
+
389
+ return {
390
+ brushCursor,
391
+ centerCanvas,
392
+ segmentIndex,
393
+ segmentationId,
394
+ segmentationRepresentationUID,
395
+ segmentColor,
396
+ viewportIdsToRender,
397
+ };
398
+ }
399
+
400
+ private getActiveSegmentationData() {
369
401
  const toolGroupId = this.toolGroupId;
370
402
 
371
403
  const activeSegmentationRepresentation =
@@ -388,30 +420,11 @@ class BrushTool extends BaseTool {
388
420
  segmentIndex
389
421
  );
390
422
 
391
- const viewportIdsToRender = [viewport.id];
392
-
393
- // Center of circle in canvas Coordinates
394
-
395
- const brushCursor = {
396
- metadata: {
397
- viewPlaneNormal: <Types.Point3>[...viewPlaneNormal],
398
- viewUp: <Types.Point3>[...viewUp],
399
- FrameOfReferenceUID: viewport.getFrameOfReferenceUID(),
400
- referencedImageId: '',
401
- toolName: this.getToolName(),
402
- segmentColor,
403
- },
404
- data: {},
405
- };
406
-
407
423
  return {
408
- brushCursor,
409
- centerCanvas,
410
424
  segmentIndex,
411
425
  segmentationId,
412
426
  segmentationRepresentationUID,
413
427
  segmentColor,
414
- viewportIdsToRender,
415
428
  };
416
429
  }
417
430
 
@@ -428,6 +441,10 @@ class BrushTool extends BaseTool {
428
441
 
429
442
  this._calculateCursor(element, centerCanvas);
430
443
 
444
+ if (!this._hoverData) {
445
+ return;
446
+ }
447
+
431
448
  triggerAnnotationRenderForViewportUIDs(
432
449
  getEnabledElement(element).renderingEngine,
433
450
  this._hoverData.viewportIdsToRender
@@ -549,6 +566,10 @@ class BrushTool extends BaseTool {
549
566
  rightCursorInWorld[i] = centerCursorInWorld[i] + viewRight[i] * brushSize;
550
567
  }
551
568
 
569
+ if (!this._hoverData) {
570
+ return;
571
+ }
572
+
552
573
  const { brushCursor } = this._hoverData;
553
574
  const { data } = brushCursor;
554
575
 
@@ -674,11 +695,17 @@ class BrushTool extends BaseTool {
674
695
  };
675
696
 
676
697
  public invalidateBrushCursor() {
677
- if (this._hoverData !== undefined) {
678
- const { data } = this._hoverData.brushCursor;
679
-
680
- data.invalidated = true;
698
+ if (this._hoverData === undefined) {
699
+ return;
681
700
  }
701
+ const { data } = this._hoverData.brushCursor;
702
+
703
+ data.invalidated = true;
704
+
705
+ // Todo: figure out if other brush metadata (other than segment color) should get updated
706
+ // during the brush cursor invalidation
707
+ const { segmentColor } = this.getActiveSegmentationData() || {};
708
+ this._hoverData.brushCursor.metadata.segmentColor = segmentColor;
682
709
  }
683
710
 
684
711
  renderAnnotation(
@@ -709,6 +736,10 @@ class BrushTool extends BaseTool {
709
736
  }
710
737
 
711
738
  const toolMetadata = brushCursor.metadata;
739
+ if (!toolMetadata) {
740
+ return;
741
+ }
742
+
712
743
  const annotationUID = toolMetadata.brushCursorUID;
713
744
 
714
745
  const data = brushCursor.data;
@@ -725,7 +756,7 @@ class BrushTool extends BaseTool {
725
756
 
726
757
  const radius = Math.abs(bottom[1] - Math.floor((bottom[1] + top[1]) / 2));
727
758
 
728
- const color = `rgb(${toolMetadata.segmentColor.slice(0, 3)})`;
759
+ const color = `rgb(${toolMetadata.segmentColor?.slice(0, 3) || [0, 0, 0]})`;
729
760
 
730
761
  // If rendering engine has been destroyed while rendering
731
762
  if (!viewport.getRenderingEngine()) {
@@ -89,6 +89,13 @@ class CircleScissorsTool extends BaseTool {
89
89
  *
90
90
  */
91
91
  preMouseDownCallback = (evt: EventTypes.InteractionEventType): boolean => {
92
+ // if we are already drawing, means we have started with a click, and now we
93
+ // are moving the mouse (not dragging) so the final click should not
94
+ // be handled by this preMouseDownCallback but rather the endCallback
95
+ if (this.isDrawing === true) {
96
+ return;
97
+ }
98
+
92
99
  const eventDetail = evt.detail;
93
100
  const { currentPoints, element } = eventDetail;
94
101
  const worldPos = currentPoints.world;
@@ -292,6 +299,7 @@ class CircleScissorsTool extends BaseTool {
292
299
  element.addEventListener(Events.MOUSE_UP, this._endCallback);
293
300
  element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
294
301
  element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
302
+ element.addEventListener(Events.MOUSE_MOVE, this._dragCallback);
295
303
 
296
304
  element.addEventListener(Events.TOUCH_TAP, this._endCallback);
297
305
  element.addEventListener(Events.TOUCH_DRAG, this._dragCallback);
@@ -305,6 +313,7 @@ class CircleScissorsTool extends BaseTool {
305
313
  element.removeEventListener(Events.MOUSE_UP, this._endCallback);
306
314
  element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
307
315
  element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
316
+ element.removeEventListener(Events.MOUSE_MOVE, this._dragCallback);
308
317
 
309
318
  element.removeEventListener(Events.TOUCH_END, this._endCallback);
310
319
  element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
@@ -91,6 +91,13 @@ class RectangleScissorsTool extends BaseTool {
91
91
  *
92
92
  */
93
93
  preMouseDownCallback = (evt: EventTypes.InteractionEventType): boolean => {
94
+ // if we are already drawing, means we have started with a click, and now we
95
+ // are moving the mouse (not dragging) so the final click should not
96
+ // be handled by this preMouseDownCallback but rather the endCallback
97
+ if (this.isDrawing === true) {
98
+ return;
99
+ }
100
+
94
101
  const eventDetail = evt.detail;
95
102
  const { currentPoints, element } = eventDetail;
96
103
  const worldPos = currentPoints.world;
@@ -315,6 +322,7 @@ class RectangleScissorsTool extends BaseTool {
315
322
  _activateDraw = (element) => {
316
323
  element.addEventListener(Events.MOUSE_UP, this._endCallback);
317
324
  element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
325
+ element.addEventListener(Events.MOUSE_MOVE, this._dragCallback);
318
326
  element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
319
327
 
320
328
  element.addEventListener(Events.TOUCH_END, this._endCallback);
@@ -328,9 +336,10 @@ class RectangleScissorsTool extends BaseTool {
328
336
  _deactivateDraw = (element) => {
329
337
  element.removeEventListener(Events.MOUSE_UP, this._endCallback);
330
338
  element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
339
+ element.removeEventListener(Events.MOUSE_MOVE, this._dragCallback);
331
340
  element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
332
- element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
333
341
 
342
+ element.removeEventListener(Events.TOUCH_TAP, this._endCallback);
334
343
  element.removeEventListener(Events.TOUCH_END, this._endCallback);
335
344
  element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
336
345
  };
@@ -0,0 +1,182 @@
1
+ import {
2
+ cache,
3
+ getEnabledElement,
4
+ utilities as csUtils,
5
+ } from '@cornerstonejs/core';
6
+ import type { Types } from '@cornerstonejs/core';
7
+
8
+ import { BaseTool } from '../base';
9
+ import {
10
+ PublicToolProps,
11
+ ToolProps,
12
+ EventTypes,
13
+ Segmentation,
14
+ } from '../../types';
15
+ import { triggerSegmentationModified } from '../../stateManagement/segmentation/triggerSegmentationEvents';
16
+ import triggerAnnotationRenderForViewportIds from '../../utilities/triggerAnnotationRenderForViewportIds';
17
+ import {
18
+ LabelmapSegmentationDataStack,
19
+ LabelmapSegmentationDataVolume,
20
+ } from '../../types/LabelmapTypes';
21
+ import { isVolumeSegmentation } from './strategies/utils/stackVolumeCheck';
22
+ import {
23
+ getActiveSegmentation,
24
+ getActiveSegmentationRepresentation,
25
+ } from '../../stateManagement/segmentation/activeSegmentation';
26
+ import RepresentationTypes from '../../enums/SegmentationRepresentations';
27
+ import { setActiveSegmentIndex } from '../../stateManagement/segmentation/segmentIndex';
28
+
29
+ /**
30
+ * Represents a tool used for segment selection. It is used to select a segment
31
+ * by hovering over it.
32
+ *
33
+ */
34
+ class SegmentSelectTool extends BaseTool {
35
+ static toolName;
36
+ private hoverTimer: ReturnType<typeof setTimeout> | null;
37
+
38
+ constructor(
39
+ toolProps: PublicToolProps = {},
40
+ defaultToolProps: ToolProps = {
41
+ supportedInteractionTypes: ['Mouse', 'Touch'],
42
+ configuration: {
43
+ hoverTimeout: 750,
44
+ },
45
+ }
46
+ ) {
47
+ super(toolProps, defaultToolProps);
48
+ this.hoverTimer = null;
49
+ }
50
+
51
+ mouseMoveCallback = (evt: EventTypes.InteractionEventType): boolean => {
52
+ if (this.hoverTimer) {
53
+ clearTimeout(this.hoverTimer);
54
+ }
55
+
56
+ this.hoverTimer = setTimeout(() => {
57
+ this._setActiveSegment(evt);
58
+ this.hoverTimer = null;
59
+ }, this.configuration.hoverTimeout);
60
+
61
+ return true;
62
+ };
63
+
64
+ onSetToolEnabled = (): void => {
65
+ this.onSetToolActive();
66
+ };
67
+
68
+ onSetToolActive = (): void => {
69
+ this.hoverTimer = null;
70
+ };
71
+
72
+ onSetToolDisabled = (): void => {
73
+ this.hoverTimer = null;
74
+ };
75
+
76
+ _setActiveSegment(evt = {} as EventTypes.InteractionEventType): void {
77
+ const { element, currentPoints } = evt.detail;
78
+
79
+ const worldPoint = currentPoints.world;
80
+
81
+ const enabledElement = getEnabledElement(element);
82
+
83
+ if (!enabledElement) {
84
+ return;
85
+ }
86
+
87
+ const { viewport } = enabledElement;
88
+
89
+ const activeSegmentation = getActiveSegmentation(this.toolGroupId);
90
+
91
+ if (activeSegmentation.type === RepresentationTypes.Labelmap) {
92
+ this._setActiveSegmentLabelmap(activeSegmentation, worldPoint, viewport);
93
+ } else {
94
+ throw Error('non-labelmap segmentation not supported yet');
95
+ }
96
+ }
97
+
98
+ _setActiveSegmentLabelmap(
99
+ activeSegmentation: Segmentation,
100
+ worldPoint: Types.Point3,
101
+ viewport: Types.IStackViewport | Types.IVolumeViewport
102
+ ): void {
103
+ const imageDataInfo = viewport.getImageData();
104
+
105
+ if (!imageDataInfo) {
106
+ return;
107
+ }
108
+
109
+ const labelmapData = activeSegmentation.representationData.LABELMAP;
110
+
111
+ let hoveredSegmentIndex;
112
+
113
+ if (isVolumeSegmentation(activeSegmentation.representationData.LABELMAP)) {
114
+ const { volumeId } = labelmapData as LabelmapSegmentationDataVolume;
115
+
116
+ const segmentationVolume = cache.getVolume(volumeId);
117
+
118
+ if (!segmentationVolume) {
119
+ return;
120
+ }
121
+
122
+ hoveredSegmentIndex =
123
+ segmentationVolume.imageData.getScalarValueFromWorld(worldPoint);
124
+ } else {
125
+ const { imageIdReferenceMap } =
126
+ labelmapData as LabelmapSegmentationDataStack;
127
+
128
+ const currentImageId = viewport.getCurrentImageId();
129
+ const segmentationImageId = imageIdReferenceMap.get(currentImageId);
130
+
131
+ const image = cache.getImage(segmentationImageId);
132
+
133
+ if (!image) {
134
+ return;
135
+ }
136
+
137
+ const activeSegmentationRepresentation =
138
+ getActiveSegmentationRepresentation(this.toolGroupId);
139
+
140
+ if (!activeSegmentationRepresentation) {
141
+ return;
142
+ }
143
+
144
+ const segmentationActor = viewport.getActor(
145
+ activeSegmentationRepresentation.segmentationRepresentationUID
146
+ );
147
+
148
+ const imageData = segmentationActor?.actor.getMapper().getInputData();
149
+
150
+ const indexIJK = csUtils.transformWorldToIndex(imageData, worldPoint);
151
+
152
+ // since it is a stack we don't need to check the z
153
+ const flattenedIndex = indexIJK[0] + indexIJK[1] * image.columns;
154
+
155
+ const scalars = imageData.getPointData().getScalars().getData();
156
+
157
+ hoveredSegmentIndex = scalars[flattenedIndex];
158
+ }
159
+
160
+ // No need to select background
161
+ if (!hoveredSegmentIndex || hoveredSegmentIndex === 0) {
162
+ return;
163
+ }
164
+
165
+ setActiveSegmentIndex(
166
+ activeSegmentation.segmentationId,
167
+ hoveredSegmentIndex
168
+ );
169
+
170
+ const renderingEngine = viewport.getRenderingEngine();
171
+
172
+ // update states
173
+ triggerSegmentationModified(activeSegmentation.segmentationId);
174
+ triggerAnnotationRenderForViewportIds(
175
+ renderingEngine,
176
+ renderingEngine.getViewports().map((v) => v.id)
177
+ );
178
+ }
179
+ }
180
+
181
+ SegmentSelectTool.toolName = 'SegmentSelectTool';
182
+ export default SegmentSelectTool;
@@ -91,6 +91,13 @@ class SphereScissorsTool extends BaseTool {
91
91
  *
92
92
  */
93
93
  preMouseDownCallback = (evt: EventTypes.InteractionEventType): true => {
94
+ // if we are already drawing, means we have started with a click, and now we
95
+ // are moving the mouse (not dragging) so the final click should not
96
+ // be handled by this preMouseDownCallback but rather the endCallback
97
+ if (this.isDrawing === true) {
98
+ return;
99
+ }
100
+
94
101
  const eventDetail = evt.detail;
95
102
  const { currentPoints, element } = eventDetail;
96
103
  const worldPos = currentPoints.world;
@@ -296,6 +303,7 @@ class SphereScissorsTool extends BaseTool {
296
303
  element.addEventListener(Events.MOUSE_UP, this._endCallback);
297
304
  element.addEventListener(Events.MOUSE_DRAG, this._dragCallback);
298
305
  element.addEventListener(Events.MOUSE_CLICK, this._endCallback);
306
+ element.addEventListener(Events.MOUSE_MOVE, this._dragCallback);
299
307
 
300
308
  element.addEventListener(Events.TOUCH_END, this._endCallback);
301
309
  element.addEventListener(Events.TOUCH_TAP, this._endCallback);
@@ -309,6 +317,7 @@ class SphereScissorsTool extends BaseTool {
309
317
  element.removeEventListener(Events.MOUSE_UP, this._endCallback);
310
318
  element.removeEventListener(Events.MOUSE_DRAG, this._dragCallback);
311
319
  element.removeEventListener(Events.MOUSE_CLICK, this._endCallback);
320
+ element.removeEventListener(Events.MOUSE_MOVE, this._dragCallback);
312
321
 
313
322
  element.removeEventListener(Events.TOUCH_END, this._endCallback);
314
323
  element.removeEventListener(Events.TOUCH_DRAG, this._dragCallback);
@@ -10,6 +10,7 @@ import type {
10
10
  LabelmapToolOperationDataAny,
11
11
  LabelmapToolOperationDataVolume,
12
12
  } from '../../../types/LabelmapToolOperationData';
13
+ import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
13
14
 
14
15
  const { VoxelManager } = csUtils;
15
16
 
@@ -21,7 +22,7 @@ export type InitializedOperationData = LabelmapToolOperationDataAny & {
21
22
  viewport: Types.IViewport;
22
23
  imageVoxelManager: csUtils.VoxelManager<number>;
23
24
  segmentationVoxelManager: csUtils.VoxelManager<number>;
24
- segmentationImageData: ImageData;
25
+ segmentationImageData: vtkImageData;
25
26
  previewVoxelManager: csUtils.VoxelManager<number>;
26
27
  // The index to use for the preview segment. Currently always undefined or 255
27
28
  // but define it here for future expansion of LUT tables
@@ -6,23 +6,20 @@ import {
6
6
  getCanvasEllipseCorners,
7
7
  precalculatePointInEllipse,
8
8
  } from '../../../utilities/math/ellipse';
9
- import pointInSphere from '../../../utilities/math/sphere/pointInSphere';
10
- import { getBoundingBoxAroundShape } from '../../../utilities/boundingBox';
9
+ import { getBoundingBoxAroundShapeIJK } from '../../../utilities/boundingBox';
11
10
  import BrushStrategy from './BrushStrategy';
12
11
  import type { Composition, InitializedOperationData } from './BrushStrategy';
13
12
  import type { CanvasCoordinates } from '../../../types';
14
13
  import { StrategyCallbacks } from '../../../enums';
15
14
  import compositions from './compositions';
15
+ import { pointInSphere } from '../../../utilities/math/sphere';
16
16
 
17
- const { transformWorldToIndex } = csUtils;
18
- const EPSILON = 1e-4;
19
- const nearOrZero = (testValue, nearValue) =>
20
- Math.abs(testValue) < EPSILON || Math.abs(testValue - nearValue) < EPSILON;
17
+ const { transformWorldToIndex, isEqual } = csUtils;
21
18
 
22
19
  const initializeCircle = {
23
20
  [StrategyCallbacks.Initialize]: (operationData: InitializedOperationData) => {
24
21
  const {
25
- points,
22
+ points, // bottom, top, left, right
26
23
  imageVoxelManager: imageVoxelManager,
27
24
  viewport,
28
25
  segmentationImageData,
@@ -45,6 +42,7 @@ const initializeCircle = {
45
42
  segmentationImageData,
46
43
  center as Types.Point3
47
44
  );
45
+
48
46
  const canvasCoordinates = points.map((p) =>
49
47
  viewport.worldToCanvas(p)
50
48
  ) as CanvasCoordinates;
@@ -58,17 +56,18 @@ const initializeCircle = {
58
56
  const topLeftWorld = viewport.canvasToWorld(topLeftCanvas);
59
57
  const bottomRightWorld = viewport.canvasToWorld(bottomRightCanvas);
60
58
 
61
- const ellipsoidCornersIJK = [
62
- <Types.Point3>transformWorldToIndex(segmentationImageData, topLeftWorld),
63
- <Types.Point3>(
64
- transformWorldToIndex(segmentationImageData, bottomRightWorld)
65
- ),
66
- ];
59
+ const circleCornersIJK = points.map((world) => {
60
+ return transformWorldToIndex(segmentationImageData, world);
61
+ });
67
62
 
68
- segmentationVoxelManager.boundsIJK = getBoundingBoxAroundShape(
69
- ellipsoidCornersIJK,
70
- segmentationVoxelManager.dimensions
63
+ // get the bounds from the circle points since in oblique images the
64
+ // circle will not be axis aligned
65
+ const boundsIJK = getBoundingBoxAroundShapeIJK(
66
+ circleCornersIJK,
67
+ segmentationImageData.getDimensions()
71
68
  );
69
+
70
+ segmentationVoxelManager.boundsIJK = boundsIJK;
72
71
  imageVoxelManager.isInObject = createPointInEllipse({
73
72
  topLeftWorld,
74
73
  bottomRightWorld,
@@ -98,9 +97,9 @@ function createPointInEllipse(worldInfo: {
98
97
 
99
98
  const radius = Math.max(xRadius, yRadius, zRadius);
100
99
  if (
101
- nearOrZero(xRadius, radius) &&
102
- nearOrZero(yRadius, radius) &&
103
- nearOrZero(zRadius, radius)
100
+ isEqual(xRadius, radius) &&
101
+ isEqual(yRadius, radius) &&
102
+ isEqual(zRadius, radius)
104
103
  ) {
105
104
  const sphereObj = {
106
105
  center,
@@ -116,9 +115,8 @@ function createPointInEllipse(worldInfo: {
116
115
  yRadius,
117
116
  zRadius,
118
117
  };
119
- const inverts = precalculatePointInEllipse(ellipseObj);
120
- const { precalculated } = inverts;
121
118
 
119
+ const { precalculated } = precalculatePointInEllipse(ellipseObj, {});
122
120
  return precalculated;
123
121
  }
124
122