ViewNodeFactory

factory that chooses vtkViewNodes to create

Class tells VTK which specific vtkViewNode subclass to make when it is
asked to make a vtkViewNode for a particular renderable. modules for
different rendering backends are expected to use this to customize the
set of instances for their own purposes

registerOverride(apiName, createFunc)

Give a functin pointer to a class that will manufacture a
vtkViewNode when given a class name string.

createNode(apiName)

Creates and returns a vtkViewNode for the provided renderable.

Source

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

// ----------------------------------------------------------------------------
// vtkViewNodeFactory methods
// ----------------------------------------------------------------------------

function vtkViewNodeFactory(publicAPI, model) {
// Make sure our overrides is just for our instance not shared with everyone...
model.overrides = {};

// Set our className
model.classHierarchy.push('vtkViewNodeFactory');

publicAPI.createNode = (dataObject) => {
if (dataObject.isDeleted()) {
return null;
}

let cpt = 0;
let className = dataObject.getClassName(cpt++);
let isObject = false;
const keys = Object.keys(model.overrides);
while (className && !isObject) {
if (keys.indexOf(className) !== -1) {
isObject = true;
} else {
className = dataObject.getClassName(cpt++);
}
}

if (!isObject) {
return null;
}
const vn = model.overrides[className]();
vn.setMyFactory(publicAPI);
return vn;
};

publicAPI.registerOverride = (className, func) => {
model.overrides[className] = func;
};
}

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

const DEFAULT_VALUES = {
// overrides: {},
};

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

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

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

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

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

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

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

export default { newInstance, extend };