PolyLine

Introduction

vtkPolyLine is a cell which representant a poly line.

See Also

vtkCell

Methods

evaluateLocation

Determine global coordinate (x[3]) from subId and parametric coordinates.
Also returns interpolation weights. (The number of weights is equal to
the number of points in the cell.)

Argument Type Required Description
subId number Yes
pcoords Vector3 Yes The parametric coordinates
x Vector3 Yes The global coordinate
weights Vector2 Yes The interpolation weights

extend

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

getCellDimension

Get the topological dimensional of the cell (0, 1, 2 or 3).

intersectWithLine

Argument Type Required Description
t1 number Yes
t2 number Yes
p1 Vector3 Yes The first point coordinate.
p2 Vector3 Yes The second point coordinate.
tol Number Yes The tolerance to use.
x Vector3 Yes The point which intersect the line.
pcoords Vector3 Yes The parametric coordinates.

newInstance

Method used to create a new instance of vtkPolyLine.

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

Source

index.d.ts
import { Vector2, Vector3 } from '../../../types';
import vtkCell, { ICellInitialValues } from '../Cell';
import { IIntersectWithLine } from '../Line';

export interface IPolyLineInitialValues extends ICellInitialValues { }

export interface vtkPolyLine extends vtkCell {

/**
* Get the topological dimensional of the cell (0, 1, 2 or 3).
*/
getCellDimension(): number;

/**
* @param {number} t1
* @param {number} t2
* @param {Vector3} p1 The first point coordinate.
* @param {Vector3} p2 The second point coordinate.
* @param {Number} tol The tolerance to use.
* @param {Vector3} x The point which intersect the line.
* @param {Vector3} pcoords The parametric coordinates.
*/
intersectWithLine(t1: number, t2: number, p1: Vector3, p2: Vector3, tol: number, x: Vector3, pcoords: Vector3): IIntersectWithLine;

/**
* Determine global coordinate (x[3]) from subId and parametric coordinates.
* Also returns interpolation weights. (The number of weights is equal to
* the number of points in the cell.)
*
* @param {number} subId
* @param {Vector3} pcoords The parametric coordinates
* @param {Vector3} x The global coordinate
* @param {Vector2} weights The interpolation weights
*/
evaluateLocation(subId: number, pcoords: Vector3, x: Vector3, weights: Vector2): void
}

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

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

/**
* vtkPolyLine is a cell which representant a poly line.
*
* @see vtkCell
*/
export declare const vtkPolyLine: {
newInstance: typeof newInstance,
extend: typeof extend;
};

export default vtkPolyLine;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkCell from 'vtk.js/Sources/Common/DataModel/Cell';
import vtkLine from 'vtk.js/Sources/Common/DataModel/Line';

function vtkPolyLine(publicAPI, model) {
model.classHierarchy.push('vtkPolyLine');
const superClass = { ...publicAPI };

const line = vtkLine.newInstance();
line.getPoints().setNumberOfPoints(2);

publicAPI.getCellDimension = () => 1;
publicAPI.intersectWithLine = (t1, t2, p1, p2, tol, x, pcoords) => {
const outObj = {
intersect: 0,
t: Number.MAX_VALUE,
subId: 0,
betweenPoints: null,
};

const numLines = superClass.getPoints().getNumberOfPoints() - 1;
let pDistMin = Number.MAX_VALUE;
const minXYZ = [0, 0, 0];
const minPCoords = [0, 0, 0];
for (let subId = 0; subId < numLines; subId++) {
const pCoords = [0, 0, 0];

line
.getPoints()
.getData()
.set(model.points.getData().subarray(3 * subId, 3 * (subId + 2)));

const lineIntersected = line.intersectWithLine(p1, p2, tol, x, pcoords);

if (
lineIntersected.intersect === 1 &&
lineIntersected.t <= outObj.t + tol &&
lineIntersected.t >= t1 &&
lineIntersected.t <= t2
) {
outObj.intersect = 1;
const pDist = line.getParametricDistance(pCoords);
if (
pDist < pDistMin ||
(pDist === pDistMin && lineIntersected.t < outObj.t)
) {
outObj.subId = subId;
outObj.t = lineIntersected.t;
pDistMin = pDist;
for (let k = 0; k < 3; k++) {
minXYZ[k] = x[k];
minPCoords[k] = pCoords[k];
}
}
}
}

return outObj;
};

publicAPI.evaluateLocation = (subId, pcoords, x, weights) => {
line
.getPoints()
.getData()
.set(model.points.getData().subarray(3 * subId, 3 * (subId + 2)));

return line.evaluateLocation(pcoords, x, weights);
};
}

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

const DEFAULT_VALUES = {};

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

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

vtkCell.extend(publicAPI, model, initialValues);

vtkPolyLine(publicAPI, model);
}

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

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

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

export default { newInstance, extend };