@cornerstonejs/tools 4.13.5 → 4.13.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.
@@ -68,6 +68,10 @@ declare class AdvancedMagnifyTool extends AnnotationTool {
68
68
  renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
69
69
  showZoomFactorsList(evt: EventTypes.InteractionEventType, annotation: AdvancedMagnifyAnnotation): void;
70
70
  private _getZoomFactorsListDropdown;
71
+ private _getWorldHandlePoints;
72
+ private _getCanvasCircleData;
73
+ private _getWorldDeltaFromCanvasDelta;
74
+ private _applyWorldDelta;
71
75
  private _getCanvasHandlePoints;
72
76
  }
73
77
  declare class AdvancedMagnifyViewport {
@@ -64,7 +64,7 @@ class AdvancedMagnifyTool extends AnnotationTool {
64
64
  const canvasPos = currentPoints.canvas;
65
65
  const { magnifyingGlass: config } = this.configuration;
66
66
  const { radius, zoomFactor, autoPan } = config;
67
- const canvasHandlePoints = this._getCanvasHandlePoints(canvasPos, radius);
67
+ const worldHandlePoints = this._getWorldHandlePoints(viewport, canvasPos, radius);
68
68
  const camera = viewport.getCamera();
69
69
  const { viewPlaneNormal, viewUp } = camera;
70
70
  const referencedImageId = this.getReferencedImageId(viewport, worldPos, viewPlaneNormal, viewUp);
@@ -86,9 +86,9 @@ class AdvancedMagnifyTool extends AnnotationTool {
86
86
  sourceViewportId: viewport.id,
87
87
  magnifyViewportId,
88
88
  zoomFactor,
89
- isCanvasAnnotation: true,
89
+ isCanvasAnnotation: false,
90
90
  handles: {
91
- points: canvasHandlePoints,
91
+ points: worldHandlePoints,
92
92
  activeHandleIndex: null,
93
93
  },
94
94
  },
@@ -104,13 +104,14 @@ class AdvancedMagnifyTool extends AnnotationTool {
104
104
  padding: autoPan.padding,
105
105
  callback: (data) => {
106
106
  const annotationPoints = annotation.data.handles.points;
107
- const { canvas: canvasDelta } = data.delta;
107
+ const { world: worldDelta } = data.delta;
108
108
  for (let i = 0, len = annotationPoints.length; i < len; i++) {
109
109
  const point = annotationPoints[i];
110
- point[0] += canvasDelta[0];
111
- point[1] += canvasDelta[1];
112
- annotation.invalidated = true;
110
+ point[0] += worldDelta[0];
111
+ point[1] += worldDelta[1];
112
+ point[2] += worldDelta[2];
113
113
  }
114
+ annotation.invalidated = true;
114
115
  },
115
116
  },
116
117
  });
@@ -130,17 +131,9 @@ class AdvancedMagnifyTool extends AnnotationTool {
130
131
  });
131
132
  };
