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

78.57% Statements 11/14
62.5% Branches 5/8
100% Functions 1/1
78.57% Lines 11/14

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                    2x       2x           2x 2x   2x       2x   2x   2x 1x 1x     2x          
import { getSegmentation } from '../../stateManagement/segmentation/segmentationState';
import { 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() };
  }
 
  const { annotationUIDsMap } = segmentation.representationData.CONTOUR;
 
  let annotationsUIDsSet = annotationUIDsMap.get(segmentIndex);
 
  if (!annotationsUIDsSet) {
    annotationsUIDsSet = new Set();
    annotationUIDsMap.set(segmentIndex, annotationsUIDsSet);
  }
 
  annotationUIDsMap.set(
    segmentIndex,
    annotationsUIDsSet.add(annotation.annotationUID)
  );
}