@cornerstonejs/tools 1.50.2 → 1.51.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 (489) hide show
  1. package/dist/cjs/eventListeners/annotations/annotationCompletedListener.d.ts +2 -0
  2. package/dist/cjs/eventListeners/annotations/annotationCompletedListener.js +35 -0
  3. package/dist/cjs/eventListeners/annotations/annotationCompletedListener.js.map +1 -0
  4. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +2 -0
  5. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +174 -0
  6. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -0
  7. package/dist/cjs/eventListeners/annotations/contourSegmentation/index.d.ts +1 -0
  8. package/dist/cjs/eventListeners/annotations/contourSegmentation/index.js +9 -0
  9. package/dist/cjs/eventListeners/annotations/contourSegmentation/index.js.map +1 -0
  10. package/dist/cjs/eventListeners/annotations/index.d.ts +2 -1
  11. package/dist/cjs/eventListeners/annotations/index.js +3 -1
  12. package/dist/cjs/eventListeners/annotations/index.js.map +1 -1
  13. package/dist/cjs/eventListeners/index.d.ts +2 -2
  14. package/dist/cjs/eventListeners/index.js +2 -1
  15. package/dist/cjs/eventListeners/index.js.map +1 -1
  16. package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts +3 -0
  17. package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +89 -0
  18. package/dist/cjs/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js.map +1 -0
  19. package/dist/cjs/eventListeners/segmentation/segmentationDataModifiedEventListener.js +5 -53
  20. package/dist/cjs/eventListeners/segmentation/segmentationDataModifiedEventListener.js.map +1 -1
  21. package/dist/cjs/init.js +2 -0
  22. package/dist/cjs/init.js.map +1 -1
  23. package/dist/cjs/stateManagement/annotation/helpers/state.d.ts +3 -1
  24. package/dist/cjs/stateManagement/annotation/helpers/state.js +21 -1
  25. package/dist/cjs/stateManagement/annotation/helpers/state.js.map +1 -1
  26. package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +1 -0
  27. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +3 -0
  28. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  29. package/dist/cjs/store/addTool.d.ts +1 -0
  30. package/dist/cjs/store/addTool.js +6 -1
  31. package/dist/cjs/store/addTool.js.map +1 -1
  32. package/dist/cjs/store/index.d.ts +2 -2
  33. package/dist/cjs/store/index.js +2 -1
  34. package/dist/cjs/store/index.js.map +1 -1
  35. package/dist/cjs/store/removeEnabledElement.js +1 -2
  36. package/dist/cjs/store/removeEnabledElement.js.map +1 -1
  37. package/dist/cjs/tools/AdvancedMagnifyTool.js +3 -10
  38. package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
  39. package/dist/cjs/tools/annotation/AngleTool.js +5 -18
  40. package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
  41. package/dist/cjs/tools/annotation/ArrowAnnotateTool.js +9 -28
  42. package/dist/cjs/tools/annotation/ArrowAnnotateTool.js.map +1 -1
  43. package/dist/cjs/tools/annotation/BidirectionalTool.js +7 -22
  44. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  45. package/dist/cjs/tools/annotation/CircleROITool.js +7 -22
  46. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  47. package/dist/cjs/tools/annotation/CobbAngleTool.js +5 -18
  48. package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
  49. package/dist/cjs/tools/annotation/EllipticalROITool.js +7 -22
  50. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  51. package/dist/cjs/tools/annotation/KeyImageTool.js +5 -12
  52. package/dist/cjs/tools/annotation/KeyImageTool.js.map +1 -1
  53. package/dist/cjs/tools/annotation/LengthTool.js +5 -18
  54. package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
  55. package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +4 -1
  56. package/dist/cjs/tools/annotation/LivewireContourTool.js +30 -22
  57. package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
  58. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +2 -1
  59. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js +11 -0
  60. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
  61. package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +2 -10
  62. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +6 -22
  63. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  64. package/dist/cjs/tools/annotation/ProbeTool.js +8 -23
  65. package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
  66. package/dist/cjs/tools/annotation/RectangleROITool.js +8 -22
  67. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  68. package/dist/cjs/tools/annotation/SplineROITool.d.ts +8 -9
  69. package/dist/cjs/tools/annotation/SplineROITool.js +27 -10
  70. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  71. package/dist/cjs/tools/annotation/UltrasoundDirectionalTool.js +5 -18
  72. package/dist/cjs/tools/annotation/UltrasoundDirectionalTool.js.map +1 -1
  73. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +7 -6
  74. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  75. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +8 -5
  76. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  77. package/dist/cjs/tools/annotation/planarFreehandROITool/editLoopCommon.js +8 -8
  78. package/dist/cjs/tools/annotation/planarFreehandROITool/editLoopCommon.js.map +1 -1
  79. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +6 -5
  80. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  81. package/dist/cjs/tools/base/ContourBaseTool.d.ts +2 -8
  82. package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
  83. package/dist/cjs/tools/base/ContourSegmentationBaseTool.d.ts +3 -2
  84. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js +13 -1
  85. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  86. package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js +3 -9
  87. package/dist/cjs/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
  88. package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js +3 -9
  89. package/dist/cjs/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
  90. package/dist/cjs/types/AnnotationRenderContext.d.ts +11 -0
  91. package/dist/cjs/types/AnnotationRenderContext.js +3 -0
  92. package/dist/cjs/types/AnnotationRenderContext.js.map +1 -0
  93. package/dist/cjs/types/IToolGroup.d.ts +2 -1
  94. package/dist/cjs/types/index.d.ts +2 -1
  95. package/dist/cjs/utilities/contourSegmentation/areSameSegment.d.ts +2 -0
  96. package/dist/cjs/utilities/contourSegmentation/areSameSegment.js +12 -0
  97. package/dist/cjs/utilities/contourSegmentation/areSameSegment.js.map +1 -0
  98. package/dist/cjs/utilities/contourSegmentation/index.d.ts +2 -0
  99. package/dist/cjs/utilities/contourSegmentation/index.js +11 -0
  100. package/dist/cjs/utilities/contourSegmentation/index.js.map +1 -0
  101. package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts +3 -0
  102. package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.js +8 -0
  103. package/dist/cjs/utilities/contourSegmentation/isContourSegmentationAnnotation.js.map +1 -0
  104. package/dist/cjs/utilities/contours/areCoplanarContours.d.ts +2 -0
  105. package/dist/cjs/utilities/contours/areCoplanarContours.js +19 -0
  106. package/dist/cjs/utilities/contours/areCoplanarContours.js.map +1 -0
  107. package/dist/cjs/utilities/contours/index.d.ts +2 -1
  108. package/dist/cjs/utilities/contours/index.js +3 -1
  109. package/dist/cjs/utilities/contours/index.js.map +1 -1
  110. package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js +3 -22
  111. package/dist/cjs/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
  112. package/dist/cjs/utilities/math/aabb/index.d.ts +1 -0
  113. package/dist/cjs/utilities/math/aabb/index.js +3 -1
  114. package/dist/cjs/utilities/math/aabb/index.js.map +1 -1
  115. package/dist/cjs/utilities/math/aabb/intersectAABB.d.ts +2 -0
  116. package/dist/cjs/utilities/math/aabb/intersectAABB.js +10 -0
  117. package/dist/cjs/utilities/math/aabb/intersectAABB.js.map +1 -0
  118. package/dist/cjs/utilities/math/point/distanceToPointSquared.js +4 -1
  119. package/dist/cjs/utilities/math/point/distanceToPointSquared.js.map +1 -1
  120. package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.d.ts +2 -0
  121. package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.js +59 -0
  122. package/dist/cjs/utilities/math/polyline/areLineSegmentsIntersecting.js.map +1 -0
  123. package/dist/cjs/utilities/math/polyline/combinePolyline.d.ts +4 -0
  124. package/dist/cjs/utilities/math/polyline/combinePolyline.js +213 -0
  125. package/dist/cjs/utilities/math/polyline/combinePolyline.js.map +1 -0
  126. package/dist/cjs/utilities/math/polyline/containsPoint.d.ts +2 -0
  127. package/dist/cjs/utilities/math/polyline/containsPoint.js +36 -0
  128. package/dist/cjs/utilities/math/polyline/containsPoint.js.map +1 -0
  129. package/dist/cjs/utilities/math/polyline/getAABB.d.ts +2 -0
  130. package/dist/cjs/utilities/math/polyline/getAABB.js +18 -0
  131. package/dist/cjs/utilities/math/polyline/getAABB.js.map +1 -0
  132. package/dist/cjs/utilities/math/polyline/getArea.d.ts +2 -0
  133. package/dist/cjs/utilities/math/polyline/{calculateAreaOfPoints.js → getArea.js} +3 -3
  134. package/dist/cjs/utilities/math/polyline/getArea.js.map +1 -0
  135. package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts +5 -0
  136. package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.js +51 -0
  137. package/dist/cjs/utilities/math/polyline/getClosestLineSegmentIntersection.js.map +1 -0
  138. package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts +2 -0
  139. package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js +28 -0
  140. package/dist/cjs/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js.map +1 -0
  141. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts +2 -0
  142. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js +20 -0
  143. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js.map +1 -0
  144. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts +2 -0
  145. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js +22 -0
  146. package/dist/cjs/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js.map +1 -0
  147. package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.d.ts +2 -0
  148. package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.js +21 -0
  149. package/dist/cjs/utilities/math/polyline/getLineSegmentsIntersection.js.map +1 -0
  150. package/dist/cjs/utilities/math/polyline/getNormal2.d.ts +2 -0
  151. package/dist/cjs/utilities/math/polyline/getNormal2.js +12 -0
  152. package/dist/cjs/utilities/math/polyline/getNormal2.js.map +1 -0
  153. package/dist/cjs/utilities/math/polyline/getNormal3.d.ts +2 -0
  154. package/dist/cjs/utilities/math/polyline/getNormal3.js +29 -0
  155. package/dist/cjs/utilities/math/polyline/getNormal3.js.map +1 -0
  156. package/dist/cjs/utilities/math/polyline/getSignedArea.d.ts +2 -0
  157. package/dist/cjs/utilities/math/polyline/getSignedArea.js +20 -0
  158. package/dist/cjs/utilities/math/polyline/getSignedArea.js.map +1 -0
  159. package/dist/cjs/utilities/math/polyline/index.d.ts +14 -3
  160. package/dist/cjs/utilities/math/polyline/index.js +28 -6
  161. package/dist/cjs/utilities/math/polyline/index.js.map +1 -1
  162. package/dist/cjs/utilities/math/polyline/intersectPolyline.d.ts +2 -0
  163. package/dist/cjs/utilities/math/polyline/intersectPolyline.js +20 -0
  164. package/dist/cjs/utilities/math/polyline/intersectPolyline.js.map +1 -0
  165. package/dist/cjs/utilities/math/polyline/isClosed.d.ts +2 -0
  166. package/dist/cjs/utilities/math/polyline/isClosed.js +39 -0
  167. package/dist/cjs/utilities/math/polyline/isClosed.js.map +1 -0
  168. package/dist/esm/eventListeners/annotations/annotationCompletedListener.js +9 -0
  169. package/dist/esm/eventListeners/annotations/annotationCompletedListener.js.map +1 -0
  170. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +153 -0
  171. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -0
  172. package/dist/esm/eventListeners/annotations/contourSegmentation/index.js +2 -0
  173. package/dist/esm/eventListeners/annotations/contourSegmentation/index.js.map +1 -0
  174. package/dist/esm/eventListeners/annotations/index.js +2 -1
  175. package/dist/esm/eventListeners/annotations/index.js.map +1 -1
  176. package/dist/esm/eventListeners/index.js +2 -2
  177. package/dist/esm/eventListeners/index.js.map +1 -1
  178. package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +61 -0
  179. package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js.map +1 -0
  180. package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js +5 -53
  181. package/dist/esm/eventListeners/segmentation/segmentationDataModifiedEventListener.js.map +1 -1
  182. package/dist/esm/init.js +3 -1
  183. package/dist/esm/init.js.map +1 -1
  184. package/dist/esm/stateManagement/annotation/helpers/state.js +19 -1
  185. package/dist/esm/stateManagement/annotation/helpers/state.js.map +1 -1
  186. package/dist/esm/store/ToolGroupManager/ToolGroup.js +3 -0
  187. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  188. package/dist/esm/store/addTool.js +4 -0
  189. package/dist/esm/store/addTool.js.map +1 -1
  190. package/dist/esm/store/index.js +2 -2
  191. package/dist/esm/store/index.js.map +1 -1
  192. package/dist/esm/store/removeEnabledElement.js +1 -2
  193. package/dist/esm/store/removeEnabledElement.js.map +1 -1
  194. package/dist/esm/tools/AdvancedMagnifyTool.js +4 -11
  195. package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
  196. package/dist/esm/tools/annotation/AngleTool.js +6 -19
  197. package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
  198. package/dist/esm/tools/annotation/ArrowAnnotateTool.js +10 -29
  199. package/dist/esm/tools/annotation/ArrowAnnotateTool.js.map +1 -1
  200. package/dist/esm/tools/annotation/BidirectionalTool.js +8 -23
  201. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  202. package/dist/esm/tools/annotation/CircleROITool.js +8 -23
  203. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  204. package/dist/esm/tools/annotation/CobbAngleTool.js +6 -19
  205. package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
  206. package/dist/esm/tools/annotation/EllipticalROITool.js +8 -23
  207. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  208. package/dist/esm/tools/annotation/KeyImageTool.js +6 -13
  209. package/dist/esm/tools/annotation/KeyImageTool.js.map +1 -1
  210. package/dist/esm/tools/annotation/LengthTool.js +6 -19
  211. package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
  212. package/dist/esm/tools/annotation/LivewireContourTool.js +31 -23
  213. package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
  214. package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js +11 -0
  215. package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -1
  216. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +7 -23
  217. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  218. package/dist/esm/tools/annotation/ProbeTool.js +9 -24
  219. package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
  220. package/dist/esm/tools/annotation/RectangleROITool.js +9 -23
  221. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  222. package/dist/esm/tools/annotation/SplineROITool.js +26 -9
  223. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  224. package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js +6 -19
  225. package/dist/esm/tools/annotation/UltrasoundDirectionalTool.js.map +1 -1
  226. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +7 -6
  227. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  228. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +8 -5
  229. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  230. package/dist/esm/tools/annotation/planarFreehandROITool/editLoopCommon.js +8 -8
  231. package/dist/esm/tools/annotation/planarFreehandROITool/editLoopCommon.js.map +1 -1
  232. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +6 -5
  233. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  234. package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
  235. package/dist/esm/tools/base/ContourSegmentationBaseTool.js +13 -1
  236. package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  237. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js +4 -10
  238. package/dist/esm/tools/segmentation/RectangleROIStartEndThresholdTool.js.map +1 -1
  239. package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js +4 -10
  240. package/dist/esm/tools/segmentation/RectangleROIThresholdTool.js.map +1 -1
  241. package/dist/esm/types/AnnotationRenderContext.js +2 -0
  242. package/dist/esm/types/AnnotationRenderContext.js.map +1 -0
  243. package/dist/esm/utilities/contourSegmentation/areSameSegment.js +9 -0
  244. package/dist/esm/utilities/contourSegmentation/areSameSegment.js.map +1 -0
  245. package/dist/esm/utilities/contourSegmentation/index.js +3 -0
  246. package/dist/esm/utilities/contourSegmentation/index.js.map +1 -0
  247. package/dist/esm/utilities/contourSegmentation/isContourSegmentationAnnotation.js +4 -0
  248. package/dist/esm/utilities/contourSegmentation/isContourSegmentationAnnotation.js.map +1 -0
  249. package/dist/esm/utilities/contours/areCoplanarContours.js +16 -0
  250. package/dist/esm/utilities/contours/areCoplanarContours.js.map +1 -0
  251. package/dist/esm/utilities/contours/index.js +2 -1
  252. package/dist/esm/utilities/contours/index.js.map +1 -1
  253. package/dist/esm/utilities/contours/reverseIfAntiClockwise.js +3 -22
  254. package/dist/esm/utilities/contours/reverseIfAntiClockwise.js.map +1 -1
  255. package/dist/esm/utilities/math/aabb/index.js +1 -0
  256. package/dist/esm/utilities/math/aabb/index.js.map +1 -1
  257. package/dist/esm/utilities/math/aabb/intersectAABB.js +7 -0
  258. package/dist/esm/utilities/math/aabb/intersectAABB.js.map +1 -0
  259. package/dist/esm/utilities/math/point/distanceToPointSquared.js +4 -1
  260. package/dist/esm/utilities/math/point/distanceToPointSquared.js.map +1 -1
  261. package/dist/esm/utilities/math/polyline/areLineSegmentsIntersecting.js +56 -0
  262. package/dist/esm/utilities/math/polyline/areLineSegmentsIntersecting.js.map +1 -0
  263. package/dist/esm/utilities/math/polyline/combinePolyline.js +187 -0
  264. package/dist/esm/utilities/math/polyline/combinePolyline.js.map +1 -0
  265. package/dist/esm/utilities/math/polyline/containsPoint.js +30 -0
  266. package/dist/esm/utilities/math/polyline/containsPoint.js.map +1 -0
  267. package/dist/esm/utilities/math/polyline/getAABB.js +15 -0
  268. package/dist/esm/utilities/math/polyline/getAABB.js.map +1 -0
  269. package/dist/esm/utilities/math/polyline/{calculateAreaOfPoints.js → getArea.js} +2 -2
  270. package/dist/esm/utilities/math/polyline/getArea.js.map +1 -0
  271. package/dist/esm/utilities/math/polyline/getClosestLineSegmentIntersection.js +45 -0
  272. package/dist/esm/utilities/math/polyline/getClosestLineSegmentIntersection.js.map +1 -0
  273. package/dist/esm/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js +22 -0
  274. package/dist/esm/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.js.map +1 -0
  275. package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js +14 -0
  276. package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.js.map +1 -0
  277. package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js +16 -0
  278. package/dist/esm/utilities/math/polyline/getLineSegmentIntersectionsIndexes.js.map +1 -0
  279. package/dist/esm/utilities/math/polyline/getLineSegmentsIntersection.js +18 -0
  280. package/dist/esm/utilities/math/polyline/getLineSegmentsIntersection.js.map +1 -0
  281. package/dist/esm/utilities/math/polyline/getNormal2.js +6 -0
  282. package/dist/esm/utilities/math/polyline/getNormal2.js.map +1 -0
  283. package/dist/esm/utilities/math/polyline/getNormal3.js +26 -0
  284. package/dist/esm/utilities/math/polyline/getNormal3.js.map +1 -0
  285. package/dist/esm/utilities/math/polyline/getSignedArea.js +17 -0
  286. package/dist/esm/utilities/math/polyline/getSignedArea.js.map +1 -0
  287. package/dist/esm/utilities/math/polyline/index.js +14 -3
  288. package/dist/esm/utilities/math/polyline/index.js.map +1 -1
  289. package/dist/esm/utilities/math/polyline/intersectPolyline.js +14 -0
  290. package/dist/esm/utilities/math/polyline/intersectPolyline.js.map +1 -0
  291. package/dist/esm/utilities/math/polyline/isClosed.js +13 -0
  292. package/dist/esm/utilities/math/polyline/isClosed.js.map +1 -0
  293. package/dist/types/eventListeners/annotations/annotationCompletedListener.d.ts +3 -0
  294. package/dist/types/eventListeners/annotations/annotationCompletedListener.d.ts.map +1 -0
  295. package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +3 -0
  296. package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts.map +1 -0
  297. package/dist/types/eventListeners/annotations/contourSegmentation/index.d.ts +2 -0
  298. package/dist/types/eventListeners/annotations/contourSegmentation/index.d.ts.map +1 -0
  299. package/dist/types/eventListeners/annotations/index.d.ts +2 -1
  300. package/dist/types/eventListeners/annotations/index.d.ts.map +1 -1
  301. package/dist/types/eventListeners/index.d.ts +2 -2
  302. package/dist/types/eventListeners/index.d.ts.map +1 -1
  303. package/dist/types/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts +4 -0
  304. package/dist/types/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.d.ts.map +1 -0
  305. package/dist/types/eventListeners/segmentation/segmentationDataModifiedEventListener.d.ts.map +1 -1
  306. package/dist/types/init.d.ts.map +1 -1
  307. package/dist/types/stateManagement/annotation/helpers/state.d.ts +3 -1
  308. package/dist/types/stateManagement/annotation/helpers/state.d.ts.map +1 -1
  309. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts +1 -0
  310. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
  311. package/dist/types/store/addTool.d.ts +1 -0
  312. package/dist/types/store/addTool.d.ts.map +1 -1
  313. package/dist/types/store/index.d.ts +2 -2
  314. package/dist/types/store/index.d.ts.map +1 -1
  315. package/dist/types/store/removeEnabledElement.d.ts.map +1 -1
  316. package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
  317. package/dist/types/tools/annotation/AngleTool.d.ts.map +1 -1
  318. package/dist/types/tools/annotation/ArrowAnnotateTool.d.ts.map +1 -1
  319. package/dist/types/tools/annotation/BidirectionalTool.d.ts.map +1 -1
  320. package/dist/types/tools/annotation/CircleROITool.d.ts.map +1 -1
  321. package/dist/types/tools/annotation/CobbAngleTool.d.ts.map +1 -1
  322. package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
  323. package/dist/types/tools/annotation/KeyImageTool.d.ts.map +1 -1
  324. package/dist/types/tools/annotation/LengthTool.d.ts.map +1 -1
  325. package/dist/types/tools/annotation/LivewireContourTool.d.ts +4 -1
  326. package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
  327. package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +2 -1
  328. package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts.map +1 -1
  329. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +2 -10
  330. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  331. package/dist/types/tools/annotation/ProbeTool.d.ts.map +1 -1
  332. package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
  333. package/dist/types/tools/annotation/SplineROITool.d.ts +8 -9
  334. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  335. package/dist/types/tools/annotation/UltrasoundDirectionalTool.d.ts.map +1 -1
  336. package/dist/types/tools/annotation/planarFreehandROITool/closedContourEditLoop.d.ts.map +1 -1
  337. package/dist/types/tools/annotation/planarFreehandROITool/drawLoop.d.ts.map +1 -1
  338. package/dist/types/tools/annotation/planarFreehandROITool/editLoopCommon.d.ts.map +1 -1
  339. package/dist/types/tools/annotation/planarFreehandROITool/openContourEditLoop.d.ts.map +1 -1
  340. package/dist/types/tools/base/ContourBaseTool.d.ts +2 -8
  341. package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -1
  342. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts +3 -2
  343. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
  344. package/dist/types/tools/segmentation/RectangleROIStartEndThresholdTool.d.ts.map +1 -1
  345. package/dist/types/tools/segmentation/RectangleROIThresholdTool.d.ts.map +1 -1
  346. package/dist/types/types/AnnotationRenderContext.d.ts +12 -0
  347. package/dist/types/types/AnnotationRenderContext.d.ts.map +1 -0
  348. package/dist/types/types/IToolGroup.d.ts +2 -1
  349. package/dist/types/types/IToolGroup.d.ts.map +1 -1
  350. package/dist/types/types/index.d.ts +2 -1
  351. package/dist/types/types/index.d.ts.map +1 -1
  352. package/dist/types/utilities/contourSegmentation/areSameSegment.d.ts +3 -0
  353. package/dist/types/utilities/contourSegmentation/areSameSegment.d.ts.map +1 -0
  354. package/dist/types/utilities/contourSegmentation/index.d.ts +3 -0
  355. package/dist/types/utilities/contourSegmentation/index.d.ts.map +1 -0
  356. package/dist/types/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts +4 -0
  357. package/dist/types/utilities/contourSegmentation/isContourSegmentationAnnotation.d.ts.map +1 -0
  358. package/dist/types/utilities/contours/areCoplanarContours.d.ts +3 -0
  359. package/dist/types/utilities/contours/areCoplanarContours.d.ts.map +1 -0
  360. package/dist/types/utilities/contours/index.d.ts +2 -1
  361. package/dist/types/utilities/contours/index.d.ts.map +1 -1
  362. package/dist/types/utilities/contours/reverseIfAntiClockwise.d.ts.map +1 -1
  363. package/dist/types/utilities/math/aabb/index.d.ts +1 -0
  364. package/dist/types/utilities/math/aabb/index.d.ts.map +1 -1
  365. package/dist/types/utilities/math/aabb/intersectAABB.d.ts +3 -0
  366. package/dist/types/utilities/math/aabb/intersectAABB.d.ts.map +1 -0
  367. package/dist/types/utilities/math/point/distanceToPointSquared.d.ts.map +1 -1
  368. package/dist/types/utilities/math/polyline/areLineSegmentsIntersecting.d.ts +3 -0
  369. package/dist/types/utilities/math/polyline/areLineSegmentsIntersecting.d.ts.map +1 -0
  370. package/dist/types/utilities/math/polyline/combinePolyline.d.ts +5 -0
  371. package/dist/types/utilities/math/polyline/combinePolyline.d.ts.map +1 -0
  372. package/dist/types/utilities/math/polyline/containsPoint.d.ts +3 -0
  373. package/dist/types/utilities/math/polyline/containsPoint.d.ts.map +1 -0
  374. package/dist/types/utilities/math/polyline/getAABB.d.ts +3 -0
  375. package/dist/types/utilities/math/polyline/getAABB.d.ts.map +1 -0
  376. package/dist/types/utilities/math/polyline/getArea.d.ts +3 -0
  377. package/dist/types/utilities/math/polyline/getArea.d.ts.map +1 -0
  378. package/dist/types/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts +6 -0
  379. package/dist/types/utilities/math/polyline/getClosestLineSegmentIntersection.d.ts.map +1 -0
  380. package/dist/types/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts +3 -0
  381. package/dist/types/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.d.ts.map +1 -0
  382. package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts +3 -0
  383. package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.d.ts.map +1 -0
  384. package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts +3 -0
  385. package/dist/types/utilities/math/polyline/getLineSegmentIntersectionsIndexes.d.ts.map +1 -0
  386. package/dist/types/utilities/math/polyline/getLineSegmentsIntersection.d.ts +3 -0
  387. package/dist/types/utilities/math/polyline/getLineSegmentsIntersection.d.ts.map +1 -0
  388. package/dist/types/utilities/math/polyline/getNormal2.d.ts +3 -0
  389. package/dist/types/utilities/math/polyline/getNormal2.d.ts.map +1 -0
  390. package/dist/types/utilities/math/polyline/getNormal3.d.ts +3 -0
  391. package/dist/types/utilities/math/polyline/getNormal3.d.ts.map +1 -0
  392. package/dist/types/utilities/math/polyline/getSignedArea.d.ts +3 -0
  393. package/dist/types/utilities/math/polyline/getSignedArea.d.ts.map +1 -0
  394. package/dist/types/utilities/math/polyline/index.d.ts +14 -3
  395. package/dist/types/utilities/math/polyline/index.d.ts.map +1 -1
  396. package/dist/types/utilities/math/polyline/intersectPolyline.d.ts +3 -0
  397. package/dist/types/utilities/math/polyline/intersectPolyline.d.ts.map +1 -0
  398. package/dist/types/utilities/math/polyline/isClosed.d.ts +3 -0
  399. package/dist/types/utilities/math/polyline/isClosed.d.ts.map +1 -0
  400. package/dist/umd/index.js +1 -2
  401. package/dist/umd/index.js.map +1 -1
  402. package/package.json +3 -3
  403. package/src/eventListeners/annotations/annotationCompletedListener.ts +13 -0
  404. package/src/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.ts +273 -0
  405. package/src/eventListeners/annotations/contourSegmentation/index.ts +1 -0
  406. package/src/eventListeners/annotations/index.ts +6 -1
  407. package/src/eventListeners/index.ts +2 -0
  408. package/src/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.ts +117 -0
  409. package/src/eventListeners/segmentation/segmentationDataModifiedEventListener.ts +5 -99
  410. package/src/init.ts +12 -1
  411. package/src/stateManagement/annotation/helpers/state.ts +42 -2
  412. package/src/store/ToolGroupManager/ToolGroup.ts +10 -0
  413. package/src/store/addTool.ts +11 -0
  414. package/src/store/index.ts +2 -1
  415. package/src/store/removeEnabledElement.ts +2 -1
  416. package/src/tools/AdvancedMagnifyTool.ts +4 -21
  417. package/src/tools/annotation/AngleTool.ts +8 -32
  418. package/src/tools/annotation/ArrowAnnotateTool.ts +12 -45
  419. package/src/tools/annotation/BidirectionalTool.ts +11 -39
  420. package/src/tools/annotation/CircleROITool.ts +10 -34
  421. package/src/tools/annotation/CobbAngleTool.ts +9 -32
  422. package/src/tools/annotation/EllipticalROITool.ts +10 -34
  423. package/src/tools/annotation/KeyImageTool.ts +9 -23
  424. package/src/tools/annotation/LengthTool.ts +9 -33
  425. package/src/tools/annotation/LivewireContourTool.ts +58 -33
  426. package/src/tools/annotation/PlanarFreehandContourSegmentationTool.ts +22 -1
  427. package/src/tools/annotation/PlanarFreehandROITool.ts +10 -53
  428. package/src/tools/annotation/ProbeTool.ts +11 -36
  429. package/src/tools/annotation/RectangleROITool.ts +11 -33
  430. package/src/tools/annotation/SplineROITool.ts +53 -24
  431. package/src/tools/annotation/UltrasoundDirectionalTool.ts +8 -29
  432. package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +9 -11
  433. package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +8 -5
  434. package/src/tools/annotation/planarFreehandROITool/editLoopCommon.ts +9 -8
  435. package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +7 -6
  436. package/src/tools/base/ContourBaseTool.ts +5 -8
  437. package/src/tools/base/ContourSegmentationBaseTool.ts +29 -6
  438. package/src/tools/segmentation/RectangleROIStartEndThresholdTool.ts +3 -13
  439. package/src/tools/segmentation/RectangleROIThresholdTool.ts +3 -14
  440. package/src/types/AnnotationRenderContext.ts +13 -0
  441. package/src/types/IToolGroup.ts +3 -1
  442. package/src/types/index.ts +3 -0
  443. package/src/utilities/contourSegmentation/areSameSegment.ts +24 -0
  444. package/src/utilities/contourSegmentation/index.ts +2 -0
  445. package/src/utilities/contourSegmentation/isContourSegmentationAnnotation.ts +8 -0
  446. package/src/utilities/contours/areCoplanarContours.ts +39 -0
  447. package/src/utilities/contours/index.ts +2 -0
  448. package/src/utilities/contours/reverseIfAntiClockwise.ts +6 -25
  449. package/src/utilities/math/aabb/index.ts +1 -0
  450. package/src/utilities/math/aabb/intersectAABB.ts +19 -0
  451. package/src/utilities/math/point/distanceToPointSquared.ts +6 -1
  452. package/src/utilities/math/polyline/areLineSegmentsIntersecting.ts +118 -0
  453. package/src/utilities/math/polyline/combinePolyline.ts +350 -0
  454. package/src/utilities/math/polyline/containsPoint.ts +63 -0
  455. package/src/utilities/math/polyline/getAABB.ts +20 -0
  456. package/src/utilities/math/polyline/{calculateAreaOfPoints.ts → getArea.ts} +1 -1
  457. package/src/utilities/math/polyline/getClosestLineSegmentIntersection.ts +72 -0
  458. package/src/utilities/math/polyline/getFirstLineSegmentIntersectionIndexes.ts +42 -0
  459. package/src/utilities/math/polyline/getLineSegmentIntersectionsCoordinates.ts +30 -0
  460. package/src/utilities/math/polyline/getLineSegmentIntersectionsIndexes.ts +35 -0
  461. package/src/utilities/math/polyline/getLineSegmentsIntersection.ts +47 -0
  462. package/src/utilities/math/polyline/getNormal2.ts +17 -0
  463. package/src/utilities/math/polyline/getNormal3.ts +53 -0
  464. package/src/utilities/math/polyline/getSignedArea.ts +47 -0
  465. package/src/utilities/math/polyline/index.ts +27 -8
  466. package/src/utilities/math/polyline/intersectPolyline.ts +34 -0
  467. package/src/utilities/math/polyline/isClosed.ts +26 -0
  468. package/dist/cjs/utilities/math/polyline/calculateAreaOfPoints.d.ts +0 -2
  469. package/dist/cjs/utilities/math/polyline/calculateAreaOfPoints.js.map +0 -1
  470. package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.d.ts +0 -9
  471. package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js +0 -160
  472. package/dist/cjs/utilities/math/polyline/getIntersectionWithPolyline.js.map +0 -1
  473. package/dist/cjs/utilities/math/polyline/pointInPolyline.d.ts +0 -2
  474. package/dist/cjs/utilities/math/polyline/pointInPolyline.js +0 -15
  475. package/dist/cjs/utilities/math/polyline/pointInPolyline.js.map +0 -1
  476. package/dist/esm/utilities/math/polyline/calculateAreaOfPoints.js.map +0 -1
  477. package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js +0 -154
  478. package/dist/esm/utilities/math/polyline/getIntersectionWithPolyline.js.map +0 -1
  479. package/dist/esm/utilities/math/polyline/pointInPolyline.js +0 -12
  480. package/dist/esm/utilities/math/polyline/pointInPolyline.js.map +0 -1
  481. package/dist/types/utilities/math/polyline/calculateAreaOfPoints.d.ts +0 -3
  482. package/dist/types/utilities/math/polyline/calculateAreaOfPoints.d.ts.map +0 -1
  483. package/dist/types/utilities/math/polyline/getIntersectionWithPolyline.d.ts +0 -10
  484. package/dist/types/utilities/math/polyline/getIntersectionWithPolyline.d.ts.map +0 -1
  485. package/dist/types/utilities/math/polyline/pointInPolyline.d.ts +0 -3
  486. package/dist/types/utilities/math/polyline/pointInPolyline.d.ts.map +0 -1
  487. package/dist/umd/index.js.LICENSE.txt +0 -6
  488. package/src/utilities/math/polyline/getIntersectionWithPolyline.ts +0 -275
  489. package/src/utilities/math/polyline/pointInPolyline.ts +0 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.50.2",
