All files / tools/src/utilities/volumeCropping extractVolumeDirectionVectors.ts

0% Statements 0/2
100% Branches 0/0
0% Functions 0/1
0% Lines 0/2

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                                                                         
import { vec3 } from 'gl-matrix';
import type { Types } from '@cornerstonejs/core';
 
export interface ImageDataWithDirection {
  getDirection(): number[];
}
 
/**
 * Extract volume direction vectors from imageData.
 * The direction matrix defines the volume's orientation in world space.
 * @param imageData - The VTK image data
 * @returns Object containing the three orthogonal direction vectors
 */
export function extractVolumeDirectionVectors(
  imageData: ImageDataWithDirection
): {
  xDir: Types.Point3;
  yDir: Types.Point3;
  zDir: Types.Point3;
} {
  const direction = imageData.getDirection();
  return {
    xDir: vec3.normalize(
      [0, 0, 0],
      direction.slice(0, 3) as [number, number, number]
    ) as Types.Point3,
    yDir: vec3.normalize(
      [0, 0, 0],
      direction.slice(3, 6) as [number, number, number]
    ) as Types.Point3,
    zDir: vec3.normalize(
      [0, 0, 0],
      direction.slice(6, 9) as [number, number, number]
    ) as Types.Point3,
  };
}