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

0% Statements 0/11
0% Branches 0/8
0% Functions 0/1
0% Lines 0/11

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                                                                       
import { getSegmentation } from '../../stateManagement/segmentation/getSegmentation';
import type { ContourSegmentationAnnotation } from '../../types';
 
/**
 * Removes a contour segmentation annotation from the given annotation.
 * If the annotation does not have a segmentation data, this method returns
 * quietly.  This can occur for interpolated segmentations that have not yet
 * been converted to real segmentations or other in-process segmentations.
 * @param annotation - The contour segmentation annotation to remove.
 */
export function removeContourSegmentationAnnotation(
  annotation: ContourSegmentationAnnotation
) {
  if (!annotation.data.segmentation) {
    throw new Error(
      'removeContourSegmentationAnnotation: annotation does not have a segmentation data'
    );
  }
 
  const { segmentationId, segmentIndex } = annotation.data.segmentation;
  const segmentation = getSegmentation(segmentationId);
  const { annotationUIDsMap } = segmentation?.representationData.Contour || {};
  const annotationsUIDsSet = annotationUIDsMap?.get(segmentIndex);
 
  if (!annotationsUIDsSet) {
    return;
  }
 
  annotationsUIDsSet.delete(annotation.annotationUID);
 
  // Delete segmentIndex Set if there is no more annotations
  if (!annotationsUIDsSet.size) {
    annotationUIDsMap.delete(segmentIndex);
  }
}