ImageProperty

Introduction

vtkImageProperty provides 2D image display support for vtk.
It can be associated with a vtkImageSlice prop and placed within a Renderer.

This class resolves coincident topology with the same methods as vtkMapper.

Methods

extend

Method use to decorate a given object (publicAPI+model) with vtkImageProperty characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues IImageMapperInitialValues No (default: {})

getAmbient

getColorLevel

getColorWindow

getComponentWeight

Argument Type Required Description
index Number Yes

getDiffuse

getIndependentComponents

getInterpolationTypeAsString

getInterpolationTypeAsString

getOpacity

getPiecewiseFunction

Get the component weighting function.

Argument Type Required Description
idx Yes

getRGBTransferFunction

Get the currently set RGB transfer function.

Argument Type Required Description
idx Number Yes

getScalarOpacity

Alias to get the piecewise function (backwards compatibility)

Argument Type Required Description
idx Yes

newInstance

Method use to create a new instance of vtkImageProperty

Argument Type Required Description
initialValues IImageMapperInitialValues No for pre-setting some of its content

setAmbient

Set the lighting coefficient.

Argument Type Required Description
ambient Number Yes

setColorLevel

setColorWindow

setComponentWeight

Argument Type Required Description
index Number Yes
value Yes

setDiffuse

setIndependentComponents

setInterpolationType

setInterpolationTypeToLinear

setInterpolationTypeToNearest

setOpacity

Argument Type Required Description
opacity Number Yes The opacity value.

setPiecewiseFunction

Set the piecewise function

Argument Type Required Description
index Number Yes
func Yes

setRGBTransferFunction

Set the color of a volume to an RGB transfer function

Argument Type Required Description
index Number Yes
func Yes

setScalarOpacity

Alias to set the piecewise function

Argument Type Required Description
index Number Yes
func Yes

Source

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

export default {
InterpolationType,
};
index.d.ts
import { vtkAlgorithm, vtkObject } from "vtk.js/Sources/interfaces";

export enum InterpolationType {
NEAREST,
LINEAR,
}

interface IComponentData {
piecewiseFunction: number;
componentWeight: number;
}

interface IImageMapperInitialValues {
independentComponents: boolean;
interpolationType: InterpolationType;
colorWindow: number;
colorLevel: number;
ambient: number;
diffuse: number;
opacity: number;
componentData: IComponentData[];
}

export interface vtkImageProperty extends vtkObject {

/**
*
* @default 1.0
*/
getAmbient(): number;

/**
*
* @default 127.5
*/
getColorLevel(): number;

/**
*
* @default 255
*/
getColorWindow(): number;

/**
*
* @param {Number} index
*/
getComponentWeight(index: number): number;

/**
*
* @default 1.0
*/
getDiffuse(): number;

/**
*
* @default false
*/
getIndependentComponents(): boolean;

/**
*
*/
getInterpolationTypeAsString(): InterpolationType;

/**
*
*/
getInterpolationTypeAsString(): string;

/**
*
* @default 1.0
*/
getOpacity(): number;

/**
* Get the component weighting function.
* @param idx
*/
getPiecewiseFunction(idx: number): number;

/**
* Get the currently set RGB transfer function.
* @param {Number} idx
*/
getRGBTransferFunction(idx: number): any;

/**
* Alias to get the piecewise function (backwards compatibility)
* @param idx
*/
getScalarOpacity(idx: any): number;

/**
* Set the lighting coefficient.
* @param {Number} ambient
*/
setAmbient(ambient: number): boolean;

/**
*
*/
setColorLevel(colorLevel: number): boolean;

/**
*
*/
setColorWindow(colorWindow: number): boolean;

/**
*
* @param {Number} index
* @param value
*/
setComponentWeight(index: number, value: number): boolean;

/**
*
*/
setDiffuse(diffse: number): boolean;

/**
*
*/
setIndependentComponents(independentComponents: boolean): boolean;

/**
*
*/
setInterpolationType(interpolationType: InterpolationType): boolean;

/**
*
*/
setInterpolationTypeToLinear(): boolean;

/**
*
*/
setInterpolationTypeToNearest(): boolean;

/**
*
* @param {Number} opacity The opacity value.
*/
setOpacity(opacity: number): boolean;

/**
* Set the piecewise function
* @param {Number} index
* @param func
*/
setPiecewiseFunction(index: number, func: any): boolean;

/**
* Set the color of a volume to an RGB transfer function
* @param {Number} index
* @param func
*/
setRGBTransferFunction(index: number, func: any): boolean;


/**
* Alias to set the piecewise function
* @param {Number} index
* @param func
*/
setScalarOpacity(index: any, func: any): boolean;
}

/**
* Method use to decorate a given object (publicAPI+model) with vtkImageProperty characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IImageMapperInitialValues} [initialValues] (default: {})
*/
export function extend(publicAPI: object, model: object, initialValues?: IImageMapperInitialValues): void;

/**
* Method use to create a new instance of vtkImageProperty
* @param {IImageMapperInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: IImageMapperInitialValues): vtkImageProperty;

/**
* vtkImageProperty provides 2D image display support for vtk.
* It can be associated with a vtkImageSlice prop and placed within a Renderer.
*
* This class resolves coincident topology with the same methods as vtkMapper.
*/
export declare const vtkImageProperty: {
newInstance: typeof newInstance;
extend: typeof extend;
}
export default vtkImageProperty;
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 };