@cornerstonejs/tools 1.50.3 → 1.51.1

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
@@ -0,0 +1,350 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import * as mathPoint from '../point';
3
+ import getLineSegmentIntersectionsIndexes from './getLineSegmentIntersectionsIndexes';
4
+ import containsPoint from './containsPoint';
5
+ import getNormal2 from './getNormal2';
6
+ import { glMatrix, vec3 } from 'gl-matrix';
7
+ import getLineSegmentsIntersection from './getLineSegmentsIntersection';
8
+
9
+ enum PolylinePointType {
10
+ Vertex,
11
+ Intersection,
12
+ }
13
+
14
+ // Position of the point related to the intersection region
15
+ enum PolylinePointPosition {
16
+ Outside = -1,
17
+ Edge = 0,
18
+ Inside = 1,
19
+ }
20
+
21
+ // Direction from last point to the intersection point to know if it is entering
22
+ // or exiting the intersection region
23
+ enum PolylinePointDirection {
24
+ Exiting = -1,
25
+ Unknown = 0,
26
+ Entering = 1,
27
+ }
28
+
29
+ type PolylinePoint = {
30
+ type: PolylinePointType;
31
+ coordinates: Types.Point2;
32
+ position?: PolylinePointPosition;
33
+ visited: boolean;
34
+ next: PolylinePoint;
35
+ };
36
+
37
+ type PolylineIntersectionPoint = PolylinePoint & {
38
+ direction: PolylinePointDirection;
39
+ cloned?: boolean;
40
+ };
41
+
42
+ /**
43
+ * Ensure all polyline point objects are pointing to the next object in case
44
+ * it is still not point to anyone.
45
+ * @param polylinePoints - Array that contains all polyline points (vertices and intersections)
46
+ */
47
+ function ensuresNextPointers(polylinePoints: PolylinePoint[]) {
48
+ // Make sure all nodes point to a valid node
49
+ for (let i = 0, len = polylinePoints.length; i < len; i++) {
50
+ const currentPoint = polylinePoints[i];
51
+
52
+ if (!currentPoint.next) {
53
+ currentPoint.next = polylinePoints[i === len - 1 ? 0 : i + 1];
54
+ }
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Creates one linked list per polyline that contains all vertices and intersections
60
+ * found while walking along the edges.
61
+ *
62
+ * @param targetPolyline - Target polyline
63
+ * @param sourcePolyline - Source polyline
64
+ * @returns Two linked lists with all vertices and intersections.
65
+ */
66
+ function getSourceAndTargetPointsList(
67
+ targetPolyline: Types.Point2[],
68
+ sourcePolyline: Types.Point2[]
69
+ ) {
70
+ const targetPolylinePoints: PolylinePoint[] = [];
71
+ const sourcePolylinePoints: PolylinePoint[] = [];
72
+ const sourceIntersectionsCache = new Map<
73
+ number,
74
+ PolylineIntersectionPoint[]
75
+ >();
76
+
77
+ const isFisrtPointInside = containsPoint(sourcePolyline, targetPolyline[0]);
78
+
79
+ let intersectionPointDirection = isFisrtPointInside
80
+ ? PolylinePointDirection.Exiting
81
+ : PolylinePointDirection.Entering;
82
+
83
+ // Store all vertices and intersection for target contour
84
+ for (let i = 0, len = targetPolyline.length; i < len; i++) {
85
+ const p1 = targetPolyline[i];
86
+ const pointInside = containsPoint(sourcePolyline, p1);
87
+ const vertexPoint: PolylinePoint = {
88
+ type: PolylinePointType.Vertex,
89
+ coordinates: p1,
90
+ position: pointInside
91
+ ? PolylinePointPosition.Inside
92
+ : PolylinePointPosition.Outside,
93
+ visited: false,
94
+ next: null,
95
+ };
96
+
97
+ targetPolylinePoints.push(vertexPoint);
98
+
99
+ const q1 = targetPolyline[i === len - 1 ? 0 : i + 1];
100
+ const intersectionsInfo = getLineSegmentIntersectionsIndexes(
101
+ sourcePolyline,
102
+ p1,
103
+ q1
104
+ ).map((intersectedLineSegment) => {
105
+ const sourceLineSegmentId: number = intersectedLineSegment[0];
106
+ const p2 = sourcePolyline[intersectedLineSegment[0]];
107
+ const q2 = sourcePolyline[intersectedLineSegment[1]];
108
+
109
+ // lineSegment.intersectLine returns `undefined` when the intersection
110
+ // is at one of the line vertices.
111
+ // Examples:
112
+ // - [(0, 0), (1, 1)] x [(1, 1), (1, 2)]
113
+ // - [(0, 1), (2, 1)] x [(1, 1), (1, 2)]
114
+ const intersectionCoordinate = getLineSegmentsIntersection(
115
+ p1,
116
+ q1,
117
+ p2,
118
+ q2
119
+ ) as Types.Point2;
120
+
121
+ const targetStartPointDistSquared = mathPoint.distanceToPointSquared(
122
+ p1,
123
+ intersectionCoordinate
124
+ );
125
+
126
+ return {
127
+ sourceLineSegmentId,
128
+ coordinate: intersectionCoordinate,
129
+ targetStartPointDistSquared,
130
+ };
131
+ });
132
+
133
+ intersectionsInfo.sort(
134
+ (left, right) =>
135
+ left.targetStartPointDistSquared - right.targetStartPointDistSquared
136
+ );
137
+
138
+ intersectionsInfo.forEach((intersectionInfo) => {
139
+ const { sourceLineSegmentId, coordinate: intersectionCoordinate } =
140
+ intersectionInfo;
141
+
142
+ // Intersection point to be added to the target polyline list
143
+ const targetEdgePoint: PolylineIntersectionPoint = {
144
+ type: PolylinePointType.Intersection,
145
+ coordinates: intersectionCoordinate,
146
+ position: PolylinePointPosition.Edge,
147
+ direction: intersectionPointDirection,
148
+ visited: false,
149
+ next: null,
150
+ };
151
+
152
+ // Intersection point to be added to the source polyline list.
153
+ // At this point there is no way to know if the point is entering or
154
+ // exiting the intersection region but that is not going to be used
155
+ // hence it is set to "unknown".
156
+ const sourceEdgePoint: PolylineIntersectionPoint = {
157
+ ...targetEdgePoint,
158
+ direction: PolylinePointDirection.Unknown,
159
+ cloned: true,
160
+ };
161
+
162
+ if (intersectionPointDirection === PolylinePointDirection.Entering) {
163
+ targetEdgePoint.next = sourceEdgePoint;
164
+ } else {
165
+ sourceEdgePoint.next = targetEdgePoint;
166
+ }
167
+
168
+ let sourceIntersectionPoints =
169
+ sourceIntersectionsCache.get(sourceLineSegmentId);
170
+
171
+ if (!sourceIntersectionPoints) {
172
+ sourceIntersectionPoints = [];
173
+ sourceIntersectionsCache.set(
174
+ sourceLineSegmentId,
175
+ sourceIntersectionPoints
176
+ );
177
+ }
178
+
179
+ targetPolylinePoints.push(targetEdgePoint);
180
+ sourceIntersectionPoints.push(sourceEdgePoint);
181
+
182
+ // Switches from "exiting" to "entering" and vice-versa
183
+ intersectionPointDirection *= -1;
184
+ });
185
+ }
186
+
187
+ // Store all vertices and intersections for source contour
188
+ for (let i = 0, len = sourcePolyline.length; i < len; i++) {
189
+ const lineSegmentId: number = i;
190
+ const p1 = sourcePolyline[i];
191
+ const vertexPoint: PolylinePoint = {
192
+ type: PolylinePointType.Vertex,
193
+ coordinates: p1,
194
+ visited: false,
195
+ next: null,
196
+ };
197
+
198
+ sourcePolylinePoints.push(vertexPoint);
199
+
200
+ const sourceIntersectionPoints =
201
+ sourceIntersectionsCache.get(lineSegmentId);
202
+
203
+ if (!sourceIntersectionPoints?.length) {
204
+ continue;
205
+ }
206
+
207
+ // Calculate the distance between each intersection point to the start point
208
+ // of the line segment, sort them by distance and return a sorted array that
209
+ // contains all intersection points.
210
+ sourceIntersectionPoints
211
+ .map((intersectionPoint) => ({
212
+ intersectionPoint,
213
+ lineSegStartDistSquared: mathPoint.distanceToPointSquared(
214
+ p1,
215
+ intersectionPoint.coordinates
216
+ ),
217
+ }))
218
+ .sort(
219
+ (left, right) =>
220
+ left.lineSegStartDistSquared - right.lineSegStartDistSquared
221
+ )
222
+ .map(({ intersectionPoint }) => intersectionPoint)
223
+ .forEach((intersectionPoint) =>
224
+ sourcePolylinePoints.push(intersectionPoint)
225
+ );
226
+ }
227
+
228
+ ensuresNextPointers(targetPolylinePoints);
229
+ ensuresNextPointers(sourcePolylinePoints);
230
+
231
+ return { targetPolylinePoints, sourcePolylinePoints };
232
+ }
233
+
234
+ /**
235
+ * Get the next unvisited polyline points that is outside the intersection region.
236
+ * @param polylinePoints - All polyline points (vertices and intersections)
237
+ * @returns Any unvisited point that is outside the intersection region if it
238
+ * exists or `undefined` otherwise
239
+ */
240
+ function getUnvisitedOutsidePoint(polylinePoints: PolylinePoint[]) {
241
+ for (let i = 0, len = polylinePoints.length; i < len; i++) {
242
+ const point = polylinePoints[i];
243
+
244
+ if (!point.visited && point.position === PolylinePointPosition.Outside) {
245
+ return point;
246
+ }
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Merge two planar polylines (2D)
252
+ */
253
+ function mergePolylines(
254
+ targetPolyline: Types.Point2[],
255
+ sourcePolyline: Types.Point2[]
256
+ ) {
257
+ const targetNormal = getNormal2(targetPolyline);
258
+ const sourceNormal = getNormal2(sourcePolyline);
259
+ const dotNormals = vec3.dot(sourceNormal, targetNormal);
260
+
261
+ // Both polylines need to be CW or CCW to be merged and one of them needs to
262
+ // be reversed if theirs orientation are not the same
263
+ if (!glMatrix.equals(1, dotNormals)) {
264
+ sourcePolyline = sourcePolyline.slice().reverse();
265
+ }
266
+
267
+ const { targetPolylinePoints } = getSourceAndTargetPointsList(
268
+ targetPolyline,
269
+ sourcePolyline
270
+ );
271
+ const startPoint: PolylinePoint =
272
+ getUnvisitedOutsidePoint(targetPolylinePoints);
273
+
274
+ // Source polyline contains target polyline
275
+ if (!startPoint) {
276
+ return targetPolyline.slice();
277
+ }
278
+
279
+ const mergedPolyline = [startPoint.coordinates];
280
+ let currentPoint = startPoint.next;
281
+
282
+ while (currentPoint !== startPoint) {
283
+ if (
284
+ currentPoint.type === PolylinePointType.Intersection &&
285
+ (<PolylineIntersectionPoint>currentPoint).cloned
286
+ ) {
287
+ currentPoint = currentPoint.next;
288
+ continue;
289
+ }
290
+
291
+ mergedPolyline.push(currentPoint.coordinates);
292
+ currentPoint = currentPoint.next;
293
+ }
294
+
295
+ return mergedPolyline;
296
+ }
297
+
298
+ /**
299
+ * Subtract two planar polylines (2D)
300
+ */
301
+ function subtractPolylines(
302
+ targetPolyline: Types.Point2[],
303
+ sourcePolyline: Types.Point2[]
304
+ ): Types.Point2[][] {
305
+ const targetNormal = getNormal2(targetPolyline);
306
+ const sourceNormal = getNormal2(sourcePolyline);
307
+ const dotNormals = vec3.dot(sourceNormal, targetNormal);
308
+
309
+ // The polylines need to have different orientation (CW+CCW or CCW+CW) to be
310
+ // subtracted and one of them needs to be reversed if theirs orientation are
311
+ // the same
312
+ if (!glMatrix.equals(-1, dotNormals)) {
313
+ sourcePolyline = sourcePolyline.slice().reverse();
314
+ }
315
+
316
+ const { targetPolylinePoints } = getSourceAndTargetPointsList(
317
+ targetPolyline,
318
+ sourcePolyline
319
+ );
320
+ let startPoint: PolylinePoint = null;
321
+ const subtractedPolylines = [];
322
+
323
+ while ((startPoint = getUnvisitedOutsidePoint(targetPolylinePoints))) {
324
+ const subtractedPolyline = [startPoint.coordinates];
325
+ let currentPoint = startPoint.next;
326
+
327
+ startPoint.visited = true;
328
+
329
+ while (currentPoint !== startPoint) {
330
+ currentPoint.visited = true;
331
+
332
+ if (
333
+ currentPoint.type === PolylinePointType.Intersection &&
334
+ (<PolylineIntersectionPoint>currentPoint).cloned
335
+ ) {
336
+ currentPoint = currentPoint.next;
337
+ continue;
338
+ }
339
+
340
+ subtractedPolyline.push(currentPoint.coordinates);
341
+ currentPoint = currentPoint.next;
342
+ }
343
+
344
+ subtractedPolylines.push(subtractedPolyline);
345
+ }
346
+
347
+ return subtractedPolylines;
348
+ }
349
+
350
+ export { mergePolylines, subtractPolylines };
@@ -0,0 +1,63 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import isClosed from './isClosed';
3
+
4
+ /**
5
+ * Checks if a 2D point is inside the polyline.
6
+ *
7
+ * A point is inside a curve/polygon if the number of intersections between the horizontal
8
+ * ray emanating from the given point and to the right and the line segments is odd.
9
+ * https://www.eecs.umich.edu/courses/eecs380/HANDOUTS/PROJ2/InsidePoly.html
10
+ *
11
+ * @param polyline - Polyline points (2D)
12
+ * @param point - 2D Point
13
+ * @returns True is the point is inside the polyline or false otherwise
14
+ */
15
+ export default function containsPoint(
16
+ polyline: Types.Point2[],
17
+ point: Types.Point2,
18
+ closed?: boolean
19
+ ): boolean {
20
+ if (polyline.length < 3) {
21
+ return false;
22
+ }
23
+
24
+ const numPolylinePoints = polyline.length;
25
+ let numIntersections = 0;
26
+
27
+ // Test intersection agains [end, start] line segment if it should be closed
28
+ const shouldClose = !(closed === undefined ? isClosed(polyline) : closed);
29
+ const maxSegmentIndex = polyline.length - (shouldClose ? 1 : 2);
30
+
31
+ for (let i = 0; i <= maxSegmentIndex; i++) {
32
+ const p1 = polyline[i];
33
+
34
+ // Calculating the next point index without using % (mod) operator like in
35
+ // `(i + 1) % numPolylinePoints` to make it 20% faster
36
+ const p2Index = i === numPolylinePoints - 1 ? 0 : i + 1;
37
+ const p2 = polyline[p2Index];
38
+
39
+ // Calculating min/max without using Math.min/max to make it ~3% faster
40
+ const maxX = p1[0] >= p2[0] ? p1[0] : p2[0];
41
+ const maxY = p1[1] >= p2[1] ? p1[1] : p2[1];
42
+ const minY = p1[1] <= p2[1] ? p1[1] : p2[1];
43
+
44
+ const mayIntersectLineSegment =
45
+ point[0] <= maxX && point[1] >= minY && point[1] < maxY;
46
+
47
+ if (mayIntersectLineSegment) {
48
+ const isVerticalLine = p1[0] === p2[0];
49
+ let intersects = isVerticalLine;
50
+
51
+ if (!intersects) {
52
+ const xIntersection =
53
+ ((point[1] - p1[1]) * (p2[0] - p1[0])) / (p2[1] - p1[1]) + p1[0];
54
+
55
+ intersects = point[0] <= xIntersection;
56
+ }
57
+
58
+ numIntersections += intersects ? 1 : 0;
59
+ }
60
+ }
61
+
62
+ return !!(numIntersections % 2);
63
+ }
@@ -0,0 +1,20 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ export default function getAABB(polyline: Types.Point2[]): Types.AABB2 {
4
+ let minX = Infinity;
5
+ let minY = Infinity;
6
+ let maxX = -Infinity;
7
+ let maxY = -Infinity;
8
+
9
+ for (let i = 0, len = polyline.length; i < len; i++) {
10
+ const [x, y] = polyline[i];
11
+
12
+ // No Math.min/max calls for better performance
13
+ minX = minX < x ? minX : x;
14
+ minY = minY < y ? minY : y;
15
+ maxX = maxX > x ? maxX : x;
16
+ maxY = maxY > y ? maxY : y;
17
+ }
18
+
19
+ return { minX, maxX, minY, maxY };
20
+ }
@@ -7,7 +7,7 @@ import type { Types } from '@cornerstonejs/core';
7
7
  * the points are in canvas, then the result is in canvas pixels ^2; If they are
8
8
  * in mm, then the result is in mm^2; etc.
9
9
  */
10
- export default function calculateAreaOfPoints(points: Types.Point2[]): number {
10
+ export default function getArea(points: Types.Point2[]): number {
11
11
  // Shoelace algorithm.
12
12
  const n = points.length;
13
13
  let area = 0.0;
@@ -0,0 +1,72 @@
1
+ import { vec2 } from 'gl-matrix';
2
+ import type { Types } from '@cornerstonejs/core';
3
+ import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
4
+
5
+ /**
6
+ * Checks whether the line (`p1`,`q1`) intersects any of the other lines in the
7
+ * `points`, and returns the closest value.
8
+ * @param points - Polyline points
9
+ * @param p1 - Start point of the line segment
10
+ * @param q1 - End point of the line segment
11
+ * @param closed - Test the intersection against the line that connects the first to the last when closed
12
+ * @returns The closest line segment from polyline that intersects the line segment [p1, q1]
13
+ */
14
+ export default function getClosestLineSegmentIntersection(
15
+ points: Types.Point2[],
16
+ p1: Types.Point2,
17
+ q1: Types.Point2,
18
+ closed = true
19
+ ): { segment: Types.Point2; distance: number } | undefined {
20
+ let initialQ2Index;
21
+ let p2Index;
22
+
23
+ if (closed) {
24
+ p2Index = points.length - 1;
25
+ initialQ2Index = 0;
26
+ } else {
27
+ p2Index = 0;
28
+ initialQ2Index = 1;
29
+ }
30
+
31
+ const intersections = [];
32
+
33
+ for (let q2Index = initialQ2Index; q2Index < points.length; q2Index++) {
34
+ const p2 = points[p2Index];
35
+ const q2 = points[q2Index];
36
+
37
+ if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
38
+ intersections.push([p2Index, q2Index]);
39
+ }
40
+
41
+ p2Index = q2Index;
42
+ }
43
+
44
+ if (intersections.length === 0) {
45
+ return;
46
+ }
47
+
48
+ // Find intersection closest to the start point
49
+ const distances = [];
50
+
51
+ intersections.forEach((intersection) => {
52
+ const intersectionPoints = [
53
+ points[intersection[0]],
54
+ points[intersection[1]],
55
+ ];
56
+
57
+ const midpoint = [
58
+ (intersectionPoints[0][0] + intersectionPoints[1][0]) / 2,
59
+ (intersectionPoints[0][1] + intersectionPoints[1][1]) / 2,
60
+ ];
61
+
62
+ distances.push(vec2.distance(<vec2>midpoint, p1));
63
+ });
64
+
65
+ const minDistance = Math.min(...distances);
66
+ const indexOfMinDistance = distances.indexOf(minDistance);
67
+
68
+ return {
69
+ segment: intersections[indexOfMinDistance],
70
+ distance: minDistance,
71
+ };
72
+ }
@@ -0,0 +1,42 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
3
+
4
+ /**
5
+ * Checks whether the line (`p1`,`q1`) intersects any of the other lines in the
6
+ * `points`, and returns the first value.
7
+ *
8
+ * @param points - Polyline points
9
+ * @param p1 - First point of the line segment that is being tested
10
+ * @param q1 - Second point of the line segment that is being tested
11
+ * @param closed - Test the intersection with the line segment that connects
12
+ * the last and first points of the polyline
13
+ * @returns Indexes of the line segment points from the polyline that intersects [p1, q1]
14
+ */
15
+ export default function getFirstLineSegmentIntersectionIndexes(
16
+ points: Types.Point2[],
17
+ p1: Types.Point2,
18
+ q1: Types.Point2,
19
+ closed = true
20
+ ): Types.Point2 | undefined {
21
+ let initialI;
22
+ let j;
23
+
24
+ if (closed) {
25
+ j = points.length - 1;
26
+ initialI = 0;
27
+ } else {
28
+ j = 0;
29
+ initialI = 1;
30
+ }
31
+
32
+ for (let i = initialI; i < points.length; i++) {
33
+ const p2 = points[j];
34
+ const q2 = points[i];
35
+
36
+ if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
37
+ return [j, i];
38
+ }
39
+
40
+ j = i;
41
+ }
42
+ }
@@ -0,0 +1,30 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import getLineSegmentIntersectionsIndexes from './getLineSegmentIntersectionsIndexes';
3
+ import getLineSegmentsIntersection from './getLineSegmentsIntersection';
4
+
5
+ /**
6
+ * Returns all intersections points between a line segment and a polyline
7
+ */
8
+ export default function getLineSegmentIntersectionsCoordinates(
9
+ points: Types.Point2[],
10
+ p1: Types.Point2,
11
+ q1: Types.Point2,
12
+ closed = true
13
+ ): Types.Point2[] {
14
+ const result = [];
15
+ const polylineIndexes = getLineSegmentIntersectionsIndexes(
16
+ points,
17
+ p1,
18
+ q1,
19
+ closed
20
+ );
21
+
22
+ for (let i = 0; i < polylineIndexes.length; i++) {
23
+ const p2 = points[polylineIndexes[i][0]];
24
+ const q2 = points[polylineIndexes[i][1]];
25
+ const intersection = getLineSegmentsIntersection(p1, q1, p2, q2);
26
+ result.push(intersection);
27
+ }
28
+
29
+ return result;
30
+ }
@@ -0,0 +1,35 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import areLineSegmentsIntersecting from './areLineSegmentsIntersecting';
3
+
4
+ /**
5
+ * Get all intersections between a polyline and a line segment.
6
+ * @param polyline - Polyline points
7
+ * @param p1 - Start point of line segment
8
+ * @param q1 - End point of line segment
9
+ * @param closed - Test the intersection against the line segment that connects
10
+ * the last to the first point when set to true
11
+ * @returns Start/end point indexes of all line segments that intersect (p1, q1)
12
+ */
13
+ export default function getLineSegmentIntersectionsIndexes(
14
+ polyline: Types.Point2[],
15
+ p1: Types.Point2,
16
+ q1: Types.Point2,
17
+ closed = true
18
+ ): Types.Point2[] {
19
+ const intersections: Types.Point2[] = [];
20
+ const numPoints = polyline.length;
21
+ const maxI = numPoints - (closed ? 1 : 2);
22
+
23
+ for (let i = 0; i <= maxI; i++) {
24
+ const p2 = polyline[i];
25
+ // Do not use % operator for better performance
26
+ const j = i === numPoints - 1 ? 0 : i + 1;
27
+ const q2 = polyline[j];
28
+
29
+ if (areLineSegmentsIntersecting(p1, q1, p2, q2)) {
30
+ intersections.push([i, j]);
31
+ }
32
+ }
33
+
34
+ return intersections;
35
+ }
@@ -0,0 +1,47 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+
3
+ // ATTENTION: this is an internal function and it should not be added to "polyline"
4
+ // namespace because there is another one from lineSegment.intersectLine that also
5
+ // finds an intersection between two line segments. This one should be removed but
6
+ // it is faster and able to find intersections when the intersection is one of the
7
+ // two points of a line segment.
8
+ //
9
+ // Example:
10
+ // Line 1: (0, 0), (1, 1) x Line 2 (1, 1), (1, 2)
11
+ // Line 1: (0, 1), (2, 1) x Line 2 (1, 1), (1, 2)
12
+ //
13
+ // This function must replace `lineSegment.intersectLine` but it requires some
14
+ // tests first
15
+
16
+ /**
17
+ * Gets the intersection between the line segments (`p1`,`q1`) and (`p2`,`q2`)
18
+ *
19
+ * http://jsfiddle.net/justin_c_rounds/Gd2S2/light/
20
+ * https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
21
+ */
22
+ export default function getLineSegmentsIntersection(
23
+ p1: Types.Point2,
24
+ q1: Types.Point2,
25
+ p2: Types.Point2,
26
+ q2: Types.Point2
27
+ ): Types.Point2 {
28
+ const diffQ1P1 = [q1[0] - p1[0], q1[1] - p1[1]];
29
+ const diffQ2P2 = [q2[0] - p2[0], q2[1] - p2[1]];
30
+ const denominator = diffQ2P2[1] * diffQ1P1[0] - diffQ2P2[0] * diffQ1P1[1];
31
+
32
+ if (denominator == 0) {
33
+ return;
34
+ }
35
+
36
+ let a = p1[1] - p2[1];
37
+ let b = p1[0] - p2[0];
38
+ const numerator1 = diffQ2P2[0] * a - diffQ2P2[1] * b;
39
+ const numerator2 = diffQ1P1[0] * a - diffQ1P1[1] * b;
40
+ a = numerator1 / denominator;
41
+ b = numerator2 / denominator;
42
+
43
+ const resultX = p1[0] + a * diffQ1P1[0];
44
+ const resultY = p1[1] + a * diffQ1P1[1];
45
+
46
+ return [resultX, resultY];
47
+ }
@@ -0,0 +1,17 @@
1
+ import { Types } from '@cornerstonejs/core';
2
+ import getSignedArea from './getSignedArea';
3
+
4
+ /**
5
+ * Calculate the normal of a 2D polyline
6
+ * https://www.youtube.com/watch?v=GpsKrAipXm8&t=1982s
7
+ *
8
+ * @param polyline - Planar polyline in 2D space
9
+ * @returns Normal of the 2D planar polyline
10
+ */
11
+ export default function getNormal2(polyline: Types.Point2[]): Types.Point3 {
12
+ const area = getSignedArea(polyline);
13
+
14
+ // The normal of a 2D polyline is (0, 0, 1) or (0, 0, -1) depending if it
15
+ // is CW or CCW polyline
16
+ return [0, 0, area / Math.abs(area)] as Types.Point3;
17
+ }