All files / packages/tools/src/synchronizers/callbacks voiSyncCallback.ts

72.22% Statements 13/18
50% Branches 5/10
100% Functions 1/1
66.66% Lines 10/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                                                2x 2x   2x 2x           2x     2x       2x       2x 2x             2x    
import {
  BaseVolumeViewport,
  getRenderingEngine,
  StackViewport,
  Types,
} from '@cornerstonejs/core';
 
/**
 * Synchronizer callback to synchronize the voi of volumeActors of identical volumes
 * in different viewports.
 *
 * @param synchronizerInstance - The Instance of the Synchronizer
 * @param sourceViewport - The list of IDs defining the source viewport.
 * @param targetViewport - The list of IDs defining the target viewport.
 * @param voiModifiedEvent - The VOI_MODIFIED event.
 * @param options - Options for the synchronizer.
 */
export default function voiSyncCallback(
  synchronizerInstance,
  sourceViewport: Types.IViewportId,
  targetViewport: Types.IViewportId,
  voiModifiedEvent: Types.EventTypes.VoiModifiedEvent,
  options?: any
): void {
  const eventDetail = voiModifiedEvent.detail;
  const { volumeId, range, invertStateChanged, invert } = eventDetail;
 
  const renderingEngine = getRenderingEngine(targetViewport.renderingEngineId);
  Iif (!renderingEngine) {
    throw new Error(
      `Rendering Engine does not exist: ${targetViewport.renderingEngineId}`
    );
  }
 
  const tViewport = renderingEngine.getViewport(targetViewport.viewportId);
  const tProperties:
    | Types.VolumeViewportProperties
    | Types.StackViewportProperties = {
    voiRange: range,
  };
 
  Iif (options.syncInvertState && invertStateChanged) {
    tProperties.invert = invert;
  }
 
  Eif (tViewport instanceof BaseVolumeViewport) {
    tViewport.setProperties(tProperties, volumeId);
  } else if (tViewport instanceof StackViewport) {
    tViewport.setProperties(tProperties);
  } else {
    throw new Error('Viewport type not supported.');
  }
 
  tViewport.render();
}