All files / extensions/cornerstone/src/services/SegmentationService/RTSTRUCT mapROIContoursToRTStructData.ts

100% Statements 7/7
50% Branches 1/2
100% Functions 4/4
100% Lines 7/7

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                    4x 70x 4852x 1304686x     4852x           70x   70x                  
/**
 * Maps a DICOM RT Struct ROI Contour to a RTStruct data that can be used
 * in Segmentation Service
 *
 * @param structureSet - A DICOM RT Struct ROI Contour
 * @param rtDisplaySetUID - A CornerstoneTools DisplaySet UID
 * @returns An array of object that includes data, id, segmentIndex, color
 * and geometry Id
 */
export function mapROIContoursToRTStructData(structureSet: unknown, rtDisplaySetUID: unknown) {
  return structureSet.ROIContours.map(({ contourPoints, ROINumber, ROIName, colorArray }) => {
    const data = contourPoints.map(({ points, ...rest }) => {
      const newPoints = points.map(({ x, y, z }) => {
        return [x, y, z];
      });
 
      return {
        ...rest,
        points: newPoints,
      };
    });
 
    const id = ROIName || ROINumber;
 
    return {
      data,
      id,
      segmentIndex: ROINumber,
      color: colorArray,
      geometryId: `${rtDisplaySetUID}:${id}:segmentIndex-${ROINumber}`,
    };
  });
}