All files / tools/src/eventListeners/segmentation/labelmap performVolumeLabelmapUpdate.ts

83.33% Statements 10/12
75% Branches 3/4
100% Functions 2/2
83.33% Lines 10/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                                  1437x       1437x         1437x       1437x 1059x   378x 378x     1437x 92574x           1437x    
import { cache } from '@cornerstonejs/core';
 
import type { SegmentationRepresentations } from '../../../enums';
import type { LabelmapSegmentationDataVolume } from '../../../types/LabelmapTypes';
 
/**
 * Updates the labelmap volume in GPU for volume viewports
 */
export function performVolumeLabelmapUpdate({
  modifiedSlicesToUse,
  representationData,
  type,
}: {
  modifiedSlicesToUse: number[];
  representationData: Record<string, unknown>;
  type: SegmentationRepresentations;
}): void {
  const segmentationVolume = cache.getVolume(
    (representationData[type] as LabelmapSegmentationDataVolume).volumeId
  );
 
  Iif (!segmentationVolume) {
    console.warn('segmentation not found in cache');
    return;
  }
 
  const { imageData, vtkOpenGLTexture } = segmentationVolume;
 
  // Update the texture for the volume in the GPU
  let slicesToUpdate;
  if (modifiedSlicesToUse?.length > 0) {
    slicesToUpdate = modifiedSlicesToUse;
  } else {
    const numSlices = imageData.getDimensions()[2];
    slicesToUpdate = [...Array(numSlices).keys()];
  }
 
  slicesToUpdate.forEach((i) => {
    vtkOpenGLTexture.setUpdatedFrame(i);
  });
 
  // Trigger modified on the imageData to update the image
  // this is the start of the rendering pipeline for updating the texture
  // to the gpu
  imageData.modified();
}