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

90% Statements 9/10
50% Branches 1/2
100% Functions 1/1
90% Lines 9/10

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                                91x   91x       91x   91x     91x       91x 91x 91x   91x    
import { vtkSharedVolumeMapper } from '../vtkClasses';
import { getConfiguration } from '../../init';
/**
 * 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();
 
  Iif (getConfiguration().rendering.preferSizeOverAccuracy) {
    volumeMapper.setPreferSizeOverAccuracy(true);
  }
 
  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.
  // Todo: why we are setting this to 4000? Is this a good number? it should be configurable
  volumeMapper.setMaximumSamplesPerRay(4000);
  volumeMapper.setSampleDistance(sampleDistance);
  volumeMapper.setScalarTexture(vtkOpenGLTexture);
 
  return volumeMapper;
}