@cornerstonejs/tools 5.10.6 → 5.10.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.
@@ -17,7 +17,9 @@ export default function mouseDownActivate(evt) {
17
17
  if (activeTool.addNewAnnotation) {
18
18
  try {
19
19
  const annotation = activeTool.addNewAnnotation(evt, 'mouse');
20
- setAnnotationSelected(annotation.annotationUID);
20
+ if (annotation) {
21
+ setAnnotationSelected(annotation.annotationUID);
22
+ }
21
23
  }
22
24
  catch (error) {
23
25
  cs3dLogger.warn('Error adding new annotation, viewport not ready:', error);
@@ -17,7 +17,9 @@ export default function touchStartActivate(evt) {
17
17
  if (activeTool.addNewAnnotation) {
18
18
  try {
19
19
  const annotation = activeTool.addNewAnnotation(evt, 'touch');
20
- setAnnotationSelected(annotation.annotationUID);
20
+ if (annotation) {
21
+ setAnnotationSelected(annotation.annotationUID);
22
+ }
21
23
  }
22
24
  catch (error) {
23
25
  cs3dLogger.warn('Error adding new annotation, viewport not ready:', error);
@@ -140,7 +140,7 @@ class SliceIntersectionTool extends AnnotationTool {
140
140
  if (!enabledElement) {
141
141
  return false;
142
142
  }
143
- return !!this._findLineNear(enabledElement.viewport.id, canvasCoords, LINE_PROXIMITY, true);
143
+ return !!this._findLineNear(enabledElement.viewport.id, canvasCoords, LINE_PROXIMITY, { includeHandles: true });
144
144
  };
145
145
  this.toolSelectedCallback = (evt, _annotation) => {
146
146
  const { element, currentPoints } = evt.detail;
@@ -217,7 +217,7 @@ class SliceIntersectionTool extends AnnotationTool {
217
217
  if (!this._isPlanarViewport(viewport)) {
218
218
  return false;
219
219
  }
220
- const lineInfo = this._findLineNear(viewport.id, currentPoints.canvas, LINE_PROXIMITY, true);
220
+ const lineInfo = this._findLineNear(viewport.id, currentPoints.canvas, LINE_PROXIMITY, { includeHandles: true, includeSlabLines: true });
221
221
  let needsRedraw = false;
222
222
  if (lineInfo) {
223
223
  if (this._activeGroupId !== lineInfo.groupId ||
@@ -499,7 +499,7 @@ class SliceIntersectionTool extends AnnotationTool {
499
499
  this._appendSlabGeometry(lineInfo, targetViewport, targetPlane, leaderViewport, leaderPlane);
500
500
  this._appendBoundaryGeometry(lineInfo, targetViewport, targetPlane, leaderViewport, leaderPlane);
501
501
  if (isActive) {
502
- this._appendHandles(lineInfo, targetViewport, leaderViewport);
502
+ this._appendHandles(lineInfo, leaderViewport);
503
503
  }
504
504
  return lineInfo;
505
505
  }
@@ -606,7 +606,7 @@ class SliceIntersectionTool extends AnnotationTool {
606
606
  spacing: Number.isFinite(spacing) ? spacing : 0,
607
607
  };
608
608
  }
609
- _appendHandles(lineInfo, targetViewport, leaderViewport) {
609
+ _appendHandles(lineInfo, leaderViewport) {
610
610
  const { rotatable, slabThicknessControls, showSlabThickness } = this.configuration;
611
611
  const [start, end] = lineInfo.canvasPoints;
612
612
  const volumeMode = this._isVolumeModeViewport(leaderViewport);
@@ -617,32 +617,22 @@ class SliceIntersectionTool extends AnnotationTool {
617
617
  ]);
618
618
  }
619
619
  if (slabThicknessControls && showSlabThickness && volumeMode) {
620
- lineInfo.slabHandles = this._computeSlabHandles(lineInfo, targetViewport, leaderViewport);
620
+ lineInfo.slabHandles = this._computeSlabHandles(lineInfo);
621
621
  }
622
622
  }
623
- _computeSlabHandles(lineInfo, targetViewport, leaderViewport) {
623
+ _computeSlabHandles(lineInfo) {
624
624
  const [start, end] = lineInfo.canvasPoints;
625
625
  const anchorCanvas = [
626
626
  start[0] + (end[0] - start[0]) * SLAB_HANDLE_LINE_FRACTION,
627
627
  start[1] + (end[1] - start[1]) * SLAB_HANDLE_LINE_FRACTION,
628
628
  ];
629
- const slabThickness = this._getSourceSlabThickness(leaderViewport);
630
- const anchorWorld = targetViewport.canvasToWorld(anchorCanvas);
631
- const { normal } = lineInfo.leaderPlane;
632
- const plusWorld = [
633
- anchorWorld[0] + normal[0] * (slabThickness / 2),
634
- anchorWorld[1] + normal[1] * (slabThickness / 2),
635
- anchorWorld[2] + normal[2] * (slabThickness / 2),
636
- ];
637
- const plusCanvas = targetViewport.worldToCanvas(plusWorld);
638
- const canvasOffset = Math.hypot(plusCanvas[0] - anchorCanvas[0], plusCanvas[1] - anchorCanvas[1]);
639
- if (canvasOffset >= MIN_SLAB_HANDLE_CANVAS_OFFSET) {
640
- const minusWorld = [
641
- anchorWorld[0] - normal[0] * (slabThickness / 2),
642
- anchorWorld[1] - normal[1] * (slabThickness / 2),
643
- anchorWorld[2] - normal[2] * (slabThickness / 2),
644
- ];
645
- return [plusCanvas, targetViewport.worldToCanvas(minusWorld)];
629
+ const minimumOffsetSquared = MIN_SLAB_HANDLE_CANVAS_OFFSET * MIN_SLAB_HANDLE_CANVAS_OFFSET;
630
+ const handles = lineInfo.slabLineSegments
631
+ .map(([segmentStart, segmentEnd]) => lineSegment.distanceToPointSquaredInfo(segmentStart, segmentEnd, anchorCanvas))
632
+ .filter((info) => info.distanceSquared >= minimumOffsetSquared)
633
+ .map((info) => info.point);
634
+ if (handles.length) {
635
+ return handles;
646
636
  }
647
637
  const direction = vec2.normalize(vec2.create(), vec2.subtract(vec2.create(), end, start));
648
638
  const perpendicular = [-direction[1], direction[0]];
@@ -951,7 +941,7 @@ class SliceIntersectionTool extends AnnotationTool {
951
941
  targetViewportId: lineInfo.targetViewportId,
952
942
  });
953
943
  }
954
- _findLineNear(viewportId, canvasCoords, proximity, includeHandles = false) {
944
+ _findLineNear(viewportId, canvasCoords, proximity, { includeHandles = false, includeSlabLines = false, } = {}) {
955
945
  const lines = this._renderedLines.get(viewportId) ?? [];
956
946
  const handleReach = this.configuration.handleRadius + proximity;
957
947
  for (const lineInfo of lines) {
@@ -969,6 +959,22 @@ class SliceIntersectionTool extends AnnotationTool {
969
959
  }
970
960
  }
971
961
  }
962
+ if (includeSlabLines && this.configuration.slabThicknessControls) {
963
+ let slabLineInfo = null;
964
+ let slabLineDistance = Infinity;
965
+ for (const lineInfo of lines) {
966
+ for (const [segmentStart, segmentEnd] of lineInfo.slabLineSegments) {
967
+ const distance = lineSegment.distanceToPoint(segmentStart, segmentEnd, canvasCoords);
968
+ if (distance <= proximity && distance < slabLineDistance) {
969
+ slabLineDistance = distance;
970
+ slabLineInfo = lineInfo;
971
+ }
972
+ }
973
+ }
974
+ if (slabLineInfo) {
975
+ return slabLineInfo;
976
+ }
977
+ }
972
978
  return null;
973
979
  }
974
980
  _getViewportsInfo() {
@@ -23,7 +23,7 @@ declare abstract class AnnotationTool extends AnnotationDisplayTool {
23
23
  static createAndAddAnnotation(viewport: any, ...annotationBaseData: any[]): void;
24
24
  static toolName: any;
25
25
  constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
26
- abstract addNewAnnotation(evt: EventTypes.InteractionEventType, interactionType: InteractionTypes): Annotation;
26
+ abstract addNewAnnotation(evt: EventTypes.InteractionEventType, interactionType: InteractionTypes): Annotation | null;
27
27
  abstract cancel(element: HTMLDivElement): any;
28
28
  abstract handleSelectedCallback(evt: EventTypes.InteractionEventType, annotation: Annotation, handle: ToolHandle, interactionType: InteractionTypes): void;
29
29
  abstract toolSelectedCallback(evt: EventTypes.InteractionEventType, annotation: Annotation, interactionType: InteractionTypes, canvasCoords?: Types.Point2): void;
@@ -47,6 +47,10 @@ declare abstract class AnnotationTool extends AnnotationDisplayTool {
47
47
  }): boolean;
48
48
  static isSuvScaled(viewport: Types.IStackViewport | Types.IVolumeViewport, targetId: string, imageId?: string): boolean;
49
49
  isSuvScaled: typeof AnnotationTool.isSuvScaled;
50
+ protected getTargetVolume(viewport: Types.IViewport): {
51
+ targetId: string;
52
+ imageVolume: Types.IImageVolume;
53
+ } | null;
50
54
  protected getAnnotationStyle(context: {
51
55
  annotation: Annotation;
52
56
  styleSpecifier: StyleSpecifier;
@@ -196,6 +196,13 @@ class AnnotationTool extends AnnotationDisplayTool {
196
196
  const scalingModule = imageId && metaData.get('scalingModule', imageId);
197
197
  return typeof scalingModule?.suvbw === 'number';
198
198
  }
199
+ getTargetVolume(viewport) {
200
+ const targetId = this.getTargetId(viewport);
201
+ const imageVolume = targetId
202
+ ? cache.getVolume(csUtils.getVolumeId(targetId))
203
+ : undefined;
204
+ return imageVolume ? { targetId, imageVolume } : null;
205
+ }
199
206
  getAnnotationStyle(context) {
200
207
  const { annotation, styleSpecifier } = context;
201
208
  const getStyle = (property) => this.getStyle(property, styleSpecifier, annotation);
@@ -16,7 +16,7 @@ declare class CircleROIStartEndThresholdTool extends CircleROITool {
16
16
  isDrawing: boolean;
17
17
  isHandleOutsideImage: boolean;
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
- addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation;
19
+ addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation | null;
20
20
  _endCallback: (evt: EventTypes.InteractionEventType) => void;
21
21
  renderAnnotation: (enabledElement: Types.IEnabledElement, svgDrawingHelper: SVGDrawingHelper) => boolean;
22
22
  _computeProjectionPoints(annotation: CircleROIStartEndThresholdAnnotation, imageVolume: Types.IImageVolume): void;
@@ -1,4 +1,4 @@
1
- import { StackViewport, cache, getEnabledElement, utilities as csUtils, utilities as coreUtils, } from '@cornerstonejs/core';
1
+ import { StackViewport, getEnabledElement, utilities as csUtils, utilities as coreUtils, } from '@cornerstonejs/core';
2
2
  import { vec3 } from 'gl-matrix';
3
3
  import { addAnnotation, removeAnnotation, getAnnotations, } from '../../stateManagement/annotation/annotationState.js';
4
4
  import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking.js';
@@ -44,19 +44,19 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
44
44
  const worldPos = currentPoints.world;
45
45
  const enabledElement = getEnabledElement(element);
46
46
  const { viewport } = enabledElement;
47
- this.isDrawing = true;
48
47
  const camera = viewport.getCamera();
49
48
  const { viewPlaneNormal, viewUp } = camera;
50
- let referencedImageId, imageVolume, volumeId;
51
49
  if (viewport instanceof StackViewport) {
52
50
  throw new Error('Stack Viewport Not implemented');
53
51
  }
54
- else {
55
- const targetId = this.getTargetId(viewport);
56
- volumeId = csUtils.getVolumeId(targetId);
57
- imageVolume = cache.getVolume(volumeId);
58
- referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
52
+ const target = this.getTargetVolume(viewport);
53
+ if (!target) {
54
+ return null;
59
55
  }
56
+ const volumeId = csUtils.getVolumeId(target.targetId);
57
+ const imageVolume = target.imageVolume;
58
+ const referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
59
+ this.isDrawing = true;
60
60
  const spacingInNormal = csUtils.getSpacingInNormalDirection(imageVolume, viewPlaneNormal);
61
61
  const startCoord = this._getStartCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
62
62
  const endCoord = this._getEndCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
@@ -148,9 +148,10 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
148
148
  this.configuration.preventHandleOutsideImage) {
149
149
  removeAnnotation(annotation.annotationUID);
150
150
  }
151
- const targetId = this.getTargetId(enabledElement.viewport);
152
- const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
153
- this._computePointsInsideVolume(annotation, imageVolume, targetId, enabledElement);
151
+ const target = this.getTargetVolume(enabledElement.viewport);
152
+ if (target) {
153
+ this._computePointsInsideVolume(annotation, target.imageVolume, target.targetId, enabledElement);
154
+ }
154
155
  triggerAnnotationRenderForViewportIds(viewportIdsToRender);
155
156
  if (newAnnotation) {
156
157
  triggerAnnotationCompleted(annotation);
@@ -221,12 +222,10 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
221
222
  isMiddleSlice = true;
222
223
  }
223
224
  data.handles.points[0][this._getIndexOfCoordinatesForViewplaneNormal(viewplaneNormal)] = middleCoordinate;
224
- const iteratorVolumeIDs = annotationEnabledElement.viewport?.volumeIds.values();
225
- for (const volumeId of iteratorVolumeIDs) {
226
- if (annotation.invalidated &&
227
- annotation.metadata.volumeId === volumeId) {
228
- this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
229
- }
225
+ const annotationViewport = annotationEnabledElement?.viewport;
226
+ if (annotation.invalidated &&
227
+ annotationViewport?.hasVolumeId?.(metadata.volumeId)) {
228
+ this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
230
229
  }
231
230
  if (!viewport.getRenderingEngine()) {
232
231
  cs3dLogger.warn('Rendering Engine has been destroyed');
@@ -364,7 +363,8 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
364
363
  const basePos1 = viewport.canvasToWorld(baseTopLeftCanvas);
365
364
  const basePos2 = viewport.canvasToWorld(baseBottomRightCanvas);
366
365
  const { worldWidth, worldHeight } = getWorldWidthAndHeightFromTwoPoints(viewPlaneNormal, viewUp, basePos1, basePos2);
367
- const measureInfo = getCalibratedLengthUnitsAndScale(image, data.handles.points);
366
+ const indexCoordinates = data.handles.points.map((point) => image.imageData.worldToIndex(point));
367
+ const measureInfo = getCalibratedLengthUnitsAndScale(image, indexCoordinates);
368
368
  const aspect = getCalibratedAspect(image);
369
369
  const area = Math.abs(Math.PI *
370
370
  (worldWidth / measureInfo.scale / 2) *
@@ -373,7 +373,8 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
373
373
  isPreScaled: isViewportPreScaled(viewport, targetId),
374
374
  isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
375
375
  };
376
- const modalityUnit = getPixelValueUnits(metadata.Modality, annotation.metadata.referencedImageId, modalityUnitOptions);
376
+ const modality = imageVolume?.metadata?.Modality;
377
+ const modalityUnit = getPixelValueUnits(modality, annotation.metadata.referencedImageId, modalityUnitOptions);
377
378
  for (let i = 0; i < projectionPoints.length; i++) {
378
379
  if (!imageVolume) {
379
380
  continue;
@@ -437,7 +438,7 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
437
438
  const stats = this.configuration.statsCalculator.getStatistics();
438
439
  data.cachedStats.pointsInVolume = pointsInsideVolume;
439
440
  data.cachedStats.statistics = {
440
- Modality: metadata.Modality,
441
+ Modality: modality,
441
442
  area,
442
443
  mean: stats.mean?.value,
443
444
  stdDev: stats.stdDev?.value,
@@ -451,8 +452,12 @@ class CircleROIStartEndThresholdTool extends CircleROITool {
451
452
  const data = annotation.data;
452
453
  const { viewport } = enabledElement;
453
454
  const { cachedStats } = data;
454
- const targetId = this.getTargetId(viewport);
455
- const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
455
+ const target = this.getTargetVolume(viewport);
456
+ if (!target) {
457
+ annotation.invalidated = false;
458
+ return cachedStats;
459
+ }
460
+ const { targetId, imageVolume } = target;
456
461
  this._computeProjectionPoints(annotation, imageVolume);
457
462
  this._computePointsInsideVolume(annotation, imageVolume, targetId, enabledElement);
458
463
  annotation.invalidated = false;
@@ -1,7 +1,7 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
2
  import { vec3 } from 'gl-matrix';
3
3
  import type { PublicToolProps, ToolProps, EventTypes, SVGDrawingHelper, Annotation } from '../../types/index.js';
4
- import type { RectangleROIStartEndThresholdAnnotation, ROICachedStats } from '../../types/ToolSpecificAnnotationTypes.js';
4
+ import type { RectangleROIStartEndThresholdAnnotation } from '../../types/ToolSpecificAnnotationTypes.js';
5
5
  import RectangleROITool from '../annotation/RectangleROITool.js';
6
6
  declare class RectangleROIStartEndThresholdTool extends RectangleROITool {
7
7
  static toolName: any;
@@ -18,45 +18,7 @@ declare class RectangleROIStartEndThresholdTool extends RectangleROITool {
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
19
  private _isCoordinateTuple;
20
20
  private _resolveViewPlaneCoordinate;
21
- addNewAnnotation: (evt: EventTypes.InteractionEventType) => {
22
- highlighted: boolean;
23
- invalidated: boolean;
24
- metadata: {
25
- viewPlaneNormal: Types.Point3;
26
- enabledElement: Types.IEnabledElement;
27
- viewUp: Types.Point3;
28
- FrameOfReferenceUID: string;
29
- referencedImageId: any;
30
- toolName: string;
31
- volumeId: any;
32
- spacingInNormal: number;
33
- };
34
- data: {
35
- label: string;
36
- startCoordinate: number;
37
- endCoordinate: number;
38
- cachedStats: {
39
- pointsInVolume: any[];
40
- projectionPoints: any[];
41
- projectionPointsImageIds: any[];
42
- statistics: ROICachedStats;
43
- };
44
- handles: {
45
- textBox: {
46
- hasMoved: boolean;
47
- worldPosition: Types.Point3;
48
- worldBoundingBox: {
49
- topLeft: Types.Point3;
50
- topRight: Types.Point3;
51
- bottomLeft: Types.Point3;
52
- bottomRight: Types.Point3;
53
- };
54
- };
55
- points: Types.Point3[];
56
- activeHandleIndex: any;
57
- };
58
- };
59
- };
21
+ addNewAnnotation: (evt: EventTypes.InteractionEventType) => Annotation | null;
60
22
  _endCallback: (evt: EventTypes.InteractionEventType) => void;
61
23
  _computeProjectionPoints(annotation: RectangleROIStartEndThresholdAnnotation, imageVolume: Types.IImageVolume): void;
62
24
  _computePointsInsideVolume(annotation: any, targetId: any, imageVolume: any, enabledElement: any): void;
@@ -1,4 +1,4 @@
1
- import { getEnabledElement, cache, StackViewport, utilities as csUtils, } from '@cornerstonejs/core';
1
+ import { getEnabledElement, StackViewport, utilities as csUtils, } from '@cornerstonejs/core';
2
2
  import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits.js';
3
3
  import { vec3 } from 'gl-matrix';
4
4
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/index.js';
@@ -40,19 +40,19 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
40
40
  const worldPos = currentPoints.world;
41
41
  const enabledElement = getEnabledElement(element);
42
42
  const { viewport, renderingEngine } = enabledElement;
43
- this.isDrawing = true;
44
43
  const camera = viewport.getCamera();
45
44
  const { viewPlaneNormal, viewUp } = camera;
46
- let referencedImageId, imageVolume, volumeId;
47
45
  if (viewport instanceof StackViewport) {
48
46
  throw new Error('Stack Viewport Not implemented');
49
47
  }
50
- else {
51
- const targetId = this.getTargetId(viewport);
52
- volumeId = csUtils.getVolumeId(targetId);
53
- imageVolume = cache.getVolume(volumeId);
54
- referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
48
+ const target = this.getTargetVolume(viewport);
49
+ if (!target) {
50
+ return null;
55
51
  }
52
+ const volumeId = csUtils.getVolumeId(target.targetId);
53
+ const imageVolume = target.imageVolume;
54
+ const referencedImageId = csUtils.getClosestImageId(imageVolume, worldPos, viewPlaneNormal);
55
+ this.isDrawing = true;
56
56
  const spacingInNormal = csUtils.getSpacingInNormalDirection(imageVolume, viewPlaneNormal);
57
57
  const startCoord = this._getStartCoordinate(worldPos, viewPlaneNormal);
58
58
  const endCoord = this._getEndCoordinate(worldPos, spacingInNormal, viewPlaneNormal);
@@ -137,10 +137,11 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
137
137
  this.configuration.preventHandleOutsideImage) {
138
138
  removeAnnotation(annotation.annotationUID);
139
139
  }
140
- const targetId = this.getTargetId(enabledElement.viewport);
141
- const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
142
- this._computeProjectionPoints(annotation, imageVolume);
143
- this._computePointsInsideVolume(annotation, targetId, imageVolume, enabledElement);
140
+ const target = this.getTargetVolume(enabledElement.viewport);
141
+ if (target) {
142
+ this._computeProjectionPoints(annotation, target.imageVolume);
143
+ this._computePointsInsideVolume(annotation, target.targetId, target.imageVolume, enabledElement);
144
+ }
144
145
  triggerAnnotationRenderForViewportIds(viewportIdsToRender);
145
146
  if (newAnnotation) {
146
147
  triggerAnnotationCompleted(annotation);
@@ -195,12 +196,10 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
195
196
  roundedCoord > Math.max(roundedStartCoord, roundedEndCoord)) {
196
197
  continue;
197
198
  }
198
- const iteratorVolumeIDs = annotationEnabledElement.viewport?.volumeIds.values();
199
- for (const volumeId of iteratorVolumeIDs) {
200
- if (annotation.invalidated &&
201
- annotation.metadata.volumeId === volumeId) {
202
- this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
203
- }
199
+ const annotationViewport = annotationEnabledElement?.viewport;
200
+ if (annotation.invalidated &&
201
+ annotationViewport?.hasVolumeId?.(metadata.volumeId)) {
202
+ this._throttledCalculateCachedStats(annotation, annotationEnabledElement);
204
203
  }
205
204
  let firstOrLastSlice = false;
206
205
  if (roundedCoord === roundedStartCoord ||
@@ -323,14 +322,16 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
323
322
  const worldPos1 = data.handles.points[0];
324
323
  const worldPos2 = data.handles.points[3];
325
324
  const { worldWidth, worldHeight } = getWorldWidthAndHeightFromCorners(viewPlaneNormal, viewUp, worldPos1, worldPos2);
326
- const measureInfo = getCalibratedLengthUnitsAndScale(image, data.habdles);
325
+ const indexCoordinates = data.handles.points.map((point) => image.imageData.worldToIndex(point));
326
+ const measureInfo = getCalibratedLengthUnitsAndScale(image, indexCoordinates);
327
327
  const area = Math.abs(worldWidth * worldHeight) /
328
328
  (measureInfo.scale * measureInfo.scale);
329
329
  const modalityUnitOptions = {
330
330
  isPreScaled: isViewportPreScaled(viewport, targetId),
331
331
  isSuvScaled: this.isSuvScaled(viewport, targetId, annotation.metadata.referencedImageId),
332
332
  };
333
- const modalityUnit = getPixelValueUnits(metadata.Modality, annotation.metadata.referencedImageId, modalityUnitOptions);
333
+ const modality = imageVolume?.metadata?.Modality;
334
+ const modalityUnit = getPixelValueUnits(modality, annotation.metadata.referencedImageId, modalityUnitOptions);
334
335
  for (let i = 0; i < projectionPoints.length; i++) {
335
336
  if (!imageVolume) {
336
337
  continue;
@@ -375,7 +376,7 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
375
376
  const stats = this.configuration.statsCalculator.getStatistics();
376
377
  data.cachedStats.pointsInVolume = pointsInsideVolume;
377
378
  data.cachedStats.statistics = {
378
- Modality: metadata.Modality,
379
+ Modality: modality,
379
380
  area,
380
381
  mean: stats.mean?.value,
381
382
  stdDev: stats.stdDev?.value,
@@ -389,8 +390,12 @@ class RectangleROIStartEndThresholdTool extends RectangleROITool {
389
390
  const data = annotation.data;
390
391
  const { viewport } = enabledElement;
391
392
  const { cachedStats } = data;
392
- const targetId = this.getTargetId(viewport);
393
- const imageVolume = cache.getVolume(targetId.split(/volumeId:|\?/)[1]);
393
+ const target = this.getTargetVolume(viewport);
394
+ if (!target) {
395
+ annotation.invalidated = false;
396
+ return cachedStats;
397
+ }
398
+ const { targetId, imageVolume } = target;
394
399
  this._computeProjectionPoints(annotation, imageVolume);
395
400
  this._computePointsInsideVolume(annotation, targetId, imageVolume, enabledElement);
396
401
  annotation.invalidated = false;
@@ -1 +1 @@
1
- export declare const version = "5.10.6";
1
+ export declare const version = "5.10.7";
@@ -1 +1 @@
1
- export const version = '5.10.6';
1
+ export const version = '5.10.7';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "5.10.6",
3
+ "version": "5.10.7",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -126,11 +126,11 @@
126
126
  "lodash.get": "4.4.2"
127
127
  },
128
128
  "devDependencies": {
129
- "@cornerstonejs/core": "5.10.6",
129
+ "@cornerstonejs/core": "5.10.7",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.10.6",
133
+ "@cornerstonejs/core": "5.10.7",
134
134
  "@kitware/vtk.js": "36.4.1",
135
135
  "@types/d3-array": "3.2.1",
136
136
  "@types/d3-interpolate": "3.0.4",