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().
| Argument | Type | Required | Description |
|---|---|---|---|
extraNumTuples | Number | Yes | Number 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.
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);| Argument | Type | Required | Description |
|---|---|---|---|
values | Array[Number] | Yes | Array to go through to extract the range from |
component | Number | No | (default: 0) indice to use inside tuple size |
numberOfComponents | Number | No | (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.
| Argument | Type | Required | Description |
|---|---|---|---|
other | vtkDataArray | Yes |
extend
Method use to decorate a given object (publicAPI+model) with vtkDataArray 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 | object | No | (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.
| Argument | Type | Required | Description |
|---|---|---|---|
values | Array[Number] | Yes | Array to go through to extract the range from |
offset | Number | Yes | offset index to select the desired component in the tuple |
numberOfComponents | Number | Yes | size 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.
| Argument | Type | Required | Description |
|---|---|---|---|
tupleToSearch | Array<Number> or TypedArray | Yes | |
precision | Number | Yes | (1e-6 by default) |
Returns
| Type | Description |
|---|---|
| Number | the index of the tuple if found, -1 otherwise. |
getComponent
Get the component for a given tupleIdx.
| Argument | Type | Required | Description |
|---|---|---|---|
tupleIdx | Number | Yes | |
componentIndex | Number | No | (default: 0) |
getData
getDataType
Return the name of a typed array
const isFloat32 = ('Float32Array' === getDataType(array));
const clone = new macro.TYPED_ARRAYS[getDataType(array)](array.length);| Argument | Type | Required | Description |
|---|---|---|---|
typedArray | Yes | to extract its type from |
getDataType
Get the data type of this array as a string.
Returns
| Type | Description |
|---|---|
| String |
getElementComponentSize
Get the size, in bytes, of the lowest-level element of an array.
getMaxNorm
Return the max norm of a given vtkDataArray
| Argument | Type | Required | Description |
|---|---|---|---|
dataArray | Yes | to process |
getName
Get the name of the array.
Returns
| Type | Description |
|---|---|
| String |
getNumberOfComponents
Get the dimension (n) of the components.
Returns
| Type | Description |
|---|---|
| Number |
getNumberOfTuples
Get the actual number of complete tuples (a component group) in the array.
Returns
| Type | Description |
|---|---|
| Number |
getNumberOfValues
Get the actual number of values in the array, which is equal to getNumberOfTuples() * getNumberOfComponents().
Returns
| Type | Description |
|---|---|
| Number |
getRange
Get the range of the given component.
| Argument | Type | Required | Description |
|---|---|---|---|
componentIndex | Number | Yes | (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.
| Argument | Type | Required | Description |
|---|---|---|---|
computeRanges | boolean | No | (default: true) |
Returns
| Type | Description |
|---|---|
| Array[vtkRange] |
getState
Get the state of this array.
Returns
| Type | Description |
|---|---|
| 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);...
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | Yes | |
tupleToFill | Array[Number] or TypedArray | No | (default []) |
Returns
| Type | Description |
|---|---|
| Array[Number] or TypedArray |
getTupleLocation
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | No | (default: 1) |
Returns
| Type | Description |
|---|---|
| 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.
| Argument | Type | Required | Description |
|---|---|---|---|
fromId | Number | No | (default: 0) |
toId | Number | No | (default: publicAPI.getNumberOfTuples()) |
Returns
| Type | Description |
|---|---|
| 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.
| Argument | Type | Required | Description |
|---|---|---|---|
tuple | Array<Number> or TypedArray | Yes |
Returns
| Type | Description |
|---|---|
| Number | Index of the inserted tuple. |
insertNextTuples
Convenience function to insert an array of tuples with insertNextTuple. NOTE: tuples.length must be a multiple of getNumberOfComponents.
| Argument | Type | Required | Description |
|---|---|---|---|
tuples | Array<Number> or TypedArray | Yes |
Returns
| Type | Description |
|---|---|
| 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()).
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | Yes | |
tuple | Array<Number> or TypedArray | Yes |
Returns
| Type | Description |
|---|---|
| Number | Index of the inserted tuple |
insertTuples
Insert tuples starting at the given idx.
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | Yes | |
tuples | Array<Number> or TypedArray | Yes | Flat array of tuples to insert |
Returns
| Type | Description |
|---|---|
| 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.
| Argument | Type | Required | Description |
|---|---|---|---|
idx, | int | Yes | |
source1, | vtkDataArray | Yes | |
source1Idx, | int | Yes | |
source2, | vtkDataArray | Yes | |
source2Idx, | int | Yes | |
t | float | Yes |
newClone
Return a clone of this array.
Returns
| Type | Description |
|---|---|
| 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.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | object | No | for 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.
| Argument | Type | Required | Description |
|---|---|---|---|
requestedNumTuples | Number | Yes | Final expected number of tuples; must be >= 0 |
Returns
| Type | Description |
|---|---|
| Boolean | True if a resize occured, false otherwise |
setComponent
Set the component value for a given tupleIdx and componentIndex.
| Argument | Type | Required | Description |
|---|---|---|---|
tupleIdx | Number | Yes | |
componentIndex | Number | Yes | |
value | Number | Yes |
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.
| Argument | Type | Required | Description |
|---|---|---|---|
typedArray | Array[Number] or TypedArray | Yes | The Array value. |
numberOfComponents | Number | No |
setName
Set the name of this array.
| Argument | Type | Required | Description |
|---|---|---|---|
name | String | Yes |
Returns
| Type | Description |
|---|---|
| Boolean |
setNumberOfComponents
Set the dimension (n) of the components.
| Argument | Type | Required | Description |
|---|---|---|---|
numberOfComponents | Number | Yes |
setRange
| Argument | Type | Required | Description |
|---|---|---|---|
rangeValue | vtkRange | Yes | |
componentIndex | Number | Yes |
setTuple
Set the given tuple at the given index.
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | Yes | |
tuple | Array<Number> or TypedArray | Yes |
setTuples
Set the given tuples starting at the given index.
| Argument | Type | Required | Description |
|---|---|---|---|
idx | Number | Yes | |
tuples | Array<Number> or TypedArray | Yes |