All files / packages/core/src/utilities getVolumeSliceRangeInfo.ts

80% Statements 12/15
50% Branches 2/4
100% Functions 1/1
76.92% Lines 10/13

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                                              1x 1x 1x 1x   1x           1x   1x         1x 1x   1x                
import getSliceRange from './getSliceRange';
import getTargetVolumeAndSpacingInNormalDir from './getTargetVolumeAndSpacingInNormalDir';
import {
  ActorSliceRange,
  IVolumeViewport,
  ICamera,
  VolumeActor,
} from '../types';
 
/**
 * Calculates the slice range for the given volume based on its orientation
 * @param viewport - Volume viewport
 * @param volumeId - Id of one of the volumes loaded on the given viewport
 * @returns slice range information
 */
function getVolumeSliceRangeInfo(
  viewport: IVolumeViewport,
  volumeId: string
): {
  sliceRange: ActorSliceRange;
  spacingInNormalDirection: number;
  camera: ICamera;
} {
  const camera = viewport.getCamera();
  const { focalPoint, viewPlaneNormal } = camera;
  const { spacingInNormalDirection, actorUID } =
    getTargetVolumeAndSpacingInNormalDir(viewport, camera, volumeId);
 
  Iif (!actorUID) {
    throw new Error(
      `Could not find image volume with id ${volumeId} in the viewport`
    );
  }
 
  const actorEntry = viewport.getActor(actorUID);
 
  Iif (!actorEntry) {
    console.warn('No actor found for with actorUID of', actorUID);
    return null;
  }
 
  const volumeActor = actorEntry.actor as VolumeActor;
  const sliceRange = getSliceRange(volumeActor, viewPlaneNormal, focalPoint);
 
  return {
    sliceRange,
    spacingInNormalDirection,
    camera,
  };
}
 
export default getVolumeSliceRangeInfo;