ViewNodeFactory

Introduction

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

Methods

createNode

Creates and returns a vtkViewNode for the provided renderable.

Argument Type Required Description
dataObject Yes

extend

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

newInstance

Method used to create a new instance of vtkViewNodeFactory.

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

registerOverride

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

Argument Type Required Description
className Yes
func Yes

Source

index.d.ts
import { vtkObject } from "../../../interfaces";

/**
*
*/
export interface IViewNodeFactoryInitialValues {}

export interface vtkViewNodeFactory extends vtkObject {

/**
* Creates and returns a vtkViewNode for the provided renderable.
* @param dataObject
*/
createNode(dataObject: any): void;

/**
* Give a function pointer to a class that will manufacture a vtkViewNode
* when given a class name string.
* @param className
* @param func
*/
registerOverride(className: any, func: any): void;
}

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

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

/**
* 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
*/
export declare const vtkViewNodeFactory: {
newInstance: typeof newInstance,
extend: typeof extend,
};
export default vtkViewNodeFactory;
index.js
import macro from 'vtk.js/Sources/macros';

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

function vtkViewNodeFactory(publicAPI, model) {
// Make sure our overrides is just for our instance not shared with everyone...
if (!model.overrides) {
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 };