@cornerstonejs/tools 2.2.20 → 2.3.1

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 (36) hide show
  1. package/dist/esm/enums/StrategyCallbacks.d.ts +2 -1
  2. package/dist/esm/enums/StrategyCallbacks.js +1 -0
  3. package/dist/esm/stateManagement/segmentation/events/triggerSegmentationDataModified.d.ts +1 -1
  4. package/dist/esm/stateManagement/segmentation/events/triggerSegmentationDataModified.js +2 -1
  5. package/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.d.ts +1 -0
  6. package/dist/esm/stateManagement/segmentation/helpers/getSegmentationActor.js +4 -1
  7. package/dist/esm/tools/annotation/AngleTool.d.ts +3 -0
  8. package/dist/esm/tools/annotation/AngleTool.js +34 -1
  9. package/dist/esm/tools/annotation/ArrowAnnotateTool.d.ts +3 -0
  10. package/dist/esm/tools/annotation/ArrowAnnotateTool.js +35 -1
  11. package/dist/esm/tools/annotation/EllipticalROITool.d.ts +3 -0
  12. package/dist/esm/tools/annotation/EllipticalROITool.js +37 -1
  13. package/dist/esm/tools/base/BaseTool.d.ts +1 -1
  14. package/dist/esm/tools/base/BaseTool.js +2 -2
  15. package/dist/esm/tools/displayTools/Surface/addOrUpdateSurfaceToElement.js +2 -2
  16. package/dist/esm/tools/segmentation/BrushTool.d.ts +1 -0
  17. package/dist/esm/tools/segmentation/BrushTool.js +11 -10
  18. package/dist/esm/tools/segmentation/strategies/BrushStrategy.d.ts +6 -0
  19. package/dist/esm/tools/segmentation/strategies/BrushStrategy.js +6 -4
  20. package/dist/esm/tools/segmentation/strategies/compositions/determineSegmentIndex.js +1 -1
  21. package/dist/esm/tools/segmentation/strategies/compositions/index.d.ts +5 -0
  22. package/dist/esm/tools/segmentation/strategies/compositions/index.js +2 -0
  23. package/dist/esm/tools/segmentation/strategies/compositions/islandRemoval.js +1 -1
  24. package/dist/esm/tools/segmentation/strategies/compositions/labelmapStatistics.d.ts +7 -0
  25. package/dist/esm/tools/segmentation/strategies/compositions/labelmapStatistics.js +32 -0
  26. package/dist/esm/tools/segmentation/strategies/compositions/preview.js +2 -2
  27. package/dist/esm/tools/segmentation/strategies/fillCircle.js +2 -2
  28. package/dist/esm/tools/segmentation/strategies/fillSphere.d.ts +2 -1
  29. package/dist/esm/tools/segmentation/strategies/fillSphere.js +4 -2
  30. package/dist/esm/types/EventTypes.d.ts +1 -0
  31. package/dist/esm/utilities/math/basic/BasicStatsCalculator.js +3 -1
  32. package/dist/esm/utilities/segmentation/VolumetricCalculator.d.ts +8 -0
  33. package/dist/esm/utilities/segmentation/VolumetricCalculator.js +18 -0
  34. package/dist/esm/utilities/segmentation/index.d.ts +2 -1
  35. package/dist/esm/utilities/segmentation/index.js +2 -1
  36. package/package.json +3 -3
@@ -9,6 +9,7 @@ declare enum StrategyCallbacks {
9
9
  CreateIsInThreshold = "createIsInThreshold",
10
10
  Initialize = "initialize",
11
11
  INTERNAL_setValue = "setValue",
12
- ComputeInnerCircleRadius = "computeInnerCircleRadius"
12
+ ComputeInnerCircleRadius = "computeInnerCircleRadius",
13
+ GetStatistics = "getStatistics"
13
14
  }
14
15
  export default StrategyCallbacks;
@@ -11,5 +11,6 @@ var StrategyCallbacks;
11
11
  StrategyCallbacks["Initialize"] = "initialize";
12
12
  StrategyCallbacks["INTERNAL_setValue"] = "setValue";
13
13
  StrategyCallbacks["ComputeInnerCircleRadius"] = "computeInnerCircleRadius";
14
+ StrategyCallbacks["GetStatistics"] = "getStatistics";
14
15
  })(StrategyCallbacks || (StrategyCallbacks = {}));
15
16
  export default StrategyCallbacks;
@@ -1 +1 @@
1
- export declare function triggerSegmentationDataModified(segmentationId: string, modifiedSlicesToUse?: number[]): void;
1
+ export declare function triggerSegmentationDataModified(segmentationId: string, modifiedSlicesToUse?: number[], segmentIndex?: number): void;
@@ -1,10 +1,11 @@
1
1
  import { triggerEvent, eventTarget } from '@cornerstonejs/core';
2
2
  import { Events } from '../../../enums';
3
3
  import { setSegmentationDirty } from '../../../utilities/segmentation/utilities';
