@cornerstonejs/tools 5.16.0 → 5.17.0

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 (25) hide show
  1. package/dist/esm/eventListeners/segmentation/labelmap/onLabelmapSegmentationDataModified.js +8 -2
  2. package/dist/esm/eventListeners/segmentation/labelmap/performVolumeLabelmapUpdate.d.ts +2 -1
  3. package/dist/esm/eventListeners/segmentation/labelmap/performVolumeLabelmapUpdate.js +20 -12
  4. package/dist/esm/stateManagement/segmentation/events/triggerSegmentationDataModified.d.ts +3 -1
  5. package/dist/esm/stateManagement/segmentation/events/triggerSegmentationDataModified.js +2 -1
  6. package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLayerStore.d.ts +2 -1
  7. package/dist/esm/stateManagement/segmentation/labelmapModel/labelmapLayerStore.js +13 -7
  8. package/dist/esm/tools/TrackballRotateTool.js +4 -2
  9. package/dist/esm/tools/VolumeCroppingTool.js +4 -2
  10. package/dist/esm/tools/displayTools/Labelmap/addVolumesAsIndependentComponents.js +1 -3
  11. package/dist/esm/tools/displayTools/Labelmap/labelmapRenderPlan/legacyVolumePlan.js +19 -2
  12. package/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.js +2 -0
  13. package/dist/esm/tools/displayTools/Labelmap/volumeLabelmapImageMapper.js +2 -0
  14. package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.d.ts +12 -15
  15. package/dist/esm/tools/segmentation/strategies/utils/getStrategyData.js +1 -1
  16. package/dist/esm/types/EventTypes.d.ts +1 -0
  17. package/dist/esm/utilities/segmentation/createLabelmapMemo.d.ts +2 -3
  18. package/dist/esm/utilities/segmentation/utilsForWorker.d.ts +2 -15
  19. package/dist/esm/utilities/stackPrefetch/stackContextPrefetch.js +4 -1
  20. package/dist/esm/utilities/stackPrefetch/stackPrefetch.js +27 -1
  21. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.d.ts +1 -0
  22. package/dist/esm/utilities/stackPrefetch/stackPrefetchUtils.js +5 -1
  23. package/dist/esm/version.d.ts +1 -1
  24. package/dist/esm/version.js +1 -1
  25. package/package.json +3 -3
@@ -12,8 +12,9 @@ const getViewportByViewportId = (viewportId) => {
12
12
  const enabledElement = getEnabledElementByViewportId(viewportId);
13
13
  return enabledElement?.viewport ?? undefined;
14
14
  };
