AbstractMapper

Introduction

vtkAbstractMapper is an abstract class to specify interface between data and
graphics primitives or software rendering techniques. Subclasses of
vtkAbstractMapper can be used for rendering 2D data, geometry, or volumetric
data.

Methods

addClippingPlane

Added plane needs to be a vtkPlane object.

Argument Type Required Description
plane vtkPlane Yes

extend

Method use to decorate a given object (publicAPI+model) with vtkAbstractMapper 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 IAbstractMapperInitialValues No (default: {})

getClippingPlaneInDataCoords

Get the ith clipping plane as a homogeneous plane equation.
Use getNumberOfClippingPlanes() to get the number of planes.

Argument Type Required Description
propMatrix mat4 Yes
i Number Yes
hnormal Array. Yes

getClippingPlanes

Get all clipping planes.

getNumberOfClippingPlanes

Get number of clipping planes.

removeAllClippingPlanes

Remove all clipping planes.

removeClippingPlane

Remove clipping plane.

Argument Type Required Description
plane vtkPlane Yes

setClippingPlanes

Set clipping planes.

Argument Type Required Description
planes Array. Yes

update

Source

index.d.ts
import { vtkAlgorithm, vtkObject } from "../../../interfaces";
import vtkPlane from "../../../Common/DataModel/Plane";
import { mat4 } from "gl-matrix";

/**
*
*/
export interface IAbstractMapperInitialValues {
clippingPlanes?: vtkPlane[];
}

type vtkAbstractMapperBase = vtkObject & Omit<vtkAlgorithm,
| 'getOutputData'
| 'getOutputPort'> ;

export interface vtkAbstractMapper extends vtkAbstractMapperBase {

/**
* Added plane needs to be a vtkPlane object.
* @param {vtkPlane} plane
*/
addClippingPlane(plane: vtkPlane): boolean;

/**
* Get number of clipping planes.
* @return {Number} The number of clipping planes.
*/
getNumberOfClippingPlanes(): number;

/**
* Get all clipping planes.
* @return {vtkPlane[]} An array of the clipping planes objects
*/
getClippingPlanes(): vtkPlane[];

/**
* Remove all clipping planes.
* @return true if there were planes, false otherwise.
*/
removeAllClippingPlanes(): boolean;

/**
* Remove clipping plane.
* @param {vtkPlane} plane
* @return true if plane existed and therefore is removed, false otherwise.
*/
removeClippingPlane(plane: vtkPlane): boolean;

/**
* Set clipping planes.
* @param {vtkPlane[]} planes
*/
setClippingPlanes(planes: vtkPlane[]): void;

/**
* Get the ith clipping plane as a homogeneous plane equation.
* Use getNumberOfClippingPlanes() to get the number of planes.
* @param {mat4} propMatrix
* @param {Number} i
* @param {Number[]} hnormal
*/
getClippingPlaneInDataCoords(propMatrix : mat4, i : number, hnormal : number[]): void;

/**
*
*/
update(): void;
}

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

/**
* vtkAbstractMapper is an abstract class to specify interface between data and
* graphics primitives or software rendering techniques. Subclasses of
* vtkAbstractMapper can be used for rendering 2D data, geometry, or volumetric
* data.
*/
export declare const vtkAbstractMapper: {
extend: typeof extend,
};
export default vtkAbstractMapper;
index.js
import macro from 'vtk.js/Sources/macros';

// ----------------------------------------------------------------------------
// vtkAbstractMapper methods
// ----------------------------------------------------------------------------

function vtkAbstractMapper(publicAPI, model) {
model.classHierarchy.push('vtkAbstractMapper');
publicAPI.update = () => {
publicAPI.getInputData();
};

publicAPI.addClippingPlane = (plane) => {
if (!plane.isA('vtkPlane')) {
return false;
}
if (!model.clippingPlanes.includes(plane)) {
model.clippingPlanes.push(plane);
publicAPI.modified();
return true;
}
return false;
};

publicAPI.getNumberOfClippingPlanes = () => model.clippingPlanes.length;

publicAPI.removeAllClippingPlanes = () => {
if (model.clippingPlanes.length === 0) {
return false;
}
model.clippingPlanes.length = 0;
publicAPI.modified();
return true;
};

publicAPI.removeClippingPlane = (clippingPlane) => {
const i = model.clippingPlanes.indexOf(clippingPlane);
if (i === -1) {
return false;
}
model.clippingPlanes.splice(i, 1);
publicAPI.modified();
return true;
};

publicAPI.getClippingPlanes = () => model.clippingPlanes;

publicAPI.setClippingPlanes = (planes) => {
if (!planes) {
return;
}
if (!Array.isArray(planes)) {
publicAPI.addClippingPlane(planes);
} else {
const nbPlanes = planes.length;
for (let i = 0; i < nbPlanes && i < 6; i++) {
publicAPI.addClippingPlane(planes[i]);
}
}
};

publicAPI.getClippingPlaneInDataCoords = (propMatrix, i, hnormal) => {
const clipPlanes = model.clippingPlanes;
const mat = propMatrix;

if (clipPlanes) {
const n = clipPlanes.length;
if (i >= 0 && i < n) {
// Get the plane
const plane = clipPlanes[i];
const normal = plane.getNormal();
const origin = plane.getOrigin();

// Compute the plane equation
const v1 = normal[0];
const v2 = normal[1];
const v3 = normal[2];
const v4 = -(v1 * origin[0] + v2 * origin[1] + v3 * origin[2]);

// Transform normal from world to data coords
hnormal[0] = v1 * mat[0] + v2 * mat[4] + v3 * mat[8] + v4 * mat[12];
hnormal[1] = v1 * mat[1] + v2 * mat[5] + v3 * mat[9] + v4 * mat[13];
hnormal[2] = v1 * mat[2] + v2 * mat[6] + v3 * mat[10] + v4 * mat[14];
hnormal[3] = v1 * mat[3] + v2 * mat[7] + v3 * mat[11] + v4 * mat[15];

return;
}
}
macro.vtkErrorMacro(`Clipping plane index ${i} is out of range.`);
};
}

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

const DEFAULT_VALUES = {
clippingPlanes: [],
};

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

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

// Object methods
macro.obj(publicAPI, model);
macro.algo(publicAPI, model, 1, 0);

if (!model.clippingPlanes) {
model.clippingPlanes = [];
}

vtkAbstractMapper(publicAPI, model);
}

// ----------------------------------------------------------------------------
export default { extend };