All files / packages/tools/src/utilities/contours AnnotationToPointData.ts

20% Statements 3/15
0% Branches 0/8
25% Functions 1/4
20% Lines 3/15

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 59 60 61 62                          1x                                                                                 1x       1x      
import RectangleROIStartEndThreshold from './RectangleROIStartEndThreshold';
 
function validateAnnotation(annotation) {
  if (!annotation?.data) {
    throw new Error('Tool data is empty');
  }
 
  if (!annotation.metadata || annotation.metadata.referenceImageId) {
    throw new Error('Tool data is not associated with any imageId');
  }
}
 
class AnnotationToPointData {
  static TOOL_NAMES: Record<string, any> = {};
 
  constructor() {
    // empty
  }
 
  static convert(annotation, index, metadataProvider) {
    validateAnnotation(annotation);
 
    const { toolName } = annotation.metadata;
    const toolClass = AnnotationToPointData.TOOL_NAMES[toolName];
 
    if (!toolClass) {
      throw new Error(
        `Unknown tool type: ${toolName}, cannot convert to RTSSReport`
      );
    }
 
    // Each toolData should become a list of contours, ContourSequence
    // contains a list of contours with their pointData, their geometry
    // type and their length.
    const ContourSequence = toolClass.getContourSequence(
      annotation,
      metadataProvider
    );
 
    // Todo: random rgb color for now, options should be passed in
    const color = [
      Math.floor(Math.random() * 255),
      Math.floor(Math.random() * 255),
      Math.floor(Math.random() * 255),
    ];
 
    return {
      ReferencedROINumber: index + 1,
      ROIDisplayColor: color,
      ContourSequence,
    };
  }
 
  static register(toolClass) {
    AnnotationToPointData.TOOL_NAMES[toolClass.toolName] = toolClass;
  }
}
 
AnnotationToPointData.register(RectangleROIStartEndThreshold);
 
export default AnnotationToPointData;