Skip to content

DataArray

Introduction

vtkDataArray is an abstract superclass for data array objects containing numeric data.

Methods

allocate

Resize the array to the requested number of extra tuples (added to the current number of tuples) and preserve data. model.size WILL NOT be modified. This is useful before multiple calls to insertNextTuple() or insertNextTuples().

ArgumentTypeRequiredDescription
extraNumTuplesNumberYesNumber of tuples to allocate memory wise.

computeRange

Compute range of a given array. The array could be composed of tuples and individual component range could be computed as well as magnitude.

js
const array = [x0, y0, z0, x1, y1, z1, ..., xn, yn, zn];
const { min: yMin, max: yMax } = computeRange(array, 1, 3);
const { min: minMagnitude, max: maxMagnitude } = computeRange(array, -1, 3);
ArgumentTypeRequiredDescription
valuesArray[Number]YesArray to go through to extract the range from
componentNumberNo(default: 0) indice to use inside tuple size
numberOfComponentsNumberNo(default: 1) size of the tuple

dataChange

Call this method when the underlying data has changed This method calls modified() For example, when you need to modify chunks of the array, it is faster to get the underlying array with getData(), modify it, and then call dataChange().

deepCopy

Deep copy of another vtkDataArray into this one.

ArgumentTypeRequiredDescription
othervtkDataArrayYes

extend

Method use to decorate a given object (publicAPI+model) with vtkDataArray characteristics.

ArgumentTypeRequiredDescription
publicAPIYesobject on which methods will be bounds (public)
modelYesobject on which data structure will be bounds (protected)
initialValuesobjectNo(default: {}) Must pass a number > 0 for size except if empty: true is also passed or a non-empty typed array for values.

fastComputeRange

Compute range of a given array, it only supports 1D arrays.

ArgumentTypeRequiredDescription
valuesArray[Number]YesArray to go through to extract the range from
offsetNumberYesoffset index to select the desired component in the tuple
numberOfComponentsNumberYessize of tuple in a multi-channel array

findTuple

Convenient method to search the index of the first matching tuple in the array. This is a naïve search, consider using a "locator" instead.

ArgumentTypeRequiredDescription
tupleToSearchArray<Number> or TypedArrayYes
precisionNumberYes(1e-6 by default)

Returns

TypeDescription
Numberthe index of the tuple if found, -1 otherwise.

getComponent

Get the component for a given tupleIdx.

ArgumentTypeRequiredDescription
tupleIdxNumberYes
componentIndexNumberNo(default: 0)

getData

getDataType

Return the name of a typed array

js
const isFloat32 = ('Float32Array' === getDataType(array));
const clone = new macro.TYPED_ARRAYS[getDataType(array)](array.length);
ArgumentTypeRequiredDescription
typedArrayYesto extract its type from

getDataType

Get the data type of this array as a string.

Returns

TypeDescription
String

getElementComponentSize

Get the size, in bytes, of the lowest-level element of an array.

getMaxNorm

Return the max norm of a given vtkDataArray

ArgumentTypeRequiredDescription
dataArrayYesto process

getName

Get the name of the array.

Returns

TypeDescription
String

getNumberOfComponents

Get the dimension (n) of the components.

Returns

TypeDescription
Number

getNumberOfTuples

Get the actual number of complete tuples (a component group) in the array.

Returns

TypeDescription
Number

getNumberOfValues

Get the actual number of values in the array, which is equal to getNumberOfTuples() * getNumberOfComponents().

Returns

TypeDescription
Number

getRange

Get the range of the given component.

ArgumentTypeRequiredDescription
componentIndexNumberYes(default: -1)

getRanges

Returns an array of the ranges for each component of the DataArray. Defaults to computing all the ranges if they aren't already computed.

If the number of components is greater than 1, the last element in the ranges array is the min,max magnitude of the dataset. This is the same as calling getRange(-1).

Passing getRanges(false) will return a clone of the ranges that have already been computed. This is useful when you want to avoid recomputing the ranges, which can be expensive.

ArgumentTypeRequiredDescription
computeRangesbooleanNo(default: true)

Returns

TypeDescription
Array[vtkRange]

getState

Get the state of this array.

Returns

TypeDescription
object

getTuple

Get the tuple at the given index.

