@cornerstonejs/tools 1.52.0 → 1.53.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 (251) hide show
  1. package/dist/cjs/drawingSvg/drawPath.d.ts +11 -0
  2. package/dist/cjs/drawingSvg/drawPath.js +55 -0
  3. package/dist/cjs/drawingSvg/drawPath.js.map +1 -0
  4. package/dist/cjs/drawingSvg/drawPolyline.d.ts +1 -1
  5. package/dist/cjs/drawingSvg/drawPolyline.js +2 -10
  6. package/dist/cjs/drawingSvg/drawPolyline.js.map +1 -1
  7. package/dist/cjs/drawingSvg/index.d.ts +2 -1
  8. package/dist/cjs/drawingSvg/index.js +3 -1
  9. package/dist/cjs/drawingSvg/index.js.map +1 -1
  10. package/dist/cjs/eventDispatchers/shared/getActiveToolForMouseEvent.js.map +1 -1
  11. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +1 -1
  12. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +165 -78
  13. package/dist/cjs/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
  14. package/dist/cjs/stateManagement/annotation/annotationState.d.ts +6 -1
  15. package/dist/cjs/stateManagement/annotation/annotationState.js +49 -1
  16. package/dist/cjs/stateManagement/annotation/annotationState.js.map +1 -1
  17. package/dist/cjs/stateManagement/annotation/helpers/state.d.ts +2 -1
  18. package/dist/cjs/stateManagement/annotation/helpers/state.js +14 -3
  19. package/dist/cjs/stateManagement/annotation/helpers/state.js.map +1 -1
  20. package/dist/cjs/stateManagement/index.d.ts +6 -1
  21. package/dist/cjs/stateManagement/index.js +6 -1
  22. package/dist/cjs/stateManagement/index.js.map +1 -1
  23. package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +3 -1
  24. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +3 -2
  25. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  26. package/dist/cjs/tools/SegmentationIntersectionTool.js +1 -1
  27. package/dist/cjs/tools/SegmentationIntersectionTool.js.map +1 -1
  28. package/dist/cjs/tools/annotation/LivewireContourSegmentationTool.js +1 -1
  29. package/dist/cjs/tools/annotation/LivewireContourSegmentationTool.js.map +1 -1
  30. package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +4 -3
  31. package/dist/cjs/tools/annotation/LivewireContourTool.js +26 -26
  32. package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
  33. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +1 -0
  34. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  35. package/dist/cjs/tools/annotation/SplineROITool.d.ts +6 -3
  36. package/dist/cjs/tools/annotation/SplineROITool.js +37 -18
  37. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  38. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +12 -7
  39. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  40. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +24 -18
  41. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  42. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +16 -10
  43. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  44. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js +19 -7
  45. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  46. package/dist/cjs/tools/annotation/splines/LinearSpline.js +1 -1
  47. package/dist/cjs/tools/annotation/splines/LinearSpline.js.map +1 -1
  48. package/dist/cjs/tools/annotation/splines/Spline.d.ts +2 -0
  49. package/dist/cjs/tools/annotation/splines/Spline.js +7 -3
  50. package/dist/cjs/tools/annotation/splines/Spline.js.map +1 -1
  51. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  52. package/dist/cjs/tools/base/ContourBaseTool.d.ts +1 -0
  53. package/dist/cjs/tools/base/ContourBaseTool.js +18 -1
  54. package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -1
  55. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js +4 -0
  56. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  57. package/dist/cjs/tools/displayTools/Contour/contourConfig.js +1 -0
  58. package/dist/cjs/tools/displayTools/Contour/contourConfig.js.map +1 -1
  59. package/dist/cjs/types/AnnotationTypes.d.ts +2 -0
  60. package/dist/cjs/types/ContourAnnotation.d.ts +6 -0
  61. package/dist/cjs/types/ContourAnnotation.js +7 -0
  62. package/dist/cjs/types/ContourAnnotation.js.map +1 -1
  63. package/dist/cjs/types/ContourTypes.d.ts +1 -0
  64. package/dist/cjs/types/EventTypes.d.ts +4 -1
  65. package/dist/cjs/types/ISpline.d.ts +1 -0
  66. package/dist/cjs/types/SplineProps.d.ts +1 -0
  67. package/dist/cjs/utilities/contours/getContourHolesDataCanvas.d.ts +3 -0
  68. package/dist/cjs/utilities/contours/getContourHolesDataCanvas.js +21 -0
  69. package/dist/cjs/utilities/contours/getContourHolesDataCanvas.js.map +1 -0
  70. package/dist/cjs/utilities/contours/getContourHolesDataWorld.d.ts +3 -0
  71. package/dist/cjs/utilities/contours/getContourHolesDataWorld.js +10 -0
  72. package/dist/cjs/utilities/contours/getContourHolesDataWorld.js.map +1 -0
  73. package/dist/cjs/utilities/contours/index.d.ts +4 -1
  74. package/dist/cjs/utilities/contours/index.js +7 -1
  75. package/dist/cjs/utilities/contours/index.js.map +1 -1
  76. package/dist/cjs/utilities/contours/updateContourPolyline.d.ts +10 -0
  77. package/dist/cjs/utilities/contours/updateContourPolyline.js +64 -0
  78. package/dist/cjs/utilities/contours/updateContourPolyline.js.map +1 -0
  79. package/dist/cjs/utilities/math/polyline/containsPoints.d.ts +2 -0
  80. package/dist/cjs/utilities/math/polyline/containsPoints.js +16 -0
  81. package/dist/cjs/utilities/math/polyline/containsPoints.js.map +1 -0
  82. package/dist/cjs/utilities/math/polyline/getWindingDirection.d.ts +2 -0
  83. package/dist/cjs/utilities/math/polyline/getWindingDirection.js +12 -0
  84. package/dist/cjs/utilities/math/polyline/getWindingDirection.js.map +1 -0
  85. package/dist/cjs/utilities/math/polyline/index.d.ts +3 -1
  86. package/dist/cjs/utilities/math/polyline/index.js +5 -1
  87. package/dist/cjs/utilities/math/polyline/index.js.map +1 -1
  88. package/dist/cjs/utilities/math/polyline/planarFreehandROIInternalTypes.d.ts +1 -0
  89. package/dist/esm/drawingSvg/drawPath.js +49 -0
  90. package/dist/esm/drawingSvg/drawPath.js.map +1 -0
  91. package/dist/esm/drawingSvg/drawPolyline.js +2 -10
  92. package/dist/esm/drawingSvg/drawPolyline.js.map +1 -1
  93. package/dist/esm/drawingSvg/index.js +2 -1
  94. package/dist/esm/drawingSvg/index.js.map +1 -1
  95. package/dist/esm/eventDispatchers/shared/getActiveToolForMouseEvent.js.map +1 -1
  96. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js +106 -32
  97. package/dist/esm/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.js.map +1 -1
  98. package/dist/esm/stateManagement/annotation/annotationState.js +42 -1
  99. package/dist/esm/stateManagement/annotation/annotationState.js.map +1 -1
  100. package/dist/esm/stateManagement/annotation/helpers/state.js +12 -2
  101. package/dist/esm/stateManagement/annotation/helpers/state.js.map +1 -1
  102. package/dist/esm/stateManagement/index.js +2 -2
  103. package/dist/esm/stateManagement/index.js.map +1 -1
  104. package/dist/esm/store/ToolGroupManager/ToolGroup.js +3 -2
  105. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  106. package/dist/esm/tools/SegmentationIntersectionTool.js +1 -1
  107. package/dist/esm/tools/SegmentationIntersectionTool.js.map +1 -1
  108. package/dist/esm/tools/annotation/LivewireContourSegmentationTool.js +1 -1
  109. package/dist/esm/tools/annotation/LivewireContourSegmentationTool.js.map +1 -1
  110. package/dist/esm/tools/annotation/LivewireContourTool.js +28 -28
  111. package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
  112. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +2 -1
  113. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  114. package/dist/esm/tools/annotation/SplineROITool.js +37 -19
  115. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  116. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +12 -7
  117. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  118. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +25 -19
  119. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  120. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +16 -10
  121. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  122. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js +20 -8
  123. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  124. package/dist/esm/tools/annotation/splines/LinearSpline.js +1 -1
  125. package/dist/esm/tools/annotation/splines/LinearSpline.js.map +1 -1
  126. package/dist/esm/tools/annotation/splines/Spline.js +5 -1
  127. package/dist/esm/tools/annotation/splines/Spline.js.map +1 -1
  128. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  129. package/dist/esm/tools/base/ContourBaseTool.js +20 -3
  130. package/dist/esm/tools/base/ContourBaseTool.js.map +1 -1
  131. package/dist/esm/tools/base/ContourSegmentationBaseTool.js +4 -0
  132. package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -1
  133. package/dist/esm/tools/displayTools/Contour/contourConfig.js +1 -0
  134. package/dist/esm/tools/displayTools/Contour/contourConfig.js.map +1 -1
  135. package/dist/esm/types/ContourAnnotation.js +6 -1
  136. package/dist/esm/types/ContourAnnotation.js.map +1 -1
  137. package/dist/esm/utilities/contours/getContourHolesDataCanvas.js +15 -0
  138. package/dist/esm/utilities/contours/getContourHolesDataCanvas.js.map +1 -0
  139. package/dist/esm/utilities/contours/getContourHolesDataWorld.js +6 -0
  140. package/dist/esm/utilities/contours/getContourHolesDataWorld.js.map +1 -0
  141. package/dist/esm/utilities/contours/index.js +4 -1
  142. package/dist/esm/utilities/contours/index.js.map +1 -1
  143. package/dist/esm/utilities/contours/updateContourPolyline.js +38 -0
  144. package/dist/esm/utilities/contours/updateContourPolyline.js.map +1 -0
  145. package/dist/esm/utilities/math/polyline/containsPoints.js +10 -0
  146. package/dist/esm/utilities/math/polyline/containsPoints.js.map +1 -0
  147. package/dist/esm/utilities/math/polyline/getWindingDirection.js +6 -0
  148. package/dist/esm/utilities/math/polyline/getWindingDirection.js.map +1 -0
  149. package/dist/esm/utilities/math/polyline/index.js +3 -1
  150. package/dist/esm/utilities/math/polyline/index.js.map +1 -1
  151. package/dist/types/drawingSvg/drawPath.d.ts +12 -0
  152. package/dist/types/drawingSvg/drawPath.d.ts.map +1 -0
  153. package/dist/types/drawingSvg/drawPolyline.d.ts +1 -1
  154. package/dist/types/drawingSvg/drawPolyline.d.ts.map +1 -1
  155. package/dist/types/drawingSvg/index.d.ts +2 -1
  156. package/dist/types/drawingSvg/index.d.ts.map +1 -1
  157. package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts +1 -1
  158. package/dist/types/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.d.ts.map +1 -1
  159. package/dist/types/stateManagement/annotation/annotationState.d.ts +6 -1
  160. package/dist/types/stateManagement/annotation/annotationState.d.ts.map +1 -1
  161. package/dist/types/stateManagement/annotation/helpers/state.d.ts +2 -1
  162. package/dist/types/stateManagement/annotation/helpers/state.d.ts.map +1 -1
  163. package/dist/types/stateManagement/index.d.ts +6 -1
  164. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts +3 -1
  165. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
  166. package/dist/types/tools/annotation/LivewireContourTool.d.ts +4 -3
  167. package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
  168. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  169. package/dist/types/tools/annotation/SplineROITool.d.ts +6 -3
  170. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  171. package/dist/types/tools/annotation/planarFreehandROITool/closedContourEditLoop.d.ts.map +1 -1
  172. package/dist/types/tools/annotation/planarFreehandROITool/drawLoop.d.ts.map +1 -1
  173. package/dist/types/tools/annotation/planarFreehandROITool/openContourEditLoop.d.ts.map +1 -1
  174. package/dist/types/tools/annotation/planarFreehandROITool/renderMethods.d.ts.map +1 -1
  175. package/dist/types/tools/annotation/splines/Spline.d.ts +2 -0
  176. package/dist/types/tools/annotation/splines/Spline.d.ts.map +1 -1
  177. package/dist/types/tools/base/AnnotationTool.d.ts.map +1 -1
  178. package/dist/types/tools/base/ContourBaseTool.d.ts +1 -0
  179. package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -1
  180. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -1
  181. package/dist/types/tools/displayTools/Contour/contourConfig.d.ts.map +1 -1
  182. package/dist/types/types/AnnotationTypes.d.ts +2 -0
  183. package/dist/types/types/AnnotationTypes.d.ts.map +1 -1
  184. package/dist/types/types/ContourAnnotation.d.ts +6 -0
  185. package/dist/types/types/ContourAnnotation.d.ts.map +1 -1
  186. package/dist/types/types/ContourTypes.d.ts +1 -0
  187. package/dist/types/types/ContourTypes.d.ts.map +1 -1
  188. package/dist/types/types/EventTypes.d.ts +4 -1
  189. package/dist/types/types/EventTypes.d.ts.map +1 -1
  190. package/dist/types/types/ISpline.d.ts +1 -0
  191. package/dist/types/types/ISpline.d.ts.map +1 -1
  192. package/dist/types/types/SplineProps.d.ts +1 -0
  193. package/dist/types/types/SplineProps.d.ts.map +1 -1
  194. package/dist/types/utilities/contours/getContourHolesDataCanvas.d.ts +4 -0
  195. package/dist/types/utilities/contours/getContourHolesDataCanvas.d.ts.map +1 -0
  196. package/dist/types/utilities/contours/getContourHolesDataWorld.d.ts +4 -0
  197. package/dist/types/utilities/contours/getContourHolesDataWorld.d.ts.map +1 -0
  198. package/dist/types/utilities/contours/index.d.ts +4 -1
  199. package/dist/types/utilities/contours/index.d.ts.map +1 -1
  200. package/dist/types/utilities/contours/updateContourPolyline.d.ts +11 -0
  201. package/dist/types/utilities/contours/updateContourPolyline.d.ts.map +1 -0
  202. package/dist/types/utilities/math/polyline/containsPoints.d.ts +3 -0
  203. package/dist/types/utilities/math/polyline/containsPoints.d.ts.map +1 -0
  204. package/dist/types/utilities/math/polyline/getWindingDirection.d.ts +3 -0
  205. package/dist/types/utilities/math/polyline/getWindingDirection.d.ts.map +1 -0
  206. package/dist/types/utilities/math/polyline/index.d.ts +3 -1
  207. package/dist/types/utilities/math/polyline/index.d.ts.map +1 -1
  208. package/dist/types/utilities/math/polyline/planarFreehandROIInternalTypes.d.ts +1 -0
  209. package/dist/types/utilities/math/polyline/planarFreehandROIInternalTypes.d.ts.map +1 -1
  210. package/dist/umd/index.js +1 -1
  211. package/dist/umd/index.js.map +1 -1
  212. package/package.json +3 -3
  213. package/src/drawingSvg/drawPath.ts +96 -0
  214. package/src/drawingSvg/drawPolyline.ts +12 -16
  215. package/src/drawingSvg/index.ts +2 -0
  216. package/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +1 -1
  217. package/src/eventListeners/annotations/contourSegmentation/contourSegmentationCompleted.ts +194 -58
  218. package/src/stateManagement/annotation/annotationState.ts +101 -0
  219. package/src/stateManagement/annotation/helpers/state.ts +29 -1
  220. package/src/stateManagement/index.js +10 -0
  221. package/src/store/ToolGroupManager/ToolGroup.ts +9 -2
  222. package/src/tools/SegmentationIntersectionTool.ts +1 -1
  223. package/src/tools/annotation/LivewireContourSegmentationTool.ts +1 -1
  224. package/src/tools/annotation/LivewireContourTool.ts +65 -38
  225. package/src/tools/annotation/PlanarFreehandROITool.ts +6 -1
  226. package/src/tools/annotation/SplineROITool.ts +75 -28
  227. package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +20 -11
  228. package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +40 -21
  229. package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +28 -13
  230. package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +28 -10
  231. package/src/tools/annotation/splines/LinearSpline.ts +1 -1
  232. package/src/tools/annotation/splines/Spline.ts +13 -1
  233. package/src/tools/base/AnnotationTool.ts +1 -0
  234. package/src/tools/base/ContourBaseTool.ts +45 -3
  235. package/src/tools/base/ContourSegmentationBaseTool.ts +6 -0
  236. package/src/tools/displayTools/Contour/contourConfig.ts +1 -0
  237. package/src/types/AnnotationTypes.ts +14 -0
  238. package/src/types/ContourAnnotation.ts +13 -0
  239. package/src/types/ContourTypes.ts +3 -0
  240. package/src/types/EventTypes.ts +9 -0
  241. package/src/types/ISpline.ts +3 -0
  242. package/src/types/SplineProps.ts +10 -0
  243. package/src/utilities/contours/getContourHolesDataCanvas.ts +33 -0
  244. package/src/utilities/contours/getContourHolesDataWorld.ts +19 -0
  245. package/src/utilities/contours/index.ts +6 -0
  246. package/src/utilities/contours/updateContourPolyline.ts +74 -0
  247. package/src/utilities/math/polyline/containsPoint.ts +1 -1
  248. package/src/utilities/math/polyline/containsPoints.ts +22 -0
  249. package/src/utilities/math/polyline/getWindingDirection.ts +14 -0
  250. package/src/utilities/math/polyline/index.ts +4 -0
  251. package/src/utilities/math/polyline/planarFreehandROIInternalTypes.ts +1 -0
