VolumeMapper

Introduction

A volume mapper that performs ray casting on
the GPU using fragment programs.

Methods

set/getSampleDistance

Set/Get the distance between samples used for rendering
Initial value is 1.0.

set/getImageSampleDistance

Sampling distance in the XY image dimensions. Default value of 1 meaning
1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If
set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. T

Source

Constants.js
export const BlendMode = {
COMPOSITE_BLEND: 0,
MAXIMUM_INTENSITY_BLEND: 1,
MINIMUM_INTENSITY_BLEND: 2,
AVERAGE_INTENSITY_BLEND: 3,
};

export default {
BlendMode,
};
index.js
import macro from 'vtk.js/Sources/macro';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import Constants from 'vtk.js/Sources/Rendering/Core/VolumeMapper/Constants';

const { BlendMode } = Constants;

// ----------------------------------------------------------------------------
// vtkVolumeMapper methods
// ----------------------------------------------------------------------------

function vtkVolumeMapper(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkVolumeMapper');

publicAPI.getBounds = () => {
const input = publicAPI.getInputData();
if (!input) {
model.bounds = vtkMath.createUninitializedBounds();
} else {
if (!model.static) {
publicAPI.update();
}
model.bounds = input.getBounds();
}
return model.bounds;
};

publicAPI.update = () => {
publicAPI.getInputData();
};

publicAPI.setBlendModeToComposite = () => {
publicAPI.setBlendMode(BlendMode.COMPOSITE_BLEND);
};

publicAPI.setBlendModeToMaximumIntensity = () => {
publicAPI.setBlendMode(BlendMode.MAXIMUM_INTENSITY_BLEND);
};

publicAPI.setBlendModeToMinimumIntensity = () => {
publicAPI.setBlendMode(BlendMode.MINIMUM_INTENSITY_BLEND);
};

publicAPI.setBlendModeToAverageIntensity = () => {
publicAPI.setBlendMode(BlendMode.AVERAGE_INTENSITY_BLEND);
};

publicAPI.getBlendModeAsString = () =>
macro.enumToString(BlendMode, model.blendMode);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

// TODO: what values to use for averageIPScalarRange to get GLSL to use max / min values like [-Math.inf, Math.inf]?
const DEFAULT_VALUES = {
bounds: [1, -1, 1, -1, 1, -1],
sampleDistance: 1.0,
imageSampleDistance: 1.0,
maximumSamplesPerRay: 1000,
autoAdjustSampleDistances: true,
blendMode: BlendMode.COMPOSITE_BLEND,
averageIPScalarRange: [-1000000.0, 1000000.0],
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Build VTK API
macro.obj(publicAPI, model);
macro.algo(publicAPI, model, 1, 0);

macro.setGet(publicAPI, model, [
'sampleDistance',
'imageSampleDistance',
'maximumSamplesPerRay',
'autoAdjustSampleDistances',
'blendMode',
]);

macro.setGetArray(publicAPI, model, ['averageIPScalarRange'], 2);

macro.event(publicAPI, model, 'lightingActivated');

// Object methods
vtkVolumeMapper(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkVolumeMapper');

// ----------------------------------------------------------------------------

export default { newInstance, extend };