3
+ "version": "1.51.0",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.50.2",
32
+ "@cornerstonejs/core": "^1.51.0",
33
33
  "comlink": "^4.4.1",
34
34
  "lodash.clonedeep": "4.5.0",
35
35
  "lodash.get": "^4.4.2"
@@ -53,5 +53,5 @@
53
53
  "type": "individual",
54
54
  "url": "https://ohif.org/donate"
55
55
  },
56
- "gitHead": "88d59969255f209d95ecdb72e6576f19ecfe97b3"
56
+ "gitHead": "a4ca4dde651d17e658a4aec5a4e3ec1b274dc580"
57
57
  }
@@ -0,0 +1,13 @@
1
+ import { AnnotationCompletedEventType } from '../../types/EventTypes';
2
+ import * as contourSegUtils from '../../utilities/contourSegmentation';
3
+ import { contourSegmentationCompleted } from './contourSegmentation';
4
+
5
+ export default function annotationCompletedListener(
6
+ evt: AnnotationCompletedEventType
7
+ ) {
8
+ const annotation = evt.detail.annotation;
9
+
10
+ if (contourSegUtils.isContourSegmentationAnnotation(annotation)) {
11
+ contourSegmentationCompleted(evt);
12
+ }
13
+ }
@@ -0,0 +1,273 @@
1
+ import {
2
+ getEnabledElement,
3
+ utilities as csUtils,
4
+ Types,
5
+ } from '@cornerstonejs/core';
6
+ import { ContourSegmentationAnnotation } from '../../../types/ContourSegmentationAnnotation';
7
+ import {
8
+ getViewportForAnnotation,
9
+ math,
10
+ triggerAnnotationRenderForViewportIds,
11
+ } from '../../../utilities';
12
+ import { getViewportIdsWithToolToRender } from '../../../utilities/viewportFilters';
13
+ import {
14
+ getAnnotations,
15
+ addAnnotation,
16
+ removeAnnotation,
17
+ } from '../../../stateManagement/annotation/annotationState';
18
+ import { AnnotationCompletedEventType } from '../../../types/EventTypes';
19
+ import * as contourUtils from '../../../utilities/contours';
20
+ import * as contourSegUtils from '../../../utilities/contourSegmentation';
21
+ import { ToolGroupManager, hasTool as cstHasTool } from '../../../store';
22
+ import { PlanarFreehandContourSegmentationTool } from '../../../tools';
23
+
24
+ const DEFAULT_CONTOUR_SEG_TOOLNAME = 'PlanarFreehandContourSegmentationTool';
25
+
26
+ export default function contourSegmentationCompletedListener(
27
+ evt: AnnotationCompletedEventType
28
+ ) {
29
+ const sourceAnnotation = evt.detail
30
+ .annotation as ContourSegmentationAnnotation;
31
+
32
+ if (!contourSegUtils.isContourSegmentationAnnotation(sourceAnnotation)) {
33
+ return;
34
+ }
35
+
36
+ const viewport = getViewportForAnnotation(sourceAnnotation);
37
+ const contourSegmentationAnnotations =
38
+ getValidContourSegmentationAnnotations(sourceAnnotation);
39
+
40
+ if (!contourSegmentationAnnotations.length) {
41
+ return;
42
+ }
43
+
44
+ const sourcePolyline = convertContourPolylineToCanvasSpace(
45
+ sourceAnnotation.data.contour.polyline,
46
+ viewport
47
+ );
48
+
49
+ const targetAnnotationInfo = findIntersectingContour(
50
+ viewport,
51
+ sourcePolyline,
52
+ contourSegmentationAnnotations
53
+ );
54
+
55
+ if (!targetAnnotationInfo) {
56
+ return;
57
+ }
58
+
59
+ if (!isFreehandContourSegToolRegistered(viewport)) {
60
+ return;
61
+ }
62
+
63
+ const { targetAnnotation, targetPolyline } = targetAnnotationInfo;
64
+
65
+ processContours(
66
+ viewport,
67
+ sourceAnnotation,
68
+ sourcePolyline,
69
+ targetAnnotation,
70
+ targetPolyline
71
+ );
72
+ }
73
+
74
+ function isFreehandContourSegToolRegistered(viewport: Types.IViewport) {
75
+ const { toolName } = PlanarFreehandContourSegmentationTool;
76
+
77
+ if (!cstHasTool(PlanarFreehandContourSegmentationTool)) {
78
+ console.warn(`${toolName} is not registered in cornerstone`);
79
+ return false;
80
+ }
81
+
82
+ const toolGroup = ToolGroupManager.getToolGroupForViewport(
83
+ viewport.id,
84
+ viewport.renderingEngineId
85
+ );
86
+
87
+ if (!toolGroup.hasTool(toolName)) {
88
+ console.warn(`Tool ${toolName} not added to ${toolGroup.id} toolGroup`);
89
+ return false;
90
+ }
91
+
92
+ if (!toolGroup.getToolOptions(toolName)) {
93
+ console.warn(`Tool ${toolName} must be in active/passive state`);
94
+ return false;
95
+ }
96
+
97
+ return true;
98
+ }
99
+
100
+ function convertContourPolylineToCanvasSpace(
101
+ polyline: Types.Point3[],
102
+ viewport: Types.IViewport
103
+ ): Types.Point2[] {
104
+ const numPoints = polyline.length;
105
+ const projectedPolyline = new Array(numPoints);
106
+
107
+ for (let i = 0; i < numPoints; i++) {
108
+ projectedPolyline[i] = viewport.worldToCanvas(polyline[i]);
109
+ }
110
+
111
+ return projectedPolyline;
112
+ }
113
+
114
+ function convertPolylineToWorldSpace(
115
+ polyline: Types.Point2[],
116
+ viewport: Types.IViewport
117
+ ): Types.Point3[] {
118
+ const numPoints = polyline.length;
119
+ const projectedPolyline = new Array(numPoints);
120
+
121
+ for (let i = 0; i < numPoints; i++) {
122
+ projectedPolyline[i] = viewport.canvasToWorld(polyline[i]);
123
+ }
124
+
125
+ return projectedPolyline;
126
+ }
127
+
128
+ function getValidContourSegmentationAnnotations(
129
+ sourceAnnotation: ContourSegmentationAnnotation
130
+ ): ContourSegmentationAnnotation[] {
131
+ const { annotationUID: sourceAnnotationUID } = sourceAnnotation;
132
+ const { FrameOfReferenceUID } = sourceAnnotation.metadata;
133
+
134
+ // Get all annotations and filter all contour segmentations locally
135
+ const toolName = undefined;
136
+ const annotationsGroups = getAnnotations(toolName, FrameOfReferenceUID);
137
+ const toolNames = Object.keys(annotationsGroups);
138
+
139
+ return toolNames.reduce((validAnnotations, toolName) => {
140
+ const toolAnnotations = annotationsGroups[toolName].filter(
141
+ (targetAnnotation) =>
142
+ targetAnnotation.annotationUID &&
143
+ targetAnnotation.annotationUID !== sourceAnnotationUID &&
144
+ contourSegUtils.isContourSegmentationAnnotation(targetAnnotation) &&
145
+ contourSegUtils.areSameSegment(targetAnnotation, sourceAnnotation) &&
146
+ contourUtils.areCoplanarContours(targetAnnotation, sourceAnnotation)
147
+ );
148
+
149
+ return validAnnotations.concat(toolAnnotations);
150
+ }, []);
151
+ }
152
+
153
+ function findIntersectingContour(
154
+ viewport: Types.IViewport,
155
+ sourcePolyline: Types.Point2[],
156
+ contourSegmentationAnnotations: ContourSegmentationAnnotation[]
157
+ ): {
158
+ targetAnnotation: ContourSegmentationAnnotation;
159
+ targetPolyline: Types.Point2[];
160
+ } {
161
+ const sourceAABB = math.polyline.getAABB(sourcePolyline);
162
+
163
+ for (let i = 0; i < contourSegmentationAnnotations.length; i++) {
164
+ const targetAnnotation = contourSegmentationAnnotations[i];
165
+ const targetPolyline = convertContourPolylineToCanvasSpace(
166
+ targetAnnotation.data.contour.polyline,
167
+ viewport
168
+ );
169
+
170
+ const targetAABB = math.polyline.getAABB(targetPolyline);
171
+ const polylinesIntersect =
172
+ math.aabb.intersectAABB(sourceAABB, targetAABB) &&
173
+ math.polyline.intersectPolyline(sourcePolyline, targetPolyline);
174
+
175
+ if (polylinesIntersect) {
176
+ return { targetAnnotation, targetPolyline };
177
+ }
178
+ }
179
+ }
180
+
181
+ function processContours(
182
+ viewport: Types.IViewport,
183
+ sourceAnnotation: ContourSegmentationAnnotation,
184
+ sourcePolyline: Types.Point2[],
185
+ targetAnnotation: ContourSegmentationAnnotation,
186
+ targetPolyline: Types.Point2[]
187
+ ) {
188
+ const sourceStartPoint = sourcePolyline[0];
189
+ const mergePolylines = math.polyline.containsPoint(
190
+ targetPolyline,
191
+ sourceStartPoint
192
+ );
193
+
194
+ const newPolylines = [];
195
+
196
+ if (mergePolylines) {
197
+ const mergedPolyline = math.polyline.mergePolylines(
198
+ targetPolyline,
199
+ sourcePolyline
200
+ );
201
+
202
+ newPolylines.push(mergedPolyline);
203
+ } else {
204
+ const subtractedPolylines = math.polyline.subtractPolylines(
205
+ targetPolyline,
206
+ sourcePolyline
207
+ );
208
+
209
+ subtractedPolylines.forEach((newPolyline) =>
210
+ newPolylines.push(newPolyline)
211
+ );
212
+ }
213
+
214
+ removeAnnotation(sourceAnnotation.annotationUID);
215
+ removeAnnotation(targetAnnotation.annotationUID);
216
+
217
+ const { element } = viewport;
218
+ const enabledElement = getEnabledElement(element);
219
+ const { renderingEngine } = enabledElement;
220
+ const { metadata, data } = targetAnnotation;
221
+ const { handles, segmentation } = data;
222
+ const { textBox } = handles;
223
+
224
+ for (let i = 0; i < newPolylines.length; i++) {
225
+ const polyline = convertPolylineToWorldSpace(newPolylines[i], viewport);
226
+ const startPoint = polyline[0];
227
+ const endPoint = polyline[polyline.length - 1];
228
+ const newAnnotation = {
229
+ metadata: {
230
+ ...metadata,
231
+ toolName: DEFAULT_CONTOUR_SEG_TOOLNAME,
232
+ },
233
+ data: {
234
+ cachedStats: {},
235
+ handles: {
236
+ points: [startPoint, endPoint],
237
+ textBox: textBox ? { ...textBox } : undefined,
238
+ },
239
+ contour: {
240
+ polyline,
241
+ closed: true,
242
+ },
243
+ segmentation: {
244
+ ...segmentation,
245
+ },
246
+ },
247
+ annotationUID: csUtils.uuidv4() as string,
248
+ highlighted: true,
249
+ invalidated: true,
250
+ isLocked: false,
251
+ isVisible: undefined,
252
+ };
253
+
254
+ addAnnotation(newAnnotation, element);
255
+
256
+ // Updating a Spline contours, for example, should also update freehand contours
257
+ const updatedTtoolNames = new Set([
258
+ DEFAULT_CONTOUR_SEG_TOOLNAME,
259
+ targetAnnotation.metadata.toolName,
260
+ ]);
261
+
262
+ for (const toolName of updatedTtoolNames.values()) {
263
+ const viewportIdsToRender = getViewportIdsWithToolToRender(
264
+ element,
265
+ toolName
266
+ );
267
+ triggerAnnotationRenderForViewportIds(
268
+ renderingEngine,
269
+ viewportIdsToRender
270
+ );
271
+ }
272
+ }
273
+ }
@@ -0,0 +1 @@
1
+ export { default as contourSegmentationCompleted } from './contourSegmentationCompleted';
@@ -1,4 +1,9 @@
1
+ import annotationCompletedListener from './annotationCompletedListener';
1
2
  import annotationSelectionListener from './annotationSelectionListener';
