CellTypes

Source

Constants.js
export const CellType = {
// Linear cells
VTK_EMPTY_CELL: 0,
VTK_VERTEX: 1,
VTK_POLY_VERTEX: 2,
VTK_LINE: 3,
VTK_POLY_LINE: 4,
VTK_TRIANGLE: 5,
VTK_TRIANGLE_STRIP: 6,
VTK_POLYGON: 7,
VTK_PIXEL: 8,
VTK_QUAD: 9,
VTK_TETRA: 10,
VTK_VOXEL: 11,
VTK_HEXAHEDRON: 12,
VTK_WEDGE: 13,
VTK_PYRAMID: 14,
VTK_PENTAGONAL_PRISM: 15,
VTK_HEXAGONAL_PRISM: 16,

// Quadratic, isoparametric cells
VTK_QUADRATIC_EDGE: 21,
VTK_QUADRATIC_TRIANGLE: 22,
VTK_QUADRATIC_QUAD: 23,
VTK_QUADRATIC_POLYGON: 36,
VTK_QUADRATIC_TETRA: 24,
VTK_QUADRATIC_HEXAHEDRON: 25,
VTK_QUADRATIC_WEDGE: 26,
VTK_QUADRATIC_PYRAMID: 27,
VTK_BIQUADRATIC_QUAD: 28,
VTK_TRIQUADRATIC_HEXAHEDRON: 29,
VTK_QUADRATIC_LINEAR_QUAD: 30,
VTK_QUADRATIC_LINEAR_WEDGE: 31,
VTK_BIQUADRATIC_QUADRATIC_WEDGE: 32,
VTK_BIQUADRATIC_QUADRATIC_HEXAHEDRON: 33,
VTK_BIQUADRATIC_TRIANGLE: 34,

// Cubic, isoparametric cell
VTK_CUBIC_LINE: 35,

// Special class of cells formed by convex group of points
VTK_CONVEX_POINT_SET: 41,

// Polyhedron cell (consisting of polygonal faces)
VTK_POLYHEDRON: 42,

// Higher order cells in parametric form
VTK_PARAMETRIC_CURVE: 51,
VTK_PARAMETRIC_SURFACE: 52,
VTK_PARAMETRIC_TRI_SURFACE: 53,
VTK_PARAMETRIC_QUAD_SURFACE: 54,
VTK_PARAMETRIC_TETRA_REGION: 55,
VTK_PARAMETRIC_HEX_REGION: 56,

// Higher order cells
VTK_HIGHER_ORDER_EDGE: 60,
VTK_HIGHER_ORDER_TRIANGLE: 61,
VTK_HIGHER_ORDER_QUAD: 62,
VTK_HIGHER_ORDER_POLYGON: 63,
VTK_HIGHER_ORDER_TETRAHEDRON: 64,
VTK_HIGHER_ORDER_WEDGE: 65,
VTK_HIGHER_ORDER_PYRAMID: 66,
VTK_HIGHER_ORDER_HEXAHEDRON: 67,

// Arbitrary order Lagrange elements (formulated separated from generic higher order cells)
VTK_LAGRANGE_CURVE: 68,
VTK_LAGRANGE_TRIANGLE: 69,
VTK_LAGRANGE_QUADRILATERAL: 70,
VTK_LAGRANGE_TETRAHEDRON: 71,
VTK_LAGRANGE_HEXAHEDRON: 72,
VTK_LAGRANGE_WEDGE: 73,
VTK_LAGRANGE_PYRAMID: 74,

VTK_NUMBER_OF_CELL_TYPES: 75,
};

// This list should contain the cell class names in
// the same order as in CellType.
export const CellTypesStrings = [
'vtkEmptyCell',
'vtkVertex',
'vtkPolyVertex',
'vtkLine',
'vtkPolyLine',
'vtkTriangle',
'vtkTriangleStrip',
'vtkPolygon',
'vtkPixel',
'vtkQuad',
'vtkTetra',
'vtkVoxel',
'vtkHexahedron',
'vtkWedge',
'vtkPyramid',
'vtkPentagonalPrism',
'vtkHexagonalPrism',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'vtkQuadraticEdge',
'vtkQuadraticTriangle',
'vtkQuadraticQuad',
'vtkQuadraticTetra',
'vtkQuadraticHexahedron',
'vtkQuadraticWedge',
'vtkQuadraticPyramid',
'vtkBiQuadraticQuad',
'vtkTriQuadraticHexahedron',
'vtkQuadraticLinearQuad',
'vtkQuadraticLinearWedge',
'vtkBiQuadraticQuadraticWedge',
'vtkBiQuadraticQuadraticHexahedron',
'vtkBiQuadraticTriangle',
'vtkCubicLine',
'vtkQuadraticPolygon',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'vtkConvexPointSet',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'vtkParametricCurve',
'vtkParametricSurface',
'vtkParametricTriSurface',
'vtkParametricQuadSurface',
'vtkParametricTetraRegion',
'vtkParametricHexRegion',
'UnknownClass',
'UnknownClass',
'UnknownClass',
'vtkHigherOrderEdge',
'vtkHigherOrderTriangle',
'vtkHigherOrderQuad',
'vtkHigherOrderPolygon',
'vtkHigherOrderTetrahedron',
'vtkHigherOrderWedge',
'vtkHigherOrderPyramid',
'vtkHigherOrderHexahedron',
];