15
+ const segmentationsWithStaleVolume = new Set();
15
16
  const onLabelmapSegmentationDataModified = function (evt) {
16
- const { segmentationId, modifiedSlicesToUse } = evt.detail;
17
+ const { segmentationId, modifiedSlicesToUse, voxelsUnchanged } = evt.detail;
17
18
  const { representationData } = getSegmentation(segmentationId);
18
19
  const viewportIds = getViewportIdsWithSegmentation(segmentationId);
19
20
  const volumeViewportIds = [];
@@ -49,11 +50,16 @@ const onLabelmapSegmentationDataModified = function (evt) {
49
50
  const hasVolumeViewport = volumeViewportIds.length > 0;
50
51
  const hasStackViewport = stackViewportIds.length > 0;
51
52
  const hasBothStackAndVolume = hasVolumeViewport && hasStackViewport;
53
+ if (!hasVolumeViewport && !voxelsUnchanged) {
54
+ segmentationsWithStaleVolume.add(segmentationId);
55
+ }
52
56
  if (hasVolumeViewport) {
57
+ const volumeIsStale = segmentationsWithStaleVolume.delete(segmentationId);
53
58
  performVolumeLabelmapUpdate({
54
- modifiedSlicesToUse: hasBothStackAndVolume ? [] : modifiedSlicesToUse,
59
+ modifiedSlicesToUse: hasBothStackAndVolume || volumeIsStale ? [] : modifiedSlicesToUse,
55
60
  representationData,
56
61
  type: SegmentationRepresentations.Labelmap,
62
+ voxelsUnchanged: Boolean(voxelsUnchanged) && !volumeIsStale,
57
63
  });
58
64
  }
59
65
  if (hasStackViewport) {
@@ -1,6 +1,7 @@
1
1
  import type { SegmentationRepresentations } from '../../../enums/index.js';
2
- export declare function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData, type, }: {
2
+ export declare function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData, type, voxelsUnchanged, }: {
3
3
  modifiedSlicesToUse: number[];
4
4
  representationData: Record<string, unknown>;
5
5
  type: SegmentationRepresentations;
6
+ voxelsUnchanged?: boolean;
6
7
  }): void;
@@ -1,10 +1,14 @@
1
1
  import { cache, eventTarget, triggerEvent, Enums } from '@cornerstonejs/core';
2
2
  import { getOrCreateLabelmapVolume } from '../../../stateManagement/segmentation/helpers/labelmapSegmentationState.js';
3
- export function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData, type, }) {
3
+ export function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representationData, type, voxelsUnchanged = false, }) {
4
4
  const labelmapData = representationData[type];
5
5
  const volumes = getVolumesToUpdate(labelmapData);
6
6
  volumes.forEach((segmentationVolume) => {
7
- const { imageData, vtkOpenGLTexture, voxelManager } = segmentationVolume;
7
+ const { imageData, voxelManager } = segmentationVolume;
8
+ if (voxelsUnchanged) {
9
+ triggerVolumeModified(segmentationVolume);
10
+ return;
11
+ }
8
12
  let slicesToUpdate;
9
13
  if (modifiedSlicesToUse?.length > 0) {
10
14
  slicesToUpdate = modifiedSlicesToUse;
@@ -13,20 +17,24 @@ export function performVolumeLabelmapUpdate({ modifiedSlicesToUse, representatio
13
17
  const numSlices = imageData.getDimensions()[2];
14
18
  slicesToUpdate = [...Array(numSlices).keys()];
15
19
  }
16
- vtkOpenGLTexture?.setUpdatedFrame &&
20
+ segmentationVolume.markFrameModified &&
17
21
  slicesToUpdate.forEach((i) => {
18
- vtkOpenGLTexture.setUpdatedFrame(i);
22
+ segmentationVolume.markFrameModified(i);
19
23
  });
20
24
  voxelManager?.invalidateCache?.();
21
25
  imageData.modified();
22
- const numberOfFrames = segmentationVolume.imageIds?.length ?? imageData.getDimensions()[2] ?? 0;
23
- const FrameOfReferenceUID = segmentationVolume.metadata?.FrameOfReferenceUID ?? '';
24
- triggerEvent(eventTarget, Enums.Events.IMAGE_VOLUME_MODIFIED, {
25
- volumeId: segmentationVolume.volumeId,
26
- FrameOfReferenceUID,
27
- numberOfFrames,
28
- framesProcessed: numberOfFrames,
29
- });
26
+ triggerVolumeModified(segmentationVolume);
27
+ });
28
+ }
29
+ function triggerVolumeModified(segmentationVolume) {
30
+ const { imageData } = segmentationVolume;
31
+ const numberOfFrames = segmentationVolume.imageIds?.length ?? imageData.getDimensions()[2] ?? 0;
32
+ const FrameOfReferenceUID = segmentationVolume.metadata?.FrameOfReferenceUID ?? '';
33
+ triggerEvent(eventTarget, Enums.Events.IMAGE_VOLUME_MODIFIED, {
34
+ volumeId: segmentationVolume.volumeId,
35
+ FrameOfReferenceUID,
36
+ numberOfFrames,
37
+ framesProcessed: numberOfFrames,
30
38
  });
31
39
  }
32
40
  function getVolumesToUpdate(labelmapData) {
@@ -1 +1,3 @@
1
- export declare function triggerSegmentationDataModified(segmentationId: string, modifiedSlicesToUse?: number[], segmentIndex?: number): void;
1
+ export declare function triggerSegmentationDataModified(segmentationId: string, modifiedSlicesToUse?: number[], segmentIndex?: number, { voxelsUnchanged }?: {
2
+ voxelsUnchanged?: boolean;
3
+ }): void;
@@ -1,11 +1,12 @@
1
1
  import { triggerEvent, eventTarget } from '@cornerstonejs/core';
2
2
  import { Events } from '../../../enums/index.js';
3
3
  import { setSegmentationDirty } from '../../../utilities/segmentation/utilities.js';
4
- export function triggerSegmentationDataModified(segmentationId, modifiedSlicesToUse, segmentIndex) {
4
+ export function triggerSegmentationDataModified(segmentationId, modifiedSlicesToUse, segmentIndex, { voxelsUnchanged } = {}) {
5
5
  const eventDetail = {
6
6
  segmentationId,
7
7
  modifiedSlicesToUse,
8
8
  segmentIndex,
9
+ ...(voxelsUnchanged ? { voxelsUnchanged } : {}),
9
10
  };
10
11
  setSegmentationDirty(segmentationId);
11
12
  triggerEvent(eventTarget, Events.SEGMENTATION_DATA_MODIFIED, eventDetail);
@@ -1,6 +1,7 @@
1
1
  import type { Types } from '@cornerstonejs/core';
2
2
  import type { Segmentation } from '../../../types/SegmentationStateTypes.js';
3
3
  import type { LabelmapSegmentationData, LabelmapLayer } from '../../../types/LabelmapTypes.js';
4
+ declare function tagLabelmapVolume(volume: Types.IImageVolume | undefined): Types.IImageVolume | undefined;
4
5
  declare function getLabelmap(segmentation: Segmentation, labelmapId: string): LabelmapLayer | undefined;
5
6
  declare function getLabelmaps(segmentation: Segmentation): LabelmapLayer[];
6
7
  declare function registerLabelmap(segmentation: Segmentation, layer: LabelmapLayer): void;
@@ -12,4 +13,4 @@ declare function getScalarArrayLengthFromLabelmap(layer: LabelmapLayer): number;
12
13
  declare function getConstructorNameForLabelmap(layer: LabelmapLayer): string;
13
14
  declare function getLabelmapForImageId(segmentation: Segmentation, imageId: string): LabelmapLayer | undefined;
14
15
  declare function getLabelmapForVolumeId(segmentation: Segmentation, volumeId: string): LabelmapLayer | undefined;
15
- export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, };
16
+ export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, tagLabelmapVolume, };
@@ -1,6 +1,12 @@
1
- import { cache, imageLoader, volumeLoader } from '@cornerstonejs/core';
1
+ import { cache, imageLoader, volumeLoader, Enums } from '@cornerstonejs/core';
2
2
  import { ensureLabelmapState } from './normalizeLabelmapSegmentationData.js';
3
3
  import { forEachLabelmapImageReference, hasMultipleLabelmapImagesPerReferencedImageId, } from './labelmapImageIdMapping.js';
4
+ function tagLabelmapVolume(volume) {
5
+ if (volume) {
6
+ volume.reductionStatistic = Enums.VoxelStatistics.ForegroundMajority;
7
+ }
8
+ return volume;
9
+ }
4
10
  function getLabelmap(segmentation, labelmapId) {
5
11
  return ensureLabelmapState(segmentation)?.labelmaps?.[labelmapId];
6
12
  }
@@ -38,7 +44,7 @@ function getOrCreateLabelmapVolume(layer) {
38
44
  if (existingVolumeId) {
39
45
  const cachedVolume = cache.getVolume(existingVolumeId);
40
46
  if (cachedVolume) {
41
- return cachedVolume;
47
+ return tagLabelmapVolume(cachedVolume);
42
48
  }
43
49
  }
44
50
  const imageIds = layer.imageIds ?? [];
@@ -51,9 +57,9 @@ function getOrCreateLabelmapVolume(layer) {
51
57
  }
52
58
  const cachedVolume = cache.getVolume(volumeId);
53
59
  if (cachedVolume) {
54
- return cachedVolume;
60
+ return tagLabelmapVolume(cachedVolume);
55
61
  }
56
- return volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, imageIds);
62
+ return tagLabelmapVolume(volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, imageIds));
57
63
  }
58
64
  function getOrCreateMergedStackLabelmapVolume(layer) {
59
65
  if (layer.volumeId || !hasDuplicateReferencedImageIds(layer)) {
@@ -62,7 +68,7 @@ function getOrCreateMergedStackLabelmapVolume(layer) {
62
68
  const volumeId = layer.geometryVolumeId ?? `${layer.labelmapId}-geometry`;
63
69
  const cachedVolume = cache.getVolume(volumeId);
64
70
  if (cachedVolume) {
65
- return cachedVolume;
71
+ return tagLabelmapVolume(cachedVolume);
66
72
  }
67
73
  const imageIdsByReferencedImageId = new Map();
68
74
  forEachLabelmapImageReference(layer, (referencedImageId, imageId) => {
@@ -103,7 +109,7 @@ function getOrCreateMergedStackLabelmapVolume(layer) {
103
109
  });
104
110
  });
105
111
  layer.geometryVolumeId = volumeId;
106
- return volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, mergedImages.map((image) => image.imageId));
112
+ return tagLabelmapVolume(volumeLoader.createAndCacheVolumeFromImagesSync(volumeId, mergedImages.map((image) => image.imageId)));
107
113
  }
108
114
  function hasDuplicateReferencedImageIds(layer) {
109
115
  return hasMultipleLabelmapImagesPerReferencedImageId(layer);
@@ -157,4 +163,4 @@ function getLabelmapForImageId(segmentation, imageId) {
157
163
  function getLabelmapForVolumeId(segmentation, volumeId) {
158
164
  return getLabelmaps(segmentation).find((layer) => layer.volumeId === volumeId || layer.geometryVolumeId === volumeId);
159
165
  }
160
- export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, };
166
+ export { getConstructorNameForLabelmap, getLabelmap, getLabelmapDataById, getLabelmapForImageId, getLabelmapForVolumeId, getLabelmapIds, getLabelmaps, getOrCreateLabelmapVolume, getScalarArrayLengthFromLabelmap, registerLabelmap, removeLabelmap, tagLabelmapVolume, };
@@ -1,6 +1,6 @@
1
1
  import vtkMath from '@kitware/vtk.js/Common/Core/Math.js';
2
2
  import { Events } from '../enums/index.js';
3
- import { eventTarget, getEnabledElement, getEnabledElementByIds, utilities as csUtils, } from '@cornerstonejs/core';
3
+ import { eventTarget, getEnabledElement, getEnabledElementByIds, utilities as csUtils, getLossyDownsampling, } from '@cornerstonejs/core';
4
4
  import { mat4, vec3 } from 'gl-matrix';
5
5
  import { BaseTool } from './base/index.js';
6
6
  import { getToolGroup } from '../store/ToolGroupManager/index.js';
@@ -32,7 +32,9 @@ class TrackballRotateTool extends BaseTool {
32
32
  }
33
33
  const originalSampleDistance = mapper.getSampleDistance();
34
34
  if (!this._hasResolutionChanged) {
35
- const { rotateSampleDistanceFactor } = this.configuration;
35
+ const rotateSampleDistanceFactor = getLossyDownsampling().interactive
36
+ ? this.configuration.rotateSampleDistanceFactor
37
+ : 1;
36
38
  mapper.setSampleDistance(originalSampleDistance * rotateSampleDistanceFactor);
37
39
  this._hasResolutionChanged = true;
38
40
  if (this.cleanUp !== null) {
@@ -6,7 +6,7 @@ import vtkSphereSource from '@kitware/vtk.js/Filters/Sources/SphereSource.js';
6
6
  import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper.js';
7
7
  import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane.js';
8
8
  import { BaseTool } from './base/index.js';
9
- import { getRenderingEngine, getEnabledElementByIds, getEnabledElement, Enums, triggerEvent, eventTarget, } from '@cornerstonejs/core';
9
+ import { getRenderingEngine, getEnabledElementByIds, getEnabledElement, Enums, triggerEvent, eventTarget, getLossyDownsampling, } from '@cornerstonejs/core';
10
10
  import { getToolGroup } from '../store/ToolGroupManager/index.js';
11
11
  import getViewportICamera from '../utilities/getViewportICamera.js';
12
12
  import setViewportCamera, { resetViewportCamera, } from '../utilities/setViewportCamera.js';
@@ -123,7 +123,9 @@ class VolumeCroppingTool extends BaseTool {
123
123
  }
124
124
  const originalSampleDistance = mapper.getSampleDistance();
125
125
  if (!this._hasResolutionChanged) {
126
- const { rotateSampleDistanceFactor } = this.configuration;
126
+ const rotateSampleDistanceFactor = getLossyDownsampling().interactive
127
+ ? this.configuration.rotateSampleDistanceFactor
128
+ : 1;
127
129
  mapper.setSampleDistance(originalSampleDistance * rotateSampleDistanceFactor);
128
130
  this._hasResolutionChanged = true;
129
131
  if (this.cleanUp !== null) {
@@ -31,9 +31,7 @@ export async function addVolumesAsIndependentComponents({ viewport, volumeInputs
31
31
  const segData = segVoxelManager.getCompleteScalarDataArray();
32
32
  const { imageData: segImageData } = segImageVolume;
33
33
  const baseVolume = cache.getVolume(referenceVolumeId);
34
- const volumeTexture = baseVolume.vtkOpenGLTexture;
35
- const hasPendingFrames = volumeTexture.hasUpdatedFrames();
36
- if (hasPendingFrames) {
34
+ if (baseVolume.loadStatus?.loading) {
37
35
  return;
38
36
  }
39
37
  const baseVoxelManager = baseVolume.voxelManager;
@@ -1,6 +1,7 @@
1
- import { ActorRenderMode, addVolumesToViewports, Enums, cache, volumeLoader, utilities, } from '@cornerstonejs/core';
1
+ import { ActorRenderMode, addVolumesToViewports, Enums, cache, gpuSettingsForRender, gridLimitsOfGpuSettings, volumeLoader, utilities, } from '@cornerstonejs/core';
2
2
  import { triggerSegmentationDataModified, triggerSegmentationModified, } from '../../../../stateManagement/segmentation/triggerSegmentationEvents.js';
3
3
  import { getLabelmaps, getOrCreateLabelmapVolume, } from '../../../../stateManagement/segmentation/helpers/labelmapSegmentationState.js';
4
+ import { tagLabelmapVolume } from '../../../../stateManagement/segmentation/labelmapModel/labelmapLayerStore.js';
4
5
  import { addVolumesAsIndependentComponents } from '../addVolumesAsIndependentComponents.js';
5
6
  import { createLabelmapRepresentationUID } from '../labelmapRepresentationUID.js';
6
7
  import { createLabelmapRenderPlan, getActorEntryRenderMode, } from './createLabelmapRenderPlan.js';
@@ -60,6 +61,9 @@ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, s
60
61
  imageIds: cache.getVolume(volumeId)?.imageIds,
61
62
  });
62
63
  }
64
+ for (const layer of labelmapLayers) {
65
+ tagLabelmapVolume(cache.getVolume(layer.volumeId));
66
+ }
63
67
  let blendMode = config?.blendMode ?? Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
64
68
  let useIndependentComponents = blendMode === Enums.BlendModes.LABELMAP_EDGE_PROJECTION_BLEND;
65
69
  if (useIndependentComponents) {
@@ -86,6 +90,11 @@ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, s
86
90
  blendMode = Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
87
91
  cs3dLogger.debug('Dimensions mismatch - falling back to regular volume addition');
88
92
  }
93
+ else if (!combinedTextureFitsGpuSettings(baseVolume)) {
94
+ useIndependentComponents = false;
95
+ blendMode = Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
96
+ cs3dLogger.warn(`The GPU settings cannot hold the full-resolution two-component texture of edge projection for ${baseVolume.volumeId}, so the labelmap uses a separate actor`);
97
+ }
89
98
  }
90
99
  }
91
100
  const volumeInputs = labelmapLayers.map((layer) => ({
@@ -95,6 +104,7 @@ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, s
95
104
  segmentationId,
96
105
  referencedId: layer.labelmapId,
97
106
  }),
107
+ excludeFromFidelity: true,
98
108
  useIndependentComponents,
99
109
  blendMode,
100
110
  }));
@@ -109,7 +119,9 @@ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, s
109
119
  }
110
120
  if (!volumeInputs[0].useIndependentComponents) {
111
121
  await addVolumesToViewports(viewport.getRenderingEngine(), volumeInputs, [viewportId], immediateRender, suppressEvents);
112
- triggerSegmentationDataModified(segmentationId);
122
+ triggerSegmentationDataModified(segmentationId, undefined, undefined, {
123
+ voxelsUnchanged: true,
124
+ });
113
125
  return;
114
126
  }
115
127
  return addVolumesAsIndependentComponents({
@@ -118,6 +130,11 @@ async function mountLegacyVolumeLabelmap({ config, labelMapData, segmentation, s
118
130
  segmentationId,
119
131
  });
120
132
  }
133
+ function combinedTextureFitsGpuSettings(baseVolume) {
134
+ const gpuSettings = gpuSettingsForRender();
135
+ return (!gpuSettings ||
136
+ utilities.voxelGrid.voxelGridWithinLimits(baseVolume.voxelGrid, gridLimitsOfGpuSettings(gpuSettings, 2 * Float32Array.BYTES_PER_ELEMENT)));
137
+ }
121
138
  function canResolveLayerAsVolume(layer) {
122
139
  return Boolean(layer.volumeId || layer.geometryVolumeId || layer.imageIds?.length);
123
140
  }
@@ -79,6 +79,7 @@ export function syncStackLabelmapActors(viewport, segmentationId) {
79
79
  labelmapId: derivedImage.imageId,
80
80
  },
81
81
  representationUID,
82
+ excludeFromFidelity: true,
82
83
  },
83
84
  ]);