2
3
  import annotationModifiedListener from './annotationModifiedListener';
3
4
 
4
- export { annotationSelectionListener, annotationModifiedListener };
5
+ export {
6
+ annotationCompletedListener,
7
+ annotationSelectionListener,
8
+ annotationModifiedListener,
9
+ };
@@ -10,6 +10,7 @@ import {
10
10
  imageChangeEventListener,
11
11
  } from './segmentation';
12
12
  import {
13
+ annotationCompletedListener,
13
14
  annotationSelectionListener,
14
15
  annotationModifiedListener,
15
16
  } from './annotations';
@@ -25,6 +26,7 @@ export {
25
26
  segmentationRepresentationRemovedEventListener,
26
27
  segmentationDataModifiedEventListener,
27
28
  imageChangeEventListener,
29
+ annotationCompletedListener,
28
30
  annotationSelectionListener,
29
31
  annotationModifiedListener,
30
32
  };
@@ -0,0 +1,117 @@
1
+ import {
2
+ cache,
3
+ getEnabledElementByIds,
4
+ utilities as csUtils,
5
+ } from '@cornerstonejs/core';
6
+
7
+ import SegmentationRepresentations from '../../../enums/SegmentationRepresentations';
8
+ import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
9
+ import { SegmentationDataModifiedEventType } from '../../../types/EventTypes';
10
+ import {
11
+ LabelmapSegmentationDataStack,
12
+ LabelmapSegmentationDataVolume,
13
+ } from '../../../types/LabelmapTypes';
14
+ import { isVolumeSegmentation } from '../../../tools/segmentation/strategies/utils/stackVolumeCheck';
15
+ import { getToolGroup } from '../../../store/ToolGroupManager';
16
+
17
+ /** A callback function that is called when the segmentation data is modified which
18
+ * often is as a result of tool interactions e.g., scissors, eraser, etc.
19
+ */
20
+ const onLabelmapSegmentationDataModified = function (
21
+ evt: SegmentationDataModifiedEventType
22
+ ): void {
23
+ const { segmentationId, modifiedSlicesToUse } = evt.detail;
24
+
25
+ const { representationData, type } =
26
+ SegmentationState.getSegmentation(segmentationId);
27
+
28
+ const toolGroupIds =
29
+ SegmentationState.getToolGroupIdsWithSegmentation(segmentationId);
30
+
31
+ if (type !== SegmentationRepresentations.Labelmap) {
32
+ throw new Error(
33
+ `onLabelmapSegmentationDataModifiedListener: representationType ${type} not supported yet`
34
+ );
35
+ }
36
+
37
+ if (isVolumeSegmentation(representationData[type])) {
38
+ // get the volume from cache, we need the openGLTexture to be updated to GPU
39
+ const segmentationVolume = cache.getVolume(
40
+ (representationData[type] as LabelmapSegmentationDataVolume).volumeId
41
+ );
42
+
43
+ if (!segmentationVolume) {
44
+ console.warn('segmentation not found in cache');
45
+ return;
46
+ }
47
+
48
+ const { imageData, vtkOpenGLTexture } = segmentationVolume;
49
+
50
+ // Update the texture for the volume in the GPU
51
+ let slicesToUpdate;
52
+ if (modifiedSlicesToUse && Array.isArray(modifiedSlicesToUse)) {
53
+ slicesToUpdate = modifiedSlicesToUse;
54
+ } else {
55
+ const numSlices = imageData.getDimensions()[2];
56
+ slicesToUpdate = [...Array(numSlices).keys()];
57
+ }
58
+
59
+ slicesToUpdate.forEach((i) => {
60
+ vtkOpenGLTexture.setUpdatedFrame(i);
61
+ });
62
+
63
+ // Trigger modified on the imageData to update the image
64
+ imageData.modified();
65
+ } else {
66
+ toolGroupIds.forEach((toolGroupId) => {
67
+ const toolGroupSegmentationRepresentations =
68
+ SegmentationState.getSegmentationRepresentations(toolGroupId);
69
+
70
+ const toolGroup = getToolGroup(toolGroupId);
71
+ const viewportsInfo = toolGroup.getViewportsInfo();
72
+
73
+ toolGroupSegmentationRepresentations.forEach((representation) => {
74
+ if (representation.segmentationId !== segmentationId) {
75
+ return;
76
+ }
77
+
78
+ viewportsInfo.forEach(({ viewportId, renderingEngineId }) => {
79
+ const viewport = getEnabledElementByIds(
80
+ viewportId,
81
+ renderingEngineId
82
+ ).viewport;
83
+
84
+ const actorEntry = viewport.getActor(
85
+ representation.segmentationRepresentationUID
86
+ );
87
+
88
+ if (!actorEntry) {
89
+ return;
90
+ }
91
+
92
+ const currentImageId = viewport.getCurrentImageId();
93
+
94
+ const segImageData = actorEntry.actor.getMapper().getInputData();
95
+
96
+ const { imageIdReferenceMap } = representationData[
97
+ type
98
+ ] as LabelmapSegmentationDataStack;
99
+
100
+ const currentSegmentationImageId =
101
+ imageIdReferenceMap.get(currentImageId);
102
+
103
+ const segmentationImage = cache.getImage(currentSegmentationImageId);
104
+ segImageData.modified();
105
+
106
+ // update the cache with the new image data
107
+ csUtils.updateVTKImageDataWithCornerstoneImage(
108
+ segImageData,
109
+ segmentationImage
110
+ );
111
+ });
112
+ });
113
+ });
114
+ }
115
+ };
116
+
117
+ export default onLabelmapSegmentationDataModified;
@@ -1,19 +1,8 @@
1
- import {
2
- cache,
3
- getEnabledElementByIds,
4
- utilities as csUtils,
5
- } from '@cornerstonejs/core';
6
-
7
1
  import triggerSegmentationRender from '../../utilities/segmentation/triggerSegmentationRender';
