All files / core/src/utilities getViewSlabDepth.ts

66.66% Statements 2/3
75% Branches 3/4
100% Functions 1/1
66.66% Lines 2/3

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                                                      16154x       16154x          
import { RENDERING_DEFAULTS } from '../constants';
 
/**
 * Resolves a slab depth in mm, and reports "no slab" as undefined.
 *
 * The caller supplies a **full** depth, and the two render paths reach that
 * depth differently:
 *
 * - A volume viewport stores a half thickness, because
 *   `setOrientationOfClippingPlanes` puts the two clipping planes at
 *   `focalPoint ± slabThickness`. Such a caller passes `getSlabThickness() * 2`.
 * - A generic planar viewport uses `vtkImageResliceMapper`, where the field is
 *   already a full thickness. Such a caller passes the value as it is.
 *
 * A depth at or below twice `RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS` means
 * "no slab was requested", and not "a slab of 0.1 mm was requested". A literal
 * 0.1 mm is thinner than any real voxel, so undefined lets the caller fall back
 * to one voxel along the normal.
 *
 * See `docs/docs/concepts/cornerstone-tools/annotation/voxel-statistics.md`.
 *
 * @param depth - The full depth the viewport shows, in mm.
 * @returns The depth, or undefined when the viewport shows no slab of its own.
 */
export default function getViewSlabDepth(
  depth: number | undefined | null
): number | undefined {
  Eif (
    !Number.isFinite(depth) ||
    (depth as number) <= RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS * 2
  ) {
    return undefined;
  }
 
  return depth as number;
}