export default {
CellType,
CellTypesStrings,
};
index.js
import macro from 'vtk.js/Sources/macros';
import {
CellType,
CellTypesStrings,
} from 'vtk.js/Sources/Common/DataModel/CellTypes/Constants';

// ----------------------------------------------------------------------------
// Global methods
// ----------------------------------------------------------------------------

/**
* Given an int (as defined in vtkCellType.h) identifier for a class
* return it's classname.
*/
function getClassNameFromTypeId(typeId) {
return typeId < CellTypesStrings.length
? CellTypesStrings[typeId]
: 'UnknownClass';
}

/**
* Given a data object classname, return it's int identified (as
* defined in vtkCellType.h)
*/
function getTypeIdFromClassName(cellTypeString) {
return CellTypesStrings.findIndex(cellTypeString);
}

/**
* This convenience method is a fast check to determine if a cell type
* represents a linear or nonlinear cell. This is generally much more
* efficient than getting the appropriate vtkCell and checking its IsLinear
* method.
*/
function isLinear(type) {
return (
type < CellType.VTK_QUADRATIC_EDGE ||
type === CellType.VTK_CONVEX_POINT_SET ||
type === CellType.VTK_POLYHEDRON
);
}

function hasSubCells(cellType) {
return (
cellType === CellType.VTK_TRIANGLE_STRIP ||
cellType === CellType.VTK_POLY_LINE ||
cellType === CellType.VTK_POLY_VERTEX
);
}

// ----------------------------------------------------------------------------
// Static API
// ----------------------------------------------------------------------------

export const STATIC = {
getClassNameFromTypeId,
getTypeIdFromClassName,
isLinear,
hasSubCells,
};

// ----------------------------------------------------------------------------
// vtkCellTypes methods
// ----------------------------------------------------------------------------

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

/**
* Allocate memory for this array. Delete old storage only if necessary.
*/
publicAPI.allocate = (sz = 512, ext = 1000) => {
model.size = sz > 0 ? sz : 1;
model.extend = ext > 0 ? ext : 1;
model.maxId = -1;
model.typeArray = new Uint8Array(sz);
model.locationArray = new Uint32Array(sz);
};

/**
* Add a cell at specified id.
*/
publicAPI.insertCell = (cellId, type, loc) => {
model.typeArray[cellId] = type;
model.locationArray[cellId] = loc;

if (cellId > model.maxId) {
model.maxId = cellId;
}
};

/**
* Add a cell to the object in the next available slot.
*/
publicAPI.insertNextCell = (type, loc) => {
publicAPI.insertCell(++model.maxId, type, loc);
return model.maxId;
};

/**
* Specify a group of cell types. This version is provided to maintain
* backwards compatibility and does a copy of the cellLocations
*/
publicAPI.setCellTypes = (ncells, cellTypes, cellLocations) => {
model.size = ncells;

model.typeArray = cellTypes;
model.locationArray = cellLocations;

model.maxId = ncells - 1;
};

/**
* Return the location of the cell in the associated vtkCellArray.
*/
publicAPI.getCellLocation = (cellId) => model.locationArray[cellId];

/**
* Delete cell by setting to nullptr cell type.
*/
publicAPI.deleteCell = (cellId) => {
model.typeArray[cellId] = CellType.VTK_EMPTY_CELL;
};

/**
* Return the number of types in the list.
*/
publicAPI.getNumberOfTypes = () => model.maxId + 1;

/**
* Return true if type specified is contained in list; false otherwise.
*/
publicAPI.isType = (type) => {
const numTypes = publicAPI.getNumberOfTypes();

for (let i = 0; i < numTypes; ++i) {
if (type === publicAPI.getCellType(i)) {
return true;
}
}
return false;
};

/**
* Add the type specified to the end of the list. Range checking is performed.
*/
publicAPI.insertNextType = (type) => publicAPI.insertNextCell(type, -1);

/**
* Return the type of cell.
*/
publicAPI.getCellType = (cellId) => model.typeArray[cellId];

/**
* Reclaim any extra memory.
*/
// TODO: publicAPI.squeeze = () => {};

/**
* Initialize object without releasing memory.
*/
publicAPI.reset = () => {
model.maxId = -1;
};

/**
* Standard DeepCopy method. Since this object contains no reference
* to other objects, there is no ShallowCopy.
*/
publicAPI.deepCopy = (src) => {
publicAPI.allocate(src.getSize(), src.getExtend());
model.typeArray.set(src.getTypeArray());
model.locationArray.set(src.getLocationArray());
model.maxId = src.getMaxId();
};
}

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

const DEFAULT_VALUES = {
// typeArray: null, // pointer to types array
// locationArray: null; // pointer to array of offsets
size: 0, // allocated size of data
maxId: -1, // maximum index inserted thus far
extend: 1000, // grow array by this point
};

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

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

macro.obj(publicAPI, model);

macro.get(publicAPI, model, ['size', 'maxId', 'extend']);
macro.getArray(publicAPI, model, ['typeArray', 'locationArray']);

vtkCellTypes(publicAPI, model);
}

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

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

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

export default { newInstance, extend, ...STATIC };