vtkmodules.numpy_interface.vtk_structured_point_array#

VTKStructuredPointArray — lazy numpy-compatible wrapper for structured points.

This module provides VTKStructuredPointArray and VTKStructuredAxisArray. VTKStructuredPointArray is registered as an override on the vtkStructuredPointArray template so that the coordinate array returned by vtkImageData.points.data and vtkRectilinearGrid.points.data exposes a numpy-compatible surface without materializing the full (N, 3) array.

For a grid with dimensions (nx, ny, nz), only O(nx + ny + nz) storage is needed instead of O(nx * ny * nz * 3). Ufuncs and scalar arithmetic operate per-axis and stay lazy, producing another VTKStructuredPointArray whose backend is built via ConstructBackend. Reductions (sum, min, max, mean) use optimized O(nx+ny+nz) formulas.

VTK uses Fortran ordering where i increases fastest: flat_idx = i + j * nx + k * nx * ny

Module Contents#

Classes#

VTKStructuredAxisArray

A lazy 1D array representing one coordinate component (X, Y, or Z) of a structured point array.

VTKStructuredPointArray

Numpy-compatible mixin for vtkStructuredPointArray template instances.

Functions#

_override_structured_point_numpy

Register an array_function override for VTKStructuredPointArray.

_sp_sum

_sp_min

_sp_max

_sp_mean

_add_template_type_aliases

Add native-type aliases so template[‘float64’] etc. work.

_register_structured_point_overrides

Register VTKStructuredPointArray for all vtkStructuredPointArray template instantiations.

Data#

API#

vtkmodules.numpy_interface.vtk_structured_point_array._STRUCTURED_POINT_OVERRIDE#

None

vtkmodules.numpy_interface.vtk_structured_point_array._override_structured_point_numpy(numpy_function)#

Register an array_function override for VTKStructuredPointArray.

class vtkmodules.numpy_interface.vtk_structured_point_array.VTKStructuredAxisArray(values, axis, dims, dataset=None)#

A lazy 1D array representing one coordinate component (X, Y, or Z) of a structured point array.

For a structured grid with dims (nx, ny, nz), there are only nx unique X values, ny unique Y values, and nz unique Z values. This class stores just the unique values and expands them lazily when needed.

Repeat patterns (Fortran ordering, i fastest):

  • Axis 0 (X): X[i] appears at indices where flat_idx % nx == i

  • Axis 1 (Y): Y[j] appears at indices where (flat_idx // nx) % ny == j

  • Axis 2 (Z): Z[k] appears at indices where flat_idx // (nx * ny) == k

Initialization

Parameters

values : numpy array The unique coordinate values for this axis. axis : int Which axis (0=X, 1=Y, 2=Z). dims : tuple of 3 ints Grid dimensions (nx, ny, nz). dataset : vtkDataObject, optional The owning dataset (kept as weak reference).

property shape#
property dtype#
property ndim#
property size#
__len__()#
__repr__()#
__array__(dtype=None, **kwargs)#

Materialize the full 1D array using Fortran ordering (i fastest).

__getitem__(index)#

Index into the array using Fortran ordering.

__array_ufunc__(ufunc, method, *inputs, **kwargs)#

Handle numpy ufuncs. Unary ufuncs and scalar operations stay lazy.

__add__(other)#
__radd__(other)#
__sub__(other)#
__rsub__(other)#
__mul__(other)#
__rmul__(other)#
__truediv__(other)#
__rtruediv__(other)#
__neg__()#
__pow__(other)#
__rpow__(other)#
class vtkmodules.numpy_interface.vtk_structured_point_array.VTKStructuredPointArray(*args, **kwargs)#

Bases: vtkmodules.numpy_interface._vtk_array_mixin.VTKDataArrayMixin

Numpy-compatible mixin for vtkStructuredPointArray template instances.

Registered as an override for every vtkStructuredPointArray[dtype] instantiation. Every structured-point array returned by VTK (such as vtkImageData.points.data or vtkRectilinearGrid.points.data) is an instance of this class. Ufunc and scalar results also come back as instances of this class, built in-place via ConstructBackend.

Axis coordinates are read through the C++ GetXCoordinates() / GetYCoordinates() / GetZCoordinates() accessors so the wrapper stays in lockstep with the backing array. With an identity direction matrix (the common case), indexing and ufuncs operate per-axis and stay lazy; reductions use O(nx+ny+nz) formulas. With a non-identity direction matrix, operations fall back to a full materialization.

Initialization

classmethod from_axes(axis_arrays, dims=None)#

Build a structured-point array from three 1D axis arrays.

Picks a vtkStructuredPointArray[dtype] instantiation matching the input axes’ dtype, wraps the axes as VTK data arrays, and calls ConstructBackend to set up the lazy backend. The returned array is an instance of VTKStructuredPointArray (via the registered override) and has identity direction matrix.

_get_axis_arrays()#

Get the X, Y, Z coordinate arrays directly from the backend.

Returns a list of 3 numpy arrays [X, Y, Z], or None if the backend has not been constructed yet.

_get_dims()#

Get grid dimensions from axis arrays.

_uses_dir_matrix()#

Check if a non-identity direction matrix is being used.

property dtype#
property nbytes#
_materialize(dtype=None)#

Materialize the full array as a numpy ndarray.

When axis arrays are available and no direction matrix is used, materializes via meshgrid (efficient). Otherwise, uses DeepCopy to an AOS array.

to_numpy(dtype=None)#

Return the full (N, 3) array as a numpy ndarray.

__array__(dtype=None, copy=None)#
__buffer__(flags)#
__getitem__(index)#
__setitem__(key, value)#
__array_ufunc__(ufunc, method, *inputs, **kwargs)#
__array_function__(func, types, args, kwargs)#
__add__(other)#
__radd__(other)#
__sub__(other)#
__rsub__(other)#
__mul__(other)#
__rmul__(other)#
__truediv__(other)#
__rtruediv__(other)#
__neg__()#
__pos__()#
__abs__()#
__lt__(other)#
__le__(other)#
__eq__(other)#
__ne__(other)#
__ge__(other)#
__gt__(other)#
__iter__()#
__repr__()#
__str__()#
vtkmodules.numpy_interface.vtk_structured_point_array._sp_sum(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_structured_point_array._sp_min(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_structured_point_array._sp_max(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_structured_point_array._sp_mean(a, axis=None, **kwargs)#
vtkmodules.numpy_interface.vtk_structured_point_array._VTKTYPE_TO_MANGLING#

None

vtkmodules.numpy_interface.vtk_structured_point_array._add_template_type_aliases(template_cls, prefix)#

Add native-type aliases so template[‘float64’] etc. work.

Templates that only have vtkType-based instantiations (e.g. vtkTypeFloat64) need aliases under the native IA64 mangled names (e.g. _IdE for double) so that the Python template subscript notation template[‘float64’] can find them.

vtkmodules.numpy_interface.vtk_structured_point_array._register_structured_point_overrides()#

Register VTKStructuredPointArray for all vtkStructuredPointArray template instantiations.