@@ -11,6 +11,7 @@ import {
11
11
  AnnotationAddedEventDetail,
12
12
  AnnotationModifiedEventDetail,
13
13
  AnnotationCompletedEventDetail,
14
+ ContourAnnotationCompletedEventDetail,
14
15
  } from '../../../types/EventTypes';
15
16
 
16
17
  /**
@@ -105,11 +106,37 @@ function triggerAnnotationModified(
105
106
  * Triggers an annotation completed event.
106
107
  */
107
108
  function triggerAnnotationCompleted(annotation: Annotation): void {
108
- const eventType = Events.ANNOTATION_COMPLETED;
109
109
  const eventDetail: AnnotationCompletedEventDetail = {
110
110
  annotation,
111
111
  };
112
112
 
113
+ _triggerAnnotationCompleted(eventDetail);
114
+ }
115
+
116
+ /**
117
+ * Triggers an annotation completed event for contours (same annotation completed
118
+ * event but with more specific details).
119
+ */
120
+ function triggerContourAnnotationCompleted(
121
+ annotation: Annotation,
122
+ contourHoleProcessingEnabled = false
123
+ ): void {
124
+ const eventDetail: ContourAnnotationCompletedEventDetail = {
125
+ annotation,
126
+ contourHoleProcessingEnabled,
127
+ };
128
+
129
+ _triggerAnnotationCompleted(eventDetail);
130
+ }
131
+
132
+ /**
133
+ * Triggers an annotation completed event for the `detail` provided
134
+ * @param eventDetail - Event detail
135
+ */
136
+ function _triggerAnnotationCompleted(
137
+ eventDetail: AnnotationCompletedEventDetail
138
+ ) {
139
+ const eventType = Events.ANNOTATION_COMPLETED;
113
140
  triggerEvent(eventTarget, eventType, eventDetail);
114
141
  }
