ArcSource

Introduction

vtkArcSource is a source object that creates an arc defined by two endpoints
and a center. The number of segments composing the polyline is controlled by
setting the object resolution.

Usage

import vtkArcSource from '@kitware/vtk.js/Filters/Sources/ArcSource';

const arc = vtkArcSource.newInstance();
const polydata = arc.getOutputData();

Methods

extend

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

getAngle

Get the angle of the arc.

getCenter

Get the center of the arc.

getCenterByReference

Get the center of the arc by reference.

getNegative

Get the negative flag of the arc.

getNormal

Get the normal vector of the arc.

getNormalByReference

Get the normal vector of the arc by reference.

getOutputPointsPrecision

Get the output points precision.

getPoint1

Get the first point of the arc.

getPoint1ByReference

Get the first point of the arc by reference.

getPoint2

Get the second point of the arc.

getPoint2ByReference

Get the second point of the arc by reference.

getPolarVector

Get the polar vector of the arc.

getPolarVectorByReference

Get the polar vector of the arc by reference.

getResolution

Get the resolution of the arc.

getUseNormalAndAngle

Get the use normal and angle flag.

newInstance

Method used to create a new instance of vtkArcSource.

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

requestData

Argument Type Required Description
inData Yes
outData Yes

setAngle

Set the angle of the arc.

Argument Type Required Description
angle Number Yes The angle in radians.

setCenter

Set the center of the arc.

Argument Type Required Description
center Vector3 Yes The center point’s coordinates.

setCenterFrom

Set the center of the arc by reference.

Argument Type Required Description
center Vector3 Yes The center point’s coordinates.

setNegative

Set the negative flag of the arc.

Argument Type Required Description
negative Boolean Yes If true, the arc will be drawn in the negative direction.

setNormal

Set the normal vector of the arc.

Argument Type Required Description
normal Vector3 Yes The normal vector’s coordinates.

setNormalFrom

Set the normal vector of the arc by reference.

Argument Type Required Description
normal Vector3 Yes The normal vector’s coordinates.

setOutputPointsPrecision

Set the output points precision.

Argument Type Required Description
precision DesiredOutputPrecision Yes The desired output precision.

setPoint1

Set the first point of the arc.

Argument Type Required Description
point1 Vector3 Yes The first point’s coordinates.

setPoint1From

Set the first point of the arc by reference.

Argument Type Required Description
point1 Vector3 Yes The first point’s coordinates.

setPoint2

Set the second point of the arc.

Argument Type Required Description
point2 Vector3 Yes The second point’s coordinates.

setPoint2From

Set the second point of the arc by reference.

Argument Type Required Description
point2 Vector3 Yes The second point’s coordinates.

setPolarVector

Set the polar vector of the arc.

Argument Type Required Description
polarVector Vector3 Yes The polar vector’s coordinates.

setPolarVectorFrom

Set the polar vector of the arc by reference.

Argument Type Required Description
polarVector Vector3 Yes The polar vector’s coordinates.

setResolution

Set the resolution of the arc.

Argument Type Required Description
resolution Number Yes The number of points in the arc.

setUseNormalAndAngle

Set the use normal and angle flag.

Argument Type Required Description
useNormalAndAngle Boolean Yes If true, the normal and angle will be used to define the arc.

Source

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

/**
*
*/
export interface IArcSourceInitialValues {
point1?: Vector3;
point2?: Vector3;
center?: Vector3;
normal?: Vector3;
polarVector?: Vector3;
angle?: number;
resolution?: number;
negative?: boolean;
useNormalAndAngle?: boolean;
outputPointsPrecision?: DesiredOutputPrecision;
}

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

export interface vtkArcSource extends vtkArcSourceBase {
/**
* Get the angle of the arc.
*/
getAngle(): number;

/**
* Get the center of the arc.
*/
getCenter(): Vector3;

/**
* Get the center of the arc by reference.
*/
getCenterByReference(): Vector3;

/**
* Get the first point of the arc.
*/
getPoint1(): Vector3;

/**
* Get the first point of the arc by reference.
*/
getPoint1ByReference(): Vector3;

/**
* Get the second point of the arc.
*/
getPoint2(): Vector3;

/**
* Get the second point of the arc by reference.
*/
getPoint2ByReference(): Vector3;

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

/**
* Get the normal vector of the arc by reference.
*/
getNormalByReference(): Vector3;

/**
* Get the polar vector of the arc.
*/
getPolarVector(): Vector3;

/**
* Get the polar vector of the arc by reference.
*/
getPolarVectorByReference(): Vector3;

/**
* Get the resolution of the arc.
*/
getResolution(): number;

/**
* Get the negative flag of the arc.
*/
getNegative(): boolean;

/**
* Get the output points precision.
*/
getOutputPointsPrecision(): DesiredOutputPrecision;

/**
* Get the use normal and angle flag.
*/
getUseNormalAndAngle(): boolean;

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

/**
* Set the first point of the arc.
* @param {Vector3} point1 The first point's coordinates.
*/
setPoint1(point1: Vector3): boolean;

/**
* Set the first point of the arc by reference.
* @param {Vector3} point1 The first point's coordinates.
*/
setPoint1From(point1: Vector3): boolean;

/**
* Set the second point of the arc.
* @param {Vector3} point2 The second point's coordinates.
*/
setPoint2(point2: Vector3): boolean;

/**
* Set the second point of the arc by reference.
* @param {Vector3} point2 The second point's coordinates.
*/
setPoint2From(point2: Vector3): boolean;

/**
* Set the center of the arc.
* @param {Vector3} center The center point's coordinates.
*/
setCenter(center: Vector3): boolean;

/**
* Set the center of the arc by reference.
* @param {Vector3} center The center point's coordinates.
*/
setCenterFrom(center: Vector3): boolean;

/**
* Set the normal vector of the arc.
* @param {Vector3} normal The normal vector's coordinates.
*/
setNormal(normal: Vector3): boolean;

/**
* Set the normal vector of the arc by reference.
* @param {Vector3} normal The normal vector's coordinates.
*/
setNormalFrom(normal: Vector3): boolean;

/**
* Set the polar vector of the arc.
* @param {Vector3} polarVector The polar vector's coordinates.
*/
setPolarVector(polarVector: Vector3): boolean;

/**
* Set the polar vector of the arc by reference.
* @param {Vector3} polarVector The polar vector's coordinates.
*/
setPolarVectorFrom(polarVector: Vector3): boolean;

/**
* Set the angle of the arc.
* @param {Number} angle The angle in radians.
*/
setAngle(angle: number): boolean;

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

/**
* Set the negative flag of the arc.
* @param {Boolean} negative If true, the arc will be drawn in the negative direction.
*/
setNegative(negative: boolean): boolean;

/**
* Set the use normal and angle flag.
* @param {Boolean} useNormalAndAngle If true, the normal and angle will be used to define the arc.
*/
setUseNormalAndAngle(useNormalAndAngle: boolean): boolean;

/**
* Set the output points precision.
* @param {DesiredOutputPrecision} precision The desired output precision.
*/
setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;
}

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

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

