DiskSource

Introduction

vtkDiskSource creates a polygonal disk with a hole in the center. The disk
has zero height. The user can specify the inner and outer radius of the disk,
the radial and circumferential resolution of the polygonal representation,
and the center and plane normal of the disk (i.e., the center and disk normal
control the position and orientation of the disk).

Usage

import vtkDiskSource from '@kitware/vtk.js/Filters/Sources/DiskSource';

const disk = vtkDiskSource.newInstance({ radius: 1, resolution: 80 });
const polydata = disk.getOutputData();

Methods

extend

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

getCenter

Get the center of the disk.

getCircumferentialResolution

Get the circumferential resolution of the disk.

getInnerRadius

Get the inner radius of the disk.

getNormal

Get the normal of the disk.

getOuterRadius

Get the outer radius of the disk.

getPointType

Get the point type used for the disk.

getRadialResolution

Get the radial resolution of the disk.

newInstance

Method used to create a new instance of vtkDiskSource.

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

requestData

Expose methods

Argument Type Required Description
inData Yes
outData Yes

setCenter

Set the center of the disk.

Argument Type Required Description
center Vector3 Yes

setCircumferentialResolution

Set the circumferential resolution of the disk.

Argument Type Required Description
resolution number Yes

setInnerRadius

Set the inner radius of the disk.

Argument Type Required Description
radius number Yes

setNormal

Set the normal of the disk.

Argument Type Required Description
normal Vector3 Yes

setOuterRadius

Set the outer radius of the disk.

Argument Type Required Description
radius number Yes

setPointType

Set the point type used for the disk.

Argument Type Required Description
type string Yes

setRadialResolution

Set the radial resolution of the disk.

Argument Type Required Description
resolution number Yes

Source

index.d.ts
import { vtkAlgorithm, vtkObject } from '../../../interfaces';
import { Vector3 } from '../../../types';

/**
*
*/
export interface IDiskSourceInitialValues {
innerRadius?: number;
outerRadius?: number;
center?: Vector3;
normal?: Vector3;
radialResolution?: number;
circumferentialResolution?: number;
pointType?: string;
}

type vtkDiskSourceBase = vtkObject &
Omit<
vtkAlgorithm,
| 'getInputData'
| 'setInputData'
| 'setInputConnection'
| 'getInputConnection'
| 'addInputConnection'
| 'addInputData'
>;

export interface vtkDiskSource extends vtkDiskSourceBase {
/**
* Get the center of the disk.
*/
getCenter(): Vector3;

/**
* Get the circumferential resolution of the disk.
*/
getCircumferentialResolution(): number;

/**
* Get the inner radius of the disk.
*/
getInnerRadius(): number;

/**
* Get the normal of the disk.
*/
getNormal(): Vector3;

/**
* Get the outer radius of the disk.
*/
getOuterRadius(): number;

/**
* Get the point type used for the disk.
*/
getPointType(): string;

/**
* Get the radial resolution of the disk.
*/
getRadialResolution(): number;

/**
* Expose methods
* @param inData
* @param outData
*/
requestData(inData: any, outData: any): void;

/**
* Set the center of the disk.
* @param {Vector3} center
*/
setCenter(center: Vector3): boolean;

/**
* Set the circumferential resolution of the disk.
* @param {number} resolution
*/
setCircumferentialResolution(resolution: number): boolean;

/**
* Set the inner radius of the disk.
* @param {number} radius
*/
setInnerRadius(radius: number): boolean;

/**
* Set the normal of the disk.
* @param {Vector3} normal
*/
setNormal(normal: Vector3): boolean;

/**
* Set the outer radius of the disk.
* @param {number} radius
*/
setOuterRadius(radius: number): boolean;

/**
* Set the point type used for the disk.
* @param {string} type
*/
setPointType(type: string): boolean;

/**
* Set the radial resolution of the disk.
* @param {number} resolution
*/
setRadialResolution(resolution: number): boolean;
}

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

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

