@cornerstonejs/tools 1.43.7 → 1.44.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 (252) hide show
  1. package/dist/cjs/index.d.ts +2 -2
  2. package/dist/cjs/index.js +5 -2
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.d.ts +3 -1
  5. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js +7 -2
  6. package/dist/cjs/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
  7. package/dist/cjs/stateManagement/segmentation/config/segmentationVisibility.d.ts +2 -1
  8. package/dist/cjs/stateManagement/segmentation/config/segmentationVisibility.js +23 -9
  9. package/dist/cjs/stateManagement/segmentation/config/segmentationVisibility.js.map +1 -1
  10. package/dist/cjs/stateManagement/segmentation/helpers/normalizeSegmentationInput.js +14 -1
  11. package/dist/cjs/stateManagement/segmentation/helpers/normalizeSegmentationInput.js.map +1 -1
  12. package/dist/cjs/tools/annotation/AngleTool.js +4 -3
  13. package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
  14. package/dist/cjs/tools/annotation/ArrowAnnotateTool.js +4 -3
  15. package/dist/cjs/tools/annotation/ArrowAnnotateTool.js.map +1 -1
  16. package/dist/cjs/tools/annotation/BidirectionalTool.js +4 -4
  17. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  18. package/dist/cjs/tools/annotation/CircleROITool.js +4 -3
  19. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  20. package/dist/cjs/tools/annotation/CobbAngleTool.js +4 -3
  21. package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
  22. package/dist/cjs/tools/annotation/DragProbeTool.js +4 -1
  23. package/dist/cjs/tools/annotation/DragProbeTool.js.map +1 -1
  24. package/dist/cjs/tools/annotation/EllipticalROITool.js +4 -3
  25. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  26. package/dist/cjs/tools/annotation/KeyImageTool.js +4 -1
  27. package/dist/cjs/tools/annotation/KeyImageTool.js.map +1 -1
  28. package/dist/cjs/tools/annotation/LengthTool.js +4 -4
  29. package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
  30. package/dist/cjs/tools/annotation/LivewireContourSegmentationTool.d.ts +6 -0
  31. package/dist/cjs/tools/annotation/LivewireContourSegmentationTool.js +14 -0
  32. package/dist/cjs/tools/annotation/LivewireContourSegmentationTool.js.map +1 -0
  33. package/dist/cjs/tools/annotation/LivewireContourTool.d.ts +14 -5
  34. package/dist/cjs/tools/annotation/LivewireContourTool.js +126 -159
  35. package/dist/cjs/tools/annotation/LivewireContourTool.js.map +1 -1
  36. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +8 -0
  37. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js +24 -0
  38. package/dist/cjs/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -0
  39. package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +16 -6
  40. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +104 -134
  41. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  42. package/dist/cjs/tools/annotation/ProbeTool.js +1 -1
  43. package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
  44. package/dist/cjs/tools/annotation/RectangleROITool.js +4 -3
  45. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  46. package/dist/cjs/tools/annotation/SplineContourSegmentationTool.d.ts +8 -0
  47. package/dist/cjs/tools/annotation/SplineContourSegmentationTool.js +23 -0
  48. package/dist/cjs/tools/annotation/SplineContourSegmentationTool.js.map +1 -0
  49. package/dist/cjs/tools/annotation/SplineROITool.d.ts +15 -8
  50. package/dist/cjs/tools/annotation/SplineROITool.js +168 -240
  51. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  52. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +5 -5
  53. package/dist/cjs/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  54. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js +4 -4
  55. package/dist/cjs/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  56. package/dist/cjs/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.js +1 -1
  57. package/dist/cjs/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.js.map +1 -1
  58. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js +7 -7
  59. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  60. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js +1 -1
  61. package/dist/cjs/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js.map +1 -1
  62. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js +19 -15
  63. package/dist/cjs/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  64. package/dist/cjs/tools/base/AnnotationTool.d.ts +15 -0
  65. package/dist/cjs/tools/base/AnnotationTool.js +24 -0
  66. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  67. package/dist/cjs/tools/base/ContourBaseTool.d.ts +19 -0
  68. package/dist/cjs/tools/base/ContourBaseTool.js +130 -0
  69. package/dist/cjs/tools/base/ContourBaseTool.js.map +1 -0
  70. package/dist/cjs/tools/base/ContourSegmentationBaseTool.d.ts +18 -0
  71. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js +139 -0
  72. package/dist/cjs/tools/base/ContourSegmentationBaseTool.js.map +1 -0
  73. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +1 -0
  74. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  75. package/dist/cjs/tools/index.d.ts +4 -1
  76. package/dist/cjs/tools/index.js +7 -1
  77. package/dist/cjs/tools/index.js.map +1 -1
  78. package/dist/cjs/types/ContourAnnotation.d.ts +11 -0
  79. package/dist/cjs/types/ContourAnnotation.js +3 -0
  80. package/dist/cjs/types/ContourAnnotation.js.map +1 -0
  81. package/dist/cjs/types/ContourSegmentationAnnotation.d.ts +11 -0
  82. package/dist/cjs/types/ContourSegmentationAnnotation.js +3 -0
  83. package/dist/cjs/types/ContourSegmentationAnnotation.js.map +1 -0
  84. package/dist/cjs/types/ContourTypes.d.ts +4 -1
  85. package/dist/cjs/types/SegmentationStateTypes.d.ts +1 -1
  86. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +11 -52
  87. package/dist/cjs/types/index.d.ts +3 -1
  88. package/dist/cjs/utilities/math/vec2/liangBarksyClip.d.ts +1 -1
  89. package/dist/esm/index.js +2 -2
  90. package/dist/esm/index.js.map +1 -1
  91. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js +7 -2
  92. package/dist/esm/stateManagement/segmentation/SegmentationStateManager.js.map +1 -1
  93. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.js +20 -7
  94. package/dist/esm/stateManagement/segmentation/config/segmentationVisibility.js.map +1 -1
  95. package/dist/esm/stateManagement/segmentation/helpers/normalizeSegmentationInput.js +13 -1
  96. package/dist/esm/stateManagement/segmentation/helpers/normalizeSegmentationInput.js.map +1 -1
  97. package/dist/esm/tools/annotation/AngleTool.js +4 -3
  98. package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
  99. package/dist/esm/tools/annotation/ArrowAnnotateTool.js +4 -3
  100. package/dist/esm/tools/annotation/ArrowAnnotateTool.js.map +1 -1
  101. package/dist/esm/tools/annotation/BidirectionalTool.js +4 -4
  102. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  103. package/dist/esm/tools/annotation/CircleROITool.js +4 -3
  104. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  105. package/dist/esm/tools/annotation/CobbAngleTool.js +4 -3
  106. package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
  107. package/dist/esm/tools/annotation/DragProbeTool.js +4 -1
  108. package/dist/esm/tools/annotation/DragProbeTool.js.map +1 -1
  109. package/dist/esm/tools/annotation/EllipticalROITool.js +4 -3
  110. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  111. package/dist/esm/tools/annotation/KeyImageTool.js +4 -1
  112. package/dist/esm/tools/annotation/KeyImageTool.js.map +1 -1
  113. package/dist/esm/tools/annotation/LengthTool.js +4 -4
  114. package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
  115. package/dist/esm/tools/annotation/LivewireContourSegmentationTool.js +9 -0
  116. package/dist/esm/tools/annotation/LivewireContourSegmentationTool.js.map +1 -0
  117. package/dist/esm/tools/annotation/LivewireContourTool.js +123 -160
  118. package/dist/esm/tools/annotation/LivewireContourTool.js.map +1 -1
  119. package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js +19 -0
  120. package/dist/esm/tools/annotation/PlanarFreehandContourSegmentationTool.js.map +1 -0
  121. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +104 -134
  122. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  123. package/dist/esm/tools/annotation/ProbeTool.js +1 -1
  124. package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
  125. package/dist/esm/tools/annotation/RectangleROITool.js +4 -3
  126. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  127. package/dist/esm/tools/annotation/SplineContourSegmentationTool.js +18 -0
  128. package/dist/esm/tools/annotation/SplineContourSegmentationTool.js.map +1 -0
  129. package/dist/esm/tools/annotation/SplineROITool.js +153 -227
  130. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  131. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js +5 -5
  132. package/dist/esm/tools/annotation/planarFreehandROITool/closedContourEditLoop.js.map +1 -1
  133. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js +4 -4
  134. package/dist/esm/tools/annotation/planarFreehandROITool/drawLoop.js.map +1 -1
  135. package/dist/esm/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.js +1 -1
  136. package/dist/esm/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.js.map +1 -1
  137. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js +7 -7
  138. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEditLoop.js.map +1 -1
  139. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js +1 -1
  140. package/dist/esm/tools/annotation/planarFreehandROITool/openContourEndEditLoop.js.map +1 -1
  141. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js +19 -15
  142. package/dist/esm/tools/annotation/planarFreehandROITool/renderMethods.js.map +1 -1
  143. package/dist/esm/tools/base/AnnotationTool.js +24 -0
  144. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  145. package/dist/esm/tools/base/ContourBaseTool.js +122 -0
  146. package/dist/esm/tools/base/ContourBaseTool.js.map +1 -0
  147. package/dist/esm/tools/base/ContourSegmentationBaseTool.js +131 -0
  148. package/dist/esm/tools/base/ContourSegmentationBaseTool.js.map +1 -0
  149. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +1 -0
  150. package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  151. package/dist/esm/tools/index.js +4 -1
  152. package/dist/esm/tools/index.js.map +1 -1
  153. package/dist/esm/types/ContourAnnotation.js +2 -0
  154. package/dist/esm/types/ContourAnnotation.js.map +1 -0
  155. package/dist/esm/types/ContourSegmentationAnnotation.js +2 -0
  156. package/dist/esm/types/ContourSegmentationAnnotation.js.map +1 -0
  157. package/dist/types/index.d.ts +2 -2
  158. package/dist/types/index.d.ts.map +1 -1
  159. package/dist/types/stateManagement/segmentation/SegmentationStateManager.d.ts +3 -1
  160. package/dist/types/stateManagement/segmentation/SegmentationStateManager.d.ts.map +1 -1
  161. package/dist/types/stateManagement/segmentation/config/segmentationVisibility.d.ts +2 -1
  162. package/dist/types/stateManagement/segmentation/config/segmentationVisibility.d.ts.map +1 -1
  163. package/dist/types/stateManagement/segmentation/helpers/normalizeSegmentationInput.d.ts.map +1 -1
  164. package/dist/types/tools/annotation/AngleTool.d.ts.map +1 -1
  165. package/dist/types/tools/annotation/ArrowAnnotateTool.d.ts.map +1 -1
  166. package/dist/types/tools/annotation/CircleROITool.d.ts.map +1 -1
  167. package/dist/types/tools/annotation/CobbAngleTool.d.ts.map +1 -1
  168. package/dist/types/tools/annotation/DragProbeTool.d.ts.map +1 -1
  169. package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
  170. package/dist/types/tools/annotation/KeyImageTool.d.ts.map +1 -1
  171. package/dist/types/tools/annotation/LengthTool.d.ts.map +1 -1
  172. package/dist/types/tools/annotation/LivewireContourSegmentationTool.d.ts +7 -0
  173. package/dist/types/tools/annotation/LivewireContourSegmentationTool.d.ts.map +1 -0
  174. package/dist/types/tools/annotation/LivewireContourTool.d.ts +14 -5
  175. package/dist/types/tools/annotation/LivewireContourTool.d.ts.map +1 -1
  176. package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts +9 -0
  177. package/dist/types/tools/annotation/PlanarFreehandContourSegmentationTool.d.ts.map +1 -0
  178. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts +16 -6
  179. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  180. package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
  181. package/dist/types/tools/annotation/SplineContourSegmentationTool.d.ts +9 -0
  182. package/dist/types/tools/annotation/SplineContourSegmentationTool.d.ts.map +1 -0
  183. package/dist/types/tools/annotation/SplineROITool.d.ts +15 -8
  184. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  185. package/dist/types/tools/annotation/planarFreehandROITool/closedContourEditLoop.d.ts.map +1 -1
  186. package/dist/types/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.d.ts.map +1 -1
  187. package/dist/types/tools/annotation/planarFreehandROITool/openContourEditLoop.d.ts.map +1 -1
  188. package/dist/types/tools/annotation/planarFreehandROITool/openContourEndEditLoop.d.ts.map +1 -1
  189. package/dist/types/tools/annotation/planarFreehandROITool/renderMethods.d.ts.map +1 -1
  190. package/dist/types/tools/base/AnnotationTool.d.ts +15 -0
  191. package/dist/types/tools/base/AnnotationTool.d.ts.map +1 -1
  192. package/dist/types/tools/base/ContourBaseTool.d.ts +20 -0
  193. package/dist/types/tools/base/ContourBaseTool.d.ts.map +1 -0
  194. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts +19 -0
  195. package/dist/types/tools/base/ContourSegmentationBaseTool.d.ts.map +1 -0
  196. package/dist/types/tools/displayTools/Contour/contourDisplay.d.ts.map +1 -1
  197. package/dist/types/tools/index.d.ts +4 -1
  198. package/dist/types/tools/index.d.ts.map +1 -1
  199. package/dist/types/types/ContourAnnotation.d.ts +12 -0
  200. package/dist/types/types/ContourAnnotation.d.ts.map +1 -0
  201. package/dist/types/types/ContourSegmentationAnnotation.d.ts +12 -0
  202. package/dist/types/types/ContourSegmentationAnnotation.d.ts.map +1 -0
  203. package/dist/types/types/ContourTypes.d.ts +4 -1
  204. package/dist/types/types/ContourTypes.d.ts.map +1 -1
  205. package/dist/types/types/SegmentationStateTypes.d.ts +1 -1
  206. package/dist/types/types/SegmentationStateTypes.d.ts.map +1 -1
  207. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +11 -52
  208. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  209. package/dist/types/types/index.d.ts +3 -1
  210. package/dist/types/types/index.d.ts.map +1 -1
  211. package/dist/types/utilities/math/vec2/liangBarksyClip.d.ts +1 -1
  212. package/dist/umd/index.js +1 -1
  213. package/dist/umd/index.js.map +1 -1
  214. package/package.json +3 -3
  215. package/src/index.ts +6 -0
  216. package/src/stateManagement/segmentation/SegmentationStateManager.ts +11 -2
  217. package/src/stateManagement/segmentation/config/segmentationVisibility.ts +52 -6
  218. package/src/stateManagement/segmentation/helpers/normalizeSegmentationInput.ts +27 -1
  219. package/src/tools/annotation/AngleTool.ts +4 -3
  220. package/src/tools/annotation/ArrowAnnotateTool.ts +4 -3
  221. package/src/tools/annotation/BidirectionalTool.ts +4 -4
  222. package/src/tools/annotation/CircleROITool.ts +4 -3
  223. package/src/tools/annotation/CobbAngleTool.ts +4 -3
  224. package/src/tools/annotation/DragProbeTool.ts +4 -1
  225. package/src/tools/annotation/EllipticalROITool.ts +4 -3
  226. package/src/tools/annotation/KeyImageTool.ts +4 -1
  227. package/src/tools/annotation/LengthTool.ts +4 -5
  228. package/src/tools/annotation/LivewireContourSegmentationTool.ts +13 -0
  229. package/src/tools/annotation/LivewireContourTool.ts +75 -150
  230. package/src/tools/annotation/PlanarFreehandContourSegmentationTool.ts +30 -0
  231. package/src/tools/annotation/PlanarFreehandROITool.ts +153 -187
  232. package/src/tools/annotation/ProbeTool.ts +1 -1
  233. package/src/tools/annotation/RectangleROITool.ts +4 -3
  234. package/src/tools/annotation/SplineContourSegmentationTool.ts +28 -0
  235. package/src/tools/annotation/SplineROITool.ts +172 -282
  236. package/src/tools/annotation/planarFreehandROITool/closedContourEditLoop.ts +7 -5
  237. package/src/tools/annotation/planarFreehandROITool/drawLoop.ts +4 -4
  238. package/src/tools/annotation/planarFreehandROITool/findOpenUShapedContourVectorToPeak.ts +3 -1
  239. package/src/tools/annotation/planarFreehandROITool/openContourEditLoop.ts +12 -9
  240. package/src/tools/annotation/planarFreehandROITool/openContourEndEditLoop.ts +5 -2
  241. package/src/tools/annotation/planarFreehandROITool/renderMethods.ts +19 -14
  242. package/src/tools/base/AnnotationTool.ts +35 -0
  243. package/src/tools/base/ContourBaseTool.ts +226 -0
  244. package/src/tools/base/ContourSegmentationBaseTool.ts +276 -0
  245. package/src/tools/displayTools/Contour/contourDisplay.ts +1 -0
  246. package/src/tools/index.ts +6 -0
  247. package/src/types/ContourAnnotation.ts +13 -0
  248. package/src/types/ContourSegmentationAnnotation.ts +14 -0
  249. package/src/types/ContourTypes.ts +8 -1
  250. package/src/types/SegmentationStateTypes.ts +1 -1
  251. package/src/types/ToolSpecificAnnotationTypes.ts +17 -53
  252. package/src/types/index.ts +12 -0
