Cylinder

Introduction

vtkCylinder computes the implicit function and/or gradient for a cylinder.
vtkCylinder is a concrete implementation of vtkImplicitFunction.

Methods

evaluate

Evaluate of the cylinder equation without setting the data members center and
radius.

Argument Type Required Description
radius Number Yes
center Number Yes
axis Array. Yes
x Array. Yes

evaluateFunction

Given the point xyz (three floating value) evaluate the cylinder
equation.

Argument Type Required Description
xyz Vector3 Yes The point coordinate.

evaluateGradient

Given the point xyz (three floating values) evaluate the equation for the
cylinder gradient.

Argument Type Required Description
xyz Vector3 Yes The point coordinate.

extend

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

getAngle

Get the angle of the cone.

getAxis

Get the axis of the cylinder.

getAxisByReference

Get the axis of the cylinder.

getCenter

Get the center of the cylinder.

getCenterByReference

Get the center of the cylinder.

getRadius

Get the radius of the cylinder.

newInstance

Method used to create a new instance of vtkCylinder.

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

setAngle

Set the value representing the angle of the cone.

Argument Type Required Description
angle Number Yes The angle of the cone.

setAxis

Set the axis of the cylinder.

Argument Type Required Description
x Number Yes The x coordinate.
y Number Yes The y coordinate.
z Number Yes The z coordinate.

setAxis

Set the axis of the cylinder.

Argument Type Required Description
axis Array. Yes The axis coordinate.

setAxisFrom

Set the axis of the cylinder.

Argument Type Required Description
axis Array. Yes The axis coordinate.

setCenter

Set the center of the cylinder.

Argument Type Required Description
x Number Yes The x coordinate.
y Number Yes The y coordinate.
z Number Yes The z coordinate.

setCenter

Set the center of the cylinder.

Argument Type Required Description
center Array. Yes The center coordinate.

setCenterFrom

Set the center of the cylinder.

Argument Type Required Description
center Array. Yes The center coordinate.

setRadius

Set the radius of the cylinder.

Argument Type Required Description
radius Number Yes The radius of the cylinder.

Source

index.d.ts
import { vtkObject } from '../../../interfaces';
import { Vector3 } from '../../../types';
import vtkImplicitFunction from '../ImplicitFunction';

/**
*
*/
export interface ICylinderInitialValues {
radius?: number;
center?: number[];
axis?: number[];
}

export interface vtkCylinder extends vtkImplicitFunction {
/**
* Given the point xyz (three floating value) evaluate the cylinder
* equation.
* @param {Vector3} xyz The point coordinate.
*/
evaluateFunction(xyz: Vector3): number;

/**
* Given the point xyz (three floating values) evaluate the equation for the
* cylinder gradient.
* @param {Vector3} xyz The point coordinate.
*/
evaluateGradient(xyz: Vector3): number[];

/**
* Get the angle of the cone.
*/
getAngle(): number;

/**
* Get the axis of the cylinder.
*/
getAxis(): number[];

/**
* Get the axis of the cylinder.
*/
getAxisByReference(): number[];

/**
* Get the center of the cylinder.
*/
getCenter(): number[];

/**
* Get the center of the cylinder.
*/
getCenterByReference(): number[];

/**
* Get the radius of the cylinder.
*/
getRadius(): number;

/**
* Set the value representing the angle of the cone.
* @param {Number} angle The angle of the cone.
*/
setAngle(angle: number): boolean;

/**
* Set the axis of the cylinder.
* @param {Number[]} axis The axis coordinate.
*/
setAxis(axis: number[]): boolean;

/**
* Set the axis of the cylinder.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
*/
setAxis(x: number, y: number, z: number): boolean;

/**
* Set the axis of the cylinder.
* @param {Number[]} axis The axis coordinate.
*/
setAxisFrom(axis: number[]): boolean;

/**
* Set the center of the cylinder.
* @param {Number[]} center The center coordinate.
*/
setCenter(center: number[]): boolean;

/**
* Set the center of the cylinder.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
*/
setCenter(x: number, y: number, z: number): boolean;

/**
* Set the center of the cylinder.
* @param {Number[]} center The center coordinate.
*/
setCenterFrom(center: number[]): boolean;

/**
* Set the radius of the cylinder.
* @param {Number} radius The radius of the cylinder.
*/
setRadius(radius: number): boolean;
}

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

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

/**
* Evaluate of the cylinder equation without setting the data members center and
* radius.
* @param {Number} radius
* @param {Number} center
* @param {Number[]} axis
* @param {Number[]} x
*/
export function evaluate(
radius: number,
center: number[],
axis: number[],
x: number[]
): number;

/**
* vtkCylinder computes the implicit function and/or gradient for a cylinder.
* vtkCylinder is a concrete implementation of vtkImplicitFunction.
*/
export declare const vtkCylinder: {
newInstance: typeof newInstance;
extend: typeof extend;
evaluate: typeof evaluate;
};
export default vtkCylinder;
index.js
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkImplicitFunction from 'vtk.js/Sources/Common/DataModel/ImplicitFunction';

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

function evaluate(radius, center, axis, x) {
const x2C = new Float32Array(3);
x2C[0] = x[0] - center[0];
x2C[1] = x[1] - center[1];
x2C[2] = x[2] - center[2];

const proj = vtkMath.dot(axis, x2C);

const retVal = vtkMath.dot(x2C, x2C) - proj * proj - radius * radius;

return retVal;
}

// ----------------------------------------------------------------------------
// Static API
// ----------------------------------------------------------------------------

export const STATIC = {
evaluate,
};

// ----------------------------------------------------------------------------
// vtkCylinder methods
// ----------------------------------------------------------------------------

function vtkCylinder(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkCylinder');

publicAPI.evaluateFunction = (xyz) => {
const x2C = [
xyz[0] - model.center[0],
xyz[1] - model.center[1],
xyz[2] - model.center[2],
];

const proj = vtkMath.dot(model.axis, x2C);

const retVal =
vtkMath.dot(x2C, x2C) - proj * proj - model.radius * model.radius;

return retVal;
};

publicAPI.evaluateGradient = (xyz) => {
const t =
model.axis[0] * (xyz[0] - model.center[0]) +
model.axis[1] * (xyz[1] - model.center[1]) +
model.axis[2] * (xyz[2] - model.center[2]);

const cp = [
model.center[0] + t * model.axis[0],
model.center[1] + t * model.axis[1],
model.center[2] + t * model.axis[2],
];

const retVal = [
2.0 * (xyz[0] - cp[0]),
2.0 * (xyz[1] - cp[1]),
2.0 * (xyz[2] - cp[2]),
];
return retVal;
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
radius: 0.5,
center: [0.0, 0.0, 0.0],
axis: [0.0, 1.0, 0.0],
};

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

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

// Object methods
vtkImplicitFunction.extend(publicAPI, model, initialValues);
macro.setGet(publicAPI, model, ['radius']);
macro.setGetArray(publicAPI, model, ['center', 'axis'], 3);

vtkCylinder(publicAPI, model);
}

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

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

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

export default { newInstance, extend, ...STATIC };