All files / tools/src/tools/annotation SplineContourSegmentationTool.ts

81.81% Statements 9/11
75% Branches 3/4
80% Functions 4/5
81.81% Lines 9/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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58              428x       32x                 32x 32x           1212x       20x                           10x 10x       10x              
import { eventTarget, utilities } from '@cornerstonejs/core';
import type { PublicToolProps } from '../../types';
import SplineROITool from './SplineROITool';
import { Events } from '../../enums';
import { convertContourSegmentationAnnotation } from '../../utilities/contourSegmentation';
 
class SplineContourSegmentationTool extends SplineROITool {
  static toolName = 'SplineContourSegmentationTool';
  private annotationCutMergeCompletedBinded;
 
  constructor(toolProps: PublicToolProps) {
    const initialProps = utilities.deepMerge(
      {
        configuration: {
          calculateStats: false,
        },
      },
      toolProps
    );
 
    super(initialProps);
    this.annotationCutMergeCompletedBinded =
      this.annotationCutMergeCompleted.bind(this);
  }
 
  protected isContourSegmentationTool(): boolean {
    // Re-enable contour segmentation behavior disabled by SplineROITool
    return true;
  }
 
  protected initializeListeners() {
    eventTarget.addEventListener(
      Events.ANNOTATION_CUT_MERGE_PROCESS_COMPLETED,
      this.annotationCutMergeCompletedBinded
    );
  }
 
  protected removeListeners() {
    eventTarget.removeEventListener(
      Events.ANNOTATION_CUT_MERGE_PROCESS_COMPLETED,
      this.annotationCutMergeCompletedBinded
    );
  }
 
  protected annotationCutMergeCompleted(evt) {
    const { sourceAnnotation: annotation } = evt.detail;
    Eif (
      !this.splineToolNames.includes(annotation?.metadata?.toolName) ||
      !this.configuration.simplifiedSpline
    ) {
      return;
    }
    convertContourSegmentationAnnotation(annotation);
  }
}
 
export default SplineContourSegmentationTool;