All files / core/src/utilities autoLoad.ts

93.33% Statements 14/15
50% Branches 3/6
100% Functions 5/5
93.33% Lines 14/15

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 54 55 56 57 58 59                              428x   4017x   4017x       4017x 4017x 4017x                           4017x   4017x   4017x 4017x   4017x 4017x   9993x         4017x        
import { getRenderingEngines } from '../RenderingEngine/getRenderingEngine';
import type { IRenderingEngine } from '../types';
import getViewportsWithVolumeId from './getViewportsWithVolumeId';
 
type RenderingEngineAndViewportIds = {
  renderingEngine: IRenderingEngine | undefined;
  viewportIds: Array<string>;
};
 
/**
 * Given a volumeId, it finds the viewports and renderingEngines that
 * include that volume, and triggers a render if renderingEngine is available.
 *
 * @param volumeId - The Id of the volume
 */
const autoLoad = (volumeId: string): void => {
  const renderingEngineAndViewportIds =
    getRenderingEngineAndViewportsContainingVolume(volumeId);
 
  Iif (!renderingEngineAndViewportIds?.length) {
    return;
  }
 
  renderingEngineAndViewportIds.forEach(({ renderingEngine, viewportIds }) => {
    Eif (!renderingEngine.hasBeenDestroyed) {
      renderingEngine.renderViewports(viewportIds);
    }
  });
};
 
/**
 * Retrieves rendering engines and their viewports that contain the specified volume.
 *
 * @param volumeId - The ID of the volume to search for.
 * @returns An array of objects, each containing a rendering engine and the IDs of its viewports that contain the volume.
 */
function getRenderingEngineAndViewportsContainingVolume(
  volumeId: string
): Array<RenderingEngineAndViewportIds> {
  const renderingEnginesArray = getRenderingEngines();
  const renderingEngineAndViewportIds: Array<RenderingEngineAndViewportIds> =
    [];
 
  renderingEnginesArray.forEach((renderingEngine) => {
    const viewports = getViewportsWithVolumeId(volumeId);
 
    Eif (viewports.length) {
      renderingEngineAndViewportIds.push({
        renderingEngine,
        viewportIds: viewports.map((viewport) => viewport.id),
      });
    }
  });
 
  return renderingEngineAndViewportIds;
}
 
export default autoLoad;