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.

clippingPlanes (set/get)

Get/Set the vtkPlaneCollection which specifies the clipping planes.
Added plane needs to be a vtkPlane object.

publicAPI

addClippingPlane(plane)
removeAllClippingPlanes()
: Specify clipping planes to be applied when the data is mapped
(at most 6 clipping planes can be specified).

removeClippingPlane(i)
: Remove clipping plane at index i.

getNumberOfClippingPlanes()
: Return number of clipping planes.

Source

index.js
import macro from 'vtk.js/Sources/macro';

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

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

publicAPI.addClippingPlane = (plane) => {
if (plane.getClassName() !== 'vtkPlane') {
return;
}
model.clippingPlanes.push(plane);
};

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

publicAPI.removeAllClippingPlanes = () => {
model.clippingPlanes.length = 0;
};

publicAPI.removeClippingPlane = (i) => {
if (i < 0 || i >= 6) {
return;
}
model.clippingPlanes.splice(i, 1);
};

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]);
}
}
};
}

// ----------------------------------------------------------------------------
// 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 };