All files / tools/src/stateManagement/segmentation/helpers removeSegmentAnnotations.ts

0% Statements 0/10
0% Branches 0/6
0% Functions 0/2
0% Lines 0/10

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                                                                         
import type { ContourSegmentationAnnotation } from '../../../types/ContourSegmentationAnnotation';
import { getAnnotation } from '../../annotation/annotationState';
import {
  getAnnotationsUIDMapFromSegmentation,
  removeCompleteContourAnnotation,
} from '../utilities';
import { isContourSegmentationAnnotation } from '../../../utilities/contourSegmentation';
 
/**
 * Clears/removes all contour segment annotations for a given segment index.
 *
 * @param segmentationId - The unique identifier of the segmentation.
 * @param segmentIndex - The index of the segment to clear/remove the annotations from.
 */
export function removeContourSegmentAnnotations(
  segmentationId: string,
  segmentIndex: number
) {
  const annotationUIDsMap =
    getAnnotationsUIDMapFromSegmentation(segmentationId);
  if (!annotationUIDsMap) {
    return;
  }
 
  const annotationUIDs = annotationUIDsMap.get(segmentIndex);
  if (!annotationUIDs) {
    return;
  }
 
  annotationUIDs.forEach((annotationUID) => {
    const annotation = getAnnotation(annotationUID);
    if (isContourSegmentationAnnotation(annotation)) {
      removeCompleteContourAnnotation(annotation);
    }
  });
}