@cornerstonejs/tools 1.57.1 → 1.58.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 (232) hide show
  1. package/dist/cjs/drawingSvg/drawPath.js +1 -1
  2. package/dist/cjs/drawingSvg/drawPath.js.map +1 -1
  3. package/dist/cjs/enums/WorkerTypes.d.ts +1 -1
  4. package/dist/cjs/enums/WorkerTypes.js +1 -1
  5. package/dist/cjs/enums/WorkerTypes.js.map +1 -1
  6. package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts +17 -0
  7. package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js +112 -0
  8. package/dist/cjs/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js.map +1 -0
  9. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts +3 -1
  10. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js +4 -1
  11. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js.map +1 -1
  12. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts +8 -0
  13. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +121 -0
  14. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js.map +1 -0
  15. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts +3 -0
  16. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js +73 -0
  17. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js.map +1 -0
  18. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts +3 -0
  19. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js +25 -0
  20. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js.map +1 -0
  21. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts +1 -0
  22. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js +41 -0
  23. package/dist/cjs/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js.map +1 -0
  24. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js +2 -2
  25. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js.map +1 -1
  26. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +1 -1
  27. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
  28. package/dist/cjs/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js.map +1 -1
  29. package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js +1 -1
  30. package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js.map +1 -1
  31. package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js +1 -1
  32. package/dist/cjs/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js.map +1 -1
  33. package/dist/cjs/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js +1 -1
  34. package/dist/cjs/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js.map +1 -1
  35. package/dist/cjs/stateManagement/segmentation/triggerSegmentationEvents.js +2 -0
  36. package/dist/cjs/stateManagement/segmentation/triggerSegmentationEvents.js.map +1 -1
  37. package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.d.ts +1 -1
  38. package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.js +5 -0
  39. package/dist/cjs/store/ToolGroupManager/getToolGroupForViewport.js.map +1 -1
  40. package/dist/cjs/tools/annotation/SplineROITool.js +25 -20
  41. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  42. package/dist/cjs/tools/base/BaseTool.js +3 -0
  43. package/dist/cjs/tools/base/BaseTool.js.map +1 -1
  44. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  45. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +13 -5
  46. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  47. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
  48. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  49. package/dist/cjs/tools/displayTools/SegmentationDisplayTool.d.ts +1 -0
  50. package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js +17 -0
  51. package/dist/cjs/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
  52. package/dist/cjs/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js +4 -47
  53. package/dist/cjs/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js.map +1 -1
  54. package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.d.ts +3 -9
  55. package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js +7 -148
  56. package/dist/cjs/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
  57. package/dist/cjs/types/PolySeg.d.ts +1 -1
  58. package/dist/cjs/utilities/contourSegmentation/addContourSegmentationAnnotation.js +4 -1
  59. package/dist/cjs/utilities/contourSegmentation/addContourSegmentationAnnotation.js.map +1 -1
  60. package/dist/cjs/utilities/contourSegmentation/removeContourSegmentationAnnotation.js +3 -0
  61. package/dist/cjs/utilities/contourSegmentation/removeContourSegmentationAnnotation.js.map +1 -1
  62. package/dist/cjs/utilities/math/polyline/getAABB.d.ts +3 -1
  63. package/dist/cjs/utilities/math/polyline/getAABB.js +30 -4
  64. package/dist/cjs/utilities/math/polyline/getAABB.js.map +1 -1
  65. package/dist/cjs/utilities/planar/index.d.ts +3 -1
  66. package/dist/cjs/utilities/planar/index.js +4 -1
  67. package/dist/cjs/utilities/planar/index.js.map +1 -1
  68. package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.d.ts +1 -0
  69. package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.js +32 -0
  70. package/dist/cjs/utilities/planar/isPlaneIntersectingAABB.js.map +1 -0
  71. package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.d.ts +3 -1
  72. package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.js +97 -47
  73. package/dist/cjs/utilities/segmentation/getUniqueSegmentIndices.js.map +1 -1
  74. package/dist/cjs/workers/polySegConverters.js +73 -0
  75. package/dist/cjs/workers/polySegConverters.js.map +1 -1
  76. package/dist/esm/drawingSvg/drawPath.js +1 -1
  77. package/dist/esm/drawingSvg/drawPath.js.map +1 -1
  78. package/dist/esm/enums/WorkerTypes.js +1 -1
  79. package/dist/esm/enums/WorkerTypes.js.map +1 -1
  80. package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js +91 -0
  81. package/dist/esm/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.js.map +1 -0
  82. package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js +4 -1
  83. package/dist/esm/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.js.map +1 -1
  84. package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js +105 -0
  85. package/dist/esm/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.js.map +1 -0
  86. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js +72 -0
  87. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.js.map +1 -0
  88. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js +21 -0
  89. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.js.map +1 -0
  90. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js +26 -0
  91. package/dist/esm/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.js.map +1 -0
  92. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js +2 -2
  93. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.js.map +1 -1
  94. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js +1 -1
  95. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.js.map +1 -1
  96. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js +1 -1
  97. package/dist/esm/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.js.map +1 -1
  98. package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js +1 -1
  99. package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.js.map +1 -1
  100. package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js +1 -1
  101. package/dist/esm/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.js.map +1 -1
  102. package/dist/esm/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js +1 -1
  103. package/dist/esm/stateManagement/segmentation/polySeg/computeAndAddRepresentation.js.map +1 -1
  104. package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js +2 -0
  105. package/dist/esm/stateManagement/segmentation/triggerSegmentationEvents.js.map +1 -1
  106. package/dist/esm/store/ToolGroupManager/getToolGroupForViewport.js +4 -0
  107. package/dist/esm/store/ToolGroupManager/getToolGroupForViewport.js.map +1 -1
  108. package/dist/esm/tools/annotation/SplineROITool.js +25 -20
  109. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  110. package/dist/esm/tools/base/BaseTool.js +3 -0
  111. package/dist/esm/tools/base/BaseTool.js.map +1 -1
  112. package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  113. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +13 -5
  114. package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  115. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
  116. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  117. package/dist/esm/tools/displayTools/SegmentationDisplayTool.js +17 -0
  118. package/dist/esm/tools/displayTools/SegmentationDisplayTool.js.map +1 -1
  119. package/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js +3 -46
  120. package/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js.map +1 -1
  121. package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js +8 -139
  122. package/dist/esm/tools/displayTools/Surface/surfaceDisplay.js.map +1 -1
  123. package/dist/esm/utilities/contourSegmentation/addContourSegmentationAnnotation.js +4 -1
  124. package/dist/esm/utilities/contourSegmentation/addContourSegmentationAnnotation.js.map +1 -1
  125. package/dist/esm/utilities/contourSegmentation/removeContourSegmentationAnnotation.js +3 -0
  126. package/dist/esm/utilities/contourSegmentation/removeContourSegmentationAnnotation.js.map +1 -1
  127. package/dist/esm/utilities/math/polyline/getAABB.js +30 -4
  128. package/dist/esm/utilities/math/polyline/getAABB.js.map +1 -1
  129. package/dist/esm/utilities/planar/index.js +3 -1
  130. package/dist/esm/utilities/planar/index.js.map +1 -1
  131. package/dist/esm/utilities/planar/isPlaneIntersectingAABB.js +28 -0
  132. package/dist/esm/utilities/planar/isPlaneIntersectingAABB.js.map +1 -0
  133. package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js +92 -44
  134. package/dist/esm/utilities/segmentation/getUniqueSegmentIndices.js.map +1 -1
  135. package/dist/esm/workers/polySegConverters.js +74 -1
  136. package/dist/esm/workers/polySegConverters.js.map +1 -1
  137. package/dist/types/drawingSvg/drawPath.d.ts.map +1 -1
  138. package/dist/types/enums/WorkerTypes.d.ts +1 -1
  139. package/dist/types/enums/WorkerTypes.d.ts.map +1 -1
  140. package/dist/types/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts +18 -0
  141. package/dist/types/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.d.ts.map +1 -0
  142. package/dist/types/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts +3 -1
  143. package/dist/types/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.d.ts.map +1 -1
  144. package/dist/types/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts +9 -0
  145. package/dist/types/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.d.ts.map +1 -0
  146. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts +4 -0
  147. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.d.ts.map +1 -0
  148. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts +4 -0
  149. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.d.ts.map +1 -0
  150. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts +2 -0
  151. package/dist/types/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.d.ts.map +1 -0
  152. package/dist/types/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.d.ts.map +1 -1
  153. package/dist/types/stateManagement/segmentation/triggerSegmentationEvents.d.ts.map +1 -1
  154. package/dist/types/store/ToolGroupManager/getToolGroupForViewport.d.ts +1 -1
  155. package/dist/types/store/ToolGroupManager/getToolGroupForViewport.d.ts.map +1 -1
  156. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  157. package/dist/types/tools/base/BaseTool.d.ts.map +1 -1
  158. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
  159. package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts.map +1 -1
  160. package/dist/types/tools/displayTools/SegmentationDisplayTool.d.ts +1 -0
  161. package/dist/types/tools/displayTools/SegmentationDisplayTool.d.ts.map +1 -1
  162. package/dist/types/tools/displayTools/Surface/addOrUpdateSurfaceToElement.d.ts.map +1 -1
  163. package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts +3 -9
  164. package/dist/types/tools/displayTools/Surface/surfaceDisplay.d.ts.map +1 -1
  165. package/dist/types/types/PolySeg.d.ts +1 -1
  166. package/dist/types/types/PolySeg.d.ts.map +1 -1
  167. package/dist/types/utilities/contourSegmentation/addContourSegmentationAnnotation.d.ts.map +1 -1
  168. package/dist/types/utilities/contourSegmentation/removeContourSegmentationAnnotation.d.ts.map +1 -1
  169. package/dist/types/utilities/math/polyline/getAABB.d.ts +3 -1
  170. package/dist/types/utilities/math/polyline/getAABB.d.ts.map +1 -1
  171. package/dist/types/utilities/planar/index.d.ts +3 -1
  172. package/dist/types/utilities/planar/index.d.ts.map +1 -1
  173. package/dist/types/utilities/planar/isPlaneIntersectingAABB.d.ts +2 -0
  174. package/dist/types/utilities/planar/isPlaneIntersectingAABB.d.ts.map +1 -0
  175. package/dist/types/utilities/segmentation/getUniqueSegmentIndices.d.ts +3 -1
  176. package/dist/types/utilities/segmentation/getUniqueSegmentIndices.d.ts.map +1 -1
  177. package/dist/umd/985.index.js +1 -1
  178. package/dist/umd/985.index.js.map +1 -1
  179. package/dist/umd/index.js +1 -1
  180. package/dist/umd/index.js.map +1 -1
  181. package/package.json +4 -4
  182. package/src/drawingSvg/drawPath.ts +3 -1
  183. package/src/enums/WorkerTypes.ts +1 -1
  184. package/src/stateManagement/segmentation/helpers/clipAndCacheSurfacesForViewport.ts +203 -0
  185. package/src/stateManagement/segmentation/polySeg/Contour/computeAndAddContourRepresentation.ts +9 -2
  186. package/src/stateManagement/segmentation/polySeg/Contour/contourComputationStrategies.ts +201 -0
  187. package/src/stateManagement/segmentation/polySeg/Contour/utils/createAndAddContourSegmentationsFromClippedSurfaces.ts +103 -0
  188. package/src/stateManagement/segmentation/polySeg/Contour/utils/extractContourData.ts +38 -0
  189. package/src/stateManagement/segmentation/polySeg/Contour/utils/updateContoursOnCameraModified.ts +58 -0
  190. package/src/stateManagement/segmentation/polySeg/Labelmap/convertContourToLabelmap.ts +2 -2
  191. package/src/stateManagement/segmentation/polySeg/Labelmap/convertSurfaceToLabelmap.ts +1 -1
  192. package/src/stateManagement/segmentation/polySeg/Labelmap/labelmapComputationStrategies.ts +3 -8
  193. package/src/stateManagement/segmentation/polySeg/Surface/convertContourToSurface.ts +1 -1
  194. package/src/stateManagement/segmentation/polySeg/Surface/convertLabelmapToSurface.ts +1 -1
  195. package/src/stateManagement/segmentation/polySeg/computeAndAddRepresentation.ts +1 -1
  196. package/src/stateManagement/segmentation/triggerSegmentationEvents.ts +5 -0
  197. package/src/store/ToolGroupManager/getToolGroupForViewport.ts +8 -1
  198. package/src/tools/annotation/SplineROITool.ts +34 -27
  199. package/src/tools/base/BaseTool.ts +7 -0
  200. package/src/tools/base/ContourSegmentationBaseTool.ts +5 -0
  201. package/src/tools/displayTools/Contour/contourDisplay.ts +29 -11
  202. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +1 -1
  203. package/src/tools/displayTools/SegmentationDisplayTool.ts +26 -0
  204. package/src/tools/displayTools/Surface/addOrUpdateSurfaceToElement.ts +3 -65
  205. package/src/tools/displayTools/Surface/surfaceDisplay.ts +12 -247
  206. package/src/types/PolySeg.ts +1 -1
  207. package/src/utilities/contourSegmentation/addContourSegmentationAnnotation.ts +9 -1
  208. package/src/utilities/contourSegmentation/removeContourSegmentationAnnotation.ts +4 -0
  209. package/src/utilities/math/polyline/getAABB.ts +58 -4
  210. package/src/utilities/planar/index.ts +3 -0
  211. package/src/utilities/planar/isPlaneIntersectingAABB.ts +56 -0
  212. package/src/utilities/segmentation/getUniqueSegmentIndices.ts +115 -49
  213. package/src/workers/polySegConverters.js +117 -1
  214. package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.d.ts +0 -1
  215. package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.js +0 -27
  216. package/dist/cjs/tools/displayTools/registerDisplayToolsWorker.js.map +0 -1
  217. package/dist/cjs/workers/clippingPlaneWorker.d.ts +0 -1
  218. package/dist/cjs/workers/clippingPlaneWorker.js +0 -63
  219. package/dist/cjs/workers/clippingPlaneWorker.js.map +0 -1
  220. package/dist/esm/tools/displayTools/registerDisplayToolsWorker.js +0 -23
  221. package/dist/esm/tools/displayTools/registerDisplayToolsWorker.js.map +0 -1
  222. package/dist/esm/workers/clippingPlaneWorker.js +0 -58
  223. package/dist/esm/workers/clippingPlaneWorker.js.map +0 -1
  224. package/dist/types/tools/displayTools/registerDisplayToolsWorker.d.ts +0 -2
  225. package/dist/types/tools/displayTools/registerDisplayToolsWorker.d.ts.map +0 -1
  226. package/dist/types/workers/clippingPlaneWorker.d.ts +0 -2
  227. package/dist/types/workers/clippingPlaneWorker.d.ts.map +0 -1
  228. package/dist/umd/444.index.js +0 -3
  229. package/dist/umd/444.index.js.LICENSE.txt +0 -5
  230. package/dist/umd/444.index.js.map +0 -1
  231. package/src/tools/displayTools/registerDisplayToolsWorker.ts +0 -34
  232. package/src/workers/clippingPlaneWorker.js +0 -87
