All files / packages/core/src/utilities makeVolumeMetadata.ts

75% Statements 12/16
50% Branches 2/4
100% Functions 1/1
80% Lines 12/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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                      1x                 1x     1x   1x       1x 1x 1x   1x               1x                       1x                     1x       1x                                      
import { metaData } from '../';
import { Metadata } from '../types';
 
/**
 * It creates a metadata object for a volume given the imageIds that compose it.
 * It uses the first imageId to get the metadata.
 *
 * @param imageIds - array of imageIds
 * @returns The volume metadata
 */
export default function makeVolumeMetadata(imageIds: Array<string>): Metadata {
  const imageId0 = imageIds[0];
 
  const {
    pixelRepresentation,
    bitsAllocated,
    bitsStored,
    highBit,
    photometricInterpretation,
    samplesPerPixel,
  } = metaData.get('imagePixelModule', imageId0);
 
  // Add list of VOIs stored on the DICOM.
  const voiLut = [];
 
  const voiLutModule = metaData.get('voiLutModule', imageId0);
 
  // voiLutModule is not always present
  let voiLUTFunction;
  if (voiLutModule) {
    const { windowWidth, windowCenter } = voiLutModule;
    voiLUTFunction = voiLutModule?.voiLUTFunction;
 
    Iif (Array.isArray(windowWidth)) {
      for (let i = 0; i < windowWidth.length; i++) {
        voiLut.push({
          windowWidth: windowWidth[i],
          windowCenter: windowCenter[i],
        });
      }
    } else {
      voiLut.push({
        windowWidth: windowWidth,
        windowCenter: windowCenter,
      });
    }
  } else E{
    voiLut.push({
      windowWidth: undefined,
      windowCenter: undefined,
    });
  }
 
  const { modality, seriesInstanceUID } = metaData.get(
    'generalSeriesModule',
    imageId0
  );
 
  const {
    imageOrientationPatient,
    pixelSpacing,
    frameOfReferenceUID,
    columns,
    rows,
  } = metaData.get('imagePlaneModule', imageId0);
 
  // Map to dcmjs-style keywords. This is becoming the standard and makes it
  // Easier to swap out cornerstoneDICOMImageLoader at a later date.
  return {
    BitsAllocated: bitsAllocated,
    BitsStored: bitsStored,
    SamplesPerPixel: samplesPerPixel,
    HighBit: highBit,
    PhotometricInterpretation: photometricInterpretation,
    PixelRepresentation: pixelRepresentation,
    Modality: modality,
    ImageOrientationPatient: imageOrientationPatient,
    PixelSpacing: pixelSpacing,
    FrameOfReferenceUID: frameOfReferenceUID,
    Columns: columns,
    Rows: rows,
    // This is a reshaped object and not a dicom tag:
    voiLut,
    VOILUTFunction: voiLUTFunction,
    SeriesInstanceUID: seriesInstanceUID,
  };
}