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

69.23% Statements 9/13
33.33% Branches 2/6
100% Functions 1/1
66.66% Lines 8/12

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                                            2x 2x   2x 2x           2x   2x 2x                           2x    
import {
  getRenderingEngine,
  StackViewport,
  Types,
  VolumeViewport,
} 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.
 */
export default function voiSyncCallback(
  synchronizerInstance,
  sourceViewport: Types.IViewportId,
  targetViewport: Types.IViewportId,
  voiModifiedEvent: Types.EventTypes.VoiModifiedEvent
): void {
  const eventDetail = voiModifiedEvent.detail;
  const { volumeId, range } = eventDetail;
 
  const renderingEngine = getRenderingEngine(targetViewport.renderingEngineId);
  Iif (!renderingEngine) {
    throw new Error(
      `Rendering Engine does not exist: ${targetViewport.renderingEngineId}`
    );
  }
 
  const tViewport = renderingEngine.getViewport(targetViewport.viewportId);
 
  Eif (tViewport instanceof VolumeViewport) {
    tViewport.setProperties(
      {
        voiRange: range,
      },
      volumeId
    );
  } else if (tViewport instanceof StackViewport) {
    tViewport.setProperties({
      voiRange: range,
    });
  } else {
    throw new Error('Viewport type not supported.');
  }
 
  tViewport.render();
}