All files / packages/tools/src/utilities getViewportsForAnnotation.ts

88.88% Statements 8/9
80% Branches 4/5
100% Functions 3/3
88.88% Lines 8/9

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      1x                       13x   13x   13x 13x 13x 13x             13x    
import { getEnabledElements, utilities as csUtils } from '@cornerstonejs/core';
import type { Annotation } from '../types';
 
const { isEqual } = csUtils;
 
/**
 * Finds a all matching viewports in terms of the orientation of the annotation data
 * and the frame of reference. This doesn't mean the annotation IS being displayed
 * on these viewports, just that it could be by navigating the slice, and/or pan/zoom,
 * without changing the orientation.
 *
 * @param annotation - Annotation to find the viewports that it could display in
 * @returns All viewports to display in
 */
export default function getViewportsForAnnotation(annotation: Annotation) {
  const { metadata } = annotation;
 
  return getEnabledElements()
    .filter((enabledElement) => {
      Eif (enabledElement.FrameOfReferenceUID === metadata.FrameOfReferenceUID) {
        const viewport = enabledElement.viewport;
        const { viewPlaneNormal, viewUp } = viewport.getCamera();
        return (
          isEqual(viewPlaneNormal, metadata.viewPlaneNormal) &&
          (!metadata.viewUp || isEqual(viewUp, metadata.viewUp))
        );
      }
      return;
    })
    .map((enabledElement) => enabledElement.viewport);
}