84
85
  }
@@ -111,6 +112,7 @@ export function syncStackLabelmapActors(viewport, segmentationId) {
111
112
  labelmapId: derivedImage.imageId,
112
113
  },
113
114
  representationUID,
115
+ excludeFromFidelity: true,
114
116
  callback: ({ imageActor }) => {
115
117
  imageActor.getMapper().setInputData(imageData);
116
118
  applyInheritedLabelmapStyle(imageActor, inheritedLabelmapStyle);
@@ -28,6 +28,7 @@ function createActorEntry(args) {
28
28
  },
29
29
  referencedId: args.referencedId,
30
30
  representationUID: args.representationUID,
31
+ excludeFromFidelity: true,
31
32
  };
32
33
  }
33
34
  function getOverlayRendererId(viewportId) {
@@ -223,6 +224,7 @@ async function addPlanarLabelmapImageMapperActors(args) {
223
224
  labelmapId: layer.labelmapId,
224
225
  },
225
226
  useWorldCoordinateImageData: true,
227
+ excludeFromFidelity: true,
226
228
  callback: ({ imageActor }) => {
227
229
  const mapper = imageActor.getMapper();
228
230
  const camera = getSliceRenderingCamera(viewport);
@@ -1,22 +1,19 @@
1
1
  import { type Types } from '@cornerstonejs/core';
2
+ import type vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
2
3
  import type { LabelmapToolOperationDataStack, LabelmapToolOperationDataVolume } from '../../../../types/index.js';
4
+ export type StrategyData = {
5
+ segmentationImageData: vtkImageData;
6
+ segmentationVoxelManager: Types.IVoxelManager<number> & {
7
+ boundsIJK?: Types.BoundsIJK;
8
+ };
9
+ segmentationScalarData: unknown;
10
+ imageScalarData: unknown;
11
+ imageVoxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB> | undefined;
12
+ imageData: vtkImageData | null | undefined;
13
+ };
3
14
  declare function getStrategyData({ operationData, viewport, strategy, }: {
4
15
  operationData: LabelmapToolOperationDataStack | LabelmapToolOperationDataVolume;
5
16
  viewport?: Types.IStackViewport | Types.IVolumeViewport;
6
17
  strategy: unknown;
7
- }): {
8
- segmentationImageData: import("@kitware/vtk.js/Common/DataModel/ImageData").vtkImageData;
9
- segmentationVoxelManager: Types.IVoxelManager<number> | Types.IVoxelManager<Types.RGB>;
10
- segmentationScalarData: any;
11
- imageScalarData: any;
12
- imageVoxelManager: any;
13
- imageData: any;
14
- } | {
15
- segmentationImageData: any;
16
- readonly segmentationScalarData: unknown;
17
- imageScalarData: any;
18
- segmentationVoxelManager: any;
19
- imageVoxelManager: any;
20
- imageData: any;
21
- };
18
+ }): StrategyData | null;
22
19
  export { getStrategyData };
