@cornerstonejs/tools 2.0.0-beta.2 → 2.0.0-beta.3

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 (265) hide show
  1. package/dist/cjs/drawingSvg/getSvgDrawingHelper.js +1 -1
  2. package/dist/cjs/drawingSvg/getSvgDrawingHelper.js.map +1 -1
  3. package/dist/cjs/enums/Events.d.ts +1 -0
  4. package/dist/cjs/enums/Events.js +1 -0
  5. package/dist/cjs/enums/Events.js.map +1 -1
  6. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js +6 -1
  7. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
  8. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.d.ts +2 -0
  9. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js +41 -0
  10. package/dist/cjs/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js.map +1 -0
  11. package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts +3 -0
  12. package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +39 -0
  13. package/dist/cjs/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -0
  14. package/dist/cjs/eventListeners/mouse/mouseDownListener.js +5 -1
  15. package/dist/cjs/eventListeners/mouse/mouseDownListener.js.map +1 -1
  16. package/dist/cjs/eventListeners/mouse/mouseMoveListener.js +5 -1
  17. package/dist/cjs/eventListeners/mouse/mouseMoveListener.js.map +1 -1
  18. package/dist/cjs/index.d.ts +2 -2
  19. package/dist/cjs/index.js +5 -2
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/store/ToolGroupManager/ToolGroup.d.ts +2 -0
  22. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +35 -0
  23. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  24. package/dist/cjs/synchronizers/callbacks/stackImageSyncCallback.js +1 -1
  25. package/dist/cjs/synchronizers/callbacks/stackImageSyncCallback.js.map +1 -1
  26. package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +36 -0
  27. package/dist/cjs/tools/AdvancedMagnifyTool.js +448 -0
  28. package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -0
  29. package/dist/cjs/tools/AdvancedMagnifyViewport.d.ts +76 -0
  30. package/dist/cjs/tools/AdvancedMagnifyViewport.js +352 -0
  31. package/dist/cjs/tools/AdvancedMagnifyViewport.js.map +1 -0
  32. package/dist/cjs/tools/AdvancedMagnifyViewportManager.d.ts +36 -0
  33. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js +133 -0
  34. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js.map +1 -0
  35. package/dist/cjs/tools/MagnifyTool.js +2 -2
  36. package/dist/cjs/tools/MagnifyTool.js.map +1 -1
  37. package/dist/cjs/tools/OrientationMarkerTool.d.ts +88 -0
  38. package/dist/cjs/tools/OrientationMarkerTool.js +193 -0
  39. package/dist/cjs/tools/OrientationMarkerTool.js.map +1 -0
  40. package/dist/cjs/tools/OverlayGridTool.d.ts +31 -0
  41. package/dist/cjs/tools/OverlayGridTool.js +170 -0
  42. package/dist/cjs/tools/OverlayGridTool.js.map +1 -0
  43. package/dist/cjs/tools/ReferenceLinesTool.d.ts +3 -0
  44. package/dist/cjs/tools/ReferenceLinesTool.js +71 -2
  45. package/dist/cjs/tools/ReferenceLinesTool.js.map +1 -1
  46. package/dist/cjs/tools/annotation/AngleTool.js +2 -1
  47. package/dist/cjs/tools/annotation/AngleTool.js.map +1 -1
  48. package/dist/cjs/tools/annotation/BidirectionalTool.js +1 -1
  49. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  50. package/dist/cjs/tools/annotation/CircleROITool.d.ts +1 -2
  51. package/dist/cjs/tools/annotation/CircleROITool.js +8 -8
  52. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  53. package/dist/cjs/tools/annotation/CobbAngleTool.d.ts +31 -5
  54. package/dist/cjs/tools/annotation/CobbAngleTool.js +268 -71
  55. package/dist/cjs/tools/annotation/CobbAngleTool.js.map +1 -1
  56. package/dist/cjs/tools/annotation/DragProbeTool.js +4 -3
  57. package/dist/cjs/tools/annotation/DragProbeTool.js.map +1 -1
  58. package/dist/cjs/tools/annotation/EllipticalROITool.d.ts +2 -3
  59. package/dist/cjs/tools/annotation/EllipticalROITool.js +20 -16
  60. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  61. package/dist/cjs/tools/annotation/LengthTool.js +1 -1
  62. package/dist/cjs/tools/annotation/LengthTool.js.map +1 -1
  63. package/dist/cjs/tools/annotation/PlanarFreehandROITool.d.ts +1 -2
  64. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +22 -9
  65. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  66. package/dist/cjs/tools/annotation/ProbeTool.d.ts +1 -2
  67. package/dist/cjs/tools/annotation/ProbeTool.js +10 -9
  68. package/dist/cjs/tools/annotation/ProbeTool.js.map +1 -1
  69. package/dist/cjs/tools/annotation/RectangleROITool.d.ts +1 -1
  70. package/dist/cjs/tools/annotation/RectangleROITool.js +9 -9
  71. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  72. package/dist/cjs/tools/base/AnnotationDisplayTool.js +4 -0
  73. package/dist/cjs/tools/base/AnnotationDisplayTool.js.map +1 -1
  74. package/dist/cjs/tools/base/AnnotationTool.d.ts +1 -1
  75. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  76. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js +3 -0
  77. package/dist/cjs/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  78. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
  79. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  80. package/dist/cjs/tools/index.d.ts +4 -1
  81. package/dist/cjs/tools/index.js +7 -1
  82. package/dist/cjs/tools/index.js.map +1 -1
  83. package/dist/cjs/types/EventTypes.d.ts +9 -1
  84. package/dist/cjs/types/IToolGroup.d.ts +3 -0
  85. package/dist/cjs/types/ToolAction.d.ts +8 -0
  86. package/dist/cjs/types/ToolAction.js +3 -0
  87. package/dist/cjs/types/ToolAction.js.map +1 -0
  88. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +55 -0
  89. package/dist/cjs/types/index.d.ts +2 -1
  90. package/dist/cjs/utilities/getModalityUnit.js +5 -2
  91. package/dist/cjs/utilities/getModalityUnit.js.map +1 -1
  92. package/dist/cjs/utilities/index.d.ts +2 -2
  93. package/dist/cjs/utilities/index.js +4 -3
  94. package/dist/cjs/utilities/index.js.map +1 -1
  95. package/dist/cjs/utilities/math/angle/angleBetweenLines.d.ts +3 -1
  96. package/dist/cjs/utilities/math/angle/angleBetweenLines.js +18 -1
  97. package/dist/cjs/utilities/math/angle/angleBetweenLines.js.map +1 -1
  98. package/dist/cjs/utilities/stackPrefetch/index.d.ts +3 -2
  99. package/dist/cjs/utilities/stackPrefetch/index.js +8 -6
  100. package/dist/cjs/utilities/stackPrefetch/index.js.map +1 -1
  101. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.d.ts +16 -0
  102. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js +227 -0
  103. package/dist/cjs/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -0
  104. package/dist/cjs/utilities/stackPrefetch/stackPrefetch.d.ts +7 -1
  105. package/dist/cjs/utilities/stackPrefetch/stackPrefetch.js +23 -93
  106. package/dist/cjs/utilities/stackPrefetch/stackPrefetch.js.map +1 -1
  107. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.d.ts +14 -0
  108. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js +85 -0
  109. package/dist/cjs/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -0
  110. package/dist/esm/drawingSvg/getSvgDrawingHelper.js +1 -1
  111. package/dist/esm/drawingSvg/getSvgDrawingHelper.js.map +1 -1
  112. package/dist/esm/enums/Events.d.ts +1 -0
  113. package/dist/esm/enums/Events.js +1 -0
  114. package/dist/esm/enums/Events.js.map +1 -1
  115. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js +6 -1
  116. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDown.js.map +1 -1
  117. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.d.ts +2 -0
  118. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js +35 -0
  119. package/dist/esm/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.js.map +1 -0
  120. package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.d.ts +3 -0
  121. package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js +32 -0
  122. package/dist/esm/eventDispatchers/shared/getToolsWithActionsForMouseEvent.js.map +1 -0
  123. package/dist/esm/eventListeners/mouse/mouseDownListener.js +5 -1
  124. package/dist/esm/eventListeners/mouse/mouseDownListener.js.map +1 -1
  125. package/dist/esm/eventListeners/mouse/mouseMoveListener.js +5 -1
  126. package/dist/esm/eventListeners/mouse/mouseMoveListener.js.map +1 -1
  127. package/dist/esm/index.d.ts +2 -2
  128. package/dist/esm/index.js +2 -2
  129. package/dist/esm/index.js.map +1 -1
  130. package/dist/esm/store/ToolGroupManager/ToolGroup.d.ts +2 -0
  131. package/dist/esm/store/ToolGroupManager/ToolGroup.js +35 -1
  132. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  133. package/dist/esm/synchronizers/callbacks/stackImageSyncCallback.js +1 -1
  134. package/dist/esm/synchronizers/callbacks/stackImageSyncCallback.js.map +1 -1
  135. package/dist/esm/tools/AdvancedMagnifyTool.d.ts +36 -0
  136. package/dist/esm/tools/AdvancedMagnifyTool.js +440 -0
  137. package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -0
  138. package/dist/esm/tools/AdvancedMagnifyViewport.d.ts +76 -0
  139. package/dist/esm/tools/AdvancedMagnifyViewport.js +346 -0
  140. package/dist/esm/tools/AdvancedMagnifyViewport.js.map +1 -0
  141. package/dist/esm/tools/AdvancedMagnifyViewportManager.d.ts +36 -0
  142. package/dist/esm/tools/AdvancedMagnifyViewportManager.js +128 -0
  143. package/dist/esm/tools/AdvancedMagnifyViewportManager.js.map +1 -0
  144. package/dist/esm/tools/MagnifyTool.js +2 -2
  145. package/dist/esm/tools/MagnifyTool.js.map +1 -1
  146. package/dist/esm/tools/OrientationMarkerTool.d.ts +88 -0
  147. package/dist/esm/tools/OrientationMarkerTool.js +185 -0
  148. package/dist/esm/tools/OrientationMarkerTool.js.map +1 -0
  149. package/dist/esm/tools/OverlayGridTool.d.ts +31 -0
  150. package/dist/esm/tools/OverlayGridTool.js +165 -0
  151. package/dist/esm/tools/OverlayGridTool.js.map +1 -0
  152. package/dist/esm/tools/ReferenceLinesTool.d.ts +3 -0
  153. package/dist/esm/tools/ReferenceLinesTool.js +71 -2
  154. package/dist/esm/tools/ReferenceLinesTool.js.map +1 -1
  155. package/dist/esm/tools/annotation/AngleTool.js +2 -1
  156. package/dist/esm/tools/annotation/AngleTool.js.map +1 -1
  157. package/dist/esm/tools/annotation/BidirectionalTool.js +1 -1
  158. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  159. package/dist/esm/tools/annotation/CircleROITool.d.ts +1 -2
  160. package/dist/esm/tools/annotation/CircleROITool.js +8 -8
  161. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  162. package/dist/esm/tools/annotation/CobbAngleTool.d.ts +31 -5
  163. package/dist/esm/tools/annotation/CobbAngleTool.js +275 -72
  164. package/dist/esm/tools/annotation/CobbAngleTool.js.map +1 -1
  165. package/dist/esm/tools/annotation/DragProbeTool.js +4 -3
  166. package/dist/esm/tools/annotation/DragProbeTool.js.map +1 -1
  167. package/dist/esm/tools/annotation/EllipticalROITool.d.ts +2 -3
  168. package/dist/esm/tools/annotation/EllipticalROITool.js +20 -16
  169. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  170. package/dist/esm/tools/annotation/LengthTool.js +1 -1
  171. package/dist/esm/tools/annotation/LengthTool.js.map +1 -1
  172. package/dist/esm/tools/annotation/PlanarFreehandROITool.d.ts +1 -2
  173. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +22 -9
  174. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  175. package/dist/esm/tools/annotation/ProbeTool.d.ts +1 -2
  176. package/dist/esm/tools/annotation/ProbeTool.js +10 -9
  177. package/dist/esm/tools/annotation/ProbeTool.js.map +1 -1
  178. package/dist/esm/tools/annotation/RectangleROITool.d.ts +1 -1
  179. package/dist/esm/tools/annotation/RectangleROITool.js +9 -9
  180. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  181. package/dist/esm/tools/base/AnnotationDisplayTool.js +3 -0
  182. package/dist/esm/tools/base/AnnotationDisplayTool.js.map +1 -1
  183. package/dist/esm/tools/base/AnnotationTool.d.ts +1 -1
  184. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  185. package/dist/esm/tools/displayTools/Contour/contourDisplay.js +4 -1
  186. package/dist/esm/tools/displayTools/Contour/contourDisplay.js.map +1 -1
  187. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +1 -1
  188. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  189. package/dist/esm/tools/index.d.ts +4 -1
  190. package/dist/esm/tools/index.js +4 -1
  191. package/dist/esm/tools/index.js.map +1 -1
  192. package/dist/esm/types/EventTypes.d.ts +9 -1
  193. package/dist/esm/types/IToolGroup.d.ts +3 -0
  194. package/dist/esm/types/ToolAction.d.ts +8 -0
  195. package/dist/esm/types/ToolAction.js +2 -0
  196. package/dist/esm/types/ToolAction.js.map +1 -0
  197. package/dist/esm/types/ToolSpecificAnnotationTypes.d.ts +55 -0
  198. package/dist/esm/types/index.d.ts +2 -1
  199. package/dist/esm/utilities/getModalityUnit.js +5 -2
  200. package/dist/esm/utilities/getModalityUnit.js.map +1 -1
  201. package/dist/esm/utilities/index.d.ts +2 -2
  202. package/dist/esm/utilities/index.js +2 -2
  203. package/dist/esm/utilities/index.js.map +1 -1
  204. package/dist/esm/utilities/math/angle/angleBetweenLines.d.ts +3 -1
  205. package/dist/esm/utilities/math/angle/angleBetweenLines.js +19 -2
  206. package/dist/esm/utilities/math/angle/angleBetweenLines.js.map +1 -1
  207. package/dist/esm/utilities/stackPrefetch/index.d.ts +3 -2
  208. package/dist/esm/utilities/stackPrefetch/index.js +3 -2
  209. package/dist/esm/utilities/stackPrefetch/index.js.map +1 -1
  210. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.d.ts +16 -0
  211. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +220 -0
  212. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js.map +1 -0
  213. package/dist/esm/utilities/stackPrefetch/stackPrefetch.d.ts +7 -1
  214. package/dist/esm/utilities/stackPrefetch/stackPrefetch.js +12 -79
  215. package/dist/esm/utilities/stackPrefetch/stackPrefetch.js.map +1 -1
  216. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.d.ts +14 -0
  217. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +77 -0
  218. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js.map +1 -0
  219. package/dist/umd/index.js +1 -1
  220. package/dist/umd/index.js.map +1 -1
  221. package/package.json +3 -3
  222. package/src/drawingSvg/getSvgDrawingHelper.ts +4 -1
  223. package/src/enums/Events.ts +9 -0
  224. package/src/eventDispatchers/mouseEventHandlers/mouseDown.ts +11 -2
  225. package/src/eventDispatchers/mouseEventHandlers/mouseDownAnnotationAction.ts +72 -0
  226. package/src/eventDispatchers/shared/getToolsWithActionsForMouseEvent.ts +66 -0
  227. package/src/eventListeners/mouse/mouseDownListener.ts +7 -1
  228. package/src/eventListeners/mouse/mouseMoveListener.ts +7 -1
  229. package/src/index.ts +6 -0
  230. package/src/store/ToolGroupManager/ToolGroup.ts +79 -2
  231. package/src/synchronizers/callbacks/stackImageSyncCallback.ts +1 -1
  232. package/src/tools/AdvancedMagnifyTool.ts +725 -0
  233. package/src/tools/AdvancedMagnifyViewport.ts +624 -0
  234. package/src/tools/AdvancedMagnifyViewportManager.ts +291 -0
  235. package/src/tools/MagnifyTool.ts +2 -2
  236. package/src/tools/OrientationMarkerTool.ts +235 -0
  237. package/src/tools/OverlayGridTool.ts +357 -0
  238. package/src/tools/ReferenceLinesTool.ts +131 -3
  239. package/src/tools/annotation/AngleTool.ts +4 -1
  240. package/src/tools/annotation/BidirectionalTool.ts +1 -1
  241. package/src/tools/annotation/CircleROITool.ts +13 -20
  242. package/src/tools/annotation/CobbAngleTool.ts +422 -99
  243. package/src/tools/annotation/DragProbeTool.ts +6 -13
  244. package/src/tools/annotation/EllipticalROITool.ts +28 -29
  245. package/src/tools/annotation/LengthTool.ts +1 -1
  246. package/src/tools/annotation/PlanarFreehandROITool.ts +35 -20
  247. package/src/tools/annotation/ProbeTool.ts +17 -30
  248. package/src/tools/annotation/RectangleROITool.ts +15 -19
  249. package/src/tools/base/AnnotationDisplayTool.ts +4 -0
  250. package/src/tools/base/AnnotationTool.ts +2 -1
  251. package/src/tools/displayTools/Contour/contourDisplay.ts +8 -0
  252. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +1 -1
  253. package/src/tools/index.ts +6 -0
  254. package/src/types/EventTypes.ts +23 -0
  255. package/src/types/IToolGroup.ts +7 -0
  256. package/src/types/ToolAction.ts +54 -0
  257. package/src/types/ToolSpecificAnnotationTypes.ts +58 -0
  258. package/src/types/index.ts +2 -0
  259. package/src/utilities/getModalityUnit.ts +8 -2
  260. package/src/utilities/index.ts +2 -1
  261. package/src/utilities/math/angle/angleBetweenLines.ts +39 -9
  262. package/src/utilities/stackPrefetch/index.ts +3 -7
  263. package/src/utilities/stackPrefetch/stackContextPrefetch.ts +380 -0
  264. package/src/utilities/stackPrefetch/stackPrefetch.ts +29 -151
  265. package/src/utilities/stackPrefetch/stackPrefetchUtils.ts +114 -0
