vtkmodules.numpy_interface.vtk_implicit_array#
Notes#
Because AOS overrides are registered on concrete types (vtkFloatArray,
vtkAOSDataArrayTemplate[float32], etc.) and SOA overrides on
vtkSOADataArrayTemplate[...], those always take precedence over this
vtkDataArray-level fallback.
VTKImplicitArray — fallback numpy-compatible mixin for implicit VTK arrays.
VTK implicit arrays (vtkImplicitArrayFindNearestBaseClass resolves it to vtkDataArray — the nearest wrapped
ancestor.
This module registers a fallback mixin on vtkDataArray so that any
data array type that does not have a more-specific override (AOS, SOA, or a
dedicated implicit-array override) still gets a working numpy interface.
The mixin materialises values by deep-copying to an AOS array on first access
and caches the result. A ModifiedEvent observer invalidates the cache so
that re-reads after the underlying data changes produce correct results.
Module Contents#
Classes#
Fallback numpy-compatible mixin for implicit/unknown VTK data arrays. |
Functions#
Register VTKImplicitArray as override on vtkDataArray. |
Data#
API#
- vtkmodules.numpy_interface.vtk_implicit_array._UNINITIALIZED#
‘object(…)’
- class vtkmodules.numpy_interface.vtk_implicit_array.VTKImplicitArray(*args, **kwargs)#
Bases:
vtkmodules.numpy_interface._vtk_array_mixin.VTKDataArrayMixinFallback numpy-compatible mixin for implicit/unknown VTK data arrays.
Materialises the array to a contiguous AOS copy (via
DeepCopy) on first numpy access and caches the result. The cache is invalidated when VTK firesModifiedEventon the array.This mixin is automatically applied to any
vtkDataArraysubclass that does not already have a more specific override (AOS or SOA).Properties
shape : tuple of int
(ntuples,)for 1-component,(ntuples, ncomps)otherwise. dtype : numpy.dtype The element data type. dataset : vtkDataSet or None The owning VTK dataset, when the array is attached to one. association : int or None The attribute association (POINT, CELL, etc.).Examples
Implicit arrays from VTK are automatically wrapped::
implicit_arr = some_filter.GetOutput().GetPointData().GetArray(0) print(np.sum(implicit_arr)) # materialises once, then cached
See Also
VTKAOSArray : Mixin for array-of-structures VTK arrays (zero-copy). VTKSOAArray : Mixin for structure-of-arrays VTK arrays (zero-copy).
Initialization
- _materialise()#
Deep-copy this array into a contiguous AOS numpy array.
- property _array_view#
- _setup_observer()#
Invalidate the cached numpy array when the VTK array is modified.
- property dtype#
- property nbytes#
- __buffer__(flags)#
Expose the materialised AOS copy via the buffer protocol.
This allows
numpy.frombuffer(implicit_arr)andvtk_to_numpy(implicit_arr)to work transparently.
- __array__(dtype=None, copy=None)#
- __array_ufunc__(ufunc, method, *inputs, **kwargs)#
- __array_function__(func, types, args, kwargs)#
- __getitem__(index)#
- __setitem__(index, value)#
- _binop(other, op)#
- _rbinop(other, op)#
- __add__(other)#
- __radd__(other)#
- __sub__(other)#
- __rsub__(other)#
- __mul__(other)#
- __rmul__(other)#
- __truediv__(other)#
- __rtruediv__(other)#
- __floordiv__(other)#
- __rfloordiv__(other)#
- __pow__(other)#
- __rpow__(other)#
- __mod__(other)#
- __rmod__(other)#
- __lt__(other)#
- __le__(other)#
- __eq__(other)#
- __ne__(other)#
- __ge__(other)#
- __gt__(other)#
- __neg__()#
- __abs__()#
- __iter__()#
- __repr__()#
- __str__()#
- vtkmodules.numpy_interface.vtk_implicit_array._register_implicit_override()#
Register VTKImplicitArray as override on vtkDataArray.
This is a fallback: any array type that already has a more-specific override (AOS on vtkFloatArray, SOA on vtkSOADataArrayTemplate, etc.) is unaffected. Only types whose nearest wrapped ancestor is vtkDataArray will use this mixin.