All files / core/src/utilities getScalingParameters.ts

100% Statements 6/6
78.57% Branches 11/14
100% Functions 1/1
100% Lines 6/6

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                          342x   342x   342x   342x           342x   342x                              
import * as metaData from '../metaData';
import type { ScalingParameters } from '../types';
 
/**
 * It returns the scaling parameters for the image with the given imageId. This can be
 * used to get passed (as an option) to the imageLoader in order to apply scaling to the image inside
 * the imageLoader.
 * @param imageId - The imageId of the image
 * @returns ScalingParameters
 */
export default function getScalingParameters(
  imageId: string
): ScalingParameters {
  const modalityLutModule = metaData.get('modalityLutModule', imageId) || {};
  const generalSeriesModule =
    metaData.get('generalSeriesModule', imageId) || {};
 
  const { modality } = generalSeriesModule;
 
  const scalingParameters = {
    rescaleSlope: modalityLutModule.rescaleSlope || 1,
    rescaleIntercept: modalityLutModule.rescaleIntercept ?? 0,
    modality,
  };
 
  const scalingModules = metaData.get('scalingModule', imageId) || {};
 
  return {
    ...scalingParameters,
    ...(modality === 'PT' && {
      suvbw: scalingModules.suvbw,
      suvbsa: scalingModules.suvbsa,
      suvlbm: scalingModules.suvlbm,
    }),
    ...(modality === 'RTDOSE' && {
      doseGridScaling: scalingModules.DoseGridScaling,
      doseSummation: scalingModules.DoseSummation,
      doseType: scalingModules.DoseType,
      doseUnit: scalingModules.DoseUnit,
    }),
  };
}