All files / packages/core/src/RenderingEngine/helpers createVolumeMapper.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 1/1
100% Lines 8/8

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                                75x   75x   75x     75x     75x   75x   75x   75x    
import { vtkSharedVolumeMapper } from '../vtkClasses';
 
/**
 * Given an imageData and a vtkOpenGLTexture, it creates a "shared" vtk volume mapper
 * from which various volume actors can be created.
 *
 * @param imageData - the vtkImageData object that contains the data to
 * render.
 * @param vtkOpenGLTexture - The vtkOpenGLTexture that will be used to render
 * the volume.
 * @returns The volume mapper.
 */
export default function createVolumeMapper(
  imageData: any,
  vtkOpenGLTexture: any
): any {
  const volumeMapper = vtkSharedVolumeMapper.newInstance();
 
  volumeMapper.setInputData(imageData);
 
  const spacing = imageData.getSpacing();
  // Set the sample distance to half the mean length of one side. This is where the divide by 6 comes from.
  // https://github.com/Kitware/VTK/blob/6b559c65bb90614fb02eb6d1b9e3f0fca3fe4b0b/Rendering/VolumeOpenGL2/vtkSmartVolumeMapper.cxx#L344
  const sampleDistance = (spacing[0] + spacing[1] + spacing[2]) / 6;
 
  // This is to allow for good pixel level image quality.
  volumeMapper.setMaximumSamplesPerRay(4000);
 
  volumeMapper.setSampleDistance(sampleDistance);
 
  volumeMapper.setScalarTexture(vtkOpenGLTexture);
 
  return volumeMapper;
}