/**
* vtkArcSource is a source object that creates an arc defined by two endpoints
* and a center. The number of segments composing the polyline is controlled by
* setting the object resolution.
*
* @example
* ```js
* import vtkArcSource from '@kitware/vtk.js/Filters/Sources/ArcSource';
*
* const arc = vtkArcSource.newInstance();
* const polydata = arc.getOutputData();
* ```
*/
export declare const vtkArcSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkArcSource;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkCellArray from 'vtk.js/Sources/Common/Core/CellArray';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import { DesiredOutputPrecision } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants';

const { VtkDataTypes } = vtkDataArray;

// ----------------------------------------------------------------------------
// vtkArcSource methods
// ----------------------------------------------------------------------------

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

publicAPI.requestData = (inData, outData) => {
const numLines = model.resolution;
const numPts = model.resolution + 1;
const tc = [0.0, 0.0];

const output = outData[0]?.initialize() || vtkPolyData.newInstance();

let angle = 0.0;
let radius = 0.5;
const perpendicular = [0, 0, 0];
const v1 = [0, 0, 0];

if (model.useNormalAndAngle) {
angle = vtkMath.radiansFromDegrees(model.angle);

v1[0] = model.polarVector[0];
v1[1] = model.polarVector[1];
v1[2] = model.polarVector[2];

vtkMath.cross(model.normal, model.polarVector, perpendicular);

radius = vtkMath.normalize(v1);
} else {
vtkMath.subtract(model.point1, model.center, v1);

const v2 = [0, 0, 0];
vtkMath.subtract(model.point2, model.center, v2);

const normal = [0, 0, 0];
vtkMath.cross(v1, v2, normal);
vtkMath.cross(normal, v1, perpendicular);

const dotProduct =
vtkMath.dot(v1, v2) / (vtkMath.norm(v1) * vtkMath.norm(v2));
angle = Math.acos(dotProduct);

if (model.negative) {
angle -= 2.0 * Math.PI;
}

radius = vtkMath.normalize(v1);
}

const angleInc = angle / model.resolution;

vtkMath.normalize(perpendicular);

let pointType = 0;
if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
pointType = VtkDataTypes.FLOAT;
} else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
pointType = VtkDataTypes.DOUBLE;
}

const points = vtkPoints.newInstance({
dataType: pointType,
});
points.setNumberOfPoints(numPts);

const tcoords = vtkDataArray.newInstance({
numberOfComponents: 2,
size: numPts * 2,
dataType: VtkDataTypes.FLOAT,
name: 'TextureCoordinates',
});

const lines = vtkCellArray.newInstance();
lines.allocate(numLines);

let theta = 0.0;
for (let i = 0; i <= model.resolution; ++i, theta += angleInc) {
const cosine = Math.cos(theta);
const sine = Math.sin(theta);

const p = [
model.center[0] +
cosine * radius * v1[0] +
sine * radius * perpendicular[0],
model.center[1] +
cosine * radius * v1[1] +
sine * radius * perpendicular[1],
model.center[2] +
cosine * radius * v1[2] +
sine * radius * perpendicular[2],
];

tc[0] = i / model.resolution;
tc[1] = 0.0;

points.setPoint(i, ...p);
tcoords.setTuple(i, tc);
}

const pointIds = Array.from({ length: numPts }, (_, i) => i);

lines.insertNextCell(pointIds);

output.setPoints(points);
output.getPointData().setTCoords(tcoords);
output.setLines(lines);

outData[0] = output;
};
}

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

const DEFAULT_VALUES = {
point1: [0.0, 0.5, 0.0],
point2: [0.5, 0.0, 0.0],
center: [0.0, 0.0, 0.0],
normal: [0.0, 0.0, 1.0],
polarVector: [1.0, 0.0, 0.0],
angle: 90.0,
resolution: 6,
negative: false,
useNormalAndAngle: false,
outputPointsPrecision: DesiredOutputPrecision.SINGLE,
};

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

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

// Ensure resolution is at least 1
if (model.resolution < 1) {
model.resolution = 1;
}

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

macro.setGet(publicAPI, model, [
'resolution',
'angle',
'negative',
'useNormalAndAngle',
'outputPointsPrecision',
]);

macro.setGetArray(
publicAPI,
model,
['point1', 'point2', 'center', 'normal', 'polarVector'],
3
);

vtkArcSource(publicAPI, model);
}

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

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

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

export default { newInstance, extend };