CircleSource

Introduction

/**
vtkCircleSource creates a circle.

Usage

import vtkCircleSource from '@kitware/vtk.js/Filters/Sources/CircleSource';

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

Methods

extend

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

getCenter

Get the center of the cone.

getCenterByReference

Get the center of the cone.

getDirection

Get the orientation vector of the cone.

getDirectionByReference

Get the orientation vector of the cone.

getFace

getLines

getRadius

Get the radius of the cylinder base.

getResolution

Get the number of facets used to define cylinder.

newInstance

Method used to create a new instance of vtkCircleSource.

Argument Type Required Description
initialValues ICircleSourceInitialValues 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 circle.

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

setCenterFrom

Set the center of the circle.

Argument Type Required Description
center Vector3 Yes

setDirection

Set the direction for the circle.

Argument Type Required Description
direction Vector3 Yes The direction coordinates.

setDirection

Set the direction for the circle.

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

setDirectionFrom

Set the direction for the circle.

Argument Type Required Description
direction Vector3 Yes The direction coordinates.

setFace

Argument Type Required Description
face Boolean Yes

setLines

Argument Type Required Description
lines Boolean Yes

setRadius

Set the radius of the circle.

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

setResolution

Set the resolution of the circle.

Argument Type Required Description
resolution Number Yes The resolution of the circle.

Source

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

/**
*
*/
export interface ICircleSourceInitialValues {
radius?: number;
resolution?: number;
center?: Vector3;
pointType?: string;
lines?: boolean;
face?: boolean;
}

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

export interface vtkCircleSource extends vtkCircleSourceBase {
/**
* Get the center of the cone.
* @default [0, 0, 0]
*/
getCenter(): Vector3;

/**
* Get the center of the cone.
*/
getCenterByReference(): Vector3;

/**
* Get the orientation vector of the cone.
* @default [1.0, 0.0, 0.0]
*/
getDirection(): Vector3;

/**
* Get the orientation vector of the cone.
*/
getDirectionByReference(): Vector3;

/**
*
* @default true
*/
getFace(): boolean;

/**
*
* @default false
*/
getLines(): boolean;

/**
* Get the radius of the cylinder base.
* @default 1.0
*/
getRadius(): number;

/**
* Get the number of facets used to define cylinder.
* @default 6
*/
getResolution(): number;

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

/**
* Set the direction for the circle.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
*/
setDirection(x: number, y: number, z: number): boolean;

/**
* Set the direction for the circle.
* @param {Vector3} direction The direction coordinates.
*/
setDirection(direction: Vector3): boolean;

/**
* Set the direction for the circle.
* @param {Vector3} direction The direction coordinates.
*/
setDirectionFrom(direction: Vector3): boolean;

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

/**
* Set the center of the circle.
* @param {Vector3} center
* @default [0, 0, 0]
*/
setCenterFrom(center: Vector3): boolean;

/**
*
* @param {Boolean} face
*/
setFace(face: boolean): boolean;

/**
*
* @param {Boolean} lines
*/
setLines(lines: boolean): boolean;

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

/**
* Set the resolution of the circle.
* @param {Number} resolution The resolution of the circle.
*/
setResolution(resolution: number): boolean;
}

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

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

/**
/**
* vtkCircleSource creates a circle.
*
* @example
* ```js
* import vtkCircleSource from '@kitware/vtk.js/Filters/Sources/CircleSource';
*
* const circle = vtkCircleSource.newInstance({ radius: 1, resolution: 80 });
* const polydata = circle.getOutputData();
* ```
*/
export declare const vtkCircleSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkCircleSource;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkMatrixBuilder from 'vtk.js/Sources/Common/Core/MatrixBuilder';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math/';

// ----------------------------------------------------------------------------
// vtkCircleSource methods
// ----------------------------------------------------------------------------

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

function requestData(inData, outData) {
if (model.deleted) {
return;
}

let dataset = outData[0];

// Points
const points = macro.newTypedArray(model.pointType, model.resolution * 3);

// Lines/cells
// [# of points in line, vert_index_0, vert_index_1, ..., vert_index_0]
const edges = new Uint32Array(model.resolution + 2);
edges[0] = model.resolution + 1;

// generate polydata
const angle = (2.0 * Math.PI) / model.resolution;
for (let i = 0; i < model.resolution; i++) {
const x = model.center[0];
const y = model.radius * Math.cos(i * angle) + model.center[1];
const z = model.radius * Math.sin(i * angle) + model.center[2];
points.set([x, y, z], i * 3);
edges[i + 1] = i;
}

// connect endpoints
edges[edges.length - 1] = edges[1];

dataset = vtkPolyData.newInstance();
dataset.getPoints().setData(points, 3);
if (model.lines) {
dataset.getLines().setData(edges, 1);
}
if (model.face) {
dataset.getPolys().setData(edges, 1);
}

// translate an eventual center different to [0, 0, 0] to ensure rotation is correct
vtkMatrixBuilder
.buildFromRadian()
.translate(...model.center)
.rotateFromDirections([1, 0, 0], model.direction)
.translate(...vtkMath.multiplyScalar([...model.center], -1))
.apply(points);

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

// Expose methods
publicAPI.requestData = requestData;
}

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

function defaultValues(initialValues) {
return {
face: true,
center: [0, 0, 0],
lines: false,
direction: [1, 0, 0],
pointType: 'Float64Array',
radius: 1.0,
resolution: 6,
...initialValues,
};
}

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

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

// Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, ['radius', 'resolution', 'lines', 'face']);
macro.setGetArray(publicAPI, model, ['center', 'direction'], 3);
macro.algo(publicAPI, model, 0, 1);
vtkCircleSource(publicAPI, model);
}

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

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

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

export default { newInstance, extend };