@@ -78,6 +78,18 @@ export interface LengthAnnotation extends Annotation {
78
78
  };
79
79
  }
80
80
 
81
+ export interface AdvancedMagnifyAnnotation extends Annotation {
82
+ data: {
83
+ zoomFactor: number;
84
+ sourceViewportId: string;
85
+ magnifyViewportId: string;
86
+ handles: {
87
+ points: Types.Point3[]; // [top, right, bottom, left]
88
+ activeHandleIndex: number | null;
89
+ };
90
+ };
91
+ }
92
+
81
93
  export interface CircleROIAnnotation extends Annotation {
82
94
  data: {
83
95
  handles: {
@@ -261,6 +273,7 @@ export interface ArrowAnnotation extends Annotation {
261
273
  };
262
274
  };
263
275
  }
276
+
264
277
  export interface AngleAnnotation extends Annotation {
265
278
  data: {
266
279
  handles: {
@@ -286,6 +299,51 @@ export interface AngleAnnotation extends Annotation {
286
299
  };
287
300
  }
288
301
 
302
+ export interface CobbAngleAnnotation extends Annotation {
303
+ data: {
304
+ handles: {
305
+ points: Types.Point3[];
306
+ activeHandleIndex: number | null;
307
+ textBox: {
308
+ hasMoved: boolean;
309
+ worldPosition: Types.Point3;
310
+ worldBoundingBox: {
311
+ topLeft: Types.Point3;
312
+ topRight: Types.Point3;
313
+ bottomLeft: Types.Point3;
314
+ bottomRight: Types.Point3;
315
+ };
316
+ };
317
+ };
318
+ label: string;
319
+ cachedStats: {
320
+ [targetId: string]: {
321
+ angle: number;
322
+ arc1Angle: number;
323
+ arc2Angle: number;
324
+ points: {
325
+ world: {
326
+ arc1Start: Types.Point3;
327
+ arc1End: Types.Point3;
328
+ arc2Start: Types.Point3;
329
+ arc2End: Types.Point3;
330
+ arc1Angle: number;
331
+ arc2Angle: number;
332
+ };
333
+ canvas: {
334
+ arc1Start: Types.Point2;
335
+ arc1End: Types.Point2;
336
+ arc2Start: Types.Point2;
337
+ arc2End: Types.Point2;
338
+ arc1Angle: number;
339
+ arc2Angle: number;
340
+ };
341
+ };
342
+ };
343
+ };
344
+ };
345
+ }
346
+
289
347
  export interface ReferenceCursor extends Annotation {
290
348
  data: {
291
349
  handles: {
@@ -21,6 +21,7 @@ import type * as AnnotationStyle from './AnnotationStyle';
21
21
  import type ToolHandle from './ToolHandle';
22
22
  import type { AnnotationHandle, TextBoxHandle } from './ToolHandle';
23
23
  import type InteractionTypes from './InteractionTypes';
24
+ import type ToolAction from './ToolAction';
24
25
  import type {
25
26
  ToolProps,
26
27
  PublicToolProps,
@@ -84,6 +85,7 @@ export type {
84
85
  SetToolBindingsType,
85
86
  ToolOptionsType,
86
87
  InteractionTypes,
88
+ ToolAction,
87
89
  //
88
90
  IToolGroup,
89
91
  IToolClassReference,
@@ -28,8 +28,14 @@ function _handlePTModality(imageId: string, options: ModalityUnitOptions) {
28
28
  return 'SUV';
29
29
  }
30
30
 
31
- const petSeriesModule = metaData.get('petSeriesModule', imageId);
32
- return petSeriesModule?.units || 'unitless';
31
+ const generalSeriesModule = metaData.get('generalSeriesModule', imageId);
32
+
33
+ // it might be possible that the referenceImageId is not the one
34
+ // that is being displayed. So we need to get the modality from imageId again
35
+ if (generalSeriesModule?.modality === 'PT') {
36
+ const petSeriesModule = metaData.get('petSeriesModule', imageId);
37
+ return petSeriesModule?.units || 'unitless';
38
+ }
33
39
  }
34
40
 
35
41
  export { getModalityUnit, ModalityUnitOptions };
@@ -29,7 +29,7 @@ import * as cine from './cine';
29
29
  import * as boundingBox from './boundingBox';
30
30
  import * as planarFreehandROITool from './planarFreehandROITool';
31
31
  import * as rectangleROITool from './rectangleROITool';
32
- import * as stackPrefetch from './stackPrefetch';
32
+ import { stackPrefetch, stackContextPrefetch } from './stackPrefetch';
33
33
  import * as viewport from './viewport';
34
34
  import * as touch from './touch';
35
35
  import * as dynamicVolume from './dynamicVolume';
@@ -65,6 +65,7 @@ export {
65
65
  rectangleROITool,
66
66
  planarFreehandROITool,
67
67
  stackPrefetch,
68
+ stackContextPrefetch,
68
69
  scroll,
69
70
  roundNumber,
70
71
  };
@@ -1,17 +1,14 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
- import { vec3 } from 'gl-matrix';
2
+ import { vec2, vec3 } from 'gl-matrix';
3
3
 
4
- type Line = [Types.Point3, Types.Point3];
4
+ type Line2D = [Types.Point2, Types.Point2];
5
+ type Line3D = [Types.Point3, Types.Point3];
6
+ type Line = Line2D | Line3D;
5
7
 
6
8
  /**
7
- * It returns the angle between two lines in degrees.
8
- * The angle measured is that between the vectors
9
- * line1[1]->line1[0] AND line2[0]->line2[1].
10
- * @param line1 - Line = [p1, p2]
11
- * @param line2 - Line = [p3, p4]
12
- * @returns The angle between two lines in degrees.
9
+ * Calculates the angle between two 3D lines.
13
10
  */
14
- export default function angleBetweenLines(line1: Line, line2: Line): number {
11
+ function angleBetween3DLines(line1: Line3D, line2: Line3D): number {
15
12
  const [p1, p2] = line1;
16
13
  const [p3, p4] = line2;
17
14
 
@@ -29,3 +26,36 @@ export default function angleBetweenLines(line1: Line, line2: Line): number {
29
26
 
30
27
  return (radian * 180) / Math.PI;
31
28
  }
29
+
30
+ /**
31
+ * Calculates the angle between two 2D lines.
32
+ */
33
+ function angleBetween2DLines(line1: Line2D, line2: Line2D): number {
34
+ const [p1, p2] = line1;
35
+ const [p3, p4] = line2;
36
+
37
+ const v1 = vec2.sub(vec2.create(), p2, p1);
38
+ const v2 = vec2.sub(vec2.create(), p3, p4);
39
+
40
+ const dot = vec2.dot(v1, v2);
41
+ const v1Length = vec2.length(v1);
42
+ const v2Length = vec2.length(v2);
43
+
44
+ const cos = dot / (v1Length * v2Length);
45
+ return Math.acos(cos) * (180 / Math.PI);
46
+ }
47
+
48
+ /**
49
+ * Returns the angle between two lines in degrees.
50
+ * The angle measured is that between the vectors
51
+ * line1[1]->line1[0] AND line2[0]->line2[1].
52
+ * @param line1 - Line = [p1, p2]
53
+ * @param line2 - Line = [p3, p4]
54
+ * @returns The angle between two lines in degrees.
55
+ */
56
+ export default function angleBetweenLines(line1: Line, line2: Line): number {
57
+ const is3D = line1[0].length === 3;
58
+ return is3D
59
+ ? angleBetween3DLines(line1 as Line3D, line2 as Line3D)
60
+ : angleBetween2DLines(line1 as Line2D, line2 as Line2D);
61
+ }
@@ -1,8 +1,4 @@
1
- import {
2
- enable,
3
- disable,
4
- setConfiguration,
5
- getConfiguration,
6
- } from './stackPrefetch';
1
+ import stackPrefetch from './stackPrefetch';
2
+ import stackContextPrefetch from './stackContextPrefetch';
7
3
 
8
- export { enable, disable, setConfiguration, getConfiguration };
4
+ export { stackPrefetch, stackContextPrefetch };
@@ -0,0 +1,380 @@
1
+ import {
2
+ imageLoader,
3
+ Enums,
4
+ eventTarget,
5
+ imageLoadPoolManager,
6
+ cache,
7
+ getConfiguration as getCoreConfiguration,
8
+ } from '@cornerstonejs/core';
9
+ import { addToolState, getToolState } from './state';
10
+ import {
11
+ getStackData,
12
+ requestType,
13
+ priority,
14
+ clearFromImageIds,
15
+ getPromiseRemovedHandler,
16
+ } from './stackPrefetchUtils';
17
+ import roundNumber from '../roundNumber';
18
+
19
+ let configuration = {
20
+ maxImagesToPrefetch: Infinity,
21
+ // Fetch up to 2 image before and after
22
+ minBefore: 2,
23
+ maxAfter: 2,
24
+ // Increment the cache size by 10 images
25
+ directionExtraImages: 10,
26
+ preserveExistingPool: false,
27
+ };
28
+
29
+ let resetPrefetchTimeout;
30
+ // Starting the prefetch quickly isn't an issue as the main image is already being
31
+ // loaded, so a 5 ms prefetch delay is fine
32
+ const resetPrefetchDelay = 5;
33
+
34
+ /**
35
+ * Call this to enable stack context sensitive prefetch. Should be called
36
+ * before stack data is set in order to start prefetch after load first image.
37
+ * This will add a STACK_NEW_IMAGE to detect when a new image is displayed, and then
38
+ * update the prefetch stack. The context sensitive prefetch reacts to the
39
+ * initial display, or significant moves, the already loaded images, the
40
+ * cache size and the direction of navigation. The behaviour is:
41
+ *
42
+ * 1. On navigating to a new image initially, or one that is at a different position:
43
+ * * Fetch the next/previous 2 images
44
+ * 2. If the user is navigating forward/backward by less than 5 images, then
45
+ * * Prefetch additional images in the direction of navigation, up to 100
46
+ * 3. If all the images in a given prefetch have completed, then:
47
+ * * Use the last prefetched image size as an image size for the stack
48
+ * * Fetch up to 1/4 of the cache size images near the current image
49
+ *
50
+ * This is designed to:
51
+ * * Get nearby images immediately so that they are available for navigation
52
+ * * Under the assumption that users might click and view an image, then
53
+ * navigate to next/previous image to see the exact image they want
54
+ * * Not interfere with loading other viewports if they are still loading
55
+ * * Load priority is prefetch, and minimal images are requested initially
56
+ * * Load an entire series if it will fit in memory
57
+ * * Allows navigating to other parts of the series and display images immediately
58
+ * * Have images available for CINE/navigation in one direction even when
59
+ * there is more image data than will fit in memory.
60
+ * * Up to 100 images in the direction of travel will be prefetched
61
+ *
62
+ * @param element - to prefetch on
63
+ */
64
+ const enable = (element): void => {
65
+ const stack = getStackData(element);
66
+
67
+ if (!stack || !stack.imageIds || stack.imageIds.length === 0) {
68
+ console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
69
+ return;
70
+ }
71
+
72
+ updateToolState(element);
73
+
74
+ prefetch(element);
75
+
76
+ element.removeEventListener(Enums.Events.STACK_NEW_IMAGE, onImageUpdated);
77
+ element.addEventListener(Enums.Events.STACK_NEW_IMAGE, onImageUpdated);
78
+
79
+ const promiseRemovedHandler = getPromiseRemovedHandler(element);
80
+
81
+ eventTarget.removeEventListener(
82
+ Enums.Events.IMAGE_CACHE_IMAGE_REMOVED,
83
+ promiseRemovedHandler
84
+ );
85
+ eventTarget.addEventListener(
86
+ Enums.Events.IMAGE_CACHE_IMAGE_REMOVED,
87
+ promiseRemovedHandler
88
+ );
89
+ };
90
+
91
+ function prefetch(element) {
92
+ const stack = getStackData(element);
93
+ if (!stack?.imageIds?.length) {
94
+ console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
95
+ return;
96
+ }
97
+
98
+ // Get the stackPrefetch tool data
99
+ const stackPrefetchData = getToolState(element);
100
+
101
+ if (!stackPrefetchData) {
102
+ return;
103
+ }
104
+
105
+ const stackPrefetch = stackPrefetchData || {};
106
+
107
+ // If all the requests are complete, disable the stackPrefetch tool
108
+ stackPrefetch.enabled &&= stackPrefetch.indicesToRequest?.length;
109
+
110
+ // Make sure the tool is still enabled
111
+ if (stackPrefetch.enabled === false) {
112
+ return;
113
+ }
114
+
115
+ // Remove an imageIdIndex from the list of indices to request
116
+ // This fires when the individual image loading deferred is resolved
117
+ function removeFromList(imageIdIndex) {
118
+ const index = stackPrefetch.indicesToRequest.indexOf(imageIdIndex);
119
+
120
+ if (index > -1) {
121
+ // Don't remove last element if imageIdIndex not found
122
+ stackPrefetch.indicesToRequest.splice(index, 1);
123
+ }
124
+ }
125
+
126
+ // Remove all already cached images from the
127
+ // IndicesToRequest array.
128
+ const indicesToRequestCopy = stackPrefetch.indicesToRequest.slice();
129
+ const { currentImageIdIndex } = stack;
130
+
131
+ indicesToRequestCopy.forEach((imageIdIndex) => {
132
+ const imageId = stack.imageIds[imageIdIndex];
133
+
134
+ if (!imageId) {
135
+ return;
136
+ }
137
+
138
+ const distance = Math.abs(currentImageIdIndex - imageIdIndex);
139
+ // For nearby objects, ensure the last accessed time is updated
140
+ // by using getImageLoadObject.
141
+ // For more distant objects, just check if available, but dont
142
+ // change the access time.
143
+ // This allows throwing data that hasn't been accessed and is not
144
+ // nearby.
145
+ const imageCached =
146
+ distance < 6
147
+ ? cache.getImageLoadObject(imageId)
148
+ : cache.isLoaded(imageId);
149
+
150
+ if (imageCached) {
151
+ // Already in cache
152
+ removeFromList(imageIdIndex);
153
+ }
154
+ });
155
+
156
+ // Stop here if there are no images left to request
157
+ // After those in the cache have been removed
158
+ if (!stackPrefetch.indicesToRequest.length) {
159
+ return;
160
+ }
161
+
162
+ // Clear the requestPool of prefetch requests, if needed.
163
+ if (!configuration.preserveExistingPool) {
164
+ imageLoadPoolManager.filterRequests(clearFromImageIds(stack));
165
+ }
166
+
167
+ function doneCallback(imageId) {
168
+ const imageIdIndex = stack.imageIds.indexOf(imageId);
169
+
170
+ removeFromList(imageIdIndex);
171
+ const image = cache.getCachedImageBasedOnImageURI(imageId);
172
+ const { stats } = stackPrefetch;
173
+ const decodeTimeInMS = image?.image?.decodeTimeInMS || 0;
174
+ if (decodeTimeInMS) {
175
+ stats.imageIds.set(imageId, decodeTimeInMS);
176
+ stats.decodeTimeInMS += decodeTimeInMS;
177
+ const loadTimeInMS = image?.image?.loadTimeInMS || 0;
178
+ stats.loadTimeInMS += loadTimeInMS;
179
+ }
180
+
181
+ if (!stackPrefetch.indicesToRequest.length) {
182
+ if (image?.sizeInBytes) {
183
+ const { sizeInBytes } = image;
184
+ const usage = cache.getMaxCacheSize() / 4 / sizeInBytes;
185
+ if (!stackPrefetch.cacheFill) {
186
+ stats.initialTime = Date.now() - stats.start;
187
+ stats.initialSize = stats.imageIds.size;
188
+ updateToolState(element, usage);
189
+ prefetch(element);
190
+ } else if (stats.imageIds.size) {
191
+ stats.fillTime = Date.now() - stats.start;
192
+ const { size } = stats.imageIds;
193
+ stats.fillSize = size;
194
+ console.log(
195
+ 'Done cache fill',
196
+ stats.fillTime,
197
+ 'ms',
198
+ size,
199
+ 'items',
200
+ 'average total time',
201
+ roundNumber(stats.fillTime / size),
202
+ 'ms',
203
+ 'average load',
204
+ roundNumber(stats.loadTimeInMS / size),
205
+ 'ms',
206
+ 'average decode',
207
+ roundNumber(stats.decodeTimeInMS / size),
208
+ 'ms'
209
+ );
210
+ }
211
+ }
212
+ }
213
+ }
214
+
215
+ const requestFn = (imageId, options) =>
216
+ imageLoader
217
+ .loadAndCacheImage(imageId, options)
218
+ .then(() => doneCallback(imageId));
219
+
220
+ const { useNorm16Texture } = getCoreConfiguration().rendering;
221
+
222
+ indicesToRequestCopy.forEach((imageIdIndex) => {
223
+ const imageId = stack.imageIds[imageIdIndex];
224
+ // IMPORTANT: Request type should be passed if not the 'interaction'
225
+ // highest priority will be used for the request type in the imageRetrievalPool
226
+ const options = {
227
+ targetBuffer: {
228
+ type: useNorm16Texture ? undefined : 'Float32Array',
229
+ },
230
+ preScale: {
231
+ enabled: true,
232
+ },
233
+ requestType,
234
+ };
235
+
236
+ imageLoadPoolManager.addRequest(
237
+ requestFn.bind(null, imageId, options),
238
+ requestType,
239
+ // Additional details
240
+ {
241
+ imageId,
242
+ },
243
+ priority
244
+ // addToBeginning
245
+ );
246
+ });
247
+ }
248
+
249
+ function onImageUpdated(e) {
250
+ // Start prefetching again (after a delay)
251
+ // When the user has scrolled to a new image
252
+ clearTimeout(resetPrefetchTimeout);
253
+ resetPrefetchTimeout = setTimeout(function () {
254
+ const element = e.target;
255
+
256
+ // If playClip is enabled and the user loads a different series in the viewport
257
+ // An exception will be thrown because the element will not be enabled anymore
258
+ try {
259
+ updateToolState(element);
260
+ prefetch(element);
261
+ } catch (error) {
262
+ return;
263
+ }
264
+ }, resetPrefetchDelay);
265
+ }
266
+
267
+ // Not a full signum, but good enough for direction.
268
+ const signum = (x) => (x < 0 ? -1 : 1);
269
+
270
+ const updateToolState = (element, usage?: number) => {
271
+ const stack = getStackData(element);
272
+ if (!stack || !stack.imageIds || stack.imageIds.length === 0) {
273
+ console.warn('CornerstoneTools.stackPrefetch: No images in stack.');
274
+ return;
275
+ }
276
+
277
+ const { currentImageIdIndex } = stack;
278
+ let { maxAfter = 2, minBefore = 2 } = configuration;
279
+ const { directionExtraImages = 10 } = configuration;
280
+ // Use the currentImageIdIndex from the stack as the initialImageIdIndex
281
+ const stackPrefetchData = getToolState(element) || {
282
+ indicesToRequest: [],
283
+ currentImageIdIndex,
284
+ stackCount: 0,
285
+ enabled: true,
286
+ direction: 1,
287
+ stats: {
288
+ start: Date.now(),
289
+ imageIds: new Map(),
290
+ decodeTimeInMS: 0,
291
+ loadTimeInMS: 0,
292
+ totalBytes: 0,
293
+ },
294
+ };
295
+ const delta = currentImageIdIndex - stackPrefetchData.currentImageIdIndex;
296
+ stackPrefetchData.direction = signum(delta);
297
+ stackPrefetchData.currentImageIdIndex = currentImageIdIndex;
298
+ stackPrefetchData.enabled = true;
299
+
300
+ if (stackPrefetchData.stackCount < 100) {
301
+ stackPrefetchData.stackCount += directionExtraImages;
302
+ }
303
+
304
+ if (Math.abs(delta) > maxAfter || !delta) {
305
+ // Not incrementing by 1, so stop increasing the data size
306
+ // TODO - consider reversing the CINE playback
307
+ stackPrefetchData.stackCount = 0;
308
+ if (usage) {
309
+ // The usage of the cache that this stack can use
310
+ const positionFraction = currentImageIdIndex / stack.imageIds.length;
311
+ minBefore = Math.ceil(usage * positionFraction);
312
+ maxAfter = Math.ceil(usage * (1 - positionFraction));
313
+ stackPrefetchData.cacheFill = true;
314
+ } else {
315
+ stackPrefetchData.cacheFill = false;
316
+ }
317
+ } else if (delta < 0) {
318
+ minBefore += stackPrefetchData.stackCount;
319
+ maxAfter = 0;
320
+ } else {
321
+ maxAfter += stackPrefetchData.stackCount;
322
+ minBefore = 0;
323
+ }
324
+
325
+ const minIndex = Math.max(0, currentImageIdIndex - minBefore);
326
+
327
+ const maxIndex = Math.min(
328
+ stack.imageIds.length - 1,
329
+ currentImageIdIndex + maxAfter
330
+ );
331
+
332
+ // Order these correctly initially
333
+ const indicesToRequest = [];
334
+ for (let i = currentImageIdIndex + 1; i <= maxIndex; i++) {
335
+ indicesToRequest.push(i);
336
+ }
337
+ for (let i = currentImageIdIndex - 1; i >= minIndex; i--) {
338
+ indicesToRequest.push(i);
339
+ }
340
+ stackPrefetchData.indicesToRequest = indicesToRequest;
341
+
342
+ addToolState(element, stackPrefetchData);
343
+ };
344
+
345
+ function disable(element) {
346
+ clearTimeout(resetPrefetchTimeout);
347
+ element.removeEventListener(Enums.Events.STACK_NEW_IMAGE, onImageUpdated);
348
+
349
+ const promiseRemovedHandler = getPromiseRemovedHandler(element);
350
+
351
+ eventTarget.removeEventListener(
352
+ Enums.Events.IMAGE_CACHE_IMAGE_REMOVED,
353
+ promiseRemovedHandler
354
+ );
355
+
356
+ const stackPrefetchData = getToolState(element);
357
+ // If there is actually something to disable, disable it
358
+
359
+ if (stackPrefetchData && stackPrefetchData.data.length) {
360
+ stackPrefetchData.enabled = false;
361
+ // Don't worry about clearing the requests - there aren't that many too be bothersome
362
+ }
363
+ }
364
+
365
+ function getConfiguration() {
366
+ return configuration;
367
+ }
368
+
369
+ function setConfiguration(config) {
370
+ configuration = config;
371
+ }
372
+
373
+ const stackContextPrefetch = {
374
+ enable,
375
+ disable,
376
+ getConfiguration,
377
+ setConfiguration,
378
+ };
379
+
380
+ export default stackContextPrefetch;