@@ -1,42 +1,18 @@
1
- import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
2
- import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
3
1
  import {
4
2
  cache,
5
3
  getEnabledElementByIds,
6
4
  Types,
7
- Enums,
8
- getWebWorkerManager,
9
- eventTarget,
10
- triggerEvent,
11
- utilities,
12
5
  VolumeViewport3D,
13
6
  } from '@cornerstonejs/core';
14
7
 
15
8
  import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
16
9
  import Representations from '../../../enums/SegmentationRepresentations';
17
10
  import { getToolGroup } from '../../../store/ToolGroupManager';
18
- import {
19
- SegmentationRepresentationConfig,
20
- ToolGroupSpecificRepresentation,
21
- } from '../../../types/SegmentationStateTypes';
22
- import { registerDisplayToolsWorker } from '../registerDisplayToolsWorker';
11
+ import { ToolGroupSpecificRepresentation } from '../../../types/SegmentationStateTypes';
23
12
 
24
13
  import removeSurfaceFromElement from './removeSurfaceFromElement';
25
14
  import addOrUpdateSurfaceToElement from './addOrUpdateSurfaceToElement';
26
15
  import { polySeg } from '../../../stateManagement/segmentation';
27
- import { pointToString } from '../../../utilities';
28
- import { WorkerTypes } from '../../../enums';
29
- const workerManager = getWebWorkerManager();
30
-
31
- const polyDataCache = new Map();
32
- const currentViewportNormal = new Map();
33
-
34
- const triggerWorkerProgress = (eventTarget, progress) => {
35
- triggerEvent(eventTarget, Enums.Events.WEB_WORKER_PROGRESS, {
36
- progress,
37
- type: WorkerTypes.DISPLAY_TOOL_CLIP_SURFACE,
38
- });
39
- };
40
16
 
