Cell

Introduction

vtkCell is an abstract method to define a cell

Methods

deepCopy

Copy this cell by completely copying internal data structures.

Argument Type Required Description
cell vtkCell Yes The cell you want to use.

extend

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

getBounds

Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].

getLength2

Compute Length squared of cell (i.e., bounding box diagonal squared).

getNumberOfPoints

Get the number of points in the cell.

getParametricDistance

Get the distance of the parametric coordinate provided to the cell. If
inside the cell, a distance of zero is returned. This is used during
picking to get the correct cell picked. (The tolerance will occasionally
allow cells to be picked who are not really intersected “inside” the
cell.)

Argument Type Required Description
pcoords Vector3 Yes The coordinates of the point.

getPoints

getPointsIds

initialize

Initialize the cell with point coordinates and cell point ids, example :

const points = vtkPoints.newInstance();
points.setData(Float32Array.from([0, 0, 0, 0, 0, 1, ..., 255, 255, 255]));
const pointIdsList = [13, 10, 235];
// Create cell
const triangle = vtkTriangle.newInstance();
// Initialize cell
triangle.initialize(points, pointIdsList);

If pointIdsList is null, points are shallow copied and pointIdsList is
generated as such: [0, 1, …, N-1] where N is the number of points. If
pointIdsList is not null, only pointIdsList point coordinates are copied into
the cell. pointIdsList is shallow copied.

Argument Type Required Description
points vtkPoints Yes
pointIdsList Array. No

newInstance

Method used to create a new instance of vtkCell.

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

Source

index.d.ts
import { vtkObject } from '../../../interfaces';
import { Bounds, Vector3 } from '../../../types';
import vtkPoints from '../../Core/Points';

export interface ICellInitialValues {
bounds?: Bounds;
pointsIds?: number[];
}

export interface vtkCell extends vtkObject {
/**
* Copy this cell by completely copying internal data structures.
* @param {vtkCell} cell The cell you want to use.
*/
deepCopy(cell: vtkCell): void;

/**
* Initialize the cell with point coordinates and cell point ids, example :
*
* ```js
* const points = vtkPoints.newInstance();
* points.setData(Float32Array.from([0, 0, 0, 0, 0, 1, ..., 255, 255, 255]));
* const pointIdsList = [13, 10, 235];
* // Create cell
* const triangle = vtkTriangle.newInstance();
* // Initialize cell
* triangle.initialize(points, pointIdsList);
* ```
*
* If pointIdsList is null, points are shallow copied and pointIdsList is
* generated as such: [0, 1, ..., N-1] where N is the number of points. If
* pointIdsList is not null, only pointIdsList point coordinates are copied into
* the cell. pointIdsList is shallow copied.
* @param {vtkPoints} points
* @param {Number[]} [pointIdsList]
*/
initialize(points: vtkPoints, pointIdsList?: number[]): void;

/**
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* @return {Bounds} The bounds for the mapper.
*/
getBounds(): Bounds;

/**
* Compute Length squared of cell (i.e., bounding box diagonal squared).
*/
getLength2(): number;

/**
* Get the distance of the parametric coordinate provided to the cell. If
* inside the cell, a distance of zero is returned. This is used during
* picking to get the correct cell picked. (The tolerance will occasionally
* allow cells to be picked who are not really intersected "inside" the
* cell.)
* @param {Vector3} pcoords The coordinates of the point.
*
*/
getParametricDistance(pcoords: Vector3): number;

/**
*
*/
getPoints(): vtkPoints;

/**
*
*/
getPointsIds(): number[];

/**
* Get the number of points in the cell.
*/
getNumberOfPoints(): number;

// getCellDimension(): void;
// intersectWithLine(p1: any, p2: any, tol: any, t: any, x: any, pcoords: any, subId: any): void;
// evaluatePosition(x: Vector3, closestPoint: Vector3, subId: number, pcoords: Vector3, dist2: number, weights: any): void;
}

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

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

/**
* vtkCell is an abstract method to define a cell
*/
export declare const vtkCell: {
newInstance: typeof newInstance;
extend: typeof extend;
};
export default vtkCell;
index.js
import macro from 'vtk.js/Sources/macros';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import vtkPoints from 'vtk.js/Sources/Common/Core/Points';

