All files / packages/core/src/RenderingEngine/helpers addImageSlicesToViewports.ts

0% Statements 0/11
0% Branches 0/6
0% Functions 0/2
0% Lines 0/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 48 49 50 51 52 53 54 55                                                                                                             
import { StackViewport } from '..';
import type {
  IStackViewport,
  IStackInput,
  IRenderingEngine,
} from '../../types';
 
/**
 * For each provided viewport it adds a volume to the viewport using the
 * provided renderingEngine
 *
 *
 * @param renderingEngine - The rendering engine to use to get viewports from
 * @param volumeInputs - Array of volume inputs including volumeId. Other properties
 * such as visibility, callback, blendMode, slabThickness are optional
 * @param viewportIds - Array of viewport IDs to add the volume to
 * @param immediateRender - If true, the volumes will be rendered immediately
 * @returns A promise that resolves when all volumes have been added
 */
async function addImageSlicesToViewports(
  renderingEngine: IRenderingEngine,
  stackInputs: Array<IStackInput>,
  viewportIds: Array<string>,
  immediateRender = false,
  suppressEvents = false
): Promise<void> {
  // Check if all viewports are volumeViewports
  for (const viewportId of viewportIds) {
    const viewport = renderingEngine.getViewport(viewportId);
 
    if (!viewport) {
      throw new Error(`Viewport with Id ${viewportId} does not exist`);
    }
 
    // if not instance of BaseVolumeViewport, throw
    if (!(viewport as IStackViewport).addImages) {
      console.warn(
        `Viewport with Id ${viewportId} does not have addImages. Cannot add image segmentation to this viewport.`
      );
 
      return;
    }
  }
 
  const addStackPromises = viewportIds.map(async (viewportId) => {
    const viewport = renderingEngine.getViewport(viewportId) as IStackViewport;
 
    return viewport.addImages(stackInputs, immediateRender, suppressEvents);
  });
 
  await Promise.all(addStackPromises);
}
 
export default addImageSlicesToViewports;