All files / tools/src/utilities/contourSegmentation addContourSegmentationAnnotation.ts

75% Statements 12/16
60% Branches 6/10
100% Functions 1/1
75% Lines 12/16

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                    44x       44x           44x 44x   44x       44x   44x       44x   44x 20x 20x     44x          
import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
import type { ContourSegmentationAnnotation } from '../../types';
 
/**
 * Adds a contour segmentation annotation to the specified segmentation.
 * @param annotation - The contour segmentation annotation to add.
 */
export function addContourSegmentationAnnotation(
  annotation: ContourSegmentationAnnotation
) {
  Iif (annotation.parentAnnotationUID) {
    // Don't add it for parent annotations - this happens during interpolation
    return;
  }
  Iif (!annotation.data.segmentation) {
    throw new Error(
      'addContourSegmentationAnnotation: annotation does not have a segmentation data'
    );
  }
 
  const { segmentationId, segmentIndex } = annotation.data.segmentation;
  const segmentation = getSegmentation(segmentationId);
 
  Iif (!segmentation.representationData.Contour) {
    segmentation.representationData.Contour = { annotationUIDsMap: new Map() };
  }
 
  let { annotationUIDsMap } = segmentation.representationData.Contour;
 
  Iif (!annotationUIDsMap) {
    annotationUIDsMap = new Map();
  }
 
  let annotationsUIDsSet = annotationUIDsMap?.get(segmentIndex);
 
  if (!annotationsUIDsSet) {
    annotationsUIDsSet = new Set();
    annotationUIDsMap.set(segmentIndex, annotationsUIDsSet);
  }
 
  annotationUIDsMap.set(
    segmentIndex,
    annotationsUIDsSet.add(annotation.annotationUID)
  );
}