PointSource

Introduction

vtkPointSource is a source object that creates a user-specified number of
points within a specified radius about a specified center point. By default
location of the points is random within the sphere. It is also possible to
generate random points only on the surface of the sphere. The output PolyData
has the specified number of points and 1 cell - a vtkPolyVertex containing
all of the points.

Usage

import vtkPointSource from '@kitware/vtk.js/Filters/Sources/PointSource';

const point = vtkPointSource.newInstance({ numberOfPoints: 10 });
const polydata = point.getOutputData();

Methods

extend

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

getCenter

Get the center of the plane.

getCenterByReference

Get the center of the plane.

getNumberOfPoints

Get the number of points to generate.

getRadius

Get the radius of the point cloud.

newInstance

Method used to create a new instance of vtkPointSource.

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

requestData

Argument Type Required Description
inData Yes
outData Yes

setCenter

Set the center of the point cloud.

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

setCenter

Set the center of the point cloud.

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 point cloud.

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

setNumberOfPoints

Set the number of points to generate.

Argument Type Required Description
numberOfPoints Number Yes The number of points to generate.

setRadius

Set the radius of the point cloud. If you are generating a Gaussian
distribution, then this is the standard deviation for each of x, y, and
z.

Argument Type Required Description
radius Number Yes The radius value.

Source

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

/**
*
*/
export interface IPointSourceInitialValues {
numberOfPoints?: number;
center?: Vector3;
radius?: number;
pointType?: string;
}

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

export interface vtkPointSource extends vtkPointSourceBase {

/**
* Get the center of the plane.
* @default [0, 0, 0]
*/
getCenter(): Vector3;

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

/**
* Get the number of points to generate.
* @default 10
*/
getNumberOfPoints(): number;

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

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

/**
* Set the center of the point cloud.
* @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 point cloud.
* @param {Vector3} center The center point's coordinates.
*/
setCenter(center: Vector3): boolean;

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

/**
* Set the number of points to generate.
* @param {Number} numberOfPoints The number of points to generate.
*/
setNumberOfPoints(numberOfPoints: number): boolean;

/**
* Set the radius of the point cloud. If you are generating a Gaussian
* distribution, then this is the standard deviation for each of x, y, and
* z.
* @param {Number} radius The radius value.
*/
setRadius(radius: number): boolean;
}

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

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

/**
* vtkPointSource is a source object that creates a user-specified number of
* points within a specified radius about a specified center point. By default
* location of the points is random within the sphere. It is also possible to
* generate random points only on the surface of the sphere. The output PolyData
* has the specified number of points and 1 cell - a vtkPolyVertex containing
* all of the points.
*
* @example
* ```js
* import vtkPointSource from '@kitware/vtk.js/Filters/Sources/PointSource';
*
* const point = vtkPointSource.newInstance({ numberOfPoints: 10 });
* const polydata = point.getOutputData();
* ```
*/
export declare const vtkPointSource: {
newInstance: typeof newInstance,
extend: typeof extend,
};
export default vtkPointSource;
index.js
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';

// ----------------------------------------------------------------------------
// vtkPointSource methods
// ----------------------------------------------------------------------------

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

publicAPI.requestData = (inData, outData) => {
if (model.deleted) {
return;
}

const dataset = outData[0];

// Check input
const pointDataType = dataset
? dataset.getPoints().getDataType()
: model.pointType;
const pd = vtkPolyData.newInstance();

// hand create a point cloud
const numPts = model.numberOfPoints;

// Points
const points = macro.newTypedArray(pointDataType, numPts * 3);
pd.getPoints().setData(points, 3);

// Cells
const verts = new Uint32Array(numPts + 1);
pd.getVerts().setData(verts, 1);

let cosphi;
let sinphi;
let rho;
let radius;
let theta;
for (let i = 0; i < numPts; i++) {
cosphi = 1 - 2.0 * vtkMath.random();
sinphi = Math.sqrt(1 - cosphi * cosphi);
rho = model.radius * vtkMath.random() ** 0.33333333;
radius = rho * sinphi;
theta = 2.0 * Math.PI * vtkMath.random();
points[i * 3] = model.center[0] + radius * Math.cos(theta);
points[i * 3 + 1] = model.center[1] + radius * Math.sin(theta);
points[i * 3 + 2] = model.center[2] + rho * cosphi;
}

// Generate point connectivity
//
verts[0] = numPts;
for (let i = 0; i < numPts; i++) {
verts[i + 1] = i;
}

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

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

const DEFAULT_VALUES = {
numberOfPoints: 10,
center: [0, 0, 0],
radius: 0.5,
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, ['numberOfPoints', 'radius']);
macro.setGetArray(publicAPI, model, ['center'], 3);
macro.algo(publicAPI, model, 0, 1);
vtkPointSource(publicAPI, model);
}

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

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

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

export default { newInstance, extend };