All files / core/src/RenderingEngine/GenericViewport/Volume3D volume3DProjectionCamera.ts

0% Statements 0/10
0% Branches 0/8
0% Functions 0/5
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                                           
import type { ICamera, Point2, Point3 } from '../../../types';
import type { ProjectionScale } from '../ViewportProjectionTypes';
import type { Volume3DCamera } from './viewport3DTypes';
 
function clonePoint2(point?: Point2): Point2 | undefined {
  return point ? [point[0], point[1]] : undefined;
}
 
function clonePoint3(point?: Point3): Point3 | undefined {
  return point ? [point[0], point[1], point[2]] : undefined;
}
 
/**
 * Clones a 3D camera payload so projection snapshots cannot mutate VTK state
 * through shared point arrays.
 */
export function cloneVolume3DCamera(camera: Volume3DCamera & ICamera) {
  return {
    ...camera,
    clippingRange: clonePoint2(camera.clippingRange),
    focalPoint: clonePoint3(camera.focalPoint),
    position: clonePoint3(camera.position),
    viewPlaneNormal: clonePoint3(camera.viewPlaneNormal),
    viewUp: clonePoint3(camera.viewUp),
  } as Volume3DCamera & ICamera;
}
 
/**
 * Reports 3D parallel scale as physical canvas spacing for projection callers.
 */
export function getVolume3DProjectionScale(args: {
  camera: Volume3DCamera & ICamera;
  canvasHeight: number;
}): ProjectionScale | undefined {
  const { camera, canvasHeight } = args;
 
  if (typeof camera.parallelScale !== 'number') {
    return;
  }
 
  return {
    kind: 'physical',
    mmPerCanvasPixel: (camera.parallelScale * 2) / Math.max(canvasHeight, 1),
  };
}
 
/**
 * Reports 3D position semantics as a focal point when one is available.
 */
export function getVolume3DProjectionPosition(
  camera: Volume3DCamera & ICamera
) {
  if (!camera.focalPoint) {
    return;
  }
 
  return {
    kind: 'focalPoint' as const,
    worldPoint: clonePoint3(camera.focalPoint) as Point3,
  };
}