// ----------------------------------------------------------------------------
// vtkCell methods
// ----------------------------------------------------------------------------

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

publicAPI.initialize = (points, pointIdsList = null) => {
if (!pointIdsList) {
model.points = points;
model.pointsIds = new Array(points.getNumberOfPoints());
for (let i = points.getNumberOfPoints() - 1; i >= 0; --i) {
model.pointsIds[i] = i;
}
} else {
model.pointsIds = pointIdsList;
let triangleData = model.points.getData();
if (triangleData.length !== 3 * model.pointsIds.length) {
triangleData = macro.newTypedArray(
points.getDataType(),
3 * model.pointsIds.length
);
}
const pointsData = points.getData();
model.pointsIds.forEach((pointId, index) => {
// const start = 3 * pointId;
// pointsData.set(p.subarray(start, start + 3), 3 * index);
let pointOffset = 3 * pointId;
let trianglePointOffset = 3 * index;
triangleData[trianglePointOffset] = pointsData[pointOffset];
triangleData[++trianglePointOffset] = pointsData[++pointOffset];
triangleData[++trianglePointOffset] = pointsData[++pointOffset];
});
model.points.setData(triangleData);
}
};

publicAPI.getBounds = () => {
const nbPoints = model.points.getNumberOfPoints();
const x = [];
if (nbPoints) {
model.points.getPoint(0, x);
model.bounds[0] = x[0];
model.bounds[1] = x[0];
model.bounds[2] = x[1];
model.bounds[3] = x[1];
model.bounds[4] = x[2];
model.bounds[5] = x[2];

for (let i = 1; i < nbPoints; i++) {
model.points.getPoint(i, x);
model.bounds[0] = x[0] < model.bounds[0] ? x[0] : model.bounds[0];
model.bounds[1] = x[0] > model.bounds[1] ? x[0] : model.bounds[1];
model.bounds[2] = x[1] < model.bounds[2] ? x[1] : model.bounds[2];
model.bounds[3] = x[1] > model.bounds[3] ? x[1] : model.bounds[3];
model.bounds[4] = x[2] < model.bounds[4] ? x[2] : model.bounds[4];
model.bounds[5] = x[2] > model.bounds[5] ? x[2] : model.bounds[5];
}
} else {
vtkMath.uninitializeBounds(model.bounds);
}
return model.bounds;
};

publicAPI.getLength2 = () => {
publicAPI.getBounds();
let length = 0.0;
let diff = 0;
for (let i = 0; i < 3; i++) {
diff = model.bounds[2 * i + 1] - model.bounds[2 * i];
length += diff * diff;
}
return length;
};

publicAPI.getParametricDistance = (pcoords) => {
let pDist;
let pDistMax = 0.0;

for (let i = 0; i < 3; i++) {
if (pcoords[i] < 0.0) {
pDist = -pcoords[i];
} else if (pcoords[i] > 1.0) {
pDist = pcoords[i] - 1.0;
} else {
// inside the cell in the parametric direction
pDist = 0.0;
}
if (pDist > pDistMax) {
pDistMax = pDist;
}
}
return pDistMax;
};

publicAPI.getNumberOfPoints = () => model.points.getNumberOfPoints();

publicAPI.deepCopy = (cell) => {
cell.initialize(model.points, model.pointsIds);
};

publicAPI.getCellDimension = () => {}; // virtual
publicAPI.intersectWithLine = (p1, p2, tol, t, x, pcoords, subId) => {}; // virtual
publicAPI.evaluatePosition = (
x,
closestPoint,
subId,
pcoords,
dist2,
weights
) => {
macro.vtkErrorMacro('vtkCell.evaluatePosition is not implemented.');
}; // virtual
}

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

const DEFAULT_VALUES = {
bounds: [-1, -1, -1, -1, -1, -1],
pointsIds: [],
};

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

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

macro.obj(publicAPI, model);

if (!model.points) {
model.points = vtkPoints.newInstance();
}

macro.get(publicAPI, model, ['points', 'pointsIds']);

vtkCell(publicAPI, model);
}

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

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

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

export default { newInstance, extend };