All files / polymorphic-segmentation/src/Contour/utils updateContoursOnCameraModified.ts

0% Statements 0/16
0% Branches 0/2
0% Functions 0/2
0% Lines 0/16

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                                                                                                                     
import { utilities, type Types, Enums } from '@cornerstonejs/core';
import { extractContourData } from './extractContourData';
import { clipAndCacheSurfacesForViewport } from '../../utilities';
import { createAndAddContourSegmentationsFromClippedSurfaces } from './createAndAddContourSegmentationsFromClippedSurfaces';
 
const currentViewportNormal = new Map();
 
// Todo: this code is not used anywhere yet
export function updateContoursOnCameraModified(
  surfacesInfo,
  viewport,
  segmentationRepresentationUID
) {
  async function cameraModifiedCallback(
    evt: Types.EventTypes.CameraModifiedEvent
  ) {
    const { camera } = evt.detail;
    const { viewPlaneNormal } = camera;
 
    // Note: I think choosing one of the surfaces to see
    // if the viewPlaneNormal is the same for all surfaces is ok enough
    // to decide if we should recompute the clipping planes
    const surface1 = surfacesInfo[0];
 
    const currentNormal = currentViewportNormal.get(surface1.id);
    if (utilities.isEqual(viewPlaneNormal, currentNormal)) {
      return;
    }
    currentViewportNormal.set(surface1.id, viewPlaneNormal);
 
    const polyDataCache = await clipAndCacheSurfacesForViewport(
      surfacesInfo,
      viewport as Types.IVolumeViewport
    );
 
    const results = extractContourData(polyDataCache);
 
    createAndAddContourSegmentationsFromClippedSurfaces(
      results,
      viewport,
      segmentationRepresentationUID
    );
 
    viewport.render();
  }
 
  const camera = viewport.getCamera();
  currentViewportNormal.set(surfacesInfo[0].id, camera.viewPlaneNormal);
 
  // Remove the existing event listener
  viewport.element.removeEventListener(
    Enums.Events.CAMERA_MODIFIED,
    cameraModifiedCallback
  );
 
  // Add the event listener
  viewport.element.addEventListener(Enums.Events.CAMERA_MODIFIED);
}