CellArray

Introduction

vtkCellArray stores dataset topologies as an explicit connectivity table
listing the point ids that make up each cell.

See Also

vtkDataArray

Methods

extend

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

extractCellSizes

Argument Type Required Description
cellArray Yes

getCell

Returns the point indices at the given location as a subarray.

Argument Type Required Description
loc Yes

getCellSizes

Get the sizes of the cells in this array.

Argument Type Required Description
recompute Boolean No Recompute the cell sizes.

getNumberOfCells

Argument Type Required Description
cellArray Yes

getNumberOfCells

Get the number of cells in the array.

Argument Type Required Description
recompute Boolean No Recompute the number of cells.

insertNextCell

Insert a cell to this array in the next available slot.

Argument Type Required Description
cellPointIds Array. Yes The list of point ids (NOT prefixed with the number of points)

Returns

Type Description
Number Idx of where the cell was inserted

newInstance

Method used to create a new instance of vtkCellArray

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

setData

Set the data of this array.

Argument Type Required Description
typedArray Array. or TypedArray Yes The Array value.

Source

index.d.ts
import { TypedArray } from '../../../types';
import vtkDataArray, { IDataArrayInitialValues } from '../../Core/DataArray';

/**
* The inital values of a vtkCellArray.
*/
export interface ICellArrayInitialValues extends IDataArrayInitialValues {
empty?: boolean;
}

/**
* You are NOT allowed to modify the cell array via `getData()`.
* Only via `setData` or `insertNextCell`
*/
export interface vtkCellArray extends vtkDataArray {
/**
* Get the number of cells in the array.
* @param {Boolean} [recompute] Recompute the number of cells.
*/
getNumberOfCells(recompute?: boolean): number;

/**
* Get the sizes of the cells in this array.
* @param {Boolean} [recompute] Recompute the cell sizes.
*/
getCellSizes(recompute?: boolean): any;

/**
* Set the data of this array.
* @param {Number[]|TypedArray} typedArray The Array value.
*/
setData(typedArray: number[] | TypedArray): void;

/**
* Returns the point indices at the given location as a subarray.
* @param loc
*/
getCell(loc: any): void;

/**
* Insert a cell to this array in the next available slot.
* @param {Number[]} cellPointIds The list of point ids (NOT prefixed with the number of points)
* @returns {Number} Idx of where the cell was inserted
*/
insertNextCell(cellPointIds: number[]): number;
}

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

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

/**
* @static
* @param cellArray
*/
export function extractCellSizes(cellArray: any): any;

/**
* @static
* @param cellArray
*/
export function getNumberOfCells(cellArray: any): any;

/**
* vtkCellArray stores dataset topologies as an explicit connectivity table
* listing the point ids that make up each cell.
*
* @see [vtkDataArray](./Common_Core_DataArray.html)
*/
export declare const vtkCellArray: {
newInstance: typeof newInstance;
extend: typeof extend;
extractCellSizes: typeof extractCellSizes;
getNumberOfCells: typeof getNumberOfCells;
};
export default vtkCellArray;
index.js
import macro from 'vtk.js/Sources/macros';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants';

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

function extractCellSizes(cellArray) {
let currentIdx = 0;
return cellArray.filter((value, index) => {
if (index === currentIdx) {
currentIdx += value + 1;
return true;
}
return false;
});
}

function getNumberOfCells(cellArray) {
let cellId = 0;
for (let cellArrayIndex = 0; cellArrayIndex < cellArray.length; ) {
cellArrayIndex += cellArray[cellArrayIndex] + 1;
cellId++;
}
return cellId;
}

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

export const STATIC = {
extractCellSizes,
getNumberOfCells,
};

// ----------------------------------------------------------------------------
// vtkCellArray methods
// ----------------------------------------------------------------------------

function vtkCellArray(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkCellArray');
const superClass = { ...publicAPI };

publicAPI.getNumberOfCells = (recompute) => {
if (model.numberOfCells !== undefined && !recompute) {
return model.numberOfCells;
}

if (model.cellSizes) {
model.numberOfCells = model.cellSizes.length;
} else {
model.numberOfCells = getNumberOfCells(publicAPI.getData());
}
return model.numberOfCells;
};

publicAPI.getCellSizes = (recompute) => {
if (model.cellSizes !== undefined && !recompute) {
return model.cellSizes;
}

model.cellSizes = extractCellSizes(publicAPI.getData());
return model.cellSizes;
};

/**
* When `resize()` is being used, you then MUST use `insertNextCell()`.
*/
publicAPI.resize = (requestedNumTuples) => {
const oldNumTuples = publicAPI.getNumberOfTuples();
superClass.resize(requestedNumTuples);
const newNumTuples = publicAPI.getNumberOfTuples();
if (newNumTuples < oldNumTuples) {
if (newNumTuples === 0) {
model.numberOfCells = 0;
model.cellSizes = [];
} else {
// We do not know how many cells are left.
// Set to undefined to ensure insertNextCell works correctly.
model.numberOfCells = undefined;
model.cellSizes = undefined;
}
}
};

publicAPI.setData = (typedArray) => {
superClass.setData(typedArray, 1);
model.numberOfCells = undefined;
model.cellSizes = undefined;
};

publicAPI.getCell = (loc) => {
let cellLoc = loc;
const numberOfPoints = model.values[cellLoc++];
return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
};

publicAPI.insertNextCell = (cellPointIds) => {
const cellId = publicAPI.getNumberOfCells();
publicAPI.insertNextTuples([cellPointIds.length, ...cellPointIds]);
// By computing the number of cells earlier, we made sure that numberOfCells is defined
++model.numberOfCells;
if (model.cellSizes != null) {
model.cellSizes.push(cellPointIds.length);
}
return cellId;
};
}

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

function defaultValues(initialValues) {
return {
empty: true,
numberOfComponents: 1,
dataType: VtkDataTypes.UNSIGNED_INT,
...initialValues,
};
}

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

export function extend(publicAPI, model, initialValues = {}) {
vtkDataArray.extend(publicAPI, model, defaultValues(initialValues));
vtkCellArray(publicAPI, model);
}

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

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

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

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