All files / core/src/utilities getViewportsWithImageURI.ts

100% Statements 8/8
50% Branches 1/2
100% Functions 3/3
100% Lines 8/8

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                              15x   15x 15x 15x         15x 23x 23x         15x    
import { getRenderingEngines } from '../RenderingEngine/getRenderingEngine';
import type { IBaseVolumeViewport, IStackViewport } from '../types';
 
type Viewport = IStackViewport | IBaseVolumeViewport;
 
/**
 * Get the viewport that is rendering the image with the given imageURI (imageId without
 * the loader schema), this can be a stackViewport or a volumeViewport.
 *
 * @param renderingEngine - The rendering engine that is rendering the viewports
 * @param imageURI - The imageURI of the image that is requested
 * @returns A Viewport
 */
export default function getViewportsWithImageURI(imageURI: string): Viewport[] {
  // If rendering engine is not provided, use all rendering engines
  const renderingEngines = getRenderingEngines();
 
  const viewports = [];
  renderingEngines.forEach((renderingEngine) => {
    const viewportsForRenderingEngine = renderingEngine.getViewports() as (
      | IStackViewport
      | IBaseVolumeViewport
    )[];
 
    viewportsForRenderingEngine.forEach((viewport) => {
      Eif (viewport.hasImageURI(imageURI)) {
        viewports.push(viewport);
      }
    });
  });
 
  return viewports;
}