@@ -2,7 +2,7 @@ import { cache, Enums, eventTarget } from '@cornerstonejs/core';
2
2
  import { getCurrentLabelmapImageIdForViewport } from '../../../../stateManagement/segmentation/segmentationState.js';
3
3
  import { getLabelmapActorEntry } from '../../../../stateManagement/segmentation/helpers/index.js';
4
4
  import { getReferenceVolumeForSegmentationVolume } from '../../../../utilities/segmentation/getReferenceVolumeForSegmentationVolume.js';
5
- function getStrategyDataForVolumeViewport({ operationData }) {
5
+ function getStrategyDataForVolumeViewport({ operationData, }) {
6
6
  const { volumeId } = operationData;
7
7
  if (!volumeId) {
8
8
  const event = new CustomEvent(Enums.Events.ERROR_EVENT, {
@@ -109,6 +109,7 @@ type SegmentationDataModifiedEventDetail = {
109
109
  segmentationId: string;
110
110
  modifiedSlicesToUse?: number[];
111
111
  segmentIndex?: number;
112
+ voxelsUnchanged?: boolean;
112
113
  };
113
114
  type SegmentationRenderedEventDetail = {
114
115
  viewportId: string;
@@ -1,4 +1,3 @@
1
- import { utilities } from '@cornerstonejs/core';
2
1
  import type { Types } from '@cornerstonejs/core';
3
2
  export type LabelmapRestoreStep = {
4
3
  undo: () => void;
@@ -19,7 +18,7 @@ export declare function createLabelmapMemo<T>(segmentationId: string, segmentati
19
18
  restoreMemo: typeof restoreMemo;
20
19
  commitMemo: typeof commitMemo;
21
20
  segmentationVoxelManager: Types.IVoxelManager<T>;
22
- voxelManager: utilities.VoxelManager<T>;
21
+ voxelManager: Types.IVoxelManager<T>;
23
22
  id: string;
24
23
  operationType: string;
25
24
  };
@@ -30,7 +29,7 @@ export declare function createRleMemo<T>(segmentationId: string, segmentationVox
30
29
  restoreMemo: typeof restoreMemo;
31
30
  commitMemo: typeof commitMemo;
32
31
  segmentationVoxelManager: Types.IVoxelManager<T>;
33
- voxelManager: utilities.VoxelManager<T>;
32
+ voxelManager: Types.IVoxelManager<T>;
34
33
  id: string;
35
34
  operationType: string;
36
35
  };
@@ -1,3 +1,4 @@
1
+ import type { StrategyData } from '../../tools/segmentation/strategies/utils/getStrategyData.js';
1
2
  export declare const triggerWorkerProgress: (workerType: any, progress: any) => void;
2
3
  export declare const getSegmentationDataForWorker: (segmentationId: any, segmentIndices: any) => {
3
4
  operationData: {
@@ -10,21 +11,7 @@ export declare const getSegmentationDataForWorker: (segmentationId: any, segment
10
11
  reconstructableVolume: boolean;
11
12
  indices: any;
12
13
  };
13
- export declare const prepareVolumeStrategyDataForWorker: (operationData: any) => {
14
- segmentationImageData: import("@kitware/vtk.js/Common/DataModel/ImageData").vtkImageData;
15
- segmentationVoxelManager: import("packages/core/dist/esm/types").IVoxelManager<number> | import("packages/core/dist/esm/types").IVoxelManager<import("packages/core/dist/esm/types").RGB>;
16
- segmentationScalarData: any;
17
- imageScalarData: any;
18
- imageVoxelManager: any;
19
- imageData: any;
20
- } | {
21
- segmentationImageData: any;
22
- readonly segmentationScalarData: unknown;
23
- imageScalarData: any;
24
- segmentationVoxelManager: any;
25
- imageVoxelManager: any;
26
- imageData: any;
27
- };
14
+ export declare const prepareVolumeStrategyDataForWorker: (operationData: any) => StrategyData | null;
28
15
  export declare const prepareImageInfo: (imageVoxelManager: any, imageData: any) => {
29
16
  scalarData: any;
30
17
  dimensions: any;
@@ -1,6 +1,6 @@
1
1
  import { imageLoader, Enums, eventTarget, imageLoadPoolManager, cache, metaData, utilities, triggerEvent, } from '@cornerstonejs/core';
2
2
  import { addToolState, getToolState } from './state.js';
3
- import { getStackData, requestType, clearFromImageIds, getPromiseRemovedHandler, } from './stackPrefetchUtils.js';
3
+ import { getStackData, requestType, clearFromImageIds, getPromiseRemovedHandler, isLoadedByProgressiveVolume, } from './stackPrefetchUtils.js';
4
4
  import { Events } from '../../enums/index.js';
5
5
  import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
6
6
  const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('utilities.stackPrefetch.stackContextPrefetch');
@@ -42,6 +42,9 @@ function prefetch(element, priority = 0) {
42
42
  cs3dLogger.warn('CornerstoneTools.stackPrefetch: No images in stack.');
43
43
  return;
44
44
  }
45
+ if (isLoadedByProgressiveVolume(stack.imageIds)) {
46
+ return;
47
+ }
45
48
  const stackPrefetchData = getToolState(element);
46
49
  if (!stackPrefetchData) {
47
50
  return;
@@ -1,6 +1,6 @@
1
1
  import { imageLoader, Enums, eventTarget, imageLoadPoolManager, cache, metaData, utilities, triggerEvent, } from '@cornerstonejs/core';
2
2
  import { addToolState, getToolState } from './state.js';
3
- import { getStackData, requestType, priority, getPromiseRemovedHandler, nearestIndex, range, } from './stackPrefetchUtils.js';
3
+ import { getStackData, requestType, priority, getPromiseRemovedHandler, nearestIndex, range, isLoadedByProgressiveVolume, } from './stackPrefetchUtils.js';
4
4
  import { Events } from '../../enums/index.js';
5
5
  import { utilities as cornerstoneUtilities } from '@cornerstonejs/core';
6
6
  const cs3dLogger = cornerstoneUtilities.logger.toolsLog.getLogger('utilities.stackPrefetch.stackPrefetch');
@@ -11,6 +11,20 @@ let configuration = {
11
11
  };
12
12
  let resetPrefetchTimeout;
13
13
  const resetPrefetchDelay = 10;
14
+ const loadingCancelledHandlers = new WeakMap();
15
+ function getLoadingCancelledHandler(element) {
16
+ return (evt) => {
17
+ const { volumeId } = evt.detail;
18
+ try {
19
+ const imageId = getStackData(element)?.imageIds[0];
20
+ if (cache.getVolume(volumeId)?.getImageIdIndex(imageId) !== undefined) {
21
+ prefetch(element);
22
+ }
23
+ }
24
+ catch {
25
+ }
26
+ };
27
+ }
14
28
  function prefetch(element) {
15
29
  const stackPrefetchData = getToolState(element);
16
30
  if (!stackPrefetchData) {
@@ -22,6 +36,9 @@ function prefetch(element) {
22
36
  cs3dLogger.warn('CornerstoneTools.stackPrefetch: No images in stack.');
23
37
  return;
24
38
  }
39
+ if (isLoadedByProgressiveVolume(stack.imageIds)) {
40
+ return;
41
+ }
25
42
  const { currentImageIdIndex } = stack;
26
43
  stackPrefetch.enabled =
27
44
  stackPrefetch.enabled && (stackPrefetch.indicesToRequest?.length ?? 0) > 0;
@@ -147,12 +164,21 @@ function enable(element) {
147
164
  const promiseRemovedHandler = getPromiseRemovedHandler(element);
148
165
  eventTarget.removeEventListener(Enums.Events.IMAGE_CACHE_IMAGE_REMOVED, promiseRemovedHandler);
149
166
  eventTarget.addEventListener(Enums.Events.IMAGE_CACHE_IMAGE_REMOVED, promiseRemovedHandler);
167
+ removeLoadingCancelledHandler(element);
168
+ const loadingCancelledHandler = getLoadingCancelledHandler(element);
169
+ loadingCancelledHandlers.set(element, loadingCancelledHandler);
170
+ eventTarget.addEventListener(Enums.Events.IMAGE_VOLUME_LOADING_CANCELLED, loadingCancelledHandler);
171
+ }
172
+ function removeLoadingCancelledHandler(element) {
173
+ eventTarget.removeEventListener(Enums.Events.IMAGE_VOLUME_LOADING_CANCELLED, loadingCancelledHandlers.get(element));
174
+ loadingCancelledHandlers.delete(element);
150
175
  }
151
176
  function disable(element) {
152
177
  clearTimeout(resetPrefetchTimeout);
153
178
  element.removeEventListener(Enums.Events.STACK_NEW_IMAGE, onImageUpdated);
154
179
  const promiseRemovedHandler = getPromiseRemovedHandler(element);
155
180
  eventTarget.removeEventListener(Enums.Events.IMAGE_CACHE_IMAGE_REMOVED, promiseRemovedHandler);
181
+ removeLoadingCancelledHandler(element);
156
182
  const stackPrefetchData = getToolState(element);
157
183
  if (stackPrefetchData && stackPrefetchData.indicesToRequest.length) {
158
184
  stackPrefetchData.enabled = false;
@@ -11,4 +11,5 @@ export declare function getStackData(element: any): {
11
11
  imageIds: string[];
12
12
  };
13
13
  export declare function getPromiseRemovedHandler(element: any): (e: any) => void;
14
+ export declare function isLoadedByProgressiveVolume(imageIds: string[]): boolean;
14
15
  export declare const clearFromImageIds: (stack: any) => (requestDetails: any) => boolean;
@@ -1,4 +1,4 @@
1
- import { getEnabledElement, Enums, utilities } from '@cornerstonejs/core';
1
+ import { getEnabledElement, Enums, utilities, cache, } from '@cornerstonejs/core';
2
2
  import { getToolState } from './state.js';
3
3
  import { viewportSupportsImageSlices } from '../viewportCapabilities.js';
4
4
  export const requestType = Enums.RequestType.Prefetch;
@@ -73,6 +73,10 @@ export function getPromiseRemovedHandler(element) {
73
73
  stackPrefetchData.indicesToRequest.push(imageIdIndex);
74
74
  };
75
75
  }
76
+ export function isLoadedByProgressiveVolume(imageIds) {
77
+ const volume = cache.getVolumeContainingImageId(imageIds[0])?.volume;
78
+ return !!volume?.isLoadingProgressively?.();
79
+ }
76
80
  export const clearFromImageIds = (stack) => {
77
81
  const imageIdSet = new Set(stack.imageIds);
78
82
  return (requestDetails) => requestDetails.type !== requestType ||
@@ -1 +1 @@
1
- export declare const version = "5.16.0";
1
+ export declare const version = "5.17.0";
@@ -1 +1 @@
1
- export const version = '5.16.0';
1
+ export const version = '5.17.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/tools",
3
- "version": "5.16.0",
3
+ "version": "5.17.0",
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.16.0",
129
+ "@cornerstonejs/core": "5.17.0",
130
130
  "canvas": "3.2.0"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cornerstonejs/core": "5.16.0",
133
+ "@cornerstonejs/core": "5.17.0",
134
134
  "@kitware/vtk.js": "36.4.1",
135
135
  "@types/d3-array": "3.2.1",
136
136
  "@types/d3-interpolate": "3.0.4",