For performance reasons, it is advised to pass a 'tupleToFill': const x = [];for (int i = 0; i < N; ++i) { dataArray.getTuple(idx, x); ...instead of:for (int i = 0; i < N; ++i) { const x = dataArray.getTuple(idx);...

ArgumentTypeRequiredDescription
idxNumberYes
tupleToFillArray[Number] or TypedArrayNo(default [])

Returns

TypeDescription
Array[Number] or TypedArray

getTupleLocation

ArgumentTypeRequiredDescription
idxNumberNo(default: 1)

Returns

TypeDescription
Number

getTuples

Get the tuples between fromId (inclusive) and toId (exclusive).

If fromId or toId is negative, it refers to a tuple index from the end of the underlying typedArray. If the range between fromId and toId is invalid, getTuples returns null.

NOTE: Any changes to the returned TypedArray will result in changes to this DataArray's underlying TypedArray.

ArgumentTypeRequiredDescription
fromIdNumberNo(default: 0)
toIdNumberNo(default: publicAPI.getNumberOfTuples())

Returns

TypeDescription
Nullable<TypedArray>

initialize

Reset this array. NOTE: This won't touch the actual memory of the underlying typedArray.

insertNextTuple

Insert the given tuple at the next available slot and return the index of the insertion. NOTE: May resize the data values array. "Safe" version of setTuple.

ArgumentTypeRequiredDescription
tupleArray<Number> or TypedArrayYes

Returns

TypeDescription
NumberIndex of the inserted tuple.

insertNextTuples

Convenience function to insert an array of tuples with insertNextTuple. NOTE: tuples.length must be a multiple of getNumberOfComponents.

ArgumentTypeRequiredDescription
tuplesArray<Number> or TypedArrayYes

Returns

TypeDescription
The index of the last inserted tuple

insertTuple

Insert the given tuple at the given index. NOTE: May resize the data values array. "Safe" version of setTuple.

A typical usage is when vtkDataArray is initialized with initialValues = { size: 0, values: new Uint8Array(1000) }, where an empty but pre-allocated array with 1'000 components is created. The component values can then be inserted with insertTuple() or insertNextTuple() without requiring new memory allocation until the size of 1'000 is exceeded (e.g. after inserting the 250th 4-component tuple).

insertTuple increases the number of tuples (getNumberOfTuples()).

ArgumentTypeRequiredDescription
idxNumberYes
tupleArray<Number> or TypedArrayYes

Returns

TypeDescription
NumberIndex of the inserted tuple

insertTuples

Insert tuples starting at the given idx.

ArgumentTypeRequiredDescription
idxNumberYes
tuplesArray<Number> or TypedArrayYesFlat array of tuples to insert

Returns

TypeDescription
The index of the last inserted tuple

interpolateTuple

Interpolate between the tuples retrieved from source1 and source2 with the resp. indices and set the resulting tuple to the idx of this DataArray.

ArgumentTypeRequiredDescription
idx,intYes
source1,vtkDataArrayYes
source1Idx,intYes
source2,vtkDataArrayYes
source2Idx,intYes
tfloatYes

newClone

Return a clone of this array.

Returns

TypeDescription
vtkDataArray

newInstance

Method use to create a new instance of vtkDataArray

If the provided values is a plain Array and dataType is not explicitly provided, then the vtkDataArray data type will be a Float32Array.

ArgumentTypeRequiredDescription
initialValuesobjectNofor pre-setting some of its content

resize

Resize the array to the requested number of tuples and preserve data. Increasing the array size may allocate extra memory beyond what was requested. Decreasing the array size will trim memory to the requested size. model.size WILL be modified according ot the new size. If requestedNumTuples > getNumberOfTuples(), it creates a new typed array and copies the old values to the new array. If requestedNumTuples < getNumberOfTuples(), the typed array is untouched, only model.size is modified.

ArgumentTypeRequiredDescription
requestedNumTuplesNumberYesFinal expected number of tuples; must be >= 0

Returns

TypeDescription
BooleanTrue if a resize occured, false otherwise

setComponent

Set the component value for a given tupleIdx and componentIndex.

ArgumentTypeRequiredDescription
tupleIdxNumberYes
componentIndexNumberYes
valueNumberYes

setData

Set the data of this array. Optionally pass ´numberOfComponents´ to overwrite this dataArray's numberOfComponents. If this dataArray's numberOfComponents doesn't divide the given array's length, this dataArray's numberOfComponents is set to 1.

ArgumentTypeRequiredDescription
typedArrayArray[Number] or TypedArrayYesThe Array value.
numberOfComponentsNumberNo

setName

Set the name of this array.

ArgumentTypeRequiredDescription
nameStringYes

Returns

TypeDescription
Boolean

setNumberOfComponents

Set the dimension (n) of the components.

ArgumentTypeRequiredDescription
numberOfComponentsNumberYes

setRange

ArgumentTypeRequiredDescription
rangeValuevtkRangeYes
componentIndexNumberYes

setTuple

Set the given tuple at the given index.

ArgumentTypeRequiredDescription
idxNumberYes
tupleArray<Number> or TypedArrayYes

setTuples

Set the given tuples starting at the given index.

ArgumentTypeRequiredDescription
idxNumberYes
tuplesArray<Number> or TypedArrayYes