All files / tools/src/utilities/segmentation getSegmentLargestBidirectional.ts

0% Statements 0/18
0% Branches 0/5
0% Functions 0/3
0% Lines 0/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                                                                                                                                                                                                                                     
import { getWebWorkerManager } from '@cornerstonejs/core';
import { WorkerTypes } from '../../enums';
import { registerComputeWorker } from '../registerComputeWorker';
import {
  triggerWorkerProgress,
  getSegmentationDataForWorker,
  prepareVolumeStrategyDataForWorker,
  prepareStackDataForWorker,
} from './utilsForWorker';
 
/**
 * Get largest bidirectional measurements for segmentation
 * @param segmentationId - The segmentation ID
 * @param segmentIndices - The segment indices
 * @param mode - The computation mode
 * @returns Bidirectional measurement data
 */
export async function getSegmentLargestBidirectional({
  segmentationId,
  segmentIndices,
  mode = 'individual',
}) {
  // Todo: handle the 'collective' mode where segment indices are merged together
  registerComputeWorker();
 
  triggerWorkerProgress(WorkerTypes.COMPUTE_LARGEST_BIDIRECTIONAL, 0);
 
  const segData = getSegmentationDataForWorker(segmentationId, segmentIndices);
 
  if (!segData) {
    return;
  }
 
  const { operationData, segImageIds, reconstructableVolume, indices } =
    segData;
 
  const bidirectionalData = reconstructableVolume
    ? await calculateVolumeBidirectional({
        operationData,
        indices,
        mode,
      })
    : await calculateStackBidirectional({
        segImageIds,
        indices,
        mode,
      });
 
  triggerWorkerProgress(WorkerTypes.COMPUTE_LARGEST_BIDIRECTIONAL, 100);
 
  return bidirectionalData;
}
 
/**
 * Calculate bidirectional measurements for a volume
 * @param operationData - The operation data
 * @param indices - The segment indices
 * @param mode - The computation mode
 * @returns Bidirectional measurement data
 */
async function calculateVolumeBidirectional({ operationData, indices, mode }) {
  // Get the strategy data
  const strategyData = prepareVolumeStrategyDataForWorker(operationData);
 
  const { segmentationVoxelManager, segmentationImageData } = strategyData;
 
  const segmentationScalarData =
    segmentationVoxelManager.getCompleteScalarDataArray();
 
  const segmentationInfo = {
    scalarData: segmentationScalarData,
    dimensions: segmentationImageData.getDimensions(),
    spacing: segmentationImageData.getSpacing(),
    origin: segmentationImageData.getOrigin(),
    direction: segmentationImageData.getDirection(),
  };
 
  const bidirectionalData = await getWebWorkerManager().executeTask(
    'compute',
    'getSegmentLargestBidirectionalInternal',
    {
      segmentationInfo,
      indices,
      mode,
    }
  );
 
  return bidirectionalData;
}
 
/**
 * Calculate bidirectional measurements for a stack
 * @param segImageIds - The segmentation image IDs
 * @param indices - The segment indices
 * @param mode - The computation mode
 * @returns Bidirectional measurement data
 */
async function calculateStackBidirectional({ segImageIds, indices, mode }) {
  // Get segmentation and image info for each image in the stack
  const { segmentationInfo } = prepareStackDataForWorker(segImageIds);
 
  const bidirectionalData = await getWebWorkerManager().executeTask(
    'compute',
    'getSegmentLargestBidirectionalInternal',
    {
      segmentationInfo,
      indices,
      mode,
      isStack: true,
    }
  );
 
  return bidirectionalData;
}