@cornerstonejs/tools 4.22.5 → 4.22.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.
@@ -6,6 +6,7 @@ export default class SegmentationStateManager {
6
6
  readonly uid: string;
7
7
  private _stackLabelmapImageIdReferenceMap;
8
8
  private _labelmapImageIdReferenceMap;
9
+ private _labelmapKeysBySegmentationId;
9
10
  constructor(uid?: string);
10
11
  getState(): Readonly<SegmentationState>;
11
12
  private updateState;
@@ -14,6 +14,7 @@ export default class SegmentationStateManager {
14
14
  constructor(uid) {
15
15
  this._stackLabelmapImageIdReferenceMap = new Map();
16
16
  this._labelmapImageIdReferenceMap = new Map();
17
+ this._labelmapKeysBySegmentationId = new Map();
17
18
  uid ||= csUtils.uuidv4();
18
19
  this.state = Object.freeze(csUtils.deepClone(initialDefaultState));
19
20
  this.uid = uid;
@@ -35,6 +36,7 @@ export default class SegmentationStateManager {
35
36
  resetState() {
36
37
  this._stackLabelmapImageIdReferenceMap.clear();
37
38
  this._labelmapImageIdReferenceMap.clear();
39
+ this._labelmapKeysBySegmentationId.clear();
38
40
  this.state = Object.freeze(csUtils.deepClone(initialDefaultState));
39
41
  }
40
42
  getSegmentation(segmentationId) {
@@ -69,6 +71,14 @@ export default class SegmentationStateManager {
69
71
  triggerSegmentationAdded(segmentation.segmentationId);
70
72
  }
71
73
  removeSegmentation(segmentationId) {
74
+ this._stackLabelmapImageIdReferenceMap.delete(segmentationId);
75
+ const keys = this._labelmapKeysBySegmentationId.get(segmentationId);
76
+ if (keys) {
77
+ for (const key of keys) {
78
+ this._labelmapImageIdReferenceMap.delete(key);
79
+ }
80
+ this._labelmapKeysBySegmentationId.delete(segmentationId);
81
+ }
72
82
  this.updateState((state) => {
73
83
  const filteredSegmentations = state.segmentations.filter((segmentation) => segmentation.segmentationId !== segmentationId);
74
84
  state.segmentations.splice(0, state.segmentations.length, ...filteredSegmentations);
@@ -363,11 +373,18 @@ export default class SegmentationStateManager {
363
373
  const key = this._generateMapKey({ segmentationId, referenceImageId });
364
374
  if (!this._labelmapImageIdReferenceMap.has(key)) {
365
375
  this._labelmapImageIdReferenceMap.set(key, [labelmapImageId]);
366
- return;
367
376
  }
368
- const currentValues = this._labelmapImageIdReferenceMap.get(key);
369
- const newValues = Array.from(new Set([...currentValues, labelmapImageId]));
370
- this._labelmapImageIdReferenceMap.set(key, newValues);
377
+ else {
378
+ const currentValues = this._labelmapImageIdReferenceMap.get(key);
379
+ const newValues = Array.from(new Set([...currentValues, labelmapImageId]));
380
+ this._labelmapImageIdReferenceMap.set(key, newValues);
381
+ }
382
+ let keys = this._labelmapKeysBySegmentationId.get(segmentationId);
383
+ if (!keys) {
384
+ keys = new Set();
385
+ this._labelmapKeysBySegmentationId.set(segmentationId, keys);
386
+ }
387
+ keys.add(key);
371
388
  }
372
389
  _setActiveSegmentation(state, viewportId, segmentationId) {
373
390
  const viewport = state.viewportSegRepresentations[viewportId];
@@ -335,12 +335,9 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
335
335
  const deltaInX = vec3.distance(originalWorldPoint, deltaXPoint);
336
336
  const deltaInY = vec3.distance(originalWorldPoint, deltaYPoint);
337
337
  const { imageData } = image;
338
- const { scale, areaUnit } = getCalibratedLengthUnitsAndScale(image, () => {
338
+ const { areaUnit } = getCalibratedLengthUnitsAndScale(image, () => {
339
339
  const { maxX: canvasMaxX, maxY: canvasMaxY, minX: canvasMinX, minY: canvasMinY, } = math.polyline.getAABB(canvasCoordinates);
340
- const topLeftBBWorld = viewport.canvasToWorld([
341
- canvasMinX,
342
- canvasMinY,
343
- ]);
340
+ const topLeftBBWorld = viewport.canvasToWorld([canvasMinX, canvasMinY]);
344
341
  const topLeftBBIndex = utilities.transformWorldToIndex(imageData, topLeftBBWorld);
345
342
  const bottomRightBBWorld = viewport.canvasToWorld([
346
343
  canvasMaxX,
@@ -349,8 +346,7 @@ class LivewireContourTool extends ContourSegmentationBaseTool {
349
346
  const bottomRightBBIndex = utilities.transformWorldToIndex(imageData, bottomRightBBWorld);
350
347
  return [topLeftBBIndex, bottomRightBBIndex];
351
348
  });
352
- let area = math.polyline.getArea(canvasCoordinates) / scale / scale;
353
- area *= deltaInX * deltaInY;
349
+ const area = math.polyline.getArea(canvasCoordinates) * deltaInX * deltaInY;
354
350
  cachedStats[targetId] = {
355
351
  Modality: metadata.Modality,
356
352
  area,
@@ -409,7 +409,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
409
409
  }
410
410
  }
411
411
  updateClosedCachedStats({ viewport, points, imageData, metadata, cachedStats, targetId, modalityUnit, canvasCoordinates, calibratedScale, deltaInX, deltaInY, }) {
412
- const { scale, areaUnit, unit } = calibratedScale;
412
+ const { areaUnit, unit } = calibratedScale;
413
413
  const { voxelManager } = viewport.getImageData();
414
414
  const indexPoints = points.map((point) => imageData.worldToIndex(point));
415
415
  let iMin = Number.MAX_SAFE_INTEGER;
@@ -427,8 +427,7 @@ class PlanarFreehandROITool extends ContourSegmentationBaseTool {
427
427
  kMin = Math.min(kMin, worldPosIndex[2]);
428
428
  kMax = Math.max(kMax, worldPosIndex[2]);
429
429
  }
430
- let area = polyline.getArea(canvasCoordinates) / scale / scale;
431
- area *= deltaInX * deltaInY;
430
+ const area = polyline.getArea(canvasCoordinates) * deltaInX * deltaInY;
432
431
  const perimeter = PlanarFreehandROITool.calculateLengthInIndex(calibratedScale, indexPoints, closed);
433
432
  const iDelta = 0.01 * (iMax - iMin);
434
433
  const jDelta = 0.01 * (jMax - jMin);
@@ -456,8 +456,14 @@ class RectangleROITool extends AnnotationTool {
456
456
  ];
457
457
  const handles = [pos1Index, pos2Index];
458
458
  const calibrate = getCalibratedLengthUnitsAndScale(image, handles);
459
- const width = RectangleROITool.calculateLengthInIndex(calibrate, indexHandles.slice(0, 2));
460
- const height = RectangleROITool.calculateLengthInIndex(calibrate, indexHandles.slice(2, 4));
459
+ const width = RectangleROITool.calculateLengthInIndex(calibrate, [
460
+ indexHandles[0],
461
+ indexHandles[1],
462
+ ]);
463
+ const height = RectangleROITool.calculateLengthInIndex(calibrate, [
464
+ indexHandles[0],
465
+ indexHandles[2],
466
+ ]);
461
467
  const area = Math.abs(width * height);
462
468
  const { areaUnit } = calibrate;
463
469
  const pixelUnitsOptions = {
@@ -473,12 +473,9 @@ class SplineROITool extends ContourSegmentationBaseTool {
473
473
  const deltaInX = vec3.distance(originalWorldPoint, deltaXPoint);
474
474
  const deltaInY = vec3.distance(originalWorldPoint, deltaYPoint);
475
475
  const { imageData } = image;
476
- const { scale, areaUnit } = getCalibratedLengthUnitsAndScale(image, () => {
476
+ const { areaUnit } = getCalibratedLengthUnitsAndScale(image, () => {
477
477
  const { maxX: canvasMaxX, maxY: canvasMaxY, minX: canvasMinX, minY: canvasMinY, } = math.polyline.getAABB(canvasCoordinates);
478
- const topLeftBBWorld = viewport.canvasToWorld([
479
- canvasMinX,
480
- canvasMinY,
481
- ]);
478
+ const topLeftBBWorld = viewport.canvasToWorld([canvasMinX, canvasMinY]);
482
479
  const topLeftBBIndex = utilities.transformWorldToIndex(imageData, topLeftBBWorld);
483
480
  const bottomRightBBWorld = viewport.canvasToWorld([
484
481
  canvasMaxX,
@@ -487,8 +484,7 @@ class SplineROITool extends ContourSegmentationBaseTool {
487
484
  const bottomRightBBIndex = utilities.transformWorldToIndex(imageData, bottomRightBBWorld);
488
485
  return [topLeftBBIndex, bottomRightBBIndex];
489
486
  });
490
- let area = math.polyline.getArea(canvasCoordinates) / scale / scale;
491
- area *= deltaInX * deltaInY;
487
+ const area = math.polyline.getArea(canvasCoordinates) * deltaInX * deltaInY;
492
488
  cachedStats[targetId] = {
493
489
  Modality: metadata.Modality,
494
490
  area,
@@ -1,8 +1,11 @@
1
1
  import { getEnabledElement } from '@cornerstonejs/core';
2
- import { getLabelmapActorUID } from '../../../stateManagement/segmentation/helpers/getSegmentationActor';
2
+ import { getLabelmapActorEntries } from '../../../stateManagement/segmentation/helpers/getSegmentationActor';
3
3
  function removeLabelmapFromElement(element, segmentationId) {
4
4
  const enabledElement = getEnabledElement(element);
5
5
  const { viewport } = enabledElement;
6
- viewport.removeActors([getLabelmapActorUID(viewport.id, segmentationId)]);
6
+ const actorEntries = getLabelmapActorEntries(viewport.id, segmentationId);
7
+ if (actorEntries?.length) {
8
+ viewport.removeActors(actorEntries.map((entry) => entry.uid));
9
+ }
7
10
  }
8
11
  export default removeLabelmapFromElement;
@@ -1 +1 @@
1
- export declare const version = "4.22.5";
1
+ export declare const version = "4.22.7";
@@ -1 +1 @@
1
- export const version = '4.22.5';
1
+ export const version = '4.22.7';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "4.22.5",
3
+ "version": "4.22.7",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -105,11 +105,11 @@
105
105
  "lodash.get": "4.4.2"
106
106
  },
107
107
  "devDependencies": {
108
- "@cornerstonejs/core": "4.22.5",
108
+ "@cornerstonejs/core": "4.22.7",
109
109
  "canvas": "3.2.0"
110
110
  },
111
111
  "peerDependencies": {
112
- "@cornerstonejs/core": "4.22.5",
112
+ "@cornerstonejs/core": "4.22.7",
113
113
  "@kitware/vtk.js": "34.15.1",
114
114
  "@types/d3-array": "3.2.1",
115
115
  "@types/d3-interpolate": "3.0.4",
@@ -128,5 +128,5 @@
128
128
  "type": "individual",
129
129
  "url": "https://ohif.org/donate"
130
130
  },
131
- "gitHead": "0f5aae8c1865161a541f7451914ad32f1793c9fb"
131
+ "gitHead": "0cc73058d26dd99741a7682ff8ee1256106a8eeb"
132
132
  }