All files / core/src/utilities/voxelSlab isPlaneDepthViewable.ts

0% Statements 0/6
0% Branches 0/3
0% Functions 0/1
0% Lines 0/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 44 45 46 47 48 49 50                                                                                                   
import { vec3 } from 'gl-matrix';
import type { Point3 } from '../../types';
import { isEqual } from '../isEqual';
import { getDisplayHalfWidth, SLAB_RELATIVE_EPSILON } from './slabMembership';
 
/**
 * The depth half of Rule D: whether a referenced plane is close enough to a
 * viewport's focal plane to be displayed.
 *
 * ```
 *   |depth| < (viewportSlabThickness + referencePlaneThickness) / 2
 * ```
 *
 * Both are full geometric thicknesses in mm. A reference with no thickness
 * falls back to an exact-to-within-`isEqual` plane match.
 *
 * See `docs/docs/concepts/cornerstone-tools/annotation/voxel-statistics.md`.
 *
 * @param planePoint - The point identifying the referenced plane's depth.
 * @param focalPoint - The viewport camera focal point.
 * @param viewPlaneNormal - The viewport view plane normal. Unit length.
 * @param referencePlaneThickness - The plane's own thickness, or undefined
 *   when not recorded.
 * @param viewportSlabThickness - Defaults to 0, which halves the window -
 *   correct for a stack viewport, which has no slab.
 */
export function isPlaneDepthViewable(
  planePoint: Point3,
  focalPoint: Point3,
  viewPlaneNormal: Point3,
  referencePlaneThickness?: number,
  viewportSlabThickness = 0
): boolean {
  const pointVector = vec3.sub(vec3.create(), planePoint, focalPoint);
  const depth = vec3.dot(pointVector, viewPlaneNormal as vec3);
 
  if (!Number.isFinite(referencePlaneThickness)) {
    return isEqual(0, depth);
  }
 
  const halfWidth = getDisplayHalfWidth(
    viewportSlabThickness,
    referencePlaneThickness as number
  );
 
  return (
    Math.abs(depth) < halfWidth - Math.abs(halfWidth) * SLAB_RELATIVE_EPSILON
  );
}