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

90% Statements 9/10
50% Branches 2/4
100% Functions 3/3
90% Lines 9/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                                        68x 68x         68x 68x 68x   68x 68x 68x         68x    
import { getRenderingEngine } from '../RenderingEngine';
import { getRenderingEngines } from '../RenderingEngine/getRenderingEngine';
import { IStackViewport, IVolumeViewport } from '../types';
 
type Viewport = IStackViewport | IVolumeViewport;
 
/**
 * 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,
  renderingEngineId?: string
): Array<Viewport> {
  // If rendering engine is not provided, use all rendering engines
  let renderingEngines;
  if (renderingEngineId) {
    renderingEngines = [getRenderingEngine(renderingEngineId)];
  } else E{
    renderingEngines = getRenderingEngines();
  }
 
  const viewports = [];
  renderingEngines.forEach((renderingEngine) => {
    const viewportsForRenderingEngine = renderingEngine.getViewports();
 
    viewportsForRenderingEngine.forEach((viewport) => {
      Eif (viewport.hasImageURI(imageURI)) {
        viewports.push(viewport);
      }
    });
  });
 
  return viewports;
}