All files / core/src/RenderingEngine/GenericViewport/Video VideoViewportLegacyAdapter.ts

0% Statements 0/53
0% Branches 0/36
0% Functions 0/10
0% Lines 0/53

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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176                                                                                                                                                                                                                                                                                                                                                               
import type {
  ImageSetOptions,
  VideoViewportProperties,
  VOIRange,
  ViewPresentation,
  ViewPresentationSelector,
} from '../../../types';
import type { Point2 } from '../../../types';
import { viewportProjection } from '../viewportProjection';
import type {
  VideoDataPresentation,
  VideoViewState,
} from './VideoViewportTypes';
import VideoViewport from './VideoViewport';
 
class VideoViewportLegacyAdapter extends VideoViewport {
  setDataIds(imageIds: string[], options?: ImageSetOptions) {
    const dataId = imageIds[0];
 
    if (!dataId) {
      return;
    }
 
    return this.setVideo(
      dataId,
      ((options?.viewReference?.sliceIndex as number) || 0) + 1
    );
  }
 
  async setVideo(imageId: string, frameNumber?: number): Promise<this> {
    await this.setDisplaySets({ displaySetId: imageId });
 
    if (typeof frameNumber === 'number') {
      this.setFrameNumber(frameNumber);
    }
 
    return this;
  }
 
  setProperties(props: VideoViewportProperties): void {
    const dataId = this.getFirstBinding()?.data.id;
 
    if (!dataId) {
      return;
    }
 
    const dataPresentation: Partial<VideoDataPresentation> = {};
    const viewPresentation: ViewPresentation = {};
 
    if (typeof props.loop === 'boolean') {
      dataPresentation.loop = props.loop;
    }
    if (typeof props.muted === 'boolean') {
      dataPresentation.muted = props.muted;
    }
    if (typeof props.playbackRate === 'number') {
      dataPresentation.playbackRate = props.playbackRate;
    }
    if (props.pan) {
      viewPresentation.pan = props.pan;
    }
    if (props.voiRange) {
      dataPresentation.voiRange = props.voiRange;
    }
    if (props.invert !== undefined) {
      dataPresentation.invert = props.invert;
    }
 
    if (Object.keys(dataPresentation).length) {
      this.setDisplaySetPresentation(dataId, dataPresentation);
    }
 
    if (Object.keys(viewPresentation).length) {
      this.setViewPresentation(viewPresentation);
    }
  }
 
  /**
   * Compatibility wrapper for legacy callers. Next viewports should read
   * presentation through `viewportProjection.getPresentation`.
   */
  getViewPresentation(
    selector?: ViewPresentationSelector
  ): ViewPresentation | undefined {
    return viewportProjection.getPresentation<ViewPresentation>(this, {
      selector,
    });
  }
 
  /**
   * Compatibility wrapper for legacy callers. Next viewports should use
   * viewport projection to derive view state, then call `setViewState`.
   */
  setViewPresentation(viewPres?: ViewPresentation): void {
    if (!viewPres) {
      return;
    }
 
    const nextViewState = viewportProjection.withPresentation<
      VideoViewState,
      ViewPresentation
    >(this, viewPres);
 
    if (nextViewState) {
      this.setViewState(nextViewState);
    }
  }
 
  /**
   * Compatibility wrapper for legacy callers. Direct Next viewports should use
   * `resetViewState`.
   */
  resetCamera(): boolean {
    return this.resetViewState();
  }
 
  getProperties(): VideoViewportProperties {
    const dataId = this.getFirstBinding()?.data.id;
    const dataPresentation = dataId
      ? this.getDisplaySetPresentation(dataId)
      : undefined;
    const viewPresentation = this.getViewPresentation();
 
    return {
      invert: dataPresentation?.invert,
      loop: dataPresentation?.loop,
      muted: dataPresentation?.muted,
      pan: viewPresentation?.pan,
      playbackRate: dataPresentation?.playbackRate,
      voiRange: dataPresentation?.voiRange,
    };
  }
 
  resetProperties(): void {
    const dataId = this.getFirstBinding()?.data.id;
 
    if (!dataId) {
      return;
    }
 
    this.setDisplaySetPresentation(dataId, {
      invert: false,
      loop: true,
      muted: true,
      playbackRate: 1,
      voiRange: undefined,
    });
    this.setViewPresentation({
      pan: [0, 0] as Point2,
      zoom: 1,
    });
  }
 
  setVOI(voiRange: VOIRange): void {
    const dataId = this.getFirstBinding()?.data.id;
 
    if (!dataId) {
      return;
    }
 
    this.setDisplaySetPresentation(dataId, { voiRange });
  }
 
  setAverageWhite(averageWhite: [number, number, number]): void {
    const dataId = this.getFirstBinding()?.data.id;
 
    if (!dataId) {
      return;
    }
 
    this.setDisplaySetPresentation(dataId, { averageWhite });
  }
}
 
export default VideoViewportLegacyAdapter;