8
2
  import SegmentationRepresentations from '../../enums/SegmentationRepresentations';
9
3
  import * as SegmentationState from '../../stateManagement/segmentation/segmentationState';
10
4
  import { SegmentationDataModifiedEventType } from '../../types/EventTypes';
11
- import {
12
- LabelmapSegmentationDataStack,
13
- LabelmapSegmentationDataVolume,
14
- } from '../../types/LabelmapTypes';
15
- import { isVolumeSegmentation } from '../../tools/segmentation/strategies/utils/stackVolumeCheck';
16
- import { getToolGroup } from '../../store/ToolGroupManager';
5
+ import onLabelmapSegmentationDataModified from './labelmap/onLabelmapSegmentationDataModified';
17
6
 
18
7
  /** A callback function that is called when the segmentation data is modified which
19
8
  * often is as a result of tool interactions e.g., scissors, eraser, etc.
@@ -21,97 +10,14 @@ import { getToolGroup } from '../../store/ToolGroupManager';
21
10
  const onSegmentationDataModified = function (
22
11
  evt: SegmentationDataModifiedEventType
23
12
  ): void {
24
- const { segmentationId, modifiedSlicesToUse } = evt.detail;
25
-
26
- const { representationData, type } =
27
- SegmentationState.getSegmentation(segmentationId);
13
+ const { segmentationId } = evt.detail;
14
+ const { type } = SegmentationState.getSegmentation(segmentationId);
28
15
 
29
16
  const toolGroupIds =
30
17
  SegmentationState.getToolGroupIdsWithSegmentation(segmentationId);
31
18
 
32
- if (type !== SegmentationRepresentations.Labelmap) {
33
- throw new Error(
34
- `onSegmentationDataModified: representationType ${type} not supported yet`
35
- );
36
- }
37
-
38
- if (isVolumeSegmentation(representationData[type])) {
39
- // get the volume from cache, we need the openGLTexture to be updated to GPU
40
- const segmentationVolume = cache.getVolume(
41
- (representationData[type] as LabelmapSegmentationDataVolume).volumeId
42
- );
43
-
44
- if (!segmentationVolume) {
45
- console.warn('segmentation not found in cache');
46
- return;
47
- }
48
-
49
- const { imageData, vtkOpenGLTexture } = segmentationVolume;
50
-
51
- // Update the texture for the volume in the GPU
52
- let slicesToUpdate;
53
- if (modifiedSlicesToUse && Array.isArray(modifiedSlicesToUse)) {
54
- slicesToUpdate = modifiedSlicesToUse;
55
- } else {
56
- const numSlices = imageData.getDimensions()[2];
57
- slicesToUpdate = [...Array(numSlices).keys()];
58
- }
59
-
60
- slicesToUpdate.forEach((i) => {
61
- vtkOpenGLTexture.setUpdatedFrame(i);
62
- });
63
-
64
- // Trigger modified on the imageData to update the image
65
- imageData.modified();
66
- } else {
67
- toolGroupIds.forEach((toolGroupId) => {
68
- const toolGroupSegmentationRepresentations =
69
- SegmentationState.getSegmentationRepresentations(toolGroupId);
70
-
71
- const toolGroup = getToolGroup(toolGroupId);
72
- const viewportsInfo = toolGroup.getViewportsInfo();
73
-
74
- toolGroupSegmentationRepresentations.forEach((representation) => {
75
- if (representation.segmentationId !== segmentationId) {
76
- return;
77
- }
78
-
79
- viewportsInfo.forEach(({ viewportId, renderingEngineId }) => {
80
- const viewport = getEnabledElementByIds(
81
- viewportId,
82
- renderingEngineId
83
- ).viewport;
84
-
85
- const actorEntry = viewport.getActor(
86
- representation.segmentationRepresentationUID
87
- );
88
-
89
- if (!actorEntry) {
90
- return;
91
- }
92
-
93
- const currentImageId = viewport.getCurrentImageId();
94
-
95
- const segImageData = actorEntry.actor.getMapper().getInputData();
96
-
97
- const { imageIdReferenceMap } = representationData[
98
- type
99
- ] as LabelmapSegmentationDataStack;
100
-
101
- const currentSegmentationImageId =
102
- imageIdReferenceMap.get(currentImageId);
103
-
104
- const segmentationImage = cache.getImage(currentSegmentationImageId);
105
- segImageData.modified();
106
-
107
- // update the cache with the new image data
108
- csUtils.updateVTKImageDataWithCornerstoneImage(
109
- segImageData,
110
- segmentationImage
111
- );
112
- });
113
- });
114
- });
19
+ if (type === SegmentationRepresentations.Labelmap) {
20
+ onLabelmapSegmentationDataModified(evt);
115
21
  }
116
22
 
117
23
  toolGroupIds.forEach((toolGroupId) => {
package/src/init.ts CHANGED
@@ -5,12 +5,13 @@ import { Events as TOOLS_EVENTS } from './enums';
5
5
  import { addEnabledElement, removeEnabledElement } from './store';
6
6
  import { resetCornerstoneToolsState } from './store/state';
7
7
  import {
8
+ annotationCompletedListener,
8
9
  annotationSelectionListener,
10
+ annotationModifiedListener,
9
11
  segmentationDataModifiedEventListener,
10
12
  segmentationRepresentationModifiedEventListener,
11
13
  segmentationRepresentationRemovedEventListener,
12
14
  segmentationModifiedListener,
13
- annotationModifiedListener,
14
15
  } from './eventListeners';
15
16
  import { annotationInterpolationEventDispatcher } from './eventDispatchers';
16
17
 
@@ -103,6 +104,11 @@ function _addCornerstoneToolsEventListeners() {
103
104
  /**
104
105
  * Annotation
105
106
  */