4
- export function triggerSegmentationDataModified(segmentationId, modifiedSlicesToUse) {
4
+ export function triggerSegmentationDataModified(segmentationId, modifiedSlicesToUse, segmentIndex) {
5
5
  const eventDetail = {
6
6
  segmentationId,
7
7
  modifiedSlicesToUse,
8
+ segmentIndex,
8
9
  };
9
10
  setSegmentationDirty(segmentationId);
10
11
  triggerEvent(eventTarget, Events.SEGMENTATION_DATA_MODIFIED, eventDetail);
@@ -2,3 +2,4 @@ export declare function getLabelmapActorUID(viewportId: string, segmentationId:
2
2
  export declare function getLabelmapActorEntry(viewportId: string, segmentationId: string): import("packages/core/dist/esm/types").ActorEntry;
3
3
  export declare function getSurfaceActorEntry(viewportId: string, segmentationId: string, segmentIndex?: number | string): import("packages/core/dist/esm/types").ActorEntry;
4
4
  export declare function getSurfaceActorUID(viewportId: string, segmentationId: string, segmentIndex?: number | string): string | undefined;
5
+ export declare function getSurfaceRepresentationUID(segmentationId: string, segmentIndex?: number | string): string;
@@ -21,10 +21,13 @@ export function getLabelmapActorEntry(viewportId, segmentationId) {
21
21
  return getActorEntry(viewportId, segmentationId, (actor) => actor.representationUID?.startsWith(`${segmentationId}-${SegmentationRepresentations.Labelmap}`));
22
22
  }
23
23
  export function getSurfaceActorEntry(viewportId, segmentationId, segmentIndex) {
24
- return getActorEntry(viewportId, segmentationId, (actor) => actor.representationUID?.startsWith(`${segmentationId}-${SegmentationRepresentations.Surface}-${segmentIndex}`));
24
+ return getActorEntry(viewportId, segmentationId, (actor) => actor.representationUID?.startsWith(getSurfaceRepresentationUID(segmentationId, segmentIndex)));
25
25
  }
26
26
  export function getSurfaceActorUID(viewportId, segmentationId, segmentIndex) {
27
27
  const segIndex = segmentIndex ? segmentIndex.toString() : '';
28
28
  const actorEntry = getSurfaceActorEntry(viewportId, segmentationId, segIndex);
29
29
  return actorEntry?.uid;
30
30
  }
31
+ export function getSurfaceRepresentationUID(segmentationId, segmentIndex) {
32
+ return `${segmentationId}-${SegmentationRepresentations.Surface}-${segmentIndex}`;
33
+ }
@@ -17,6 +17,9 @@ declare class AngleTool extends AnnotationTool {
17
17
  isDrawing: boolean;
18
18
  isHandleOutsideImage: boolean;
19
19
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
20
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
21
+ annotationUID?: string;
22
+ }) => AngleAnnotation;
20
23
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => AngleAnnotation;
21
24
  isPointNearTool: (element: HTMLDivElement, annotation: AngleAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
22
25
  toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: AngleAnnotation) => void;
@@ -1,5 +1,5 @@
1
1
  import { Events } from '../../enums';
2
- import { getEnabledElement, utilities as csUtils } from '@cornerstonejs/core';
2
+ import { getEnabledElement, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { AnnotationTool } from '../base';
4
4
  import throttle from '../../utilities/throttle';
5
5
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
@@ -377,6 +377,39 @@ class AngleTool extends AnnotationTool {
377
377
  };
378
378
  this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
379
379
  }
380
+ static { this.hydrate = (viewportId, points, options) => {
381
+ const enabledElement = getEnabledElementByViewportId(viewportId);
382
+ if (!enabledElement) {
383
+ return;
384
+ }
385
+ const { viewport } = enabledElement;
386
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
387
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
388
+ const instance = new this();
389
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
390
+ const annotation = {
391
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
392
+ data: {
393
+ handles: {
394
+ points,
395
+ },
396
+ },
397
+ highlighted: false,
398
+ autoGenerated: false,
399
+ invalidated: false,
400
+ isLocked: false,
401
+ isVisible: true,
402
+ metadata: {
403
+ toolName: instance.getToolName(),
404
+ viewPlaneNormal,
405
+ FrameOfReferenceUID,
406
+ referencedImageId,
407
+ ...options,
408
+ },
409
+ };
410
+ addAnnotation(annotation, viewport.element);
411
+ triggerAnnotationRenderForViewportIds([viewport.id]);
412
+ }; }
380
413
  handleSelectedCallback(evt, annotation, handle) {
381
414
  const eventDetail = evt.detail;
382
415
  const { element } = eventDetail;
@@ -16,6 +16,9 @@ declare class ArrowAnnotateTool extends AnnotationTool {
16
16
  isDrawing: boolean;
17
17
  isHandleOutsideImage: boolean;
18
18
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
19
+ static hydrate: (viewportId: string, points: Types.Point3[], text?: string, options?: {
20
+ annotationUID?: string;
21
+ }) => ArrowAnnotation;
19
22
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => ArrowAnnotation;
20
23
  isPointNearTool: (element: HTMLDivElement, annotation: ArrowAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
21
24
  toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: ArrowAnnotation) => void;
@@ -1,5 +1,5 @@
1
1
  import { Events } from '../../enums';
2
- import { getEnabledElement, utilities as csUtils } from '@cornerstonejs/core';
2
+ import { getEnabledElement, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { AnnotationTool } from '../base';
4
4
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
5
5
  import { isAnnotationLocked } from '../../stateManagement/annotation/annotationLocking';
@@ -372,6 +372,40 @@ class ArrowAnnotateTool extends AnnotationTool {
372
372
  return renderStatus;
373
373
  };
374
374
  }
375
+ static { this.hydrate = (viewportId, points, text, options) => {
376
+ const enabledElement = getEnabledElementByViewportId(viewportId);
377
+ if (!enabledElement) {
378
+ return;
379
+ }
380
+ const { viewport } = enabledElement;
381
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
382
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
383
+ const instance = new this();
384
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
385
+ const annotation = {
386
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
387
+ data: {
388
+ text: text || '',
389
+ handles: {
390
+ points,
391
+ },
392
+ },
393
+ highlighted: false,
394
+ autoGenerated: false,
395
+ invalidated: false,
396
+ isLocked: false,
397
+ isVisible: true,
398
+ metadata: {
399
+ toolName: instance.getToolName(),
400
+ viewPlaneNormal,
401
+ FrameOfReferenceUID,
402
+ referencedImageId,
403
+ ...options,
404
+ },
405
+ };
406
+ addAnnotation(annotation, viewport.element);
407
+ triggerAnnotationRenderForViewportIds([viewport.id]);
408
+ }; }
375
409
  handleSelectedCallback(evt, annotation, handle) {
376
410
  const eventDetail = evt.detail;
377
411
  const { element } = eventDetail;
@@ -20,6 +20,9 @@ declare class EllipticalROITool extends AnnotationTool {
20
20
  isDrawing: boolean;
21
21
  isHandleOutsideImage: boolean;
22
22
  constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
23
+ static hydrate: (viewportId: string, points: Types.Point3[], options?: {
24
+ annotationUID?: string;
25
+ }) => EllipticalROIAnnotation;
23
26
  addNewAnnotation: (evt: EventTypes.InteractionEventType) => EllipticalROIAnnotation;
24
27
  isPointNearTool: (element: HTMLDivElement, annotation: EllipticalROIAnnotation, canvasCoords: Types.Point2, proximity: number) => boolean;
25
28
  toolSelectedCallback: (evt: EventTypes.InteractionEventType, annotation: EllipticalROIAnnotation) => void;
@@ -1,5 +1,5 @@
1
1
  import { AnnotationTool } from '../base';
2
- import { getEnabledElement, VolumeViewport, utilities as csUtils, } from '@cornerstonejs/core';
2
+ import { getEnabledElement, VolumeViewport, utilities as csUtils, getEnabledElementByViewportId, } from '@cornerstonejs/core';
3
3
  import { getCalibratedLengthUnitsAndScale } from '../../utilities/getCalibratedUnits';
4
4
  import throttle from '../../utilities/throttle';
5
5
  import { addAnnotation, getAnnotations, removeAnnotation, } from '../../stateManagement/annotation/annotationState';
@@ -626,6 +626,42 @@ class EllipticalROITool extends AnnotationTool {
626
626
  };
627
627
  this._throttledCalculateCachedStats = throttle(this._calculateCachedStats, 100, { trailing: true });
628
628
  }
629
+ static { this.hydrate = (viewportId, points, options) => {
630
+ const enabledElement = getEnabledElementByViewportId(viewportId);
631
+ if (!enabledElement) {
632
+ return;
633
+ }
634
+ const { viewport } = enabledElement;
635
+ const FrameOfReferenceUID = viewport.getFrameOfReferenceUID();
636
+ const { viewPlaneNormal, viewUp } = viewport.getCamera();
637
+ const instance = new this();
638
+ const referencedImageId = instance.getReferencedImageId(viewport, points[0], viewPlaneNormal, viewUp);
639
+ const annotation = {
640
+ annotationUID: options?.annotationUID || csUtils.uuidv4(),
641
+ data: {
642
+ handles: {
643
+ points,
644
+ activeHandleIndex: null,
645
+ },
646
+ label: '',
647
+ cachedStats: {},
648
+ },
649
+ highlighted: false,
650
+ autoGenerated: false,
651
+ invalidated: false,
652
+ isLocked: false,
653
+ isVisible: true,
654
+ metadata: {
655
+ toolName: instance.getToolName(),
656
+ viewPlaneNormal,
657
+ FrameOfReferenceUID,
658
+ referencedImageId,
659
+ ...options,
660
+ },
661
+ };
662
+ addAnnotation(annotation, viewport.element);
663
+ triggerAnnotationRenderForViewportIds([viewport.id]);
664
+ }; }
629
665
  _pointInEllipseCanvas(ellipse, location) {
630
666
  const xRadius = ellipse.width / 2;
631
667
  const yRadius = ellipse.height / 2;
@@ -11,7 +11,7 @@ declare abstract class BaseTool {
11
11
  constructor(toolProps: PublicToolProps, defaultToolProps: ToolProps);
12
12
  getToolName(): string;
13
13
  applyActiveStrategy(enabledElement: Types.IEnabledElement, operationData: unknown): any;
14
- applyActiveStrategyCallback(enabledElement: Types.IEnabledElement, operationData: unknown, callbackType: StrategyCallbacks | string): any;
14
+ applyActiveStrategyCallback(enabledElement: Types.IEnabledElement, operationData: unknown, callbackType: StrategyCallbacks | string, ...extraArgs: any[]): any;
15
15
  setConfiguration(newConfiguration: Record<string, any>): void;
16
16
  setActiveStrategy(strategyName: string): void;
17
17
  protected getTargetImageData(targetId: string): Types.IImageData | Types.CPUIImageData;
@@ -22,12 +22,12 @@ class BaseTool {
22
22
  const { strategies, activeStrategy } = this.configuration;
23
23
  return strategies[activeStrategy]?.call(this, enabledElement, operationData);
24
24
  }
25
- applyActiveStrategyCallback(enabledElement, operationData, callbackType) {
25
+ applyActiveStrategyCallback(enabledElement, operationData, callbackType, ...extraArgs) {
26
26
  const { strategies, activeStrategy } = this.configuration;
27
27
  if (!strategies[activeStrategy]) {
28
28
  throw new Error(`applyActiveStrategyCallback: active strategy ${activeStrategy} not found, check tool configuration or spellings`);
29
29
  }
30
- return strategies[activeStrategy][callbackType]?.call(this, enabledElement, operationData);
30
+ return strategies[activeStrategy][callbackType]?.call(this, enabledElement, operationData, ...extraArgs);
31
31
  }
32
32
  setConfiguration(newConfiguration) {
33
33
  this.configuration = utilities.deepMerge(this.configuration, newConfiguration);
@@ -4,11 +4,10 @@ import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
4
4
  import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
5
5
  import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
6
6
  import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray';
7
- import { getSurfaceActorEntry, getSurfaceActorUID, } from '../../../stateManagement/segmentation/helpers/getSegmentationActor';
7
+ import { getSurfaceActorEntry, getSurfaceRepresentationUID, } from '../../../stateManagement/segmentation/helpers/getSegmentationActor';
8
8
  function addOrUpdateSurfaceToElement(element, surface, segmentationId) {
9
9
  const enabledElement = getEnabledElement(element);
10
10
  const { viewport } = enabledElement;
11
- const representationUID = getSurfaceActorUID(viewport.id, segmentationId, surface.segmentIndex);
12
11
  const surfaceActorEntry = getSurfaceActorEntry(viewport.id, segmentationId, surface.segmentIndex);
13
12
  const surfaceActor = surfaceActorEntry?.actor;
14
13
  if (surfaceActor) {
@@ -49,6 +48,7 @@ function addOrUpdateSurfaceToElement(element, surface, segmentationId) {
49
48
  actor.setMapper(mapper);
50
49
  actor.getProperty().setColor(color[0] / 255, color[1] / 255, color[2] / 255);
51
50
  actor.getProperty().setLineWidth(2);
51
+ const representationUID = getSurfaceRepresentationUID(segmentationId, surface.segmentIndex);
52
52
  viewport.addActor({
53
53
  uid: utilities.uuidv4(),
54
54
  actor: actor,
@@ -119,6 +119,7 @@ declare class BrushTool extends BaseTool {
119
119
  };
120
120
  private _calculateCursor;
121
121
  private _endCallback;
122
+ getStatistics(element: any, segmentIndices?: any): any;
122
123
  rejectPreview(element?: HTMLDivElement): void;
123
124
  acceptPreview(element?: HTMLDivElement): void;
124
125
  private _activateDraw;
@@ -1,7 +1,7 @@
1
1
  import { utilities as csUtils, cache, getEnabledElement, StackViewport, eventTarget, Enums, BaseVolumeViewport, volumeLoader, } from '@cornerstonejs/core';
2
2
  import { vec3, vec2 } from 'gl-matrix';
3
3
  import { BaseTool } from '../base';
4
- import { fillInsideSphere, thresholdInsideSphere, } from './strategies/fillSphere';
4
+ import { fillInsideSphere, thresholdInsideSphere, thresholdInsideSphereIsland, } from './strategies/fillSphere';
5
5
  import { eraseInsideSphere } from './strategies/eraseSphere';
6
6
  import { thresholdInsideCircle, fillInsideCircle, } from './strategies/fillCircle';
7
7
  import { eraseInsideCircle } from './strategies/eraseCircle';
@@ -25,6 +25,7 @@ class BrushTool extends BaseTool {
25
25
  ERASE_INSIDE_SPHERE: eraseInsideSphere,
26
26
  THRESHOLD_INSIDE_CIRCLE: thresholdInsideCircle,
27
27
  THRESHOLD_INSIDE_SPHERE: thresholdInsideSphere,
28
+ THRESHOLD_INSIDE_SPHERE_WITH_ISLAND_REMOVAL: thresholdInsideSphereIsland,
28
29
  },
29
30
  strategySpecificConfiguration: {
30
31
  THRESHOLD: {
@@ -52,14 +53,6 @@ class BrushTool extends BaseTool {
52
53
  },
53
54
  ],
54
55
  },
55
- [StrategyCallbacks.RejectPreview]: {
56
- method: StrategyCallbacks.RejectPreview,
57
- bindings: [
58
- {
59
- key: 'Escape',
60
- },
61
- ],
62
- },
63
56
  },
64
57
  },
65
58
  }) {
@@ -401,7 +394,7 @@ class BrushTool extends BaseTool {
401
394
  ];
402
395
  const activeStrategy = this.configuration.activeStrategy;
403
396
  const strategy = this.configuration.strategies[activeStrategy];
404
- if (typeof strategy.computeInnerCircleRadius === 'function') {
397
+ if (typeof strategy?.computeInnerCircleRadius === 'function') {
405
398
  strategy.computeInnerCircleRadius({
406
399
  configuration: this.configuration,
407
400
  viewport,
@@ -409,6 +402,14 @@ class BrushTool extends BaseTool {
409
402
  }
410
403
  data.invalidated = false;
411
404
  }
405
+ getStatistics(element, segmentIndices) {
406
+ if (!element) {
407
+ return;
408
+ }
409
+ const enabledElement = getEnabledElement(element);
410
+ const stats = this.applyActiveStrategyCallback(enabledElement, this.getOperationData(element), StrategyCallbacks.GetStatistics, segmentIndices);
411
+ return stats;
412
+ }
412
413
  rejectPreview(element = this._previewData.element) {
413
414
  if (!element || !this._previewData.preview) {
414
415
  return;
@@ -59,6 +59,11 @@ export default class BrushStrategy {
59
59
  threshold: {
60
60
  createIsInThreshold: (operationData: InitializedOperationData) => (index: any) => boolean;
61
61
  };
62
+ labelmapStatistics: {
63
+ getStatistics: (enabledElement: any, operationData: InitializedOperationData, options?: {
64
+ indices?: number | number[];
65
+ }) => import("../../../types").NamedStatistics;
66
+ };
62
67
  };
63
68
  protected static childFunctions: {
64
69
  onInteractionStart: (brushStrategy: any, func: any) => void;
@@ -71,6 +76,7 @@ export default class BrushStrategy {
71
76
  setValue: (brushStrategy: any, func: any) => void;
72
77
  preview: (brushStrategy: any, func: any) => void;
73
78
  computeInnerCircleRadius: (brushStrategy: any, func: any) => void;
79
+ getStatistics: (brushStrategy: any, func: any) => void;
74
80
  compositions: any;
75
81
  };
76
82
  compositions: Composition[];
@@ -17,6 +17,7 @@ export default class BrushStrategy {
17
17
  [StrategyCallbacks.INTERNAL_setValue]: addSingletonMethod(StrategyCallbacks.INTERNAL_setValue),
18
18
  [StrategyCallbacks.Preview]: addSingletonMethod(StrategyCallbacks.Preview, false),
19
19
  [StrategyCallbacks.ComputeInnerCircleRadius]: addListMethod(StrategyCallbacks.ComputeInnerCircleRadius),
20
+ [StrategyCallbacks.GetStatistics]: addSingletonMethod(StrategyCallbacks.GetStatistics),
20
21
  compositions: null,
21
22
  }; }
22
23
  constructor(name, ...initializers) {
@@ -36,8 +37,9 @@ export default class BrushStrategy {
36
37
  strategySpecificConfiguration.centerIJK = centerIJK;
37
38
  }
38
39
  this._fill.forEach((func) => func(initializedData));
39
- const { segmentationVoxelManager, previewVoxelManager, previewSegmentIndex, } = initializedData;
40
- triggerSegmentationDataModified(initializedData.segmentationId, segmentationVoxelManager.getArrayOfModifiedSlices());
40
+ const { segmentationVoxelManager, previewVoxelManager, previewSegmentIndex, segmentIndex, } = initializedData;
41
+ const isPreview = previewSegmentIndex && previewVoxelManager.modifiedSlices.size;
42
+ triggerSegmentationDataModified(initializedData.segmentationId, segmentationVoxelManager.getArrayOfModifiedSlices(), isPreview ? previewSegmentIndex : segmentIndex);
41
43
  if (!previewSegmentIndex || !previewVoxelManager.modifiedSlices.size) {
42
44
  segmentationVoxelManager.resetModifiedSlices();
43
45
  return null;
@@ -134,9 +136,9 @@ function addSingletonMethod(name, isInitialized = true) {
134
136
  }
135
137
  brushStrategy[name] = isInitialized
136
138
  ? func
137
- : (enabledElement, operationData) => {
139
+ : (enabledElement, operationData, ...args) => {
138
140
  operationData.enabledElement = enabledElement;
139
- return func.call(brushStrategy, operationData);
141
+ return func.call(brushStrategy, operationData, ...args);
140
142
  };
141
143
  };
142
144
  }
@@ -22,7 +22,7 @@ export default {
22
22
  hasSegmentIndex ||= value === segmentIndex;
23
23
  hasPreviewIndex ||= value === previewSegmentIndex;
24
24
  };
25
- imageVoxelManager.forEach(callback, {
25
+ segmentationVoxelManager.forEach(callback, {
26
26
  imageData: segmentationImageData,
27
27
  isInObject: operationData.isInObject,
28
28
  });
@@ -32,5 +32,10 @@ declare const _default: {
32
32
  threshold: {
33
33
  createIsInThreshold: (operationData: import("../BrushStrategy").InitializedOperationData) => (index: any) => boolean;
34
34
  };
35
+ labelmapStatistics: {
36
+ getStatistics: (enabledElement: any, operationData: import("../BrushStrategy").InitializedOperationData, options?: {
37
+ indices?: number | number[];
38
+ }) => import("../../../../types").NamedStatistics;
39
+ };
35
40
  };
36
41
  export default _default;
@@ -6,6 +6,7 @@ import preview from './preview';
6
6
  import regionFill from './regionFill';
7
7
  import setValue from './setValue';
8
8
  import threshold from './threshold';
9
+ import labelmapStatistics from './labelmapStatistics';
9
10
  export default {
10
11
  determineSegmentIndex,
11
12
  dynamicThreshold,
@@ -15,4 +16,5 @@ export default {
15
16
  regionFill,
16
17
  setValue,
17
18
  threshold,
19
+ labelmapStatistics,
18
20
  };
@@ -118,6 +118,6 @@ export default {
118
118
  }
119
119
  }
120
120
  }
121
- triggerSegmentationDataModified(operationData.segmentationId, previewVoxelManager.getArrayOfModifiedSlices());
121
+ triggerSegmentationDataModified(operationData.segmentationId, previewVoxelManager.getArrayOfModifiedSlices(), previewSegmentIndex);
122
122
  },
123
123
  };
@@ -0,0 +1,7 @@
1
+ import type { InitializedOperationData } from '../BrushStrategy';
2
+ declare const _default: {
3
+ getStatistics: (enabledElement: any, operationData: InitializedOperationData, options?: {
4
+ indices?: number | number[];
5
+ }) => import("../../../../types").NamedStatistics;
6
+ };
7
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
2
+ import VolumetricCalculator from '../../../../utilities/segmentation/VolumetricCalculator';
3
+ import { getActiveSegmentIndex } from '../../../../stateManagement/segmentation/getActiveSegmentIndex';
4
+ import { getStrategyData } from '../utils/getStrategyData';
5
+ export default {
6
+ [StrategyCallbacks.GetStatistics]: function (enabledElement, operationData, options) {
7
+ const { viewport } = enabledElement;
8
+ let { indices } = options;
9
+ const { segmentationId } = operationData;
10
+ if (!indices) {
11
+ indices = [getActiveSegmentIndex(segmentationId)];
12
+ }
13
+ else if (!Array.isArray(indices)) {
14
+ indices = [indices, 255];
15
+ }
16
+ const indicesArr = indices;
17
+ const { segmentationVoxelManager, imageVoxelManager, segmentationImageData, } = getStrategyData({
18
+ operationData,
19
+ viewport,
20
+ });
21
+ const spacing = segmentationImageData.getSpacing();
22
+ segmentationVoxelManager.forEach((voxel) => {
23
+ const { value, pointIJK } = voxel;
24
+ if (indicesArr.indexOf(value) === -1) {
25
+ return;
26
+ }
27
+ const imageValue = imageVoxelManager.getAtIJKPoint(pointIJK);
28
+ VolumetricCalculator.statsCallback({ value: imageValue });
29
+ });
30
+ return VolumetricCalculator.getStatistics({ spacing });
31
+ },
32
+ };
@@ -66,7 +66,7 @@ export default {
66
66
  }
67
67
  };
68
68
  tracking.forEach(callback, {});
69
- triggerSegmentationDataModified(operationData.segmentationId, tracking.getArrayOfModifiedSlices());
69
+ triggerSegmentationDataModified(operationData.segmentationId, tracking.getArrayOfModifiedSlices(), preview.segmentIndex);
70
70
  tracking.clear();
71
71
  },
72
72
  [StrategyCallbacks.RejectPreview]: (operationData) => {
@@ -78,7 +78,7 @@ export default {
78
78
  segmentationVoxelManager.setAtIndex(index, value);
79
79
  };
80
80
  previewVoxelManager.forEach(callback);
81
- triggerSegmentationDataModified(operationData.segmentationId, previewVoxelManager.getArrayOfModifiedSlices());
81
+ triggerSegmentationDataModified(operationData.segmentationId, previewVoxelManager.getArrayOfModifiedSlices(), 0);
82
82
  previewVoxelManager.clear();
83
83
  },
84
84
  };
@@ -61,8 +61,8 @@ function createPointInEllipse(worldInfo) {
61
61
  const { precalculated } = precalculatePointInEllipse(ellipseObj, {});
62
62
  return precalculated;
63
63
  }
64
- const CIRCLE_STRATEGY = new BrushStrategy('Circle', compositions.regionFill, compositions.setValue, initializeCircle, compositions.determineSegmentIndex, compositions.preview);
65
- const CIRCLE_THRESHOLD_STRATEGY = new BrushStrategy('CircleThreshold', compositions.regionFill, compositions.setValue, initializeCircle, compositions.determineSegmentIndex, compositions.dynamicThreshold, compositions.threshold, compositions.preview, compositions.islandRemoval);
64
+ const CIRCLE_STRATEGY = new BrushStrategy('Circle', compositions.regionFill, compositions.setValue, initializeCircle, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics);
65
+ const CIRCLE_THRESHOLD_STRATEGY = new BrushStrategy('CircleThreshold', compositions.regionFill, compositions.setValue, initializeCircle, compositions.determineSegmentIndex, compositions.dynamicThreshold, compositions.threshold, compositions.preview, compositions.islandRemoval, compositions.labelmapStatistics);
66
66
  const fillInsideCircle = CIRCLE_STRATEGY.strategyFunction;
67
67
  const thresholdInsideCircle = CIRCLE_THRESHOLD_STRATEGY.strategyFunction;
68
68
  export function fillOutsideCircle() {
@@ -2,5 +2,6 @@ import BrushStrategy from './BrushStrategy';
2
2
  declare const SPHERE_STRATEGY: BrushStrategy;
3
3
  declare const fillInsideSphere: (enabledElement: any, operationData: any) => unknown;
4
4
  declare const thresholdInsideSphere: (enabledElement: any, operationData: any) => unknown;
5
+ declare const thresholdInsideSphereIsland: (enabledElement: any, operationData: any) => unknown;
5
6
  export declare function fillOutsideSphere(): void;
6
- export { fillInsideSphere, thresholdInsideSphere, SPHERE_STRATEGY };
7
+ export { fillInsideSphere, thresholdInsideSphere, SPHERE_STRATEGY, thresholdInsideSphereIsland, };
@@ -28,11 +28,13 @@ const sphereComposition = {
28
28
  });
29
29
  },
30
30
  };
31
- const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview);
31
+ const SPHERE_STRATEGY = new BrushStrategy('Sphere', compositions.regionFill, compositions.setValue, sphereComposition, compositions.determineSegmentIndex, compositions.preview, compositions.labelmapStatistics);
32
32
  const fillInsideSphere = SPHERE_STRATEGY.strategyFunction;
33
33
  const SPHERE_THRESHOLD_STRATEGY = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
34
+ const SPHERE_THRESHOLD_STRATEGY_ISLAND = new BrushStrategy('SphereThreshold', ...SPHERE_STRATEGY.compositions, compositions.dynamicThreshold, compositions.threshold, compositions.islandRemoval);
34
35
  const thresholdInsideSphere = SPHERE_THRESHOLD_STRATEGY.strategyFunction;
36
+ const thresholdInsideSphereIsland = SPHERE_THRESHOLD_STRATEGY_ISLAND.strategyFunction;
35
37
  export function fillOutsideSphere() {
36
38
  throw new Error('fill outside sphere not implemented');
37
39
  }
38
- export { fillInsideSphere, thresholdInsideSphere, SPHERE_STRATEGY };
40
+ export { fillInsideSphere, thresholdInsideSphere, SPHERE_STRATEGY, thresholdInsideSphereIsland, };
@@ -108,6 +108,7 @@ type ContourAnnotationCompletedEventDetail = AnnotationCompletedEventDetail & {
108
108
  type SegmentationDataModifiedEventDetail = {
109
109
  segmentationId: string;
110
110
  modifiedSlicesToUse?: number[];
111
+ segmentIndex?: number;
111
112
  };
112
113
  type SegmentationRenderedEventDetail = {
113
114
  viewportId: string;
@@ -24,7 +24,9 @@ export default class BasicStatsCalculator extends Calculator {
24
24
  this.runMean.push(0, 0);
25
25
  this.m2.push(this.m2[0], this.m2[0]);
26
26
  }
27
- this.pointsInShape?.push(pointLPS);
27
+ if (this.pointsInShape && pointLPS) {
28
+ this.pointsInShape?.push(pointLPS);
29
+ }
28
30
  const newArray = Array.isArray(newValue) ? newValue : [newValue];
29
31
  this.count += 1;
30
32
  this.max.map((it, idx) => {
@@ -0,0 +1,8 @@
1
+ import type { NamedStatistics } from '../../types';
2
+ import { BasicStatsCalculator } from '../math/basic';
3
+ export default class VolumetricCalculator extends BasicStatsCalculator {
4
+ static getStatistics(options: {
5
+ spacing?: number;
6
+ unit?: string;
7
+ }): NamedStatistics;
8
+ }
@@ -0,0 +1,18 @@
1
+ import { BasicStatsCalculator } from '../math/basic';
2
+ export default class VolumetricCalculator extends BasicStatsCalculator {
3
+ static getStatistics(options) {
4
+ const { spacing } = options;
5
+ const stats = BasicStatsCalculator.getStatistics();
6
+ const volumeUnit = spacing ? 'mm\xb3' : 'voxels\xb3';
7
+ const volumeScale = spacing ? spacing[0] * spacing[1] * spacing[2] : 1;
8
+ stats.volume = {
9
+ value: Array.isArray(stats.count.value)
10
+ ? stats.count.value.map((v) => v * volumeScale)
11
+ : stats.count.value * volumeScale,
12
+ unit: volumeUnit,
13
+ name: 'volume',
14
+ };
15
+ stats.array.push(stats.volume);
16
+ return stats;
17
+ }
18
+ }
@@ -6,6 +6,7 @@ import { triggerSegmentationRender, triggerSegmentationRenderBySegmentationId }
6
6
  import floodFill from './floodFill';
7
7
  import { getBrushSizeForToolGroup, setBrushSizeForToolGroup } from './brushSizeForToolGroup';
8
8
  import { getBrushThresholdForToolGroup, setBrushThresholdForToolGroup } from './brushThresholdForToolGroup';
9
+ import VolumetricCalculator from './VolumetricCalculator';
9
10
  import thresholdSegmentationByRange from './thresholdSegmentationByRange';
10
11
  import contourAndFindLargestBidirectional from './contourAndFindLargestBidirectional';
11
12
  import createBidirectionalToolData from './createBidirectionalToolData';
@@ -16,4 +17,4 @@ import { getSegmentIndexAtWorldPoint } from './getSegmentIndexAtWorldPoint';
16
17
  import { getSegmentIndexAtLabelmapBorder } from './getSegmentIndexAtLabelmapBorder';
17
18
  import { getHoveredContourSegmentationAnnotation } from './getHoveredContourSegmentationAnnotation';
18
19
  import { getBrushToolInstances } from './getBrushToolInstances';
19
- export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, };
20
+ export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, };
@@ -6,6 +6,7 @@ import { triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, }
6
6
  import floodFill from './floodFill';
7
7
  import { getBrushSizeForToolGroup, setBrushSizeForToolGroup, } from './brushSizeForToolGroup';
8
8
  import { getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, } from './brushThresholdForToolGroup';
9
+ import VolumetricCalculator from './VolumetricCalculator';
9
10
  import thresholdSegmentationByRange from './thresholdSegmentationByRange';
10
11
  import contourAndFindLargestBidirectional from './contourAndFindLargestBidirectional';
11
12
  import createBidirectionalToolData from './createBidirectionalToolData';
@@ -16,4 +17,4 @@ import { getSegmentIndexAtWorldPoint } from './getSegmentIndexAtWorldPoint';
16
17
  import { getSegmentIndexAtLabelmapBorder } from './getSegmentIndexAtLabelmapBorder';
17
18
  import { getHoveredContourSegmentationAnnotation } from './getHoveredContourSegmentationAnnotation';
18
19
  import { getBrushToolInstances } from './getBrushToolInstances';
19
- export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, };
20
+ export { thresholdVolumeByRange, createMergedLabelmapForIndex, createLabelmapVolumeForViewport, rectangleROIThresholdVolumeByRange, triggerSegmentationRender, triggerSegmentationRenderBySegmentationId, floodFill, getBrushSizeForToolGroup, setBrushSizeForToolGroup, getBrushThresholdForToolGroup, setBrushThresholdForToolGroup, VolumetricCalculator, thresholdSegmentationByRange, contourAndFindLargestBidirectional, createBidirectionalToolData, segmentContourAction, invalidateBrushCursor, getUniqueSegmentIndices, getSegmentIndexAtWorldPoint, getSegmentIndexAtLabelmapBorder, getHoveredContourSegmentationAnnotation, getBrushToolInstances, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "2.2.20",
3
+ "version": "2.3.1",
4
4
  "description": "Cornerstone3D Tools",
5
5
  "types": "./dist/esm/index.d.ts",
6
6
  "module": "./dist/esm/index.js",
@@ -104,7 +104,7 @@
104
104
  "canvas": "^2.11.2"
105
105
  },
106
106
  "peerDependencies": {
107
- "@cornerstonejs/core": "^2.2.20",
107
+ "@cornerstonejs/core": "^2.3.1",
108
108
  "@kitware/vtk.js": "32.1.1",
109
109
  "@types/d3-array": "^3.0.4",
110
110
  "@types/d3-interpolate": "^3.0.1",
@@ -123,5 +123,5 @@
123
123
  "type": "individual",
124
124
  "url": "https://ohif.org/donate"
125
125
  },
126
- "gitHead": "94477145875a9cd4b23d0f6f7b822f8dbba56ee6"
126
+ "gitHead": "2f69e663044b481066b5d8c942f831b0de4446c3"
127
127
  }