All files / core/src/RenderingEngine RenderingEngine.ts

37.03% Statements 10/27
20% Branches 1/5
33.33% Functions 6/18
37.03% Lines 10/27

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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119                                          428x 428x   428x         428x 428x                             340x               96x               940x                                                                   50x       98x                                      
import { getConfiguration } from '../init';
import TiledRenderingEngine from './TiledRenderingEngine';
import ContextPoolRenderingEngine from './ContextPoolRenderingEngine';
import type BaseRenderingEngine from './BaseRenderingEngine';
import type {
  IStackViewport,
  IVolumeViewport,
  IViewport,
  PublicViewportInput,
  VtkOffscreenMultiRenderWindow,
} from '../types';
import { RenderingEngineModeEnum } from '../enums';
 
class RenderingEngine {
  public hasBeenDestroyed: boolean;
 
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  public offscreenMultiRenderWindow: VtkOffscreenMultiRenderWindow;
  private _implementation?: BaseRenderingEngine;
 
  constructor(id?: string) {
    const config = getConfiguration();
    const renderingEngineMode = config?.rendering?.renderingEngineMode;
 
    switch (renderingEngineMode) {
      case RenderingEngineModeEnum.Tiled:
        this._implementation = new TiledRenderingEngine(id);
        break;
      case RenderingEngineModeEnum.ContextPool:
        this._implementation = new ContextPoolRenderingEngine(id);
        break;
      default:
        console.warn(
          `RenderingEngine: Unknown rendering engine mode "${renderingEngineMode}". Defaulting to Next rendering engine.`
        );
        this._implementation = new ContextPoolRenderingEngine(id);
        break;
    }
  }
 
  get id(): string {
    return this._implementation.id;
  }
 
  public enableElement(viewportInputEntry: PublicViewportInput): void {
    return this._implementation.enableElement(viewportInputEntry);
  }
 
  public disableElement(viewportId: string): void {
    return this._implementation.disableElement(viewportId);
  }
 
  public setViewports(publicViewportInputEntries: PublicViewportInput[]): void {
    return this._implementation.setViewports(publicViewportInputEntries);
  }
 
  public resize(immediate = true, keepCamera = true): void {
    return this._implementation.resize(immediate, keepCamera);
  }
 
  public getViewport(viewportId: string): IViewport {
    return this._implementation.getViewport(viewportId);
  }
 
  public getViewports(): IViewport[] {
    return this._implementation.getViewports();
  }
 
  public getStackViewport(viewportId: string): IStackViewport {
    return this._implementation.getStackViewport(viewportId);
  }
 
  public getStackViewports(): IStackViewport[] {
    return this._implementation.getStackViewports();
  }
 
  public getVolumeViewports(): IVolumeViewport[] {
    return this._implementation.getVolumeViewports();
  }
 
  public getRenderer(viewportId: string) {
    return this._implementation.getRenderer(viewportId);
  }
 
  public fillCanvasWithBackgroundColor(
    canvas: HTMLCanvasElement,
    backgroundColor: [number, number, number]
  ) {
    return this._implementation.fillCanvasWithBackgroundColor(
      canvas,
      backgroundColor
    );
  }
 
  public render(): void {
    return this._implementation.render();
  }
 
  public renderViewports(viewportIds: string[]): void {
    return this._implementation.renderViewports(viewportIds);
  }
 
  public renderViewport(viewportId: string): void {
    return this._implementation.renderViewport(viewportId);
  }
 
  public destroy(): void {
    return this._implementation.destroy();
  }
 
  public getOffscreenMultiRenderWindow(
    viewportId?: string
  ): VtkOffscreenMultiRenderWindow {
    return this._implementation.getOffscreenMultiRenderWindow(viewportId);
  }
}
 
export default RenderingEngine;