/**
* vtkDiskSource creates a polygonal disk with a hole in the center. The disk
* has zero height. The user can specify the inner and outer radius of the disk,
* the radial and circumferential resolution of the polygonal representation,
* and the center and plane normal of the disk (i.e., the center and disk normal
* control the position and orientation of the disk).
*
* @example
* ```js
* import vtkDiskSource from '@kitware/vtk.js/Filters/Sources/DiskSource';
*
* const disk = vtkDiskSource.newInstance({ radius: 1, resolution: 80 });
* const polydata = disk.getOutputData();
* ```
*/
export declare const vtkDiskSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkDiskSource;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';

const { vtkErrorMacro } = macro;

// ----------------------------------------------------------------------------
// vtkDiskSource methods
// ----------------------------------------------------------------------------

function vtkDiskSource(publicAPI, model) {
// Set our classname
model.classHierarchy.push('vtkDiskSource');

publicAPI.requestData = (inData, outData) => {
const {
innerRadius,
outerRadius,
center,
normal,
radialResolution,
circumferentialResolution,
pointType,
} = model;

// Points
const points = vtkPoints.newInstance({
dataType: pointType,
});

const n = [normal[0], normal[1], normal[2]];
const length = Math.hypot(n[0], n[1], n[2]);
if (length === 0) {
vtkErrorMacro('Normal vector cannot be zero-length');
return;
}
n[0] /= length;
n[1] /= length;
n[2] /= length;

const matrix = vtkMatrixBuilder
.buildFromDegree()
.identity()
.translate(-center[0], -center[1], -center[2])
.rotateFromDirections([0, 0, 1], n)
.translate(center[0], center[1], center[2])
.getMatrix();

const polys = vtkCellArray.newInstance();

// Generate points
const deltaR = (outerRadius - innerRadius) / radialResolution;
const thetaStep = (2.0 * Math.PI) / circumferentialResolution;
for (let i = 0; i < circumferentialResolution; i++) {
const theta = i * thetaStep;
const cosT = Math.cos(theta);
const sinT = Math.sin(theta);
for (let j = 0; j <= radialResolution; j++) {
const r = innerRadius + j * deltaR;
// point in XY plane before transform
const localPoint = [
center[0] + r * cosT,
center[1] + r * sinT,
center[2],
];
// apply matrix transform
const x =
matrix[0] * localPoint[0] +
matrix[4] * localPoint[1] +
matrix[8] * localPoint[2] +
matrix[12];
const y =
matrix[1] * localPoint[0] +
matrix[5] * localPoint[1] +
matrix[9] * localPoint[2] +
matrix[13];
const z =
matrix[2] * localPoint[0] +
matrix[6] * localPoint[1] +
matrix[10] * localPoint[2] +
matrix[14];
points.insertNextPoint(x, y, z);
}
}

// Generate cell connectivity (quads)
const cellCount = radialResolution * circumferentialResolution;
const cellData = new Uint8Array(cellCount * 5);
let offset = 0;
for (let i = 0; i < model.circumferentialResolution; i++) {
for (let j = 0; j < model.radialResolution; j++) {
const p0 = i * (model.radialResolution + 1) + j;
const p1 = p0 + 1;
const p2 =
i < model.circumferentialResolution - 1
? p1 + (model.radialResolution + 1)
: j + 1; // wrap around
const p3 = p2 - 1;

cellData[offset++] = 4;
cellData[offset++] = p0;
cellData[offset++] = p1;
cellData[offset++] = p2;
cellData[offset++] = p3;
}
}
polys.setData(cellData, cellCount, 1);

const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
dataset.setPoints(points);
dataset.setPolys(polys);

// Update output
outData[0] = dataset;
};
}

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

function defaultValues(initialValues) {
return {
innerRadius: 0.25,
outerRadius: 0.5,
center: [0, 0, 0],
normal: [0, 0, 1],
radialResolution: 1,
circumferentialResolution: 6,
pointType: 'Float64Array',
...initialValues,
};
}

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

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

// Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, [
'innerRadius',
'outerRadius',
'radialResolution',
'circumferentialResolution',
'pointType',
]);
macro.setGetArray(publicAPI, model, ['center', 'normal'], 3);
macro.algo(publicAPI, model, 0, 1);
vtkDiskSource(publicAPI, model);
}

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

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

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

export default { newInstance, extend };