All files / tools/src/utilities/segmentation/growCut getViewportVoiMappingForVolume.ts

0% Statements 0/10
0% Branches 0/10
0% Functions 0/1
0% Lines 0/10

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                                                                                         
import type { Types } from '@cornerstonejs/core';
 
export type ViewportVoiMappingForTool = {
  voiRange: { lower: number; upper: number };
  VOILUTFunction?: string;
  /** Viewport invert flag (e.g. PET AC). Needed so display luma inverse-maps to the right raw end. */
  invert?: boolean;
};
 
type ViewportWithProps = Types.IViewport & {
  getProperties?: (volumeId?: string) => {
    voiRange?: { lower: number; upper: number };
    VOILUTFunction?: string;
    invert?: boolean;
  } | null;
};
 
/**
 * Reads VOI + LUT function from a volume or stack viewport for intensity mapping.
 */
export function getViewportVoiMappingForVolume(
  viewport: Types.IViewport,
  volumeId?: string
): ViewportVoiMappingForTool | null {
  const getProps = (viewport as ViewportWithProps).getProperties;
  if (typeof getProps !== 'function') {
    return null;
  }
  const props = volumeId
    ? getProps.call(viewport, volumeId)
    : getProps.call(viewport);
  if (!props?.voiRange) {
    return null;
  }
  const { lower, upper } = props.voiRange;
  if (typeof lower !== 'number' || typeof upper !== 'number') {
    return null;
  }
  return {
    voiRange: { lower, upper },
    VOILUTFunction: props.VOILUTFunction,
    invert: props.invert === true,
  };
}