@@ -0,0 +1,276 @@
1
+ import { utilities } from '@cornerstonejs/core';
2
+ import {
3
+ Annotation,
4
+ EventTypes,
5
+ PublicToolProps,
6
+ ToolProps,
7
+ } from '../../types';
8
+ import {
9
+ config as segmentationConfig,
10
+ state as segmentationState,
11
+ segmentLocking,
12
+ segmentIndex as segmentIndexController,
13
+ activeSegmentation,
14
+ } from '../../stateManagement/segmentation';
15
+ import { ContourSegmentationAnnotation } from '../../types/ContourSegmentationAnnotation';
16
+ import { StyleSpecifier } from '../../types/AnnotationStyle';
17
+ import { SegmentationRepresentations } from '../../enums';
18
+ import ContourBaseTool from './ContourBaseTool';
19
+
20
+ /**
21
+ * A base contour segmentation class responsible for rendering, registering
22
+ * and unregistering contour segmentation annotations.
23
+ */
24
+ abstract class ContourSegmentationBaseTool extends ContourBaseTool {
25
+ constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps) {
26
+ super(toolProps, defaultToolProps);
27
+ }
28
+
29
+ /**
30
+ * Allow children classes inherit from this one and disable contour segmentation
31
+ * behavior and children classes shall work like a normal contour instance which
32
+ * is useful for "hybrid" classes such as splineROI/splineSeg, livewire/livewireSeg,
33
+ * freehandROI/freehandSeg. When this method returns false:
34
+ * - contour segmentation data is not added to new annotations
35
+ * - annotations are not registered/unregistered as segmentations
36
+ * - annotation style shall not contain any segmentation style
37
+ * @returns True if it is a contour segmentation class or false otherwise
38
+ */
39
+ protected isContourSegmentationTool(): boolean {
40
+ return true;
41
+ }
42
+
43
+ protected createAnnotation(evt: EventTypes.InteractionEventType): Annotation {
44
+ const { toolGroupId } = this;
45
+ const contourAnnotation = super.createAnnotation(evt);
46
+
47
+ if (!this.isContourSegmentationTool()) {
48
+ return contourAnnotation;
49
+ }
50
+
51
+ const activeSegmentationRepresentation =
52
+ activeSegmentation.getActiveSegmentationRepresentation(toolGroupId);
53
+
54
+ if (!activeSegmentationRepresentation) {
55
+ throw new Error(
56
+ 'No active segmentation detected, create one before using scissors tool'
57
+ );
58
+ }
59
+
60
+ const { type: segmentationType } = activeSegmentationRepresentation;
61
+
62
+ if (segmentationType !== SegmentationRepresentations.Contour) {
63
+ throw new Error(`A contour segmentation must be active`);
64
+ }
65
+
66
+ const { segmentationId, segmentationRepresentationUID } =
67
+ activeSegmentationRepresentation;
68
+ const segmentIndex =
69
+ segmentIndexController.getActiveSegmentIndex(segmentationId);
70
+
71
+ return <ContourSegmentationAnnotation>utilities.deepMerge(
72
+ contourAnnotation,
73
+ {
74
+ data: {
75
+ segmentation: {
76
+ segmentationId,
77
+ segmentIndex,
78
+ segmentationRepresentationUID,
79
+ },
80
+ },
81
+ }
82
+ );
83
+ }
84
+
85
+ protected addAnnotation(
86
+ annotation: Annotation,
87
+ element: HTMLDivElement
88
+ ): string {
89
+ const annotationUID = super.addAnnotation(annotation, element);
90
+
91
+ if (this.isContourSegmentationTool()) {
92
+ this._registerContourSegmentationAnnotation(
93
+ annotation as ContourSegmentationAnnotation
94
+ );
95
+ }
96
+
97
+ return annotationUID;
98
+ }
99
+
100
+ /**
101
+ * Unregister the segmentation when the annotation is canceled
102
+ * @param annotation - Contour segmentation annotation
103
+ */
104
+ protected cancelAnnotation(annotation: Annotation): void {
105
+ if (this.isContourSegmentationTool()) {
106
+ this._unregisterContourSegmentationAnnotation(
107
+ annotation as ContourSegmentationAnnotation
108
+ );
109
+ }
110
+
111
+ super.cancelAnnotation(annotation);
112
+ }
113
+
114
+ /**
115
+ * Get the annotation style that may or may not be merged with segmentation
116
+ * style so that it can be used by ROI and contour segmentation annotations
117
+ * when rendered on a canvas or svg layer.
118
+ *
119
+ * Segmentation style shall be a combination of four different configurations
120
+ * from different levels (global, toolGroup, segmentation and segment) and it
121
+ * shall not be used when isContourSegmentationTool() is overwritten and changed
122
+ * by a child class to return `false` when that class should work only as an ROI.
123
+ */
124
+ protected getAnnotationStyle(context: {
125
+ annotation: Annotation;
126
+ styleSpecifier: StyleSpecifier;
127
+ }) {
128
+ const annotationStyle = super.getAnnotationStyle(context);
129
+
130
+ if (!this.isContourSegmentationTool()) {
131
+ return annotationStyle;
132
+ }
133
+
134
+ const contourSegmentationStyle = this._getContourSegmentationStyle(context);
135
+
136
+ return utilities.deepMerge(annotationStyle, contourSegmentationStyle);
137
+ }
138
+
139
+ /**
140
+ * Return the annotation style based on global, toolGroup, segmentation
141
+ * and segment segmentation configurations.
142
+ */
143
+ private _getContourSegmentationStyle(context: {
144
+ annotation: Annotation;
145
+ styleSpecifier: StyleSpecifier;
146
+ }): Record<string, any> {
147
+ const { toolGroupId } = this;
148
+ const annotation = context.annotation as ContourSegmentationAnnotation;
149
+ const { segmentationRepresentationUID, segmentationId, segmentIndex } =
150
+ annotation.data.segmentation;
151
+ const segmentationRepresentation =
152
+ segmentationState.getSegmentationRepresentationByUID(
153
+ toolGroupId,
154
+ segmentationRepresentationUID
155
+ );
156
+
157
+ const { active } = segmentationRepresentation;
158
+ const segmentsLocked = segmentLocking.getLockedSegments(segmentationId);
159
+ const annotationLocked = segmentsLocked.includes(segmentIndex as never);
160
+
161
+ const segmentColor = segmentationConfig.color.getColorForSegmentIndex(
162
+ toolGroupId,
163
+ segmentationRepresentationUID,
164
+ segmentIndex
165
+ );
166
+
167
+ const segmentationVisible =
168
+ segmentationConfig.visibility.getSegmentationVisibility(
169
+ toolGroupId,
170
+ segmentationRepresentationUID
171
+ );
172
+
173
+ const globalConfig = segmentationConfig.getGlobalConfig();
174
+
175
+ const toolGroupConfig =
176
+ segmentationConfig.getToolGroupSpecificConfig(toolGroupId);
177
+
178
+ const segmentationRepresentationConfig =
179
+ segmentationConfig.getSegmentationRepresentationSpecificConfig(
180
+ toolGroupId,
181
+ segmentationRepresentationUID
182
+ );
183
+
184
+ const segmentConfig = segmentationConfig.getSegmentSpecificConfig(
185
+ toolGroupId,
186
+ segmentationRepresentationUID,
187
+ segmentIndex
188
+ );
189
+
190
+ const segmentVisible = segmentationConfig.visibility.getSegmentVisibility(
191
+ toolGroupId,
192
+ segmentationRepresentationUID,
193
+ segmentIndex
194
+ );
195
+
196
+ // Merge the configurations from different levels based on its precedence
197
+ const mergedConfig = Object.assign(
198
+ {},
199
+ globalConfig?.representations?.CONTOUR ?? {},
200
+ toolGroupConfig?.representations?.CONTOUR ?? {},
201
+ segmentationRepresentationConfig?.CONTOUR ?? {},
202
+ segmentConfig?.CONTOUR ?? {}
203
+ );
204
+
205
+ let lineWidth = 1;
206
+ let lineDash = undefined;
207
+ let lineOpacity = 1;
208
+ let fillOpacity = 0;
209
+
210
+ if (active) {
211
+ lineWidth = mergedConfig.outlineWidthActive ?? lineWidth;
212
+ lineDash = mergedConfig.outlineDashActive ?? lineDash;
213
+ lineOpacity = mergedConfig.outlineOpacity ?? lineOpacity;
214
+ fillOpacity = mergedConfig.fillAlpha ?? fillOpacity;
215
+ } else {
216
+ lineWidth = mergedConfig.outlineWidthInactive ?? lineWidth;
217
+ lineDash = mergedConfig.outlineDashInactive ?? lineDash;
218
+ lineOpacity = mergedConfig.outlineOpacityInactive ?? lineOpacity;
219
+ fillOpacity = mergedConfig.fillAlphaInactive ?? fillOpacity;
220
+ }
221
+
222
+ lineWidth = mergedConfig.renderOutline ? lineWidth : 0;
223
+ fillOpacity = mergedConfig.renderFill ? fillOpacity : 0;
224
+
225
+ const color = `rgba(${segmentColor[0]}, ${segmentColor[1]}, ${segmentColor[2]}, ${lineOpacity})`;
226
+ const fillColor = `rgb(${segmentColor[0]}, ${segmentColor[1]}, ${segmentColor[2]})`;
227
+
228
+ return {
229
+ color,
230
+ fillColor,
231
+ lineWidth,
232
+ fillOpacity,
233
+ lineDash,
234
+ textbox: {
235
+ color,
236
+ },
237
+ visibility: segmentationVisible && segmentVisible,
238
+ locked: annotationLocked,
239
+ };
240
+ }
241
+
242
+ private _registerContourSegmentationAnnotation(
243
+ annotation: ContourSegmentationAnnotation
244
+ ) {
245
+ const { segmentationId, segmentIndex } = annotation.data.segmentation;
246
+ const segmentation = segmentationState.getSegmentation(segmentationId);
247
+ const { annotationUIDsMap } = segmentation.representationData.CONTOUR;
248
+
249
+ let annotationsUIDsSet = annotationUIDsMap.get(segmentIndex);
250
+
251
+ if (!annotationsUIDsSet) {
252
+ annotationsUIDsSet = new Set();
253
+ annotationUIDsMap.set(segmentIndex, annotationsUIDsSet);
254
+ }
255
+
256
+ annotationsUIDsSet.add(annotation.annotationUID);
257
+ }
258
+
259
+ private _unregisterContourSegmentationAnnotation(
260
+ annotation: ContourSegmentationAnnotation
261
+ ) {
262
+ const { segmentationId, segmentIndex } = annotation.data.segmentation;
263
+ const segmentation = segmentationState.getSegmentation(segmentationId);
264
+ const { annotationUIDsMap } = segmentation.representationData.CONTOUR;
265
+ const annotationsUIDsSet = annotationUIDsMap.get(segmentIndex);
266
+
267
+ annotationsUIDsSet.delete(annotation.annotationUID);
268
+
269
+ // Delete segmentIndex Set if there is no more annotations
270
+ if (!annotationsUIDsSet.size) {
271
+ annotationUIDsMap.delete(segmentIndex);
272
+ }
273
+ }
274
+ }
275
+
276
+ export { ContourSegmentationBaseTool as default, ContourSegmentationBaseTool };
@@ -79,6 +79,7 @@ async function render(
79
79
  console.warn(
80
80
  `No contours found for segmentationId ${segmentationId}. Skipping render.`
81
81
  );
82
+ return;
82
83
  }
