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.

initialize

Reset the cell array by setting the number of cells to 0.
NOTE: This won’t touch the actual memory of the underlying typedArray.

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;
}

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;

/**
* Reset the cell array by setting the number of cells to 0.
* NOTE: This won't touch the actual memory of the underlying typedArray.
*/
initialize(): 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');

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;
};

const superSetData = publicAPI.setData;
publicAPI.setData = (typedArray) => {
superSetData(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);
};

const superInitialize = publicAPI.initialize;
publicAPI.initialize = () => {
superInitialize();
// Set to undefined to ensure insertNextCell works correctly
model.numberOfCells = undefined;
model.cellSizes = undefined;
};

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 };