ImageProperty

Introduction

vtkImageProperty – image display properties

vtkImageProperty is an object that allows control of the display
of an image slice.

See Also

vtkImageMapper
vtkImageProperty

Methods

getInterpolationType

getInterpolationTypeAsString

setInterpolationTypeToNearest

setInterpolationTypeToLinear

Set/Get the interpolation type for sampling a volume. The initial
value is LINEAR. NEAREST interpolation will snap to the closest
voxel, LINEAR will perform bilinear interpolation to compute a
scalar value from surrounding voxels.

colorWindow

Controls the window in a window level mapping of the input image. Window
level mapping is a technique to map the raw data values of an image
into screen intensities in a manner akin to

pixelIntensity = (inputValue - level)/window;

colorLevel

Controls the level in a window level mapping of the input image. Window
level mapping is a technique to map the raw data values of an image
into screen intensities in a manner akin to

pixelIntensity = (inputValue - level)/window;

ambient

Control the ambient lighting intensity for this image.

diffuse

Control the diffuse lighting intensity of this image.

opacity

Control the opacity of this image.

independentComponents

Specify whether image components (0 - 3) are treated independently or
dependently. If independentComponents is true, each image component
will be treated as an independent “intensity” value and used to look up
a color and piecewise function value independently.

set/get rGBTransferFunction

Specify or retrieve, per component, a vtkColorTransferFunction to map
scalars to colors. If set, then colorWindow and colorLevel are not used.

The set method takes two arguments, a component index and an rgb transfer
function, in that order.

set/get scalarOpacity

The scalarOpacity property is an alias for piecewiseFunction.

set/get piecewiseFunction

Specify or retrieve, per component, a vtkPiecewiseFunction. If
independentComponents is true, the piecewise function is used as a
component weighting function, and resulting colors on the screen will
be blended using the weights which are normalized per fragment in the
fragment shader. If independentComponents is false, then the
piecewise function will be used as a traditional scalar opacity function
to map image intensities to opacities. This latter way of using the
piecewise function will only work on single-component images. In either case,
the overall image opacity can still be affected by the opacity property.

The set method takes two arguments, a component index and a piecewise
function, in that order.

set/get componentWeight

Specify or retrieve, per component, a single scalar weight value to be
applied to the entire image for that component. This can be used, for
example, to completely disgregard the contribution from a single component.

The set method takes two arguments, a component index and an floating point
component weight, in that order.

Source

Constants.js
export const InterpolationType = {
NEAREST: 0,
LINEAR: 1,
};

export default {
InterpolationType,
};
index.js
import macro from 'vtk.js/Sources/macro';
import Constants from 'vtk.js/Sources/Rendering/Core/ImageProperty/Constants';

const { InterpolationType } = Constants;
const { vtkErrorMacro } = macro;

const VTK_MAX_VRCOMP = 4;

// ----------------------------------------------------------------------------
// vtkImageProperty methods
// ----------------------------------------------------------------------------

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

publicAPI.getMTime = () => {
let mTime = model.mtime;
let time;

for (let index = 0; index < VTK_MAX_VRCOMP; index++) {
// Color MTimes
if (model.componentData[index].rGBTransferFunction) {
// time that RGB transfer function was last modified
time = model.componentData[index].rGBTransferFunction.getMTime();
mTime = mTime > time ? mTime : time;
}

// Piecewise function MTimes
if (model.componentData[index].piecewiseFunction) {
// time that weighting function was last modified
time = model.componentData[index].piecewiseFunction.getMTime();
mTime = mTime > time ? mTime : time;
}
}

return mTime;
};

// Set the color of a volume to an RGB transfer function
publicAPI.setRGBTransferFunction = (index, func) => {
// backwards compatible call without the component index
let idx = index;
let transferFunc = func;
if (!Number.isInteger(index)) {
transferFunc = index;
idx = 0;
}
if (model.componentData[idx].rGBTransferFunction !== transferFunc) {
model.componentData[idx].rGBTransferFunction = transferFunc;
publicAPI.modified();
return true;
}
return false;
};

// Get the currently set RGB transfer function.
publicAPI.getRGBTransferFunction = (idx = 0) =>
model.componentData[idx].rGBTransferFunction;

// Set the piecewise function
publicAPI.setPiecewiseFunction = (index, func) => {
let idx = index;
let transferFunc = func;
if (!Number.isInteger(index)) {
transferFunc = index;
idx = 0;
}
if (model.componentData[idx].piecewiseFunction !== transferFunc) {
model.componentData[idx].piecewiseFunction = transferFunc;
publicAPI.modified();
return true;
}
return false;
};

// Get the component weighting function.
publicAPI.getPiecewiseFunction = (idx = 0) =>
model.componentData[idx].piecewiseFunction;

// Alias to set the piecewise function
publicAPI.setScalarOpacity = (index, func) => {
// backwards compatible call without the component index
let idx = index;
let transferFunc = func;
if (!Number.isInteger(index)) {
transferFunc = index;
idx = 0;
}
return publicAPI.setPiecewiseFunction(idx, transferFunc);
};

// Alias to get the piecewise function (backwards compatibility)
publicAPI.getScalarOpacity = (idx = 0) => publicAPI.getPiecewiseFunction(idx);

publicAPI.setComponentWeight = (index, value) => {
if (index < 0 || index >= VTK_MAX_VRCOMP) {
vtkErrorMacro('Invalid index');
return false;
}

const val = Math.min(1, Math.max(0, value));
if (model.componentData[index].componentWeight !== val) {
model.componentData[index].componentWeight = val;
publicAPI.modified();
return true;
}
return false;
};

publicAPI.getComponentWeight = (index) => {
if (index < 0 || index >= VTK_MAX_VRCOMP) {
vtkErrorMacro('Invalid index');
return 0.0;
}

return model.componentData[index].componentWeight;
};

publicAPI.setInterpolationTypeToNearest = () =>
publicAPI.setInterpolationType(InterpolationType.NEAREST);

publicAPI.setInterpolationTypeToLinear = () =>
publicAPI.setInterpolationType(InterpolationType.LINEAR);

publicAPI.getInterpolationTypeAsString = () =>
macro.enumToString(InterpolationType, model.interpolationType);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
independentComponents: false,
interpolationType: InterpolationType.LINEAR,
colorWindow: 255,
colorLevel: 127.5,
ambient: 1.0,
diffuse: 0.0,
opacity: 1.0,
};

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

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

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

if (!model.componentData) {
model.componentData = [];
for (let i = 0; i < VTK_MAX_VRCOMP; i++) {
model.componentData.push({
rGBTransferFunction: null,
piecewiseFunction: null,
componentWeight: 1.0,
});
}
}

macro.setGet(publicAPI, model, [
'independentComponents',
'interpolationType',
'colorWindow',
'colorLevel',
'ambient',
'diffuse',
'opacity',
]);

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

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

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

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

export default { newInstance, extend };