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

7.14% Statements 1/14
100% Branches 0/0
0% Functions 0/6
7.14% Lines 1/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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                          1x                                                              
// comment
class RectangleROIStartEndThreshold {
  static toolName: string;
 
  constructor() {
    // empty
  }
 
  static getContourSequence(toolData, metadataProvider) {
    const { data } = toolData;
    const { projectionPoints, projectionPointsImageIds } = data.cachedStats;
 
    return projectionPoints.map((point, index) => {
      const ContourData = getPointData(point);
      const ContourImageSequence = getContourImageSequence(
        projectionPointsImageIds[index],
        metadataProvider
      );
 
      return {
        NumberOfContourPoints: ContourData.length / 3,
        ContourImageSequence,
        ContourGeometricType: 'CLOSED_PLANAR',
        ContourData,
      };
    });
  }
}
 
RectangleROIStartEndThreshold.toolName = 'RectangleROIStartEndThreshold';
 
function getPointData(points) {
  // Since this is a closed contour, the order of the points is important.
  // re-order the points to be in the correct order clockwise
  // Spread to make sure Float32Arrays are converted to arrays
  const orderedPoints = [
    ...points[0],
    ...points[1],
    ...points[3],
    ...points[2],
  ];
  const pointsArray = orderedPoints.flat();
 
  // reduce the precision of the points to 2 decimal places
  const pointsArrayWithPrecision = pointsArray.map((point) => {
    return point.toFixed(2);
  });
 
  return pointsArrayWithPrecision;
}
 
function getContourImageSequence(imageId, metadataProvider) {
  const sopCommon = metadataProvider.get('sopCommonModule', imageId);
 
  return {
    ReferencedSOPClassUID: sopCommon.sopClassUID,
    ReferencedSOPInstanceUID: sopCommon.sopInstanceUID,
  };
}
export default RectangleROIStartEndThreshold;