41
17
  /**
42
18
  * It removes a segmentation representation from the tool group's viewports and
@@ -82,16 +58,10 @@ function removeSegmentationRepresentation(
82
58
  */
83
59
  async function render(
84
60
  viewport: Types.IVolumeViewport,
85
- representation: ToolGroupSpecificRepresentation,
86
- toolGroupConfig: SegmentationRepresentationConfig
61
+ representation: ToolGroupSpecificRepresentation
87
62
  ): Promise<void> {
88
- const {
89
- colorLUTIndex,
90
- active,
91
- segmentationId,
92
- segmentationRepresentationUID,
93
- segmentsHidden,
94
- } = representation;
63
+ const { colorLUTIndex, segmentationId, segmentationRepresentationUID } =
64
+ representation;
95
65
 
96
66
  const segmentation = SegmentationState.getSegmentation(segmentationId);
97
67
 
@@ -99,6 +69,12 @@ async function render(
99
69
  return;
100
70
  }
101
71
 
72
+ if (!(viewport instanceof VolumeViewport3D)) {
73
+ throw new Error(
74
+ 'Surface rendering is only supported in 3D viewports, if you need to visualize the surface cuts in 2D viewports, you can use the Contour representation, see polySeg converters'
75
+ );
76
+ }
77
+
102
78
  let SurfaceData = segmentation.representationData[Representations.Surface];
103
79
 
104
80
  if (
@@ -134,18 +110,7 @@ async function render(
134
110
  const surfaces = [];
135
111
  geometryIds.forEach((geometryId, segmentIndex) => {
136
112
  const geometry = cache.getGeometry(geometryId);
137
- if (!geometry) {
138
- throw new Error(`No Surfaces found for geometryId ${geometryId}`);
139
- }
140
-
141
- if (geometry.type !== Enums.GeometryType.SURFACE) {
142
- // Todo: later we can support converting other geometries to Surfaces
143
- throw new Error(
144
- `Geometry type ${geometry.type} not supported for rendering.`
145
- );
146
- }
147
-
148
- if (!geometry.data) {
113
+ if (!geometry?.data) {
149
114
  console.warn(
150
115
  `No Surfaces found for geometryId ${geometryId}. Skipping render.`
151
116
  );
@@ -166,18 +131,6 @@ async function render(
166
131
  surfaces.push(surface);
167
132
  });
168
133
 
169
- if (!(viewport instanceof VolumeViewport3D)) {
170
- // const { viewPlaneNormal } = viewport.getCamera();
171
- // currentViewportNormal.set(surface.id, structuredClone(viewPlaneNormal));
172
- // if the viewport is not 3D means we should calculate
173
- // the clipping planes for the surface and cache the results
174
- generateAndCacheClippedSurfaces(
175
- surfaces,
176
- viewport,
177
- segmentationRepresentationUID
178
- );
179
- }
180
-
181
134
  viewport.render();
182
135
  }
183
136
 
@@ -206,197 +159,9 @@ function _removeSurfaceFromToolGroupViewports(
206
159
  }
207
160
  }
208
161
 
209
- async function generateAndCacheClippedSurfaces(
210
- surfaces: Types.ISurface[],
211
- viewport: Types.IVolumeViewport | Types.IStackViewport,
212
- segmentationRepresentationUID: string
213
- ) {
214
- registerDisplayToolsWorker();
215
-
216
- // All planes is an array of planes pairs for each slice, so we should loop over them and
217
- // add the planes to the clipping filter and cache the results for that slice
218
-
219
- // Fix these ts ignores
220
- // @ts-ignore
221
- const planesInfo = viewport.getSlicesClippingPlanes?.();
222
-
223
- if (!planesInfo) {
224
- // this means it is probably the stack viewport not being ready
225
- // in terms of planes which we should wait for the first render to
226
- // get the planes
227
- return;
228
- }
229
-
230
- // @ts-ignore
231
- const currentSliceIndex = viewport.getSliceIndex();
232
-
233
- // Reorder planesInfo based on proximity to currentSliceIndex
234
- planesInfo.sort((a, b) => {
235
- const diffA = Math.abs(a.sliceIndex - currentSliceIndex);
236
- const diffB = Math.abs(b.sliceIndex - currentSliceIndex);
237
- return diffA - diffB;
238
- });
239
-
240
- const pointsAndPolys = surfaces.map((surface) => {
241
- const id = surface.id;
242
- const points = surface.getPoints();
243
- const polys = surface.getPolys();
244
-
245
- return { id, points, polys };
246
- });
247
-
248
- const camera = viewport.getCamera();
249
-
250
- function cameraModifiedCallback(evt: Types.EventTypes.CameraModifiedEvent) {
251
- const { camera } = evt.detail;
252
- const { viewPlaneNormal } = camera;
253
-
254
- // Note: I think choosing one of the surfaces to see
255
- // if the viewPlaneNormal is the same for all surfaces is ok enough
256
- // to decide if we should recompute the clipping planes
257
- const surface1 = surfaces[0];
258
-
259
- if (
260
- utilities.isEqual(viewPlaneNormal, currentViewportNormal.get(surface1.id))
261
- ) {
262
- return;
263
- }
264
-
265
- currentViewportNormal.set(surface1.id, viewPlaneNormal);
266
-
267
- workerManager.terminate('displayTools');
268
-
269
- setTimeout(() => {
270
- generateAndCacheClippedSurfaces(
271
- surfaces,
272
- viewport,
273
- segmentationRepresentationUID
274
- );
275
- }, 0);
276
-
277
- viewport.render();
278
- }
279
-
280
- // Remove the existing event listener
281
- viewport.element.removeEventListener(
282
- Enums.Events.CAMERA_MODIFIED,
283
- cameraModifiedCallback as EventListener
284
- );
285
-
286
- // Add the event listener
287
- viewport.element.addEventListener(
288
- Enums.Events.CAMERA_MODIFIED,
289
- cameraModifiedCallback as EventListener
290
- );
291
-
292
- triggerWorkerProgress(eventTarget, 0);
293
-
294
- await workerManager
295
- .executeTask(
296
- 'displayTools',
297
- 'clipSurfaceWithPlanes',
298
- {
299
- planesInfo,
300
- pointsAndPolys,
301
- },
302
- {
303
- callbacks: [
304
- // progress callback
305
- ({ progress }) => {
306
- triggerWorkerProgress(eventTarget, progress);
307
- },
308
- // update cache callback
309
- ({ sliceIndex, polyDataResults }) => {
310
- polyDataResults.forEach((polyDataResult, surfaceId) => {
311
- const actorUID = `${segmentationRepresentationUID}_${surfaceId}`;
312
- const cacheId = generateCacheId(
313
- viewport,
314
- camera.viewPlaneNormal,
315
- sliceIndex
316
- );
317
- updatePolyDataCache(actorUID, cacheId, polyDataResult);
318
- });
319
- },
320
- ],
321
- }
322
- )
323
- .catch((error) => {
324
- console.error(error);
325
- });
326
-
327
- triggerWorkerProgress(eventTarget, 100);
328
- }
329
-
330
- export function getSurfaceActorUID(
331
- segmentationRepresentationUID: string,
332
- surfaceId: string
333
- ) {
334
- return `${segmentationRepresentationUID}_${surfaceId}`;
335
- }
336
-
337
- // Helper function to generate a cache ID
338
- export function generateCacheId(viewport, viewPlaneNormal, sliceIndex) {
339
- return `${viewport.id}-${pointToString(viewPlaneNormal)}-${sliceIndex}`;
340
- }
341
-
342
- // Helper function to get or create PolyData
343
- export function getOrCreatePolyData(actorEntry, cacheId, vtkPlanes) {
344
- let actorCache = polyDataCache.get(actorEntry.uid);
345
- if (!actorCache) {
346
- actorCache = new Map();
347
- polyDataCache.set(actorEntry.uid, actorCache);
348
- }
349
-
350
- let polyData = actorCache.get(cacheId);
351
- if (!polyData) {
352
- const clippingFilter = actorEntry.clippingFilter;
353
- clippingFilter.setClippingPlanes(vtkPlanes);
354
- try {
355
- clippingFilter.update();
356
- polyData = clippingFilter.getOutputData();
357
- actorCache.set(cacheId, polyData);
358
- } catch (e) {
359
- console.error('Error clipping surface', e);
360
- }
361
- }
362
- return polyData;
363
- }
364
-
365
- // Helper function to update PolyData cache
366
- export function updatePolyDataCache(actorUID, cacheId, polyDataResult) {
367
- const { points, lines } = polyDataResult;
368
- const polyData = vtkPolyData.newInstance();
369
- polyData.getPoints().setData(points, 3);
370
- const linesArray = vtkCellArray.newInstance({
371
- values: Int16Array.from(lines),
372
- });
373
- polyData.setLines(linesArray);
374
-
375
- let actorCache = polyDataCache.get(actorUID);
376
- if (!actorCache) {
377
- actorCache = new Map();
378
- polyDataCache.set(actorUID, actorCache);
379
- }
380
- actorCache.set(cacheId, polyData);
381
- }
382
-
383
- // Helper function to get and sort planes info based on slice index
384
- export function getSortedPlanesInfo(viewport) {
385
- const planesInfo = viewport.getSlicesClippingPlanes?.();
386
- const currentSliceIndex = viewport.getSliceIndex();
387
-
388
- // Sort planesInfo based on proximity to currentSliceIndex
389
- planesInfo.sort((a, b) => {
390
- const diffA = Math.abs(a.sliceIndex - currentSliceIndex);
391
- const diffB = Math.abs(b.sliceIndex - currentSliceIndex);
392
- return diffA - diffB;
393
- });
394
- return planesInfo;
395
- }
396
-
397
162
  export default {
398
163
  render,
399
164
  removeSegmentationRepresentation,
400
165
  };
401
166
 
402
- export { render, removeSegmentationRepresentation, polyDataCache };
167
+ export { render, removeSegmentationRepresentation };
@@ -3,5 +3,5 @@ import type { Types } from '@cornerstonejs/core';
3
3
  export type PolySegConversionOptions = {
4
4
  segmentIndices?: number[];
5
5
  segmentationRepresentationUID?: string;
6
- viewport?: Types.IViewport;
6
+ viewport?: Types.IStackViewport | Types.IVolumeViewport;
7
7
  };
@@ -16,6 +16,11 @@ export function addContourSegmentationAnnotation(
16
16
 
17
17
  const { segmentationId, segmentIndex } = annotation.data.segmentation;
18
18
  const segmentation = getSegmentation(segmentationId);
19
+
20
+ if (!segmentation.representationData.CONTOUR) {
21
+ segmentation.representationData.CONTOUR = { annotationUIDsMap: new Map() };
22
+ }
23
+
19
24
  const { annotationUIDsMap } = segmentation.representationData.CONTOUR;
20
25
 
21
26
  let annotationsUIDsSet = annotationUIDsMap.get(segmentIndex);
@@ -25,5 +30,8 @@ export function addContourSegmentationAnnotation(
25
30
  annotationUIDsMap.set(segmentIndex, annotationsUIDsSet);
26
31
  }
27
32
 
28
- annotationsUIDsSet.add(annotation.annotationUID);
33
+ annotationUIDsMap.set(
34
+ segmentIndex,
35
+ annotationsUIDsSet.add(annotation.annotationUID)
36
+ );
29
37
  }
@@ -21,6 +21,10 @@ export function removeContourSegmentationAnnotation(
21
21
  const { annotationUIDsMap } = segmentation.representationData.CONTOUR;
22
22
  const annotationsUIDsSet = annotationUIDsMap.get(segmentIndex);
23
23
 
24
+ if (!annotationsUIDsSet) {
25
+ return;
26
+ }
27
+
24
28
  annotationsUIDsSet.delete(annotation.annotationUID);
25
29
 
26
30
  // Delete segmentIndex Set if there is no more annotations
@@ -1,20 +1,74 @@
1
1
  import { Types } from '@cornerstonejs/core';
2
2
 
3
- export default function getAABB(polyline: Types.Point2[]): Types.AABB2 {
3
+ /**
4
+ * Calculates the axis-aligned bounding box (AABB) of a polyline.
5
+ *
6
+ * @param polyline - The polyline represented as an array of points.
7
+ * @param options - Additional options for calculating the AABB.
8
+ * @param options.isWorld - Indicates whether the polyline represents points in 3D space (true) or 2D space (false).
9
+ *
10
+ * @returns The AABB of the polyline. If the polyline represents points in 3D space, returns an AABB3 object with properties minX, maxX, minY, maxY, minZ, and maxZ. If the polyline represents points in 2D space, returns an AABB2 object with properties minX, maxX, minY, and maxY.
11
+ */
12
+ export default function getAABB(
13
+ polyline: Types.Point2[] | Types.Point3[] | number[],
14
+ options?: {
15
+ numDimensions: number;
16
+ }
17
+ ): Types.AABB2 | Types.AABB3 {
18
+ // need to check if the polyline is array of arrays or just
19
+ // a flat array of numbers
20
+ let polylineToUse = polyline;
21
+ const numDimensions = options?.numDimensions || 2;
22
+ const is3D = numDimensions === 3;
23
+
24
+ if (!Array.isArray(polyline[0])) {
25
+ const currentPolyline = polyline as number[];
26
+ // check the isWorld flag is provided or not which means every
27
+ // 3 elements in the array represent a point in 3D space
28
+ // otherwise, every 2 elements in the array represent a point in 2D space
29
+ const totalPoints = currentPolyline.length / numDimensions;
30
+
31
+ polylineToUse = new Array(currentPolyline.length / numDimensions) as
32
+ | Types.Point2[]
33
+ | Types.Point3[];
34
+
35
+ for (let i = 0, len = totalPoints; i < len; i++) {
36
+ polylineToUse[i] = [
37
+ currentPolyline[i * numDimensions],
38
+ currentPolyline[i * numDimensions + 1],
39
+ ];
40
+
41
+ if (is3D) {
42
+ polylineToUse[i].push(currentPolyline[i * numDimensions + 2]);
43
+ }
44
+ }
45
+ }
46
+
4
47
  let minX = Infinity;
5
48
  let minY = Infinity;
6
49
  let maxX = -Infinity;
7
50
  let maxY = -Infinity;
51
+ let minZ = Infinity;
52
+ let maxZ = -Infinity;
8
53
 
9
- for (let i = 0, len = polyline.length; i < len; i++) {
10
- const [x, y] = polyline[i];
54
+ polylineToUse = polylineToUse as Types.Point2[] | Types.Point3[];
55
+
56
+ for (let i = 0, len = polylineToUse.length; i < len; i++) {
57
+ const [x, y, z] = polylineToUse[i];
11
58
 
12
59
  // No Math.min/max calls for better performance
13
60
  minX = minX < x ? minX : x;
14
61
  minY = minY < y ? minY : y;
15
62
  maxX = maxX > x ? maxX : x;
16
63
  maxY = maxY > y ? maxY : y;
64
+
65
+ if (is3D) {
66
+ minZ = minZ < z ? minZ : z;
67
+ maxZ = maxZ > z ? maxZ : z;
68
+ }
17
69
  }
18
70
 
19
- return { minX, maxX, minY, maxY };
71
+ return is3D
72
+ ? { minX, maxX, minY, maxY, minZ, maxZ } // AABB3
73
+ : { minX, maxX, minY, maxY }; // AABB2
20
74
  }
@@ -2,12 +2,14 @@ import filterAnnotationsWithinSlice from './filterAnnotationsWithinSlice';
2
2
  import getWorldWidthAndHeightFromCorners from './getWorldWidthAndHeightFromCorners';
3
3
  import filterAnnotationsForDisplay from './filterAnnotationsForDisplay';
4
4
  import getPointInLineOfSightWithCriteria from './getPointInLineOfSightWithCriteria';
5
+ import { isPlaneIntersectingAABB } from './isPlaneIntersectingAABB';
5
6
 
6
7
  export default {
7
8
  filterAnnotationsWithinSlice,
8
9
  getWorldWidthAndHeightFromCorners,
9
10
  filterAnnotationsForDisplay,
10
11
  getPointInLineOfSightWithCriteria,
12
+ isPlaneIntersectingAABB,
11
13
  };
12
14
 
13
15
  export {
@@ -15,4 +17,5 @@ export {
15
17
  getWorldWidthAndHeightFromCorners,
16
18
  filterAnnotationsForDisplay,
17
19
  getPointInLineOfSightWithCriteria,
20
+ isPlaneIntersectingAABB,
18
21
  };
@@ -0,0 +1,56 @@
1
+ import { vec3 } from 'gl-matrix';
2
+
3
+ /**
4
+ * Checks if a plane intersects with an Axis-Aligned Bounding Box (AABB).
5
+ *
6
+ * @param origin - The origin point of the plane.
7
+ * @param normal - The normal vector of the plane.
8
+ * @param minX - The minimum x-coordinate of the AABB.
9
+ * @param minY - The minimum y-coordinate of the AABB.
10
+ * @param minZ - The minimum z-coordinate of the AABB.
11
+ * @param maxX - The maximum x-coordinate of the AABB.
12
+ * @param maxY - The maximum y-coordinate of the AABB.
13
+ * @param maxZ - The maximum z-coordinate of the AABB.
14
+ * @returns A boolean indicating whether the plane intersects with the AABB.
15
+ */
16
+ export const isPlaneIntersectingAABB = (
17
+ origin,
18
+ normal,
19
+ minX,
20
+ minY,
21
+ minZ,
22
+ maxX,
23
+ maxY,
24
+ maxZ
25
+ ) => {
26
+ const vertices = [
27
+ vec3.fromValues(minX, minY, minZ),
28
+ vec3.fromValues(maxX, minY, minZ),
29
+ vec3.fromValues(minX, maxY, minZ),
30
+ vec3.fromValues(maxX, maxY, minZ),
31
+ vec3.fromValues(minX, minY, maxZ),
32
+ vec3.fromValues(maxX, minY, maxZ),
33
+ vec3.fromValues(minX, maxY, maxZ),
34
+ vec3.fromValues(maxX, maxY, maxZ),
35
+ ];
36
+
37
+ const normalVec = vec3.fromValues(normal[0], normal[1], normal[2]);
38
+ const originVec = vec3.fromValues(origin[0], origin[1], origin[2]);
39
+
40
+ // Compute the distance from the plane to the origin using vec3.dot
41
+ const planeDistance = -vec3.dot(normalVec, originVec);
42
+
43
+ // Check if all vertices are on the same side of the plane
44
+ let initialSign = null;
45
+ for (const vertex of vertices) {
46
+ // Calculate distance using vec3.dot to simplify the equation
47
+ const distance = vec3.dot(normalVec, vertex) + planeDistance;
48
+ if (initialSign === null) {
49
+ initialSign = Math.sign(distance);
50
+ } else if (Math.sign(distance) !== initialSign) {
51
+ return true; // Found a vertex on the other side, so it intersects
52
+ }
53
+ }
54
+
55
+ return false;
56
+ };