115
142
 
@@ -118,4 +145,5 @@ export {
118
145
  triggerAnnotationAddedForFOR,
119
146
  triggerAnnotationModified,
120
147
  triggerAnnotationCompleted,
148
+ triggerContourAnnotationCompleted,
121
149
  };
@@ -9,10 +9,15 @@ import {
9
9
  addAnnotation,
10
10
  removeAnnotation,
11
11
  getAnnotation,
12
+ getParentAnnotation,
13
+ getChildAnnotations,
14
+ clearParentAnnotation,
15
+ addChildAnnotation,
12
16
  getNumberOfAnnotations,
13
17
  setAnnotationManager,
14
18
  getAnnotationManager,
15
19
  resetAnnotationManager,
20
+ invalidateAnnotation,
16
21
  } from './annotation/annotationState';
17
22
 
18
23
  import {
@@ -31,9 +36,14 @@ export {
31
36
  getNumberOfAnnotations,
32
37
  removeAnnotation,
33
38
  getAnnotation,
39
+ getParentAnnotation,
40
+ getChildAnnotations,
41
+ clearParentAnnotation,
42
+ addChildAnnotation,
34
43
  setAnnotationManager,
35
44
  getAnnotationManager,
36
45
  resetAnnotationManager,
46
+ invalidateAnnotation,
37
47
  // segmentations
38
48
  addSegmentationRepresentations,
39
49
  removeSegmentationsFromToolGroup,
@@ -418,8 +418,14 @@ export default class ToolGroup implements IToolGroup {
418
418
  * - Renders data if the tool has a `renderAnnotation` method.
419
419
  *
420
420
  * @param toolName - tool name
421
+ * @param options - Options used when setting the tool as passive
422
+ * - removeAllBindings: only the primary button bindings are removed but
423
+ * if this parameter is set to true all bindings are removed.
421
424
  */
422
- public setToolPassive(toolName: string): void {
425
+ public setToolPassive(
426
+ toolName: string,
427
+ options?: { removeAllBindings?: boolean }
428
+ ): void {
423
429
  const toolInstance = this._toolInstances[toolName];
424
430
 
425
431
  if (toolInstance === undefined) {
@@ -448,7 +454,8 @@ export default class ToolGroup implements IToolGroup {
448
454
  // Remove the primary button bindings without modifiers, if they exist
449
455
  toolOptions.bindings = toolOptions.bindings.filter(
450
456
  (binding) =>
451
- binding.mouseButton !== defaultMousePrimary || binding.modifierKey
457
+ options?.removeAllBindings !== true &&
458
+ (binding.mouseButton !== defaultMousePrimary || binding.modifierKey)
452
459
  );
453
460
  // If there are other bindings, set the tool to be active
454
461
  let mode = Passive;
@@ -146,7 +146,7 @@ class SegmentationIntersectionTool extends AnnotationDisplayTool {
146
146
  color: color,
147
147
  fillColor: color,
148
148
  fillOpacity: this.configuration.opacity,
149
- connectLastToFirst: true,
149
+ closePath: true,
150
150
  };
151
151
 
152
152
  const polyLineUID = actorEntry.uid + '#' + polyLineIdx;
@@ -94,7 +94,7 @@ class LivewireContourSegmentationTool extends LivewireContourTool {
94
94
  }
95
95
 
96
96
  // Now, update the rendering
97
- this.updateAnnotation(element, acceptedPath);
97
+ this.updateAnnotation(acceptedPath);
98
98
  this.scissors = null;
99
99
  this.scissorsRight = null;
100
100
  this.editData = null;
@@ -9,7 +9,7 @@ import type { Types } from '@cornerstonejs/core';
9
9
  import { removeAnnotation } from '../../stateManagement/annotation/annotationState';
10
10
  import { drawHandles as drawHandlesSvg } from '../../drawingSvg';
11
11
  import { state } from '../../store';
12
- import { Events, ChangeTypes } from '../../enums';
12
+ import { Events, KeyboardBindings, ChangeTypes } from '../../enums';
13
13
  import { resetElementCursor } from '../../cursors/elementCursor';
14
14
  import type {
15
15
  EventTypes,
@@ -18,19 +18,21 @@ import type {
18
18
  ToolProps,
19
19
  SVGDrawingHelper,
20
20
  } from '../../types';
21
+ import getMouseModifierKey from '../../eventDispatchers/shared/getMouseModifier';
21
22
  import { math, triggerAnnotationRenderForViewportIds } from '../../utilities';
22
23
  import findHandlePolylineIndex from '../../utilities/contours/findHandlePolylineIndex';
23
24
  import { LivewireContourAnnotation } from '../../types/ToolSpecificAnnotationTypes';
25
+ import { ContourWindingDirection } from '../../types/ContourAnnotation';
24
26
  import {
25
27
  triggerAnnotationModified,
26
- triggerAnnotationCompleted,
28
+ triggerContourAnnotationCompleted,
27
29
  } from '../../stateManagement/annotation/helpers/state';
28
- import reverseIfAntiClockwise from '../../utilities/contours/reverseIfAntiClockwise';
29
30
 
30
31
  import { LivewireScissors } from '../../utilities/livewire/LivewireScissors';
31
32
  import { LivewirePath } from '../../utilities/livewire/LiveWirePath';
32
33
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
33
34
  import ContourSegmentationBaseTool from '../base/ContourSegmentationBaseTool';
35
+ import updateContourPolyline from '../../utilities/contours/updateContourPolyline';
34
36
 
35
37
  const CLICK_CLOSE_CURVE_SQR_DIST = 10 ** 2; // px
36
38
 
@@ -57,6 +59,7 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
57
59
  worldToSlice?: (point: Types.Point3) => Types.Point2;
58
60
  sliceToWorld?: (point: Types.Point2) => Types.Point3;
59
61
  originalPath?: Types.Point3[];
62
+ contourHoleProcessingEnabled?: boolean;
60
63
  } | null;
61
64
  isDrawing: boolean;
62
65
  isHandleOutsideImage = false;
@@ -67,6 +70,12 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
67
70
  supportedInteractionTypes: ['Mouse', 'Touch'],
68
71
  configuration: {
69
72
  preventHandleOutsideImage: false,
73
+ /**
74
+ * Specify which modifier key is used to add a hole to a contour. The
75
+ * modifier must be pressed when the first point of a new contour is added.
76
+ */
77
+ contourHoleAdditionModifierKey: KeyboardBindings.Shift,
78
+
70
79
  /**
71
80
  * Configuring this to a value larger than 0 will snap handles to nearby
72
81
  * livewire points, within the given rectangle surrounding the clicked point.
@@ -115,7 +124,13 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
115
124
  super(toolProps, defaultToolProps);
116
125
  }
117
126
 
118
- protected setupBaseEditData(worldPos, element, annotation, rightPos?) {
127
+ protected setupBaseEditData(
128
+ worldPos,
129
+ element,
130
+ annotation,
131
+ rightPos?,
132
+ contourHoleProcessingEnabled?
133
+ ) {
119
134
  const enabledElement = getEnabledElement(element);
120
135
  const { viewport } = enabledElement;
121
136
 
@@ -233,6 +248,7 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
233
248
  this.editData?.handleIndex ?? annotation.handles?.activeHandleIndex,
234
249
  worldToSlice,
235
250
  sliceToWorld,
251
+ contourHoleProcessingEnabled,
236
252
  };
237
253
  }
238
254
 
@@ -252,8 +268,17 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
252
268
  const { world: worldPos } = currentPoints;
253
269
  const { renderingEngine } = getEnabledElement(element);
254
270
  const annotation = this.createAnnotation(evt);
271
+ const contourHoleProcessingEnabled =
272
+ getMouseModifierKey(evt.detail.event) ===
273
+ this.configuration.contourHoleAdditionModifierKey;
255
274
 
256
- this.setupBaseEditData(worldPos, element, annotation);
275
+ this.setupBaseEditData(
276
+ worldPos,
277
+ element,
278
+ annotation,
279
+ undefined,
280
+ contourHoleProcessingEnabled
281
+ );
257
282
  this.addAnnotation(annotation, element);
258
283
 
259
284
  this._activateDraw(element);
@@ -379,7 +404,12 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
379
404
  const eventDetail = evt.detail;
380
405
  const { element } = eventDetail;
381
406
 
382
- const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
407
+ const {
408
+ annotation,
409
+ viewportIdsToRender,
410
+ newAnnotation,
411
+ contourHoleProcessingEnabled,
412
+ } = this.editData;
383
413
  const { data } = annotation;
384
414
 
385
415
  data.handles.activeHandleIndex = null;
@@ -406,24 +436,18 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
406
436
  return;
407
437
  }
408
438
 
409
- // Reverse the points if needed, ensuring both the handles and the
410
- // polyline is also reversed.
411
- const { worldToSlice } = this.editData;
412
- if (worldToSlice) {
413
- reverseIfAntiClockwise(
414
- data.handles.points.map(worldToSlice),
415
- data.handles.points,
416
- data.contour.polyline
417
- );
418
- }
419
-
420
439
  triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
421
440
 
422
441
  const changeType = newAnnotation
423
442
  ? ChangeTypes.Completed
424
443
  : ChangeTypes.HandlesUpdated;
425
444
 
426
- this.triggerChangeEvent(annotation, enabledElement, changeType);
445
+ this.triggerChangeEvent(
446
+ annotation,
447
+ enabledElement,
448
+ changeType,
449
+ contourHoleProcessingEnabled
450
+ );
427
451
  this.clearEditData();
428
452
  };
429
453
 
@@ -440,10 +464,14 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
440
464
  triggerChangeEvent = (
441
465
  annotation: LivewireContourAnnotation,
442
466
  enabledElement: Types.IEnabledElement,
443
- changeType = ChangeTypes.StatsUpdated
467
+ changeType = ChangeTypes.StatsUpdated,
468
+ contourHoleProcessingEnabled = false
444
469
  ): void => {
445
470
  if (changeType === ChangeTypes.Completed) {
446
- triggerAnnotationCompleted(annotation);
471
+ triggerContourAnnotationCompleted(
472
+ annotation,
473
+ contourHoleProcessingEnabled
474
+ );
447
475
  } else {
448
476
  triggerAnnotationModified(
449
477
  annotation,
@@ -536,7 +564,7 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
536
564
 
537
565
  if (this.editData.closed) {
538
566
  // Update the annotation because `editData` will be set to null
539
- this.updateAnnotation(element, this.editData.confirmedPath);
567
+ this.updateAnnotation(this.editData.confirmedPath);
540
568
  this._endCallback(evt);
541
569
  }
542
570
 
@@ -787,11 +815,8 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
787
815
  enabledElement: Types.IEnabledElement,
788
816
  svgDrawingHelper: SVGDrawingHelper
789
817
  ): boolean {
790
- const { viewport } = enabledElement;
791
- const { element } = viewport;
792
-
793
818
  // Update the annotation that is in editData (being edited)
794
- this.updateAnnotation(element, this.editData?.currentPath);
819
+ this.updateAnnotation(this.editData?.currentPath);
795
820
 
796
821
  return super.renderAnnotation(enabledElement, svgDrawingHelper);
797
822
  }
@@ -885,27 +910,29 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
885
910
  return true;
886
911
  }
887
912
 
888
- protected updateAnnotation(_, livewirePath: LivewirePath) {
913
+ protected updateAnnotation(livewirePath: LivewirePath) {
889
914
  if (!this.editData || !livewirePath) {
890
915
  return;
891
916
  }
892
917
 
893
918
  const { annotation, sliceToWorld } = this.editData;
919
+ let { pointArray: imagePoints } = livewirePath;
894
920
 
895
- const { pointArray: imagePoints } = livewirePath;
896
- const worldPolylinePoints: Types.Point3[] = [];
897
-
898
- for (let i = 0, len = imagePoints.length; i < len; i++) {
899
- const imagePoint = imagePoints[i];
900
- const worldPoint = sliceToWorld(imagePoint);
901
- worldPolylinePoints.push(worldPoint);
921
+ if (imagePoints.length > 1) {
922
+ imagePoints = [...imagePoints, imagePoints[0]];
902
923
  }
903
924
 
904
- if (worldPolylinePoints.length > 1) {
905
- worldPolylinePoints.push([...worldPolylinePoints[0]]);
906
- }
907
-
908
- annotation.data.contour.polyline = worldPolylinePoints;
925
+ updateContourPolyline(
926
+ annotation,
927
+ {
928
+ points: imagePoints,
929
+ closed: annotation.data.contour.closed,
930
+ targetWindingDirection: ContourWindingDirection.Clockwise,
931
+ },
932
+ {
933
+ canvasToWorld: sliceToWorld,
934
+ }
935
+ );
909
936
  }
910
937
  }
911
938
 
@@ -46,7 +46,7 @@ import { isViewportPreScaled } from '../../utilities/viewport/isViewportPreScale
46
46
  import { getModalityUnit } from '../../utilities/getModalityUnit';
47
47
  import { BasicStatsCalculator } from '../../utilities/math/basic';
48
48
  import ContourSegmentationBaseTool from '../base/ContourSegmentationBaseTool';
49
- import { ChangeTypes } from '../../enums';
49
+ import { KeyboardBindings, ChangeTypes } from '../../enums';
50
50
 
51
51
  const { pointCanProjectOnLine } = polyline;
52
52
  const { EPSILON } = CONSTANTS;
@@ -178,6 +178,11 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
178
178
  configuration: {
179
179
  shadow: true,
180
180
  preventHandleOutsideImage: false,
181
+ /**
182
+ * Specify which modifier key is used to add a hole to a contour. The
183
+ * modifier must be pressed when the first point of a new contour is added.
184
+ */
185
+ contourHoleAdditionModifierKey: KeyboardBindings.Shift,
181
186
  alwaysRenderOpenContourHandles: {
182
187
  // When true, always render end points when you have an open contour, rather
183
188
  // than just rendering a line.
@@ -6,7 +6,10 @@ import {
6
6
  } from '@cornerstonejs/core';
7
7
  import type { Types } from '@cornerstonejs/core';
8
8
  import { vec3 } from 'gl-matrix';
9
- import { removeAnnotation } from '../../stateManagement/annotation/annotationState';
9
+ import {
10
+ getChildAnnotations,
11
+ removeAnnotation,
12
+ } from '../../stateManagement/annotation/annotationState';
10
13
  import {
11
14
  drawHandles as drawHandlesSvg,
12
15
  drawPolyline as drawPolylineSvg,
@@ -37,13 +40,15 @@ import {
37
40
  getCalibratedScale,
38
41
  getCalibratedAreaUnits,
39
42
  } from '../../utilities';
43
+ import getMouseModifierKey from '../../eventDispatchers/shared/getMouseModifier';
40
44
  import { getViewportIdsWithToolToRender } from '../../utilities/viewportFilters';
41
45
  import { getTextBoxCoordsCanvas } from '../../utilities/drawing';
42
46
 
43
- import { SplineROIAnnotation } from '../../types/ToolSpecificAnnotationTypes';
44
- import {
45
- AnnotationCompletedEventDetail,
47
+ import { ContourWindingDirection } from '../../types/ContourAnnotation';
48
+ import type { SplineROIAnnotation } from '../../types/ToolSpecificAnnotationTypes';
49
+ import type {
46
50
  AnnotationModifiedEventDetail,
51
+ ContourAnnotationCompletedEventDetail,
47
52
  } from '../../types/EventTypes';
48
53
  import { ISpline } from '../../types/ISpline';
49
54
  import { CardinalSpline } from './splines/CardinalSpline';
@@ -51,7 +56,7 @@ import { LinearSpline } from './splines/LinearSpline';
51
56
  import { CatmullRomSpline } from './splines/CatmullRomSpline';
52
57
  import { BSpline } from './splines/BSpline';
53
58
  import ContourSegmentationBaseTool from '../base/ContourSegmentationBaseTool';
54
- import reverseIfAntiClockwise from '../../utilities/contours/reverseIfAntiClockwise';
59
+ import updateContourPolyline from '../../utilities/contours/updateContourPolyline';
55
60
 
56
61
  const SPLINE_MIN_POINTS = 3;
57
62
  const SPLINE_CLICK_CLOSE_CURVE_DIST = 10;
@@ -93,12 +98,14 @@ class SplineROITool extends ContourSegmentationBaseTool {
93
98
  newAnnotation?: boolean;
94
99
  hasMoved?: boolean;
95
100
  lastCanvasPoint?: Types.Point2;
101
+ contourHoleProcessingEnabled?: boolean;
96
102
  } | null;
97
103
  isDrawing: boolean;
98
104
  isHandleOutsideImage = false;
99
105
  fireChangeOnUpdate: {
100
106
  annotationUID: string;
101
107
  changeType: ChangeTypes;
108
+ contourHoleProcessingEnabled: boolean;
102
109
  } = null;
103
110
 
104
111
  constructor(
@@ -109,6 +116,11 @@ class SplineROITool extends ContourSegmentationBaseTool {
109
116
  preventHandleOutsideImage: false,
110
117
  calculateStats: true,
111
118
  getTextLines: defaultGetTextLines,
119
+ /**
120
+ * Specify which modifier key is used to add a hole to a contour. The
121
+ * modifier must be pressed when the first point of a new contour is added.
122
+ */
123
+ contourHoleAdditionModifierKey: KeyboardBindings.Shift,
112
124
  spline: {
113
125
  configuration: {
114
126
  [SplineTypesEnum.Cardinal]: {
@@ -176,6 +188,9 @@ class SplineROITool extends ContourSegmentationBaseTool {
176
188
  const eventDetail = evt.detail;
177
189
  const { currentPoints, element } = eventDetail;
178
190
  const { canvas: canvasPos } = currentPoints;
191
+ const contourHoleProcessingEnabled =
192
+ getMouseModifierKey(evt.detail.event) ===
193
+ this.configuration.contourHoleAdditionModifierKey;
179
194
 
180
195
  const enabledElement = getEnabledElement(element);
181
196
  const { renderingEngine } = enabledElement;
@@ -196,6 +211,7 @@ class SplineROITool extends ContourSegmentationBaseTool {
196
211
  newAnnotation: true,
197
212
  hasMoved: false,
198
213
  lastCanvasPoint: canvasPos,
214
+ contourHoleProcessingEnabled,
199
215
  };
200
216
 
201
217
  this._activateDraw(element);
@@ -303,7 +319,12 @@ class SplineROITool extends ContourSegmentationBaseTool {
303
319
  const eventDetail = evt.detail;
304
320
  const { element } = eventDetail;
305
321
 
306
- const { annotation, viewportIdsToRender, newAnnotation } = this.editData;
322
+ const {
323
+ annotation,
324
+ viewportIdsToRender,
325
+ newAnnotation,
326
+ contourHoleProcessingEnabled,
327
+ } = this.editData;
307
328
  const { data } = annotation;
308
329
  annotation.autoGenerated = false;
309
330
 
@@ -338,6 +359,7 @@ class SplineROITool extends ContourSegmentationBaseTool {
338
359
  changeType: newAnnotation
339
360
  ? ChangeTypes.Completed
340
361
  : ChangeTypes.HandlesUpdated,
362
+ contourHoleProcessingEnabled,
341
363
  };
342
364
 
343
365
  triggerAnnotationRenderForViewportIds(renderingEngine, viewportIdsToRender);
@@ -466,14 +488,7 @@ class SplineROITool extends ContourSegmentationBaseTool {
466
488
  const { deltaPoints } = eventDetail as EventTypes.MouseDragEventDetail;
467
489
  const worldPosDelta = deltaPoints.world;
468
490
 
469
- const points = data.handles.points;
470
-
471
- points.forEach((point) => {
472
- point[0] += worldPosDelta[0];
473
- point[1] += worldPosDelta[1];
474
- point[2] += worldPosDelta[2];
475
- });
476
- annotation.invalidated = true;
491
+ this.moveAnnotation(annotation, worldPosDelta);
477
492
  } else {
478
493
  // Move mode - after double click, and mouse move to draw
479
494
  const { currentPoints } = eventDetail;
@@ -522,11 +537,15 @@ class SplineROITool extends ContourSegmentationBaseTool {
522
537
  /**
523
538
  * Triggers an annotation completed event.
524
539
  */
525
- triggerAnnotationCompleted = (annotation: SplineROIAnnotation): void => {
540
+ triggerAnnotationCompleted = (
541
+ annotation: SplineROIAnnotation,
542
+ contourHoleProcessingEnabled: boolean
543
+ ): void => {
526
544
  const eventType = Events.ANNOTATION_COMPLETED;
527
- const eventDetail: AnnotationCompletedEventDetail = {
545
+ const eventDetail: ContourAnnotationCompletedEventDetail = {
528
546
  annotation,
529
547
  changeType: ChangeTypes.Completed,
548
+ contourHoleProcessingEnabled,
530
549
  };
531
550
 
532
551
  triggerEvent(eventTarget, eventType, eventDetail);
@@ -558,10 +577,11 @@ class SplineROITool extends ContourSegmentationBaseTool {
558
577
  triggerChangeEvent = (
559
578
  annotation: SplineROIAnnotation,
560
579
  enabledElement: Types.IEnabledElement,
561
- changeType = ChangeTypes.StatsUpdated
580
+ changeType = ChangeTypes.StatsUpdated,
581
+ contourHoleProcessingEnabled
562
582
  ): void => {
563
583
  if (changeType === ChangeTypes.Completed) {
564
- this.triggerAnnotationCompleted(annotation);
584
+ this.triggerAnnotationCompleted(annotation, contourHoleProcessingEnabled);
565
585
  } else {
566
586
  this.triggerAnnotationModified(annotation, enabledElement, changeType);
567
587
  }
@@ -658,15 +678,32 @@ class SplineROITool extends ContourSegmentationBaseTool {
658
678
  const { drawPreviewEnabled } = this.configuration.spline;
659
679
  const splineType = annotation.data.spline.type;
660
680
  const splineConfig = this._getSplineConfig(splineType);
661
- const spline = this._updateSplineInstance(element, annotation);
662
- const splinePolylineCanvas = reverseIfAntiClockwise(
663
- spline.getPolylinePoints()
664
- );
665
- const splinePolylineWorld = splinePolylineCanvas.map((point2) =>
666
- viewport.canvasToWorld(point2)
667
- );
681
+ const spline = annotation.data.spline.instance;
668
682
 
669
- data.contour.polyline = splinePolylineWorld;
683
+ // Update current and all child annotations/splines
684
+ if (annotation.invalidated) {
685
+ const splineAnnotationsGroup = [
686
+ annotation,
687
+ ...getChildAnnotations(annotation),
688
+ ].filter((annotation) =>
689
+ this._isSplineROIAnnotation(annotation)
690
+ ) as SplineROIAnnotation[];
691
+
692
+ splineAnnotationsGroup.forEach((annotation) => {
693
+ const spline = this._updateSplineInstance(element, annotation);
694
+ const splinePolylineCanvas = spline.getPolylinePoints();
695
+
696
+ updateContourPolyline(
697
+ annotation,
698
+ {
699
+ points: splinePolylineCanvas,
700
+ closed: data.contour.closed,
701
+ targetWindingDirection: ContourWindingDirection.Clockwise,
702
+ },
703
+ viewport
704
+ );
705
+ });
706
+ }
670
707
 
671
708
  // Let the base class render the contour
672
709
  super.renderAnnotationInstance(renderContext);
@@ -768,7 +805,8 @@ class SplineROITool extends ContourSegmentationBaseTool {
768
805
  this.triggerChangeEvent(
769
806
  annotation,
770
807
  enabledElement,
771
- this.fireChangeOnUpdate.changeType
808
+ this.fireChangeOnUpdate.changeType,
809
+ this.fireChangeOnUpdate.contourHoleProcessingEnabled
772
810
  );
773
811
  this.fireChangeOnUpdate = null;
774
812
  }
@@ -990,6 +1028,12 @@ class SplineROITool extends ContourSegmentationBaseTool {
990
1028
  );
991
1029
  };
992
1030
 
1031
+ _isSplineROIAnnotation(
1032
+ annotation: Annotation
1033
+ ): annotation is SplineROIAnnotation {
1034
+ return !!(<SplineROIAnnotation>annotation).data?.spline;
1035
+ }
1036
+
993
1037
  /**
994
1038
  * Get a spline config merged with the default settings.
995
1039
  * @param type - Spline type (CARDINAL, CATMULLROM, LINEAR or BSPLINE)
@@ -1019,7 +1063,10 @@ class SplineROITool extends ContourSegmentationBaseTool {
1019
1063
  spline.closed = !!data.contour.closed;
1020
1064
 
1021
1065
  // Update spline resolution in case it has changed
1022
- if (spline.resolution !== splineConfig.resolution) {
1066
+ if (
1067
+ !spline.fixedResolution &&
1068
+ spline.resolution !== splineConfig.resolution
1069
+ ) {
1023
1070
  spline.resolution = parseInt(splineConfig.resolution);
1024
1071
  annotation.invalidated = true;
1025
1072
  }
@@ -7,14 +7,16 @@ import {
7
7
  resetElementCursor,
8
8
  hideElementCursor,
9
9
  } from '../../../cursors/elementCursor';
10
- import { EventTypes } from '../../../types';
10
+ import type { EventTypes } from '../../../types';
11
11
  import { polyline } from '../../../utilities/math';
12
- import { PlanarFreehandROIAnnotation } from '../../../types/ToolSpecificAnnotationTypes';
12
+ import { ContourWindingDirection } from '../../../types/ContourAnnotation';
13
+ import type { PlanarFreehandROIAnnotation } from '../../../types/ToolSpecificAnnotationTypes';
13
14
  import {
14
15
  getInterpolatedPoints,
15
16
  shouldSmooth,
16
17
  } from '../../../utilities/planarFreehandROITool/smoothPoints';
17
18
  import triggerAnnotationRenderForViewportIds from '../../../utilities/triggerAnnotationRenderForViewportIds';
19
+ import updateContourPolyline from '../../../utilities/contours/updateContourPolyline';
18
20
  import { triggerAnnotationModified } from '../../../stateManagement/annotation/helpers/state';
19
21
 
20
22
  const { getSubPixelSpacingAndXYDirections, addCanvasPointsToArray, getArea } =
@@ -223,12 +225,16 @@ function finishEditAndStartNewEdit(evt: EventTypes.InteractionEventType): void {
223
225
  const { annotation, viewportIdsToRender } = this.commonData;
224
226
  const { fusedCanvasPoints, editCanvasPoints } = this.editData;
225
227
 
226
- const worldPoints = fusedCanvasPoints.map((canvasPoint) =>
227
- viewport.canvasToWorld(canvasPoint)
228
+ updateContourPolyline(
229
+ annotation,
230
+ {
231
+ points: fusedCanvasPoints,
232
+ closed: true,
233
+ targetWindingDirection: ContourWindingDirection.Clockwise,
234
+ },
235
+ viewport
228
236
  );
229
237
 
230
- annotation.data.contour.polyline = worldPoints;
231
- annotation.data.contour.closed = true;
232
238
  // If any manual update, triggered on an annotation, then it will be treated as non-autogenerated.
233
239
  if (annotation.autoGenerated) {
234
240
  annotation.autoGenerated = false;
@@ -446,12 +452,15 @@ function completeClosedContourEdit(element: HTMLDivElement) {
446
452
  )
447
453
  : fusedCanvasPoints;
448
454
 
449
- const worldPoints = updatedPoints.map((canvasPoint) =>
450
- viewport.canvasToWorld(canvasPoint)
455
+ updateContourPolyline(
456
+ annotation,
457
+ {
458
+ points: updatedPoints,
459
+ closed: true,
460
+ targetWindingDirection: ContourWindingDirection.Clockwise,
461
+ },
462
+ viewport
451
463
  );
452
- annotation.data.contour.polyline = worldPoints;
453
- annotation.data.contour.closed = true;
454
- annotation.invalidated = true;
455
464
 
456
465
  // If any manual update, triggered on an annotation, then it will be treated as non-autogenerated.
457
466
  if (annotation.autoGenerated) {