107
+ eventTarget.addEventListener(
108
+ TOOLS_EVENTS.ANNOTATION_COMPLETED,
109
+ annotationCompletedListener
110
+ );
111
+
106
112
  eventTarget.addEventListener(
107
113
  TOOLS_EVENTS.ANNOTATION_MODIFIED,
108
114
  annotationModifiedListener
@@ -148,6 +154,11 @@ function _removeCornerstoneToolsEventListeners() {
148
154
  /**
149
155
  * Annotation
150
156
  */
157
+ eventTarget.removeEventListener(
158
+ TOOLS_EVENTS.ANNOTATION_COMPLETED,
159
+ annotationCompletedListener
160
+ );
161
+
151
162
  eventTarget.removeEventListener(
152
163
  TOOLS_EVENTS.ANNOTATION_MODIFIED,
153
164
  annotationModifiedListener
@@ -7,7 +7,11 @@ import {
7
7
  import { Events } from '../../../enums';
8
8
  import { Annotation } from '../../../types/AnnotationTypes';
9
9
  import { getToolGroupsWithToolName } from '../../../store/ToolGroupManager';
10
- import { AnnotationAddedEventDetail } from '../../../types/EventTypes';
10
+ import {
11
+ AnnotationAddedEventDetail,
12
+ AnnotationModifiedEventDetail,
13
+ AnnotationCompletedEventDetail,
14
+ } from '../../../types/EventTypes';
11
15
 
12
16
  /**
13
17
  * It triggers an event for the element when an annotation is added
@@ -76,4 +80,40 @@ function triggerAnnotationAddedForFOR(annotation: Annotation) {
76
80
  });
77
81
  }
78
82
 
79
- export { triggerAnnotationAddedForElement, triggerAnnotationAddedForFOR };
83
+ /**
84
+ * Triggers an annotation modified event.
85
+ */
86
+ function triggerAnnotationModified(
87
+ annotation: Annotation,
88
+ element: HTMLDivElement
89
+ ): void {
90
+ const enabledElement = getEnabledElement(element);
91
+ const { viewportId, renderingEngineId } = enabledElement;
92
+ const eventType = Events.ANNOTATION_MODIFIED;
93
+ const eventDetail: AnnotationModifiedEventDetail = {
94
+ annotation,
95
+ viewportId,
96
+ renderingEngineId,
97
+ };
98
+
99
+ triggerEvent(eventTarget, eventType, eventDetail);
100
+ }
101
+
102
+ /**
103
+ * Triggers an annotation completed event.
104
+ */
105
+ function triggerAnnotationCompleted(annotation: Annotation): void {
106
+ const eventType = Events.ANNOTATION_COMPLETED;
107
+ const eventDetail: AnnotationCompletedEventDetail = {
108
+ annotation,
109
+ };
110
+
111
+ triggerEvent(eventTarget, eventType, eventDetail);
112
+ }
113
+
114
+ export {
115
+ triggerAnnotationAddedForElement,
116
+ triggerAnnotationAddedForFOR,
117
+ triggerAnnotationModified,
118
+ triggerAnnotationCompleted,
119
+ };
@@ -87,6 +87,16 @@ export default class ToolGroup implements IToolGroup {
87
87
 
88
88
  return toolInstance;
89
89
  }
90
+
91
+ /**
92
+ * Check if a tool is already added to the tool group
93
+ * @param toolName - Tool name
94
+ * @returns True if the tool is already added or false otherwise
95
+ */
96
+ hasTool(toolName: string): boolean {
97
+ return !!this._toolInstances[toolName];
98
+ }
99
+
90
100
  /**
91
101
  * Add a tool to the tool group with the given tool name and tool configuration.
92
102
  * Note that adding a tool to a tool group will not automatically set the tool