132
133
  this.isPointNearTool = (element, annotation, canvasCoords, proximity) => {
133
- const { data } = annotation;
134
- const { points } = data.handles;
135
- const canvasCoordinates = points;
136
- const canvasTop = canvasCoordinates[0];
137
- const canvasBottom = canvasCoordinates[2];
138
- const canvasLeft = canvasCoordinates[3];
139
- const radius = Math.abs(canvasBottom[1] - canvasTop[1]) * 0.5;
140
- const center = [
141
- canvasLeft[0] + radius,
142
- canvasTop[1] + radius,
143
- ];
134
+ const { viewport } = getEnabledElement(element);
135
+ const { points } = annotation.data.handles;
136
+ const { radius, center } = this._getCanvasCircleData(viewport, points);
144
137
  const radiusPoint = getCanvasCircleRadius([center, canvasCoords]);
145
138
  if (Math.abs(radiusPoint - radius) < proximity * 2) {
146
139
  return true;
@@ -197,14 +190,14 @@ class AdvancedMagnifyTool extends AnnotationTool {
197
190
  this._dragDrawCallback = (evt) => {
198
191
  this.isDrawing = true;
199
192
  const eventDetail = evt.detail;
193
+ const { element } = eventDetail;
194
+ const { viewport } = getEnabledElement(element);
200
195
  const { deltaPoints } = eventDetail;
201
196
  const canvasDelta = deltaPoints?.canvas ?? [0, 0, 0];
202
197
  const { annotation, viewportIdsToRender } = this.editData;
203
198
  const { points } = annotation.data.handles;
204
- points.forEach((point) => {
205
- point[0] += canvasDelta[0];
206
- point[1] += canvasDelta[1];
207
- });
199
+ const worldDelta = this._getWorldDeltaFromCanvasDelta(viewport, points, canvasDelta);
200
+ this._applyWorldDelta(points, worldDelta);
208
201
  annotation.invalidated = true;
209
202
  this.editData.hasMoved = true;
210
203
  triggerAnnotationRenderForViewportIds(viewportIdsToRender);
@@ -217,12 +210,10 @@ class AdvancedMagnifyTool extends AnnotationTool {
217
210
  const { data } = annotation;
218
211
  if (handleIndex === undefined) {
219
212
  const { deltaPoints } = eventDetail;
220
- const canvasDelta = deltaPoints.canvas;
213
+ const canvasDelta = deltaPoints.canvas ?? [0, 0, 0];
221
214
  const points = data.handles.points;
222
- points.forEach((point) => {
223
- point[0] += canvasDelta[0];
224
- point[1] += canvasDelta[1];
225
- });
215
+ const worldDelta = this._getWorldDeltaFromCanvasDelta(getEnabledElement(element).viewport, points, canvasDelta);
216
+ this._applyWorldDelta(points, worldDelta);
226
217
  annotation.invalidated = true;
227
218
  }
228
219
  else {
@@ -233,18 +224,12 @@ class AdvancedMagnifyTool extends AnnotationTool {
233
224
  };
234
225
  this._dragHandle = (evt) => {
235
226
  const eventDetail = evt.detail;
227
+ const { element } = eventDetail;
228
+ const { viewport } = getEnabledElement(element);
236
229
  const { annotation } = this.editData;
237
230
  const { data } = annotation;
238
231
  const { points } = data.handles;
239
- const canvasCoordinates = points;
240
- const canvasTop = canvasCoordinates[0];
241
- const canvasBottom = canvasCoordinates[2];
242
- const canvasLeft = canvasCoordinates[3];
243
- const radius = Math.abs(canvasBottom[1] - canvasTop[1]) * 0.5;
244
- const canvasCenter = [
245
- canvasLeft[0] + radius,
246
- canvasTop[1] + radius,
247
- ];
232
+ const { center: canvasCenter } = this._getCanvasCircleData(viewport, points);
248
233
  const { currentPoints } = eventDetail;
249
234
  const currentCanvasPoints = currentPoints.canvas;
250
235
  const newRadius = getCanvasCircleRadius([
@@ -252,10 +237,11 @@ class AdvancedMagnifyTool extends AnnotationTool {
252
237
  currentCanvasPoints,
253
238
  ]);
254
239
  const newCanvasHandlePoints = this._getCanvasHandlePoints(canvasCenter, newRadius);
255
- points[0] = newCanvasHandlePoints[0];
256
- points[1] = newCanvasHandlePoints[1];
257
- points[2] = newCanvasHandlePoints[2];
258
- points[3] = newCanvasHandlePoints[3];
240
+ const newWorldHandlePoints = newCanvasHandlePoints.map((handle) => viewport.canvasToWorld(handle));
241
+ points[0] = newWorldHandlePoints[0];
242
+ points[1] = newWorldHandlePoints[1];
243
+ points[2] = newWorldHandlePoints[2];
244
+ points[3] = newWorldHandlePoints[3];
259
245
  };
260
246
  this.cancel = (element) => {
261
247
  if (!this.isDrawing) {
@@ -317,19 +303,11 @@ class AdvancedMagnifyTool extends AnnotationTool {
317
303
  const { annotationUID, data } = annotation;
318
304
  const { magnifyViewportId, zoomFactor, handles } = data;
319
305
  const { points, activeHandleIndex } = handles;
306
+ const { center, radius, canvasPoints } = this._getCanvasCircleData(viewport, points);
320
307
  styleSpecifier.annotationUID = annotationUID;
321
308
  const lineWidth = this.getStyle('lineWidth', styleSpecifier, annotation);
322
309
  const lineDash = this.getStyle('lineDash', styleSpecifier, annotation);
323
310
  const color = this.getStyle('color', styleSpecifier, annotation);
324
- const canvasCoordinates = points;
325
- const canvasTop = canvasCoordinates[0];
326
- const canvasBottom = canvasCoordinates[2];
327
- const canvasLeft = canvasCoordinates[3];
328
- const radius = Math.abs(canvasBottom[1] - canvasTop[1]) * 0.5;
329
- const center = [
330
- canvasLeft[0] + radius,
331
- canvasTop[1] + radius,
332
- ];
333
311
  if (!viewport.getRenderingEngine()) {
334
312
  console.warn('Rendering Engine has been destroyed');
335
313
  return renderStatus;
@@ -341,7 +319,10 @@ class AdvancedMagnifyTool extends AnnotationTool {
341
319
  if (!isAnnotationLocked(annotationUID) &&
342
320
  !this.editData &&
343
321
  activeHandleIndex !== null) {
344
- activeHandleCanvasCoords = [canvasCoordinates[activeHandleIndex]];
322
+ const activeHandle = canvasPoints[activeHandleIndex];
323
+ activeHandleCanvasCoords = [
324
+ [activeHandle[0], activeHandle[1], 0],
325
+ ];
345
326
  }
346
327
  if (activeHandleCanvasCoords) {
347
328
  const handleGroupUID = '0';
@@ -364,6 +345,22 @@ class AdvancedMagnifyTool extends AnnotationTool {
364
345
  }
365
346
  return renderStatus;
366
347
  };
348
+ this._getWorldHandlePoints = (viewport, canvasCenterPos, canvasRadius) => {
349
+ const canvasHandlePoints = this._getCanvasHandlePoints(canvasCenterPos, canvasRadius);
350
+ return canvasHandlePoints.map((handlePoint) => viewport.canvasToWorld(handlePoint));
351
+ };
352
+ this._getCanvasCircleData = (viewport, points) => {
353
+ const canvasPoints = points.map((point) => viewport.worldToCanvas(point));
354
+ const canvasTop = canvasPoints[0];
355
+ const canvasBottom = canvasPoints[2];
356
+ const canvasLeft = canvasPoints[3];
357
+ const radius = Math.abs(canvasBottom[1] - canvasTop[1]) * 0.5;
358
+ const center = [
359
+ canvasLeft[0] + radius,
360
+ canvasTop[1] + radius,
361
+ ];
362
+ return { canvasPoints, center, radius };
363
+ };
367
364
  this._getCanvasHandlePoints = (canvasCenterPos, canvasRadius) => {
368
365
  return [
369
366
  [canvasCenterPos[0], canvasCenterPos[1] - canvasRadius, 0],
@@ -430,6 +427,33 @@ class AdvancedMagnifyTool extends AnnotationTool {
430
427
  });
431
428
  return dropdown;
432
429
  }
430
+ _getWorldDeltaFromCanvasDelta(viewport, points, canvasDelta) {
431
+ if (!canvasDelta) {
432
+ return [0, 0, 0];
433
+ }
434
+ const referencePoint = points[0];
435
+ const referenceCanvasPoint = viewport.worldToCanvas(referencePoint);
436
+ const movedWorldPoint = viewport.canvasToWorld([
437
+ referenceCanvasPoint[0] + canvasDelta[0],
438
+ referenceCanvasPoint[1] + canvasDelta[1],
439
+ ]);
440
+ return [
441
+ movedWorldPoint[0] - referencePoint[0],
442
+ movedWorldPoint[1] - referencePoint[1],
443
+ movedWorldPoint[2] - referencePoint[2],
444
+ ];
445
+ }
446
+ _applyWorldDelta(points, worldDelta) {
447
+ if (!worldDelta) {
448
+ return;
449
+ }
450
+ for (let i = 0, len = points.length; i < len; i++) {
451
+ const point = points[i];
452
+ point[0] += worldDelta[0];
453
+ point[1] += worldDelta[1];
454
+ point[2] += worldDelta[2];
455
+ }
456
+ }
433
457
  }
434
458
  class AdvancedMagnifyViewportManager {
435
459
  constructor() {
@@ -42,7 +42,7 @@ class ScaleOverlayTool extends AnnotationDisplayTool {
42
42
  let annotation = this.editData?.annotation;
43
43
  const annotations = getAnnotations(this.getToolName(), viewport.element);
44
44
  if (annotations.length) {
45
- annotation = annotations.filter((thisAnnotation) => thisAnnotation.data.viewportId == viewport.id)[0];
45
+ annotation = annotations.filter((thisAnnotation) => thisAnnotation.data?.viewportId == viewport.id)[0];
46
46
  }
47
47
  enabledElements.forEach((element) => {
48
48
  const { viewport } = element;
@@ -289,10 +289,10 @@ class ScaleOverlayTool extends AnnotationDisplayTool {
289
289
  const location = this.configuration.scaleLocation;
290
290
  const { viewport } = enabledElement;
291
291
  const annotations = getAnnotations(this.getToolName(), viewport.element);
292
- const annotation = annotations.filter((thisAnnotation) => thisAnnotation.data.viewportId == viewport.id)[0];
292
+ const annotation = annotations.filter((thisAnnotation) => thisAnnotation.data?.viewportId == viewport.id)[0];
293
293
  const canvas = enabledElement.viewport.canvas;
294
294
  const renderStatus = false;
295
- if (!viewport) {
295
+ if (!viewport || !annotation) {
296
296
  return renderStatus;
297
297
  }
298
298
  const styleSpecifier = {
@@ -1,6 +1,6 @@
1
1
  import { cache, volumeLoader, utilities as csUtils, } from '@cornerstonejs/core';
2
2
  function getOrCreateImageVolume(referencedImageIds) {
3
- if (!referencedImageIds || referencedImageIds.length <= 1) {
3
+ if (!referencedImageIds?.length) {
4
4
  return;
5
5
  }
6
6
  const isValidVolume = csUtils.isValidVolume(referencedImageIds);
@@ -1,3 +1,3 @@
1
1
  import { type Types } from '@cornerstonejs/core';
2
- declare function getOrCreateSegmentationVolume(segmentationId: any): Types.IImageVolume | undefined;
2
+ declare function getOrCreateSegmentationVolume(segmentationId: string): Types.IImageVolume | undefined;
3
3
  export default getOrCreateSegmentationVolume;
@@ -1,4 +1,4 @@
1
- import { cache, volumeLoader, utilities, } from '@cornerstonejs/core';
1
+ import { cache, volumeLoader, utilities, ImageVolume, } from '@cornerstonejs/core';
2
2
  import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
3
3
  function getOrCreateSegmentationVolume(segmentationId) {
4
4
  const { representationData } = getSegmentation(segmentationId);
@@ -12,7 +12,7 @@ function getOrCreateSegmentationVolume(segmentationId) {
12
12
  }
13
13
  const { imageIds: labelmapImageIds } = representationData.Labelmap;
14
14
  volumeId = cache.generateVolumeId(labelmapImageIds);
15
- if (!labelmapImageIds || labelmapImageIds.length === 1) {
15
+ if (!labelmapImageIds || labelmapImageIds.length === 0) {
16
16
  return;
17
17
  }
18
18
  const isValidVolume = utilities.isValidVolume(labelmapImageIds);
@@ -1 +1 @@
1
- export declare const version = "4.13.5";
1
+ export declare const version = "4.13.7";
@@ -1 +1 @@
1
- export const version = '4.13.5';
1
+ export const version = '4.13.7';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "4.13.5",
3
+ "version": "4.13.7",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -108,7 +108,7 @@
108
108
  "canvas": "3.2.0"
109
109
  },
110
110
  "peerDependencies": {
111
- "@cornerstonejs/core": "4.13.5",
111
+ "@cornerstonejs/core": "4.13.7",
112
112
  "@kitware/vtk.js": "34.15.1",
113
113
  "@types/d3-array": "3.2.1",
114
114
  "@types/d3-interpolate": "3.0.4",
@@ -127,5 +127,5 @@
127
127
  "type": "individual",
128
128
  "url": "https://ohif.org/donate"
129
129
  },
130
- "gitHead": "b2709b422af903a32a518e4fa76c583371f19559"
130
+ "gitHead": "ee360e7ddba785f4980cc4a6d79c058d7d313361"
131
131
  }