ConeSource

Introduction

vtkConeSource creates a cone centered at a specified point and pointing in a specified direction.
(By default, the center is the origin and the direction is the x-axis.) Depending upon the resolution of this object,
different representations are created. If resolution=0 a line is created; if resolution=1, a single triangle is created;
if resolution=2, two crossed triangles are created. For resolution > 2, a 3D cone (with resolution number of sides)
is created. It also is possible to control whether the bottom of the cone is capped with a (resolution-sided) polygon,
and to specify the height and radius of the cone.

Usage

import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource';

const cone = vtkConeSource.newInstance({ height: 2, radius: 1, resolution: 80 });
const polydata = cone.getOutputData();

Methods

extend

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

getCapping

Get the cap the base of the cone with a polygon.

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.

getHeight

Get the height of the cone.

getRadius

Get the base radius of the cone.

getResolution

Get the number of facets used to represent the cone.

newInstance

Method used to create a new instance of vtkConeSource.

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

requestData

Expose methods

Argument Type Required Description
inData Yes
outData Yes

setCapping

Turn on/off whether to cap the base of the cone with a polygon.

Argument Type Required Description
capping Boolean Yes

setCenter

Set the center of the cone.
It is located at the middle of the axis of the cone.
!!! warning
This is not the center of the base of the cone!

Argument Type Required Description
center Vector3 Yes

setCenter

Set the center of the cone.
It is located at the middle of the axis of the cone.
!!! warning
This is not the center of the base of the cone!

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

setCenterFrom

Set the center of the cone.
It is located at the middle of the axis of the cone.
!!! warning
This is not the center of the base of the cone!

Argument Type Required Description
center Vector3 Yes

setDirection

Set the direction for the cone.

Argument Type Required Description
direction Vector3 Yes

setDirection

Set the direction for the cone.

Argument Type Required Description
direction Vector3 Yes The direction coordinates.

setDirection

Set the direction for the cone.

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 cone.

Argument Type Required Description
direction Vector3 Yes

setHeight

Set the height of the cone.
This is the height along the cone in its specified direction.

Argument Type Required Description
height Number Yes

setRadius

Set the base radius of the cone.

Argument Type Required Description
radius Number Yes

setResolution

Set the number of facets used to represent the cone.

Argument Type Required Description
resolution Yes

Source

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

/**
*
*/
export interface IConeSourceInitialValues {
height?: number;
radius?: number;
resolution?: number;
center?: Vector3;
direction?: Vector3;
capping?: boolean;
pointType?: string;
}

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

export interface vtkConeSource extends vtkConeSourceBase {
/**
* Get the cap the base of the cone with a polygon.
* @default true
*/
getCapping(): boolean;

/**
* 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;

/**
* Get the height of the cone.
* @default 1.0
*/
getHeight(): number;

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

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

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

/**
* Turn on/off whether to cap the base of the cone with a polygon.
* @param {Boolean} capping
*/
setCapping(capping: boolean): boolean;

/**
* Set the center of the cone.
* It is located at the middle of the axis of the cone.
* !!! warning
* This is not the center of the base of the cone!
* @param {Number} x
* @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 cone.
* It is located at the middle of the axis of the cone.
* !!! warning
* This is not the center of the base of the cone!
* @param {Vector3} center
* @default [0, 0, 0]
*/
setCenter(center: Vector3): boolean;

/**
* Set the center of the cone.
* It is located at the middle of the axis of the cone.
* !!! warning
* This is not the center of the base of the cone!
* @param {Vector3} center
* @default [0, 0, 0]
*/
setCenterFrom(center: Vector3): boolean;

/**
* Set the direction for the cone.
* @param {Number} x The x coordinate.
* @param {Number} y The y coordinate.
* @param {Number} z The z coordinate.
* @default [1, 0, 0]
*/
setDirection(x: number, y: number, z: number): boolean;

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

/**
* Set the direction for the cone.
* @param {Vector3} direction
* @default [1, 0, 0]
*/
setDirection(direction: Vector3): boolean;

/**
* Set the direction for the cone.
* @param {Vector3} direction
* @default [1, 0, 0]
*/
setDirectionFrom(direction: Vector3): boolean;

/**
* Set the height of the cone.
* This is the height along the cone in its specified direction.
* @param {Number} height
*/
setHeight(height: number): boolean;

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

/**
* Set the number of facets used to represent the cone.
* @param resolution
*/
setResolution(resolution: number): boolean;
}

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

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

/**
* vtkConeSource creates a cone centered at a specified point and pointing in a specified direction.
* (By default, the center is the origin and the direction is the x-axis.) Depending upon the resolution of this object,
* different representations are created. If resolution=0 a line is created; if resolution=1, a single triangle is created;
* if resolution=2, two crossed triangles are created. For resolution > 2, a 3D cone (with resolution number of sides)
* is created. It also is possible to control whether the bottom of the cone is capped with a (resolution-sided) polygon,
* and to specify the height and radius of the cone.
*
* @example
* ```js
* import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource';
*
* const cone = vtkConeSource.newInstance({ height: 2, radius: 1, resolution: 80 });
* const polydata = cone.getOutputData();
* ```
*/
export declare const vtkConeSource: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkConeSource;
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';

// ----------------------------------------------------------------------------
// vtkConeSource methods
// ----------------------------------------------------------------------------

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

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

let dataset = outData[0];

const angle = (2 * Math.PI) / model.resolution;
const xbot = -model.height / 2.0;
const numberOfPoints = model.resolution + 1;
const cellArraySize = 4 * model.resolution + 1 + model.resolution;

// Points
let pointIdx = 0;
const points = macro.newTypedArray(model.pointType, numberOfPoints * 3);

// Cells
let cellLocation = 0;
const polys = new Uint32Array(cellArraySize);

// Add summit point
points[0] = model.height / 2.0;
points[1] = 0.0;
points[2] = 0.0;

// Create bottom cell
if (model.capping) {
polys[cellLocation++] = model.resolution;
}

// Add all points
for (let i = 0; i < model.resolution; i++) {
pointIdx++;
points[pointIdx * 3 + 0] = xbot;
points[pointIdx * 3 + 1] = model.radius * Math.cos(i * angle);
points[pointIdx * 3 + 2] = model.radius * Math.sin(i * angle);

// Add points to bottom cell in reverse order
if (model.capping) {
polys[model.resolution - cellLocation++ + 1] = pointIdx;
}
}

// Add all triangle cells
for (let i = 0; i < model.resolution; i++) {
polys[cellLocation++] = 3;
polys[cellLocation++] = 0;
polys[cellLocation++] = i + 1;
polys[cellLocation++] = i + 2 > model.resolution ? 1 : i + 2;
}

// Apply transformation to the points coordinates
vtkMatrixBuilder
.buildFromRadian()
.translate(...model.center)
.rotateFromDirections([1, 0, 0], model.direction)
.apply(points);

dataset = vtkPolyData.newInstance();
dataset.getPoints().setData(points, 3);
dataset.getPolys().setData(polys, 1);

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

// Expose methods
publicAPI.requestData = requestData;
}

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

const DEFAULT_VALUES = {
height: 1.0,
radius: 0.5,
resolution: 6,
center: [0, 0, 0],
direction: [1.0, 0.0, 0.0],
capping: true,
pointType: 'Float64Array',
};

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

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

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

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

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

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

export default { newInstance, extend };