83
84
 
84
85
  // add the contour sets to the viewport
@@ -27,8 +27,11 @@ import RectangleROITool from './annotation/RectangleROITool';
27
27
  import EllipticalROITool from './annotation/EllipticalROITool';
28
28
  import CircleROITool from './annotation/CircleROITool';
29
29
  import SplineROITool from './annotation/SplineROITool';
30
+ import SplineContourSegmentationTool from './annotation/SplineContourSegmentationTool';
30
31
  import PlanarFreehandROITool from './annotation/PlanarFreehandROITool';
32
+ import PlanarFreehandContourSegmentationTool from './annotation/PlanarFreehandContourSegmentationTool';
31
33
  import LivewireContourTool from './annotation/LivewireContourTool';
34
+ import LivewireContourSegmentationTool from './annotation/LivewireContourSegmentationTool';
32
35
  import ArrowAnnotateTool from './annotation/ArrowAnnotateTool';
33
36
  import AngleTool from './annotation/AngleTool';
34
37
  import CobbAngleTool from './annotation/CobbAngleTool';
@@ -79,7 +82,9 @@ export {
79
82
  CircleROITool,
80
83
  SplineROITool,
81
84
  PlanarFreehandROITool,
85
+ PlanarFreehandContourSegmentationTool,
82
86
  LivewireContourTool,
87
+ LivewireContourSegmentationTool,
83
88
  ArrowAnnotateTool,
84
89
  AngleTool,
85
90
  CobbAngleTool,
@@ -93,6 +98,7 @@ export {
93
98
  SphereScissorsTool,
94
99
  RectangleROIThresholdTool,
95
100
  RectangleROIStartEndThresholdTool,
101
+ SplineContourSegmentationTool,
96
102
  BrushTool,
97
103
  MagnifyTool,
98
104
  AdvancedMagnifyTool,
@@ -0,0 +1,13 @@
1
+ import type { Types } from '@cornerstonejs/core';
2
+ import { Annotation } from './AnnotationTypes';
3
+
4
+ export type ContourAnnotationData = {
5
+ data: {
6
+ contour: {
7
+ polyline: Types.Point3[];
8
+ closed: boolean;
9
+ };
10
+ };
11
+ };
12
+
13
+ export type ContourAnnotation = Annotation & ContourAnnotationData;
@@ -0,0 +1,14 @@
1
+ import { ContourAnnotation } from './ContourAnnotation';
2
+
3
+ export type ContourSegmentationAnnotationData = {
4
+ data: {
5
+ segmentation: {
6
+ segmentationId: string;
7
+ segmentIndex: number;
8
+ segmentationRepresentationUID: string;
9
+ };
10
+ };
11
+ };
12
+
13
+ export type ContourSegmentationAnnotation = ContourAnnotation &
14
+ ContourSegmentationAnnotationData;
@@ -10,6 +10,10 @@ export type ContourConfig = {
10
10
  outlineOpacity?: number;
11
11
  /** alpha of outline for inactive segmentation */
12
12
  outlineOpacityInactive?: number;
13
+ /** dash style of the outline when segmentation is active */
14
+ outlineDashActive?: string;
15
+ /** dash style of the outline when segmentation is inactive */
16
+ outlineDashInactive?: string;
13
17
  /** outline visibility */
14
18
  renderOutline?: boolean;
15
19
  /** render fill */
@@ -30,5 +34,8 @@ export type ContourRenderingConfig = {
30
34
  export type ContourSegmentationData = {
31
35
  // Ids of the contourSets that are part of this segmentation
32
36
  // in the cache
33
- geometryIds: string[];
37
+ geometryIds?: string[];
38
+ // Ids of the annotations that are part of this segmentation
39
+ // grouped by segmentIndex
40
+ annotationUIDsMap?: Map<number, Set<string>>;
34
41
  };
@@ -256,7 +256,7 @@ export type SegmentationPublicInput = {
256
256
  segmentationId: string;
257
257
  representation: {
258
258
  type: Enums.SegmentationRepresentations;
259
- data:
259
+ data?:
260
260
  | LabelmapSegmentationData
261
261
  | ContourSegmentationData
262
262
  | SurfaceSegmentationData;
@@ -1,7 +1,8 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
2
  import { Annotation } from './AnnotationTypes';
3
3
  import { ISpline } from './';
4
- import { LivewirePath } from '../utilities/livewire/LiveWirePath';
4
+ import { ContourSegmentationAnnotationData } from './ContourSegmentationAnnotation';
5
+ import { ContourAnnotation } from './ContourAnnotation';
5
6
 
6
7
  interface ROICachedStats {
7
8
  [targetId: string]: {
@@ -119,29 +120,13 @@ export interface CircleROIAnnotation extends Annotation {
119
120
  };
120
121
  }
121
122
 
122
- export interface SplineROIAnnotation extends Annotation {
123
+ export type SplineROIAnnotation = ContourAnnotation & {
123
124
  data: {
124
125
  label?: string;
125
- handles: {
126
- points: Types.Point3[];
127
- activeHandleIndex: number | null;
128
- textBox?: {
129
- hasMoved: boolean;
130
- worldPosition: Types.Point3;
131
- worldBoundingBox: {
132
- topLeft: Types.Point3;
133
- topRight: Types.Point3;
134
- bottomLeft: Types.Point3;
135
- bottomRight: Types.Point3;
136
- };
137
- };
138
- };
139
126
  spline: {
140
127
  type: string;
141
128
  instance: ISpline;
142
129
  resolution: number;
143
- polyline: Types.Point3[];
144
- closed: boolean;
145
130
  };
146
131
  cachedStats?: {
147
132
  [targetId: string]: {
@@ -151,18 +136,19 @@ export interface SplineROIAnnotation extends Annotation {
151
136
  };
152
137
  };
153
138
  };
154
- }
139
+ };
155
140
 
156
- export interface LivewireContourAnnotation extends Annotation {
141
+ export type SplineContourSegmentationAnnotation = SplineROIAnnotation &
142
+ ContourSegmentationAnnotationData;
143
+
144
+ export type LivewireContourAnnotation = ContourAnnotation & {
157
145
  data: {
158
- polyline: Types.Point3[];
159
146
  label?: string;
160
- handles: {
161
- points: Types.Point3[];
162
- activeHandleIndex: number | null;
163
- };
164
147
  };
165
- }
148
+ };
149
+
150
+ export type LivewireContourSegmentationAnnotation = LivewireContourAnnotation &
151
+ ContourSegmentationAnnotationData;
166
152
 
167
153
  export interface EllipticalROIAnnotation extends Annotation {
168
154
  data: {
@@ -264,41 +250,19 @@ export interface RectangleROIStartEndThresholdAnnotation extends Annotation {
264
250
  };
265
251
  }
266
252
 
267
- export interface PlanarFreehandROIAnnotation extends Annotation {
268
- metadata: {
269
- cameraPosition?: Types.Point3;
270
- cameraFocalPoint?: Types.Point3;
271
- viewPlaneNormal?: Types.Point3;
272
- viewUp?: Types.Point3;
273
- annotationUID?: string;
274
- FrameOfReferenceUID: string;
275
- referencedImageId?: string;
276
- toolName: string;
277
- };
253
+ export type PlanarFreehandROIAnnotation = ContourAnnotation & {
278
254
  data: {
279
- polyline: Types.Point3[];
280
255
  label?: string;
281
256
  isOpenContour?: boolean;
282
257
  isOpenUShapeContour?: boolean;
283
258
  // Present if isOpenUShapeContour is true:
284
259
  openUShapeContourVectorToPeak?: Types.Point3[];
285
- handles: {
286
- points: Types.Point3[];
287
- activeHandleIndex: number | null;
288
- textBox: {
289
- hasMoved: boolean;
290
- worldPosition: Types.Point3;
291
- worldBoundingBox: {
292
- topLeft: Types.Point3;
293
- topRight: Types.Point3;
294
- bottomLeft: Types.Point3;
295
- bottomRight: Types.Point3;
296
- };
297
- };
298
- };
299
260
  cachedStats?: ROICachedStats;
300
261
  };
301
- }
262
+ };
263
+
264
+ export type PlanarFreehandContourSegmentationAnnotation =
265
+ PlanarFreehandROIAnnotation & ContourSegmentationAnnotationData;
302
266
 
303
267
  export interface ArrowAnnotation extends Annotation {
304
268
  data: {
@@ -4,6 +4,14 @@ import type {
4
4
  AnnotationState,
5
5
  GroupSpecificAnnotations,
6
6
  } from './AnnotationTypes';
7
+ import type {
8
+ ContourAnnotationData,
9
+ ContourAnnotation,
10
+ } from './ContourAnnotation';
11
+ import type {
12
+ ContourSegmentationAnnotationData,
13
+ ContourSegmentationAnnotation,
14
+ } from './ContourSegmentationAnnotation';
7
15
  import type * as EventTypes from './EventTypes';
8
16
  import type * as LabelmapTypes from './LabelmapTypes';
9
17
  import type IPoints from './IPoints';
@@ -79,6 +87,10 @@ export type {
79
87
  // AnnotationState
80
88
  Annotation,
81
89
  Annotations,
90
+ ContourAnnotationData,
91
+ ContourAnnotation,
92
+ ContourSegmentationAnnotationData,
93
+ ContourSegmentationAnnotation,
82
94
  BidirectionalData,
83
95
  CanvasCoordinates,
84
96
  IAnnotationManager,