@ohif/app 3.14.0-beta.90 → 3.14.0-beta.92

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.
@@ -1,4 +1,4 @@
1
- (globalThis["rspackChunk_ohif_app"] ||= []).push([[5383], {
1
+ (globalThis["rspackChunk_ohif_app"] ||= []).push([[8868], {
2
2
  44709(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
3
3
  "use strict";
4
4
  /**
@@ -36518,7 +36518,7 @@ async function interpolateLabelmap({ segmentationId, segmentIndex, configuration
36518
36518
 
36519
36519
 
36520
36520
  },
36521
- 9662(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
36521
+ 21363(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
36522
36522
  "use strict";
36523
36523
  // ESM COMPAT FLAG
36524
36524
  __webpack_require__.r(__webpack_exports__);
@@ -36642,51 +36642,212 @@ async function createAndCacheSurfacesFromRaw(segmentationId, rawSurfacesData, op
36642
36642
  };
36643
36643
  }
36644
36644
 
36645
+ ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/polymorphic-segmentation/dist/esm/Surface/cropLabelmapToSegment.js
36646
+ function yieldToMain() {
36647
+ if (typeof MessageChannel === 'undefined') {
36648
+ return new Promise((resolve) => setTimeout(resolve, 0));
36649
+ }
36650
+ return new Promise((resolve) => {
36651
+ const { port1, port2 } = new MessageChannel();
36652
+ port1.onmessage = () => {
36653
+ port1.close();
36654
+ resolve();
36655
+ };
36656
+ port2.postMessage(null);
36657
+ });
36658
+ }
36659
+ async function findSegmentBounds(dimensions, getFrame, segmentIndices) {
36660
+ const [width, height, depth] = dimensions;
36661
+ const found = new Map();
36662
+ const wanted = new Set(segmentIndices);
36663
+ const extend = (value, iMin, iMax, j, k) => {
36664
+ if (!wanted.has(value)) {
36665
+ return;
36666
+ }
36667
+ const bounds = found.get(value);
36668
+ if (!bounds) {
36669
+ found.set(value, { min: [iMin, j, k], max: [iMax, j, k] });
36670
+ return;
36671
+ }
36672
+ const { min, max } = bounds;
36673
+ if (iMin < min[0])
36674
+ min[0] = iMin;
36675
+ if (iMax > max[0])
36676
+ max[0] = iMax;
36677
+ if (j < min[1])
36678
+ min[1] = j;
36679
+ if (j > max[1])
36680
+ max[1] = j;
36681
+ max[2] = k;
36682
+ };
36683
+ for (let k = 0; k < depth; k++) {
36684
+ const frame = getFrame(k);
36685
+ for (let j = 0; j < height; j++) {
36686
+ if ('map' in frame) {
36687
+ for (const { start, end, value } of frame.map.getRun(j, 0) ?? []) {
36688
+ extend(value, start, end - 1, j, k);
36689
+ }
36690
+ continue;
36691
+ }
36692
+ const rowOffset = j * width;
36693
+ for (let i = 0; i < width; i++) {
36694
+ const value = frame.data[rowOffset + i];
36695
+ if (value) {
36696
+ extend(value, i, i, j, k);
36697
+ }
36698
+ }
36699
+ }
36700
+ await yieldToMain();
36701
+ }
36702
+ return found;
36703
+ }
36704
+ function getSegmentBlock({ min, max }, dimensions) {
36705
+ const start = min.map((value) => Math.max(0, value - 1));
36706
+ const end = max.map((value, axis) => Math.min(dimensions[axis] - 1, value + 1));
36707
+ return {
36708
+ start,
36709
+ dimensions: start.map((value, axis) => end[axis] - value + 1),
36710
+ };
36711
+ }
36712
+ async function cropLabelmapToBlock(dimensions, getFrame, ArrayType, { start, dimensions: blockDimensions }) {
36713
+ const width = dimensions[0];
36714
+ const [blockWidth, blockHeight, blockDepth] = blockDimensions;
36715
+ const end = start.map((value, axis) => value + blockDimensions[axis] - 1);
36716
+ const blockData = new ArrayType(blockWidth * blockHeight * blockDepth);
36717
+ for (let k = start[2]; k <= end[2]; k++) {
36718
+ const frame = getFrame(k);
36719
+ for (let j = start[1]; j <= end[1]; j++) {
36720
+ const target = ((k - start[2]) * blockHeight + (j - start[1])) * blockWidth - start[0];
36721
+ if ('map' in frame) {
36722
+ for (const { start: runStart, end: runEnd, value } of frame.map.getRun(j, 0) ?? []) {
36723
+ const iEnd = Math.min(runEnd - 1, end[0]);
36724
+ for (let i = Math.max(runStart, start[0]); i <= iEnd; i++) {
36725
+ blockData[target + i] = value;
36726
+ }
36727
+ }
36728
+ continue;
36729
+ }
36730
+ const rowOffset = j * width;
36731
+ for (let i = start[0]; i <= end[0]; i++) {
36732
+ blockData[target + i] = frame.data[rowOffset + i];
36733
+ }
36734
+ }
36735
+ await yieldToMain();
36736
+ }
36737
+ return blockData;
36738
+ }
36739
+
36645
36740
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/polymorphic-segmentation/dist/esm/Surface/convertLabelmapToSurface.js
36646
36741
 
36647
36742
 
36743
+
36648
36744
  const { WorkerTypes: convertLabelmapToSurface_WorkerTypes } = dist_esm.Enums;
36649
36745
  const { computeVolumeLabelmapFromStack } = dist_esm.utilities.segmentation;
36746
+ const cs3dLogger = esm.utilities.logger.polySegLog.getLogger('Surface.convertLabelmapToSurface');
36650
36747
  const convertLabelmapToSurface_workerManager = (0,esm.getWebWorkerManager)();
36651
- const convertLabelmapToSurface_triggerWorkerProgress = (eventTarget, progress, id) => {
36652
- (0,esm.triggerEvent)(eventTarget, esm.Enums.Events.WEB_WORKER_PROGRESS, {
36748
+ const MIB = 1024 * 1024;
36749
+ const WORKER_BYTES_PER_VOXEL = 4;
36750
+ let maxBlockMiB = 2048;
36751
+ const MIN_LIMIT_MIB = 256;
36752
+ const convertLabelmapToSurface_triggerWorkerProgress = (progress, id, error) => {
36753
+ (0,esm.triggerEvent)(esm.eventTarget, esm.Enums.Events.WEB_WORKER_PROGRESS, {
36653
36754
  progress,
36654
36755
  type: convertLabelmapToSurface_WorkerTypes.POLYSEG_LABELMAP_TO_SURFACE,
36655
36756
  id,
36757
+ error,
36656
36758
  });
36657
36759
  };
36658
- async function convertLabelmapToSurface(labelmapRepresentationData, segmentIndex) {
36659
- let volumeId;
36660
- if (labelmapRepresentationData
36661
- .volumeId) {
36662
- volumeId = labelmapRepresentationData.volumeId;
36663
- }
36664
- else {
36760
+ const reportFailure = (segmentIndex, error) => {
36761
+ cs3dLogger.warn(error);
36762
+ convertLabelmapToSurface_triggerWorkerProgress(100, segmentIndex, error);
36763
+ };
36764
+ async function getLabelmapVolume(labelmapRepresentationData) {
36765
+ let { volumeId } = labelmapRepresentationData;
36766
+ if (!volumeId) {
36665
36767
  const { imageIds } = labelmapRepresentationData;
36666
- ({ volumeId } = await computeVolumeLabelmapFromStack({
36667
- imageIds,
36668
- }));
36669
- }
36670
- const volume = esm.cache.getVolume(volumeId);
36671
- const scalarData = volume.voxelManager.getCompleteScalarDataArray();
36672
- const { dimensions, spacing, origin, direction } = volume;
36673
- convertLabelmapToSurface_triggerWorkerProgress(esm.eventTarget, 0, segmentIndex);
36674
- const results = await convertLabelmapToSurface_workerManager.executeTask('polySeg', 'convertLabelmapToSurface', {
36675
- scalarData,
36676
- dimensions,
36677
- spacing,
36678
- origin,
36679
- direction,
36680
- segmentIndex,
36681
- }, {
36682
- callbacks: [
36683
- (progress) => {
36684
- convertLabelmapToSurface_triggerWorkerProgress(esm.eventTarget, progress, segmentIndex);
36685
- },
36686
- ],
36687
- });
36688
- convertLabelmapToSurface_triggerWorkerProgress(esm.eventTarget, 100, segmentIndex);
36689
- return results;
36768
+ ({ volumeId } = await computeVolumeLabelmapFromStack({ imageIds }));
36769
+ }
36770
+ return esm.cache.getVolume(volumeId);
36771
+ }
36772
+ function getLabelmapFrames(volume) {
36773
+ const { dimensions, imageIds, voxelManager } = volume;
36774
+ const [width, height, depth] = dimensions;
36775
+ const frameSize = width * height;
36776
+ const scalarData = voxelManager.getWritableScalarData?.();
36777
+ const frameImageIds = imageIds?.length === depth ? imageIds : undefined;
36778
+ return (k) => {
36779
+ if (scalarData) {
36780
+ return { data: scalarData.subarray(k * frameSize, (k + 1) * frameSize) };
36781
+ }
36782
+ const map = frameImageIds && esm.cache.getImage(frameImageIds[k])?.voxelManager?.map;
36783
+ if (map instanceof esm.utilities.RLEVoxelMap &&
36784
+ map.width === width &&
36785
+ map.height === height &&
36786
+ !map.defaultValue) {
36787
+ return { map: map };
36788
+ }
36789
+ return {
36790
+ data: voxelManager.getSliceData({ sliceIndex: k, slicePlane: 2 }),
36791
+ };
36792
+ };
36793
+ }
36794
+ async function convertLabelmapToSurfaces(labelmapRepresentationData, segmentIndices) {
36795
+ const volume = await getLabelmapVolume(labelmapRepresentationData);
36796
+ const { dimensions, spacing, direction, voxelManager } = volume;
36797
+ const getFrame = getLabelmapFrames(volume);
36798
+ const boundsBySegment = await findSegmentBounds(dimensions, getFrame, segmentIndices);
36799
+ const surfaces = [];
36800
+ for (const segmentIndex of segmentIndices) {
36801
+ if (!volume.imageData) {
36802
+ surfaces.push(undefined);
36803
+ continue;
36804
+ }
36805
+ const bounds = boundsBySegment.get(segmentIndex);
36806
+ if (!bounds) {
36807
+ surfaces.push({ points: [], polys: [] });
36808
+ continue;
36809
+ }
36810
+ const block = getSegmentBlock(bounds, dimensions);
36811
+ const [blockWidth, blockHeight, blockDepth] = block.dimensions;
36812
+ const blockMiB = (blockWidth * blockHeight * blockDepth * WORKER_BYTES_PER_VOXEL) / MIB;
36813
+ if (blockMiB >= maxBlockMiB) {
36814
+ reportFailure(segmentIndex, `Segment ${segmentIndex} is too large for a 3D surface (${Math.ceil(blockMiB)} MiB, limit ${Math.ceil(maxBlockMiB)} MiB).`);
36815
+ surfaces.push(undefined);
36816
+ continue;
36817
+ }
36818
+ const scalarData = await cropLabelmapToBlock(dimensions, getFrame, voxelManager.getConstructor(), block);
36819
+ if (!volume.imageData) {
36820
+ surfaces.push(undefined);
36821
+ continue;
36822
+ }
36823
+ convertLabelmapToSurface_triggerWorkerProgress(0, segmentIndex);
36824
+ try {
36825
+ surfaces.push(await convertLabelmapToSurface_workerManager.executeTask('polySeg', 'convertLabelmapToSurface', {
36826
+ scalarData,
36827
+ dimensions: block.dimensions,
36828
+ spacing,
36829
+ origin: volume.imageData.indexToWorld(block.start),
36830
+ direction,
36831
+ segmentIndex,
36832
+ }, {
36833
+ callbacks: [
36834
+ (progress) => convertLabelmapToSurface_triggerWorkerProgress(progress, segmentIndex),
36835
+ ],
36836
+ }));
36837
+ convertLabelmapToSurface_triggerWorkerProgress(100, segmentIndex);
36838
+ }
36839
+ catch (error) {
36840
+ cs3dLogger.warn(error);
36841
+ let message = `The 3D surface of segment ${segmentIndex} failed (${Math.ceil(blockMiB)} MiB).`;
36842
+ if (blockMiB >= MIN_LIMIT_MIB) {
36843
+ maxBlockMiB = Math.min(maxBlockMiB, blockMiB);
36844
+ message += ' Segments of this size or more are not converted now.';
36845
+ }
36846
+ reportFailure(segmentIndex, message);
36847
+ surfaces.push(undefined);
36848
+ }
36849
+ }
36850
+ return surfaces;
36690
36851
  }
36691
36852
 
36692
36853
  ;// CONCATENATED MODULE: ../../node_modules/@cornerstonejs/polymorphic-segmentation/dist/esm/Surface/surfaceComputationStrategies.js
@@ -36695,7 +36856,7 @@ async function convertLabelmapToSurface(labelmapRepresentationData, segmentIndex
36695
36856
 
36696
36857
 
36697
36858
 
36698
- const cs3dLogger = esm.utilities.logger.polySegLog.getLogger('Surface.surfaceComputationStrategies');
36859
+ const surfaceComputationStrategies_cs3dLogger = esm.utilities.logger.polySegLog.getLogger('Surface.surfaceComputationStrategies');
36699
36860
  const { getUniqueSegmentIndices } = dist_esm.utilities.segmentation;
36700
36861
  const { getSegmentation: surfaceComputationStrategies_getSegmentation } = dist_esm.segmentation.state;
36701
36862
  async function computeSurfaceData(segmentationId, options = {}) {
@@ -36720,7 +36881,7 @@ async function computeSurfaceData(segmentationId, options = {}) {
36720
36881
  }
36721
36882
  }
36722
36883
  catch (error) {
36723
- cs3dLogger.error(error);
36884
+ surfaceComputationStrategies_cs3dLogger.error(error);
36724
36885
  throw error;
36725
36886
  }
36726
36887
  if (!rawSurfacesData) {
@@ -36732,29 +36893,22 @@ async function computeSurfaceData(segmentationId, options = {}) {
36732
36893
  async function computeSurfaceFromLabelmapSegmentation(segmentationId, options = {}) {
36733
36894
  const segmentation = surfaceComputationStrategies_getSegmentation(segmentationId);
36734
36895
  if (!segmentation?.representationData?.Labelmap) {
36735
- cs3dLogger.warn('Only support surface update from labelmaps');
36896
+ surfaceComputationStrategies_cs3dLogger.warn('Only support surface update from labelmaps');
36736
36897
  return;
36737
36898
  }
36738
36899
  const labelmapRepresentationData = segmentation.representationData.Labelmap;
36739
36900
  const segmentIndices = options.segmentIndices || getUniqueSegmentIndices(segmentationId);
36740
- const promises = segmentIndices.map((index) => {
36741
- const surface = convertLabelmapToSurface(labelmapRepresentationData, index);
36742
- return surface;
36743
- });
36744
- const surfaces = await Promise.allSettled(promises);
36745
- const errors = surfaces.filter((p) => p.status === 'rejected');
36746
- if (errors.length > 0) {
36747
- cs3dLogger.error(errors);
36901
+ let surfaces;
36902
+ try {
36903
+ surfaces = await convertLabelmapToSurfaces(labelmapRepresentationData, segmentIndices);
36904
+ }
36905
+ catch (error) {
36906
+ surfaceComputationStrategies_cs3dLogger.error(error);
36748
36907
  throw new Error('Failed to convert labelmap to surface');
36749
36908
  }
36750
- const rawSurfacesData = surfaces
36751
- .map((surface, index) => {
36752
- if (surface.status === 'fulfilled') {
36753
- return { segmentIndex: segmentIndices[index], data: surface.value };
36754
- }
36755
- })
36756
- .filter(Boolean);
36757
- return rawSurfacesData;
36909
+ return surfaces
36910
+ .map((data, index) => ({ segmentIndex: segmentIndices[index], data }))
36911
+ .filter(({ data }) => data);
36758
36912
  }
36759
36913
  async function computeSurfaceFromContourSegmentation(segmentationId, options = {}) {
36760
36914
  const segmentation = surfaceComputationStrategies_getSegmentation(segmentationId);
@@ -37506,7 +37660,38 @@ async function canConvertFromTo(fromRepresentationType, toRepresentationType) {
37506
37660
 
37507
37661
 
37508
37662
  const { utilities: { segmentation: { getUniqueSegmentIndices: updateSurfaceData_getUniqueSegmentIndices }, }, segmentation: { state: { getViewportIdsWithSegmentation, getSegmentation: updateSurfaceData_getSegmentation, getSegmentationRepresentation, }, triggerSegmentationEvents: { triggerSegmentationModified }, }, Enums: { SegmentationRepresentations: updateSurfaceData_SegmentationRepresentations }, } = dist_esm;
37509
- async function updateSurfaceData(segmentationId) {
37663
+ const updateSurfaceData_cs3dLogger = esm.utilities.logger.polySegLog.getLogger('Surface.updateSurfaceData');
37664
+ const updates = new Map();
37665
+ function updateSurfaceData(segmentationId) {
37666
+ const running = updates.get(segmentationId);
37667
+ if (running) {
37668
+ running.rerun = true;
37669
+ return running.promise;
37670
+ }
37671
+ const update = { promise: undefined, rerun: false };
37672
+ update.promise = (async () => {
37673
+ try {
37674
+ do {
37675
+ update.rerun = false;
37676
+ try {
37677
+ await updateSurfaceDataOnce(segmentationId);
37678
+ }
37679
+ catch (error) {
37680
+ if (!update.rerun) {
37681
+ throw error;
37682
+ }
37683
+ updateSurfaceData_cs3dLogger.warn(error);
37684
+ }
37685
+ } while (update.rerun);
37686
+ }
37687
+ finally {
37688
+ updates.delete(segmentationId);
37689
+ }
37690
+ })();
37691
+ updates.set(segmentationId, update);
37692
+ return update.promise;
37693
+ }
37694
+ async function updateSurfaceDataOnce(segmentationId) {
37510
37695
  const surfacesObj = await computeSurfaceFromLabelmapSegmentation(segmentationId);
37511
37696
  if (!surfacesObj) {
37512
37697
  return;