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

0% Statements 0/13
0% Branches 0/9
0% Functions 0/2
0% Lines 0/12

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                                                                                               
import { generateContourSetsFromLabelmap } from '../contours';
import findLargestBidirectional from './findLargestBidirectional';
import getOrCreateSegmentationVolume from './getOrCreateSegmentationVolume';
 
/**
 * Generates a contour object over the segment, and then uses the contouring to
 * find the largest bidirectional object that can be applied within the acquisition
 * plane that is within the segment index, or the contained segment indices.
 *
 * @param segmentation.segments - a list of segments to apply the contour to.
 * @param segmentation.segments.containedSegmentIndices - a set of segment indexes equivalent to the primary segment
 * @param segmentation.segments.label - the label for the segment
 * @param segmentation.segments.color - the color to use for the segment label
 */
export default async function contourAndFindLargestBidirectional(segmentation) {
  const contours = await generateContourSetsFromLabelmap({
    segmentations: segmentation,
  });
 
  if (!contours?.length || !contours[0].sliceContours.length) {
    return;
  }
 
  const {
    segments = [
      null,
      { label: 'Unspecified', color: null, containedSegmentIndices: null },
    ],
  } = segmentation;
 
  const vol = getOrCreateSegmentationVolume(segmentation.segmentationId);
 
  if (!vol) {
    return;
  }
 
  const segmentIndex = segments.findIndex((it) => !!it);
  if (segmentIndex === -1) {
    return;
  }
  segments[segmentIndex].segmentIndex = segmentIndex;
  return findLargestBidirectional(
    contours[0],
    vol.volumeId,
    segments[segmentIndex]
  );
}