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 indexes at the given location as a subarray.

Argument Type Required Description
loc Yes

getCellSizes

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.

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

Argument Type Required Description
typedArray TypedArray Yes The typedArray value.

Source

index.d.ts
import { TypedArray } from "../../../types";
import vtkDataArray from "../../Core/DataArray";


/**
*
*/
export interface ICellArrayInitialValues {
empty?: boolean;
numberOfComponents?: number;
}

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;

/**
*
* @param {Boolean} [recompute] Recompute the cell sizes.
*/
getCellSizes(recompute?: boolean): any;

/**
*
* @param {TypedArray} typedArray The typedArray value.
*/
setData(typedArray: TypedArray): void;

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

/**
* 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) {
return extractCellSizes(cellArray).length;
}

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

model.cellSizes = extractCellSizes(model.values);
model.numberOfCells = model.cellSizes.length;
return model.numberOfCells;
};

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

model.cellSizes = extractCellSizes(model.values);
return model.cellSizes;
};

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

/**
* Returns the point indexes at the given location as a subarray.
*/
publicAPI.getCell = (loc) => {
let cellLoc = loc;
const numberOfPoints = model.values[cellLoc++];
return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
};
}

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