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

84.61% Statements 11/13
50% Branches 1/2
75% Functions 3/4
90.9% Lines 10/11

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                                        64x 64x         64x 64x 64x   64x         64x   64x       64x     64x    
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;
  Eif (renderingEngineId) {
    renderingEngines = [getRenderingEngine(renderingEngineId)];
  } else {
    renderingEngines = getRenderingEngines();
  }
 
  const viewports = [];
  renderingEngines.forEach((renderingEngine) => {
    const stackViewports = renderingEngine.getStackViewports();
 
    const filteredStackViewports = stackViewports.filter((viewport) =>
      viewport.hasImageURI(imageURI)
    );
 
    // If no stack viewport found but a volumeViewport is rendering the same data
    const volumeViewports = renderingEngine.getVolumeViewports();
 
    const filteredVolumeViewports = volumeViewports.filter((viewport) =>
      viewport.hasImageURI(imageURI)
    );
 
    viewports.push(...filteredStackViewports, ...filteredVolumeViewports);
  });
 
  return viewports;
}