@cornerstonejs/tools 1.70.5 → 1.70.7

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 (151) hide show
  1. package/dist/cjs/enums/Events.d.ts +2 -0
  2. package/dist/cjs/enums/Events.js +2 -0
  3. package/dist/cjs/enums/Events.js.map +1 -1
  4. package/dist/cjs/store/ToolGroupManager/ToolGroup.js +12 -0
  5. package/dist/cjs/store/ToolGroupManager/ToolGroup.js.map +1 -1
  6. package/dist/cjs/tools/AdvancedMagnifyTool.d.ts +1 -1
  7. package/dist/cjs/tools/AdvancedMagnifyTool.js +35 -43
  8. package/dist/cjs/tools/AdvancedMagnifyTool.js.map +1 -1
  9. package/dist/cjs/tools/AdvancedMagnifyViewport.d.ts +1 -1
  10. package/dist/cjs/tools/AdvancedMagnifyViewport.js +8 -2
  11. package/dist/cjs/tools/AdvancedMagnifyViewport.js.map +1 -1
  12. package/dist/cjs/tools/AdvancedMagnifyViewportManager.d.ts +2 -1
  13. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js +32 -3
  14. package/dist/cjs/tools/AdvancedMagnifyViewportManager.js.map +1 -1
  15. package/dist/cjs/tools/OrientationMarkerTool.d.ts +0 -2
  16. package/dist/cjs/tools/OrientationMarkerTool.js +47 -28
  17. package/dist/cjs/tools/OrientationMarkerTool.js.map +1 -1
  18. package/dist/cjs/tools/annotation/BidirectionalTool.js +15 -8
  19. package/dist/cjs/tools/annotation/BidirectionalTool.js.map +1 -1
  20. package/dist/cjs/tools/annotation/CircleROITool.js +19 -18
  21. package/dist/cjs/tools/annotation/CircleROITool.js.map +1 -1
  22. package/dist/cjs/tools/annotation/EllipticalROITool.d.ts +1 -1
  23. package/dist/cjs/tools/annotation/EllipticalROITool.js +21 -20
  24. package/dist/cjs/tools/annotation/EllipticalROITool.js.map +1 -1
  25. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js +27 -4
  26. package/dist/cjs/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  27. package/dist/cjs/tools/annotation/RectangleROITool.js +18 -18
  28. package/dist/cjs/tools/annotation/RectangleROITool.js.map +1 -1
  29. package/dist/cjs/tools/annotation/SplineROITool.js +16 -2
  30. package/dist/cjs/tools/annotation/SplineROITool.js.map +1 -1
  31. package/dist/cjs/tools/base/AnnotationTool.js +4 -1
  32. package/dist/cjs/tools/base/AnnotationTool.js.map +1 -1
  33. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js +5 -0
  34. package/dist/cjs/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  35. package/dist/cjs/tools/segmentation/BrushTool.js +12 -1
  36. package/dist/cjs/tools/segmentation/BrushTool.js.map +1 -1
  37. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js +3 -0
  38. package/dist/cjs/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  39. package/dist/cjs/tools/segmentation/strategies/compositions/preview.js +10 -2
  40. package/dist/cjs/tools/segmentation/strategies/compositions/preview.js.map +1 -1
  41. package/dist/cjs/types/ToolSpecificAnnotationTypes.d.ts +2 -1
  42. package/dist/cjs/utilities/cine/playClip.d.ts +1 -1
  43. package/dist/cjs/utilities/cine/playClip.js +2 -5
  44. package/dist/cjs/utilities/cine/playClip.js.map +1 -1
  45. package/dist/cjs/utilities/getCalibratedUnits.d.ts +1 -5
  46. package/dist/cjs/utilities/getCalibratedUnits.js +13 -45
  47. package/dist/cjs/utilities/getCalibratedUnits.js.map +1 -1
  48. package/dist/cjs/utilities/index.d.ts +2 -2
  49. package/dist/cjs/utilities/index.js +4 -4
  50. package/dist/cjs/utilities/index.js.map +1 -1
  51. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js +3 -0
  52. package/dist/cjs/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  53. package/dist/esm/enums/Events.js +2 -0
  54. package/dist/esm/enums/Events.js.map +1 -1
  55. package/dist/esm/store/ToolGroupManager/ToolGroup.js +12 -0
  56. package/dist/esm/store/ToolGroupManager/ToolGroup.js.map +1 -1
  57. package/dist/esm/tools/AdvancedMagnifyTool.js +35 -43
  58. package/dist/esm/tools/AdvancedMagnifyTool.js.map +1 -1
  59. package/dist/esm/tools/AdvancedMagnifyViewport.js +8 -2
  60. package/dist/esm/tools/AdvancedMagnifyViewport.js.map +1 -1
  61. package/dist/esm/tools/AdvancedMagnifyViewportManager.js +38 -4
  62. package/dist/esm/tools/AdvancedMagnifyViewportManager.js.map +1 -1
  63. package/dist/esm/tools/OrientationMarkerTool.js +48 -29
  64. package/dist/esm/tools/OrientationMarkerTool.js.map +1 -1
  65. package/dist/esm/tools/annotation/BidirectionalTool.js +16 -9
  66. package/dist/esm/tools/annotation/BidirectionalTool.js.map +1 -1
  67. package/dist/esm/tools/annotation/CircleROITool.js +21 -20
  68. package/dist/esm/tools/annotation/CircleROITool.js.map +1 -1
  69. package/dist/esm/tools/annotation/EllipticalROITool.js +23 -22
  70. package/dist/esm/tools/annotation/EllipticalROITool.js.map +1 -1
  71. package/dist/esm/tools/annotation/PlanarFreehandROITool.js +29 -6
  72. package/dist/esm/tools/annotation/PlanarFreehandROITool.js.map +1 -1
  73. package/dist/esm/tools/annotation/RectangleROITool.js +19 -19
  74. package/dist/esm/tools/annotation/RectangleROITool.js.map +1 -1
  75. package/dist/esm/tools/annotation/SplineROITool.js +17 -3
  76. package/dist/esm/tools/annotation/SplineROITool.js.map +1 -1
  77. package/dist/esm/tools/base/AnnotationTool.js +4 -1
  78. package/dist/esm/tools/base/AnnotationTool.js.map +1 -1
  79. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js +5 -0
  80. package/dist/esm/tools/displayTools/Labelmap/labelmapDisplay.js.map +1 -1
  81. package/dist/esm/tools/segmentation/BrushTool.js +13 -2
  82. package/dist/esm/tools/segmentation/BrushTool.js.map +1 -1
  83. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js +3 -0
  84. package/dist/esm/tools/segmentation/strategies/compositions/dynamicThreshold.js.map +1 -1
  85. package/dist/esm/tools/segmentation/strategies/compositions/preview.js +10 -2
  86. package/dist/esm/tools/segmentation/strategies/compositions/preview.js.map +1 -1
  87. package/dist/esm/utilities/cine/playClip.js +2 -2
  88. package/dist/esm/utilities/cine/playClip.js.map +1 -1
  89. package/dist/esm/utilities/getCalibratedUnits.js +13 -41
  90. package/dist/esm/utilities/getCalibratedUnits.js.map +1 -1
  91. package/dist/esm/utilities/index.js +2 -2
  92. package/dist/esm/utilities/index.js.map +1 -1
  93. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js +3 -0
  94. package/dist/esm/utilities/planar/filterAnnotationsForDisplay.js.map +1 -1
  95. package/dist/types/enums/Events.d.ts +2 -0
  96. package/dist/types/enums/Events.d.ts.map +1 -1
  97. package/dist/types/store/ToolGroupManager/ToolGroup.d.ts.map +1 -1
  98. package/dist/types/tools/AdvancedMagnifyTool.d.ts +1 -1
  99. package/dist/types/tools/AdvancedMagnifyTool.d.ts.map +1 -1
  100. package/dist/types/tools/AdvancedMagnifyViewport.d.ts +1 -1
  101. package/dist/types/tools/AdvancedMagnifyViewport.d.ts.map +1 -1
  102. package/dist/types/tools/AdvancedMagnifyViewportManager.d.ts +2 -1
  103. package/dist/types/tools/AdvancedMagnifyViewportManager.d.ts.map +1 -1
  104. package/dist/types/tools/OrientationMarkerTool.d.ts +0 -2
  105. package/dist/types/tools/OrientationMarkerTool.d.ts.map +1 -1
  106. package/dist/types/tools/annotation/BidirectionalTool.d.ts.map +1 -1
  107. package/dist/types/tools/annotation/CircleROITool.d.ts.map +1 -1
  108. package/dist/types/tools/annotation/EllipticalROITool.d.ts +1 -1
  109. package/dist/types/tools/annotation/EllipticalROITool.d.ts.map +1 -1
  110. package/dist/types/tools/annotation/PlanarFreehandROITool.d.ts.map +1 -1
  111. package/dist/types/tools/annotation/RectangleROITool.d.ts.map +1 -1
  112. package/dist/types/tools/annotation/SplineROITool.d.ts.map +1 -1
  113. package/dist/types/tools/base/AnnotationTool.d.ts.map +1 -1
  114. package/dist/types/tools/displayTools/Labelmap/labelmapDisplay.d.ts.map +1 -1
  115. package/dist/types/tools/segmentation/BrushTool.d.ts.map +1 -1
  116. package/dist/types/tools/segmentation/strategies/compositions/dynamicThreshold.d.ts.map +1 -1
  117. package/dist/types/tools/segmentation/strategies/compositions/preview.d.ts.map +1 -1
  118. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts +2 -1
  119. package/dist/types/types/ToolSpecificAnnotationTypes.d.ts.map +1 -1
  120. package/dist/types/utilities/cine/playClip.d.ts +1 -1
  121. package/dist/types/utilities/cine/playClip.d.ts.map +1 -1
  122. package/dist/types/utilities/getCalibratedUnits.d.ts +1 -5
  123. package/dist/types/utilities/getCalibratedUnits.d.ts.map +1 -1
  124. package/dist/types/utilities/index.d.ts +2 -2
  125. package/dist/types/utilities/index.d.ts.map +1 -1
  126. package/dist/types/utilities/planar/filterAnnotationsForDisplay.d.ts.map +1 -1
  127. package/dist/umd/index.js +1 -1
  128. package/dist/umd/index.js.map +1 -1
  129. package/package.json +4 -4
  130. package/src/enums/Events.ts +6 -0
  131. package/src/store/ToolGroupManager/ToolGroup.ts +16 -0
  132. package/src/tools/AdvancedMagnifyTool.ts +42 -66
  133. package/src/tools/AdvancedMagnifyViewport.ts +11 -3
  134. package/src/tools/AdvancedMagnifyViewportManager.ts +74 -3
  135. package/src/tools/OrientationMarkerTool.ts +74 -50
  136. package/src/tools/annotation/BidirectionalTool.ts +28 -15
  137. package/src/tools/annotation/CircleROITool.ts +24 -25
  138. package/src/tools/annotation/EllipticalROITool.ts +28 -39
  139. package/src/tools/annotation/PlanarFreehandROITool.ts +56 -11
  140. package/src/tools/annotation/RectangleROITool.ts +23 -23
  141. package/src/tools/annotation/SplineROITool.ts +36 -4
  142. package/src/tools/base/AnnotationTool.ts +8 -2
  143. package/src/tools/displayTools/Labelmap/labelmapDisplay.ts +7 -0
  144. package/src/tools/segmentation/BrushTool.ts +17 -1
  145. package/src/tools/segmentation/strategies/compositions/dynamicThreshold.ts +6 -0
  146. package/src/tools/segmentation/strategies/compositions/preview.ts +14 -4
  147. package/src/types/ToolSpecificAnnotationTypes.ts +2 -1
  148. package/src/utilities/cine/playClip.ts +2 -2
  149. package/src/utilities/getCalibratedUnits.ts +18 -74
  150. package/src/utilities/index.ts +6 -6
  151. package/src/utilities/planar/filterAnnotationsForDisplay.ts +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "1.70.5",
3
+ "version": "1.70.7",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "main": "src/index.ts",
6
6
  "types": "dist/types/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
30
30
  },
31
31
  "dependencies": {
32
- "@cornerstonejs/core": "^1.70.5",
32
+ "@cornerstonejs/core": "^1.70.7",
33
33
  "@icr/polyseg-wasm": "0.4.0",
34
34
  "@types/offscreencanvas": "2019.7.3",
35
35
  "comlink": "^4.4.1",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@icr/polyseg-wasm": "0.4.0",
44
- "@kitware/vtk.js": "30.3.1",
44
+ "@kitware/vtk.js": "30.3.3",
45
45
  "@types/d3-array": "^3.0.4",
46
46
  "@types/d3-interpolate": "^3.0.1",
47
47
  "d3-array": "^3.2.3",
@@ -59,5 +59,5 @@
59
59
  "type": "individual",
60
60
  "url": "https://ohif.org/donate"
61
61
  },
62
- "gitHead": "bf3d33986d1cdad6ab4abf9e4004dcb16a1a83c9"
62
+ "gitHead": "4b6774d20ea66e2fa2815edc042b57565b816959"
63
63
  }
@@ -18,6 +18,12 @@ enum Events {
18
18
  */
19
19
  TOOL_ACTIVATED = 'CORNERSTONE_TOOLS_TOOL_ACTIVATED',
20
20
 
21
+ // fired when a viewport is added to the toolGroup
22
+ TOOLGROUP_VIEWPORT_ADDED = 'CORNERSTONE_TOOLS_TOOLGROUP_VIEWPORT_ADDED',
23
+
24
+ // fired when a viewport is removed from the toolGroup
25
+ TOOLGROUP_VIEWPORT_REMOVED = 'CORNERSTONE_TOOLS_TOOLGROUP_VIEWPORT_REMOVED',
26
+
21
27
  /**
22
28
  * Triggers on the eventTarget when a mode of a tool is changed (active, passive, enabled and disabled).
23
29
  *
@@ -239,6 +239,14 @@ export default class ToolGroup implements IToolGroup {
239
239
  if (runtimeSettings.get('useCursors')) {
240
240
  this.setViewportsCursorByToolName(toolName);
241
241
  }
242
+
243
+ const eventDetail = {
244
+ toolGroupId: this.id,
245
+ viewportId,
246
+ renderingEngineId: renderingEngineUIDToUse,
247
+ };
248
+
249
+ triggerEvent(eventTarget, Events.TOOLGROUP_VIEWPORT_ADDED, eventDetail);
242
250
  }
243
251
 
244
252
  /**
@@ -273,6 +281,14 @@ export default class ToolGroup implements IToolGroup {
273
281
  this.viewportsInfo.splice(indices[i], 1);
274
282
  }
275
283
  }
284
+
285
+ const eventDetail = {
286
+ toolGroupId: this.id,
287
+ viewportId,
288
+ renderingEngineId,
289
+ };
290
+
291
+ triggerEvent(eventTarget, Events.TOOLGROUP_VIEWPORT_REMOVED, eventDetail);
276
292
  }
277
293
 
278
294
  public setActiveStrategy(toolName: string, strategyName: string) {
@@ -66,8 +66,8 @@ class AdvancedMagnifyTool extends AnnotationTool {
66
66
  shadow: true,
67
67
  magnifyingGlass: {
68
68
  radius: 125, // px
69
- zoomFactor: 2.5,
70
- zoomFactorList: [2.5, 3, 3.5, 4, 4.5, 5],
69
+ zoomFactor: 3,
70
+ zoomFactorList: [1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5],
71
71
  autoPan: {
72
72
  enabled: true,
73
73
  padding: 10, // px
@@ -111,11 +111,10 @@ class AdvancedMagnifyTool extends AnnotationTool {
111
111
  const { magnifyingGlass: config } = this.configuration;
112
112
  const { radius, zoomFactor, autoPan } = config;
113
113
 
114
- const worldHandlesPoints = this._getWorldHandlesPoints(
115
- viewport,
114
+ const canvasHandlePoints = this._getCanvasHandlePoints(
116
115
  canvasPos,
117
116
  radius
118
- );
117
+ ) as [Types.Point3, Types.Point3, Types.Point3, Types.Point3];
119
118
 
120
119
  const camera = viewport.getCamera();
121
120
  const { viewPlaneNormal, viewUp } = camera;
@@ -146,8 +145,11 @@ class AdvancedMagnifyTool extends AnnotationTool {
146
145
  sourceViewportId: viewport.id,
147
146
  magnifyViewportId,
148
147
  zoomFactor,
148
+ // this means that the last coordinate for the points
149
+ // is 0 and should not be used for calculations
150
+ isCanvasAnnotation: true,
149
151
  handles: {
150
- points: worldHandlesPoints,
152
+ points: canvasHandlePoints,
151
153
  activeHandleIndex: null,
152
154
  },
153
155
  },
@@ -164,12 +166,13 @@ class AdvancedMagnifyTool extends AnnotationTool {
164
166
  padding: autoPan.padding,
165
167
  callback: (data: AutoPanCallbackData) => {
166
168
  const annotationPoints = annotation.data.handles.points;
167
- const { world: worldDelta } = data.delta;
169
+ const { canvas: canvasDelta } = data.delta;
168
170
 
169
171
  for (let i = 0, len = annotationPoints.length; i < len; i++) {
170
- annotationPoints[i][0] += worldDelta[0];
171
- annotationPoints[i][1] += worldDelta[1];
172
- annotationPoints[i][2] += worldDelta[2];
172
+ const point = annotationPoints[i];
173
+ point[0] += canvasDelta[0];
174
+ point[1] += canvasDelta[1];
175
+ annotation.invalidated = true;
173
176
  }
174
177
  },
175
178
  },
@@ -217,20 +220,12 @@ class AdvancedMagnifyTool extends AnnotationTool {
217
220
  canvasCoords: Types.Point2,
218
221
  proximity: number
219
222
  ): boolean => {
220
- const enabledElement = getEnabledElement(element);
221
- const { viewport } = enabledElement;
222
-
223
223
  const { data } = annotation;
224
224
  const { points } = data.handles;
225
225
 
226
226
  // For some reason Typescript doesn't understand this, so we need to be
227
227
  // more specific about the type
228
- const canvasCoordinates = points.map((p) => viewport.worldToCanvas(p)) as [
229
- Types.Point2,
230
- Types.Point2,
231
- Types.Point2,
232
- Types.Point2
233
- ];
228
+ const canvasCoordinates = points;
234
229
 
235
230
  const canvasTop = canvasCoordinates[0];
236
231
  const canvasBottom = canvasCoordinates[2];
@@ -242,7 +237,7 @@ class AdvancedMagnifyTool extends AnnotationTool {
242
237
  ] as Types.Point2;
243
238
  const radiusPoint = getCanvasCircleRadius([center, canvasCoords]);
244
239
 
245
- if (Math.abs(radiusPoint - radius) < proximity * 1.5) {
240
+ if (Math.abs(radiusPoint - radius) < proximity * 2) {
246
241
  return true;
247
242
  }
248
243
 
@@ -347,7 +342,7 @@ class AdvancedMagnifyTool extends AnnotationTool {
347
342
  this.isDrawing = true;
348
343
  const eventDetail = evt.detail;
349
344
  const { element, deltaPoints } = eventDetail;
350
- const worldPosDelta = deltaPoints?.world ?? [0, 0, 0];
345
+ const canvasDelta = deltaPoints?.canvas ?? [0, 0, 0];
351
346
  const enabledElement = getEnabledElement(element);
352
347
  const { renderingEngine } = enabledElement;
353
348
 
@@ -355,9 +350,8 @@ class AdvancedMagnifyTool extends AnnotationTool {
355
350
  const { points } = annotation.data.handles;
356
351
 
357
352
  points.forEach((point) => {
358
- point[0] += worldPosDelta[0];
359
- point[1] += worldPosDelta[1];
360
- point[2] += worldPosDelta[2];
353
+ point[0] += canvasDelta[0];
354
+ point[1] += canvasDelta[1];
361
355
  });
362
356
 
363
357
  annotation.invalidated = true;
@@ -377,14 +371,13 @@ class AdvancedMagnifyTool extends AnnotationTool {
377
371
  if (handleIndex === undefined) {
378
372
  // Moving tool
379
373
  const { deltaPoints } = eventDetail;
380
- const worldPosDelta = deltaPoints.world;
374
+ const canvasDelta = deltaPoints.canvas;
381
375
 
382
376
  const points = data.handles.points;
383
377
 
384
378
  points.forEach((point) => {
385
- point[0] += worldPosDelta[0];
386
- point[1] += worldPosDelta[1];
387
- point[2] += worldPosDelta[2];
379
+ point[0] += canvasDelta[0];
380
+ point[1] += canvasDelta[1];
388
381
  });
389
382
  annotation.invalidated = true;
390
383
  } else {
@@ -400,16 +393,12 @@ class AdvancedMagnifyTool extends AnnotationTool {
400
393
 
401
394
  _dragHandle = (evt: EventTypes.InteractionEventType): void => {
402
395
  const eventDetail = evt.detail;
403
- const { element } = eventDetail;
404
- const enabledElement = getEnabledElement(element);
405
- const { viewport } = enabledElement;
406
- const { worldToCanvas } = viewport;
407
396
 
408
397
  const { annotation } = this.editData;
409
398
  const { data } = annotation;
410
399
  const { points } = data.handles;
411
400
 
412
- const canvasCoordinates = points.map((p) => worldToCanvas(p));
401
+ const canvasCoordinates = points;
413
402
  const canvasTop = canvasCoordinates[0];
414
403
  const canvasBottom = canvasCoordinates[2];
415
404
  const canvasLeft = canvasCoordinates[3];
@@ -426,16 +415,15 @@ class AdvancedMagnifyTool extends AnnotationTool {
426
415
  canvasCenter,
427
416
  currentCanvasPoints,
428
417
  ]);
429
- const newWorldHandlesPoints = this._getWorldHandlesPoints(
430
- viewport,
418
+ const newCanvasHandlePoints = this._getCanvasHandlePoints(
431
419
  canvasCenter,
432
420
  newRadius
433
421
  );
434
422
 
435
- points[0] = newWorldHandlesPoints[0];
436
- points[1] = newWorldHandlesPoints[1];
437
- points[2] = newWorldHandlesPoints[2];
438
- points[3] = newWorldHandlesPoints[3];
423
+ points[0] = newCanvasHandlePoints[0];
424
+ points[1] = newCanvasHandlePoints[1];
425
+ points[2] = newCanvasHandlePoints[2];
426
+ points[3] = newCanvasHandlePoints[3];
439
427
  };
440
428
 
441
429
  cancel = (element: HTMLDivElement) => {
@@ -513,18 +501,18 @@ class AdvancedMagnifyTool extends AnnotationTool {
513
501
  return renderStatus;
514
502
  }
515
503
 
516
- annotations = this.filterInteractableAnnotationsForElement(
517
- element,
518
- annotations
519
- );
520
-
521
504
  annotations = annotations?.filter(
522
505
  (annotation) =>
523
506
  (<AdvancedMagnifyAnnotation>annotation).data.sourceViewportId ===
524
507
  viewport.id
525
508
  );
526
509
 
527
- if (!annotations?.length) {
510
+ const filteredAnnotations = this.filterInteractableAnnotationsForElement(
511
+ element,
512
+ annotations
513
+ );
514
+
515
+ if (!filteredAnnotations?.length) {
528
516
  return renderStatus;
529
517
  }
530
518
 
@@ -534,8 +522,8 @@ class AdvancedMagnifyTool extends AnnotationTool {
534
522
  viewportId: enabledElement.viewport.id,
535
523
  };
536
524
 
537
- for (let i = 0; i < annotations.length; i++) {
538
- const annotation = annotations[i] as AdvancedMagnifyAnnotation;
525
+ for (let i = 0; i < filteredAnnotations.length; i++) {
526
+ const annotation = filteredAnnotations[i] as AdvancedMagnifyAnnotation;
539
527
  const { annotationUID, data } = annotation;
540
528
  const { magnifyViewportId, zoomFactor, handles } = data;
541
529
  const { points, activeHandleIndex } = handles;
@@ -546,9 +534,7 @@ class AdvancedMagnifyTool extends AnnotationTool {
546
534
  const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
547
535
  const color = this.getStyle('color', styleSpecifier, annotation);
548
536
 
549
- const canvasCoordinates = points.map((p) =>
550
- viewport.worldToCanvas(p)
551
- ) as Types.Point2[];
537
+ const canvasCoordinates = points;
552
538
  const canvasTop = canvasCoordinates[0];
553
539
  const canvasBottom = canvasCoordinates[2];
554
540
  const canvasLeft = canvasCoordinates[3];
@@ -701,23 +687,13 @@ class AdvancedMagnifyTool extends AnnotationTool {
701
687
  return dropdown;
702
688
  }
703
689
 
704
- private _getWorldHandlesPoints = (
705
- viewport,
706
- canvasCenterPos,
707
- canvasRadius
708
- ): Types.Point3[] => {
709
- const canvasHandlesPoints = [
710
- [canvasCenterPos[0], canvasCenterPos[1] - canvasRadius], // top
711
- [canvasCenterPos[0] + canvasRadius, canvasCenterPos[1]], // right
712
- [canvasCenterPos[0], canvasCenterPos[1] + canvasRadius], // bottom
713
- [canvasCenterPos[0] - canvasRadius, canvasCenterPos[1]], // left
690
+ private _getCanvasHandlePoints = (canvasCenterPos, canvasRadius) => {
691
+ return [
692
+ [canvasCenterPos[0], canvasCenterPos[1] - canvasRadius, 0], // top
693
+ [canvasCenterPos[0] + canvasRadius, canvasCenterPos[1], 0], // right
694
+ [canvasCenterPos[0], canvasCenterPos[1] + canvasRadius, 0], // bottom
695
+ [canvasCenterPos[0] - canvasRadius, canvasCenterPos[1], 0], // left
714
696
  ];
715
-
716
- const worldHandlesPoints = canvasHandlesPoints.map((p) =>
717
- viewport.canvasToWorld(p)
718
- ) as Types.Point3[];
719
-
720
- return worldHandlesPoints;
721
697
  };
722
698
  }
723
699
 
@@ -91,7 +91,7 @@ class AdvancedMagnifyViewport {
91
91
  this._sourceEnabledElement = sourceEnabledElement;
92
92
  this._autoPan = autoPan;
93
93
 
94
- // Pulic properties
94
+ // Public properties
95
95
  this.radius = radius;
96
96
  this.position = position;
97
97
  this.zoomFactor = zoomFactor;
@@ -234,7 +234,7 @@ class AdvancedMagnifyViewport {
234
234
  return magnifyElement;
235
235
  }
236
236
 
237
- private _convertZoomFactorToParalellScale(
237
+ private _convertZoomFactorToParallelScale(
238
238
  viewport,
239
239
  magnifyViewport,
240
240
  zoomFactor
@@ -556,7 +556,7 @@ class AdvancedMagnifyViewport {
556
556
  const worldPos = sourceViewport.canvasToWorld(this.position);
557
557
 
558
558
  // Use the original viewport for the base for parallelScale
559
- const parallelScale = this._convertZoomFactorToParalellScale(
559
+ const parallelScale = this._convertZoomFactorToParallelScale(
560
560
  sourceViewport,
561
561
  magnifyViewport,
562
562
  this.zoomFactor
@@ -601,6 +601,11 @@ class AdvancedMagnifyViewport {
601
601
  const { viewport: sourceViewport } = this._sourceEnabledElement;
602
602
  const { viewport: magnifyViewport } = this._enabledElement;
603
603
  const sourceProperties = sourceViewport.getProperties();
604
+ const imageData = magnifyViewport.getImageData();
605
+
606
+ if (!imageData) {
607
+ return;
608
+ }
604
609
 
605
610
  magnifyViewport.setProperties(sourceProperties);
606
611
  this._syncViewportsCameras(sourceViewport, magnifyViewport);
@@ -611,6 +616,9 @@ class AdvancedMagnifyViewport {
611
616
  magnifyViewport as Types.IStackViewport
612
617
  );
613
618
  }
619
+
620
+ this._syncViewportsCameras(sourceViewport, magnifyViewport);
621
+ magnifyViewport.render();
614
622
  }
615
623
 
616
624
  private _resizeViewport() {
@@ -4,6 +4,7 @@ import {
4
4
  Enums,
5
5
  getRenderingEngine,
6
6
  CONSTANTS,
7
+ getEnabledElementByViewportId,
7
8
  } from '@cornerstonejs/core';
8
9
  import type { Types } from '@cornerstonejs/core';
9
10
  import { AnnotationRemovedEventType } from '../types/EventTypes';
@@ -47,6 +48,7 @@ export type MagnifyViewportInfo = {
47
48
  type MagnifyViewportsMapEntry = {
48
49
  annotation: AdvancedMagnifyAnnotation;
49
50
  magnifyViewport: AdvancedMagnifyViewport;
51
+ magnifyViewportInfo: MagnifyViewportInfo;
50
52
  };
51
53
 
52
54
  /**
@@ -110,6 +112,7 @@ class AdvancedMagnifyViewportManager {
110
112
  this._magnifyViewportsMap.set(magnifyViewport.viewportId, {
111
113
  annotation,
112
114
  magnifyViewport,
115
+ magnifyViewportInfo: viewportInfo,
113
116
  });
114
117
 
115
118
  return magnifyViewport;
@@ -133,7 +136,7 @@ class AdvancedMagnifyViewportManager {
133
136
  this._destroyViewports();
134
137
  }
135
138
 
136
- private _destroyViewport(magnifyViewportId: string) {
139
+ public destroyViewport(magnifyViewportId: string) {
137
140
  const magnifyViewportMapEntry =
138
141
  this._magnifyViewportsMap.get(magnifyViewportId);
139
142
 
@@ -153,7 +156,7 @@ class AdvancedMagnifyViewportManager {
153
156
  const magnifyViewportIds = Array.from(this._magnifyViewportsMap.keys());
154
157
 
155
158
  magnifyViewportIds.forEach((magnifyViewportId) =>
156
- this._destroyViewport(magnifyViewportId)
159
+ this.destroyViewport(magnifyViewportId)
157
160
  );
158
161
  }
159
162
 
@@ -164,7 +167,7 @@ class AdvancedMagnifyViewportManager {
164
167
  return;
165
168
  }
166
169
 
167
- this._destroyViewport(annotation.data.magnifyViewportId);
170
+ this.destroyViewport(annotation.data.magnifyViewportId);
168
171
  };
169
172
 
170
173
  private _getMagnifyViewportsMapEntriesBySourceViewportId(sourceViewportId) {
@@ -185,6 +188,17 @@ class AdvancedMagnifyViewportManager {
185
188
  const magnifyViewportsMapEntries =
186
189
  this._getMagnifyViewportsMapEntriesBySourceViewportId(sourceViewportId);
187
190
 
191
+ const { viewport } = getEnabledElementByViewportId(sourceViewportId);
192
+
193
+ // if the viewport was new in terms of image, we need to destroy the magnify
194
+ // viewports and recreate them, the new image might have different dimensions
195
+ // or orientation etc.
196
+ if ((viewport as Types.IStackViewport).stackActorReInitialized) {
197
+ // we should invalidate the viewport as well
198
+ // this will trigger the magnify viewport to be updated
199
+ this._reset(sourceViewportId);
200
+ }
201
+
188
202
  magnifyViewportsMapEntries.forEach(({ annotation }) => {
189
203
  annotation.metadata.referencedImageId = imageId;
190
204
  annotation.invalidated = true;
@@ -242,6 +256,29 @@ class AdvancedMagnifyViewportManager {
242
256
  });
243
257
  };
244
258
 
259
+ private _reset(sourceViewportId: string) {
260
+ const magnifyViewports =
261
+ this._getMagnifyViewportsMapEntriesBySourceViewportId(sourceViewportId);
262
+
263
+ magnifyViewports.forEach(
264
+ ({ magnifyViewport, annotation, magnifyViewportInfo }) => {
265
+ this.destroyViewport(magnifyViewport.viewportId);
266
+
267
+ // if it is new image we need to update the magnifyViewportInfo
268
+ // since it might have new image dimensions etc.
269
+ const newEnabledElement =
270
+ getEnabledElementByViewportId(sourceViewportId);
271
+
272
+ this.createViewport(annotation, {
273
+ ...magnifyViewportInfo,
274
+ sourceEnabledElement: {
275
+ ...newEnabledElement,
276
+ },
277
+ });
278
+ }
279
+ );
280
+ }
281
+
245
282
  private _addEventListeners() {
246
283
  eventTarget.addEventListener(
247
284
  cstEvents.ANNOTATION_REMOVED,
@@ -262,10 +299,30 @@ class AdvancedMagnifyViewportManager {
262
299
  this._newStackImageCallback
263
300
  );
264
301
 
302
+ const newStackHandler = (evt) => {
303
+ const { viewportId: sourceViewportId } = evt.detail;
304
+ this._reset(sourceViewportId);
305
+ };
306
+
307
+ element.addEventListener(Events.STACK_VIEWPORT_NEW_STACK, newStackHandler);
308
+
309
+ const newVolumeHandler = (evt) => {
310
+ const { viewportId: sourceViewportId } = evt.detail;
311
+ this._reset(sourceViewportId);
312
+ };
313
+ element.addEventListener(
314
+ Events.VOLUME_VIEWPORT_NEW_VOLUME,
315
+ newVolumeHandler
316
+ );
317
+
265
318
  element.addEventListener(
266
319
  Events.VOLUME_NEW_IMAGE,
267
320
  this._newVolumeImageCallback
268
321
  );
322
+
323
+ // Store the event handlers to remove later
324
+ element.newStackHandler = newStackHandler;
325
+ element.newVolumeHandler = newVolumeHandler;
269
326
  }
270
327
 
271
328
  private _removeSourceElementEventListener(element) {
@@ -278,6 +335,20 @@ class AdvancedMagnifyViewportManager {
278
335
  Events.VOLUME_NEW_IMAGE,
279
336
  this._newVolumeImageCallback
280
337
  );
338
+
339
+ // Remove using the stored handlers
340
+ element.removeEventListener(
341
+ Events.STACK_VIEWPORT_NEW_STACK,
342
+ element.newStackHandler
343
+ );
344
+ element.removeEventListener(
345
+ Events.VOLUME_VIEWPORT_NEW_VOLUME,
346
+ element.newVolumeHandler
347
+ );
348
+
349
+ // Clean up references
350
+ delete element.newStackHandler;
351
+ delete element.newVolumeHandler;
281
352
  }
282
353
 
283
354
  private _initialize() {