warp.Volume#
- class warp.Volume(*args, **kwargs)[source]#
Sparse volumetric data structure based on NanoVDB for efficient 3D sampling.
Class representing a sparse grid.
- Parameters:
data – Array of bytes representing the volume in NanoVDB format.
copy – Whether the incoming data will be copied or aliased.
Methods
allocate(min, max, voxel_size[, bg_value, ...])Allocate a new Volume based on the bounding box defined by min and max.
allocate_by_tiles(tile_points[, voxel_size, ...])Allocate a new
Volumewith active tiles for each pointtile_points.allocate_by_voxels(voxel_points[, ...])Allocate a new
Volumewith an active voxel for each point invoxel_points.array()Return the raw memory buffer of the
Volumeas an array.feature_array(feature_index[, dtype])Return one the grid's feature data arrays as a Warp array.
Return actual topology statistics from the current grid metadata.
Return the number of supplemental data arrays stored alongside the grid
get_feature_array_info(feature_index)Return the metadata associated to the feature array at
feature_index.Return the metadata associated with this Volume.
Return rebuild input kind and reserved capacity metadata.
Return the number of tiles (NanoVDB leaf nodes) of the volume.
get_tiles([out])Return the integer coordinates of all allocated tiles for this volume.
Return the total number of allocated voxels for this volume
Return the voxel size, i.e, world coordinates of voxel's diagonal vector
get_voxels([out])Return the integer coordinates of all allocated voxels for this volume.
load_from_address(grid_ptr[, buffer_size, ...])Create a new
Volumealiasing an in-memory grid buffer.load_from_numpy(ndarray[, min_world, ...])Create a
Volumeobject from a dense 3D NumPy array.load_from_nvdb(file_or_buffer[, device])Create a
Volumeobject from a serialized NanoVDB file or in-memory buffer.Create a new
Volumefor the next grid that is linked to by thisVolume.rebuild(points[, status, point_mask])Rebuild this volume's topology in place from
points.save_to_nvdb(path[, codec])Serialize the
Volumeinto a NanoVDB (.nvdb) file.Attributes
Enum value to specify nearest-neighbor interpolation during sampling
Enum value to specify trilinear interpolation during sampling
Rebuild was called with invalid arguments or on a non-rebuildable volume.
Rebuild produced more leaf nodes than the volume capacity.
Rebuild produced more lower internal nodes than the volume capacity.
Rebuild completed without setting a status flag.
Rebuild produced more upper internal nodes than the volume capacity.
Rebuild produced more active voxels than the volume capacity.
Type of the Volume's values as a Warp type.
Whether this Volume contains an index grid, that is, a type of grid that does not explicitly store values but associates each voxel to linearized index.
Whether this volume was allocated with persistent capacity for
rebuild().- CLOSEST = 0#
Enum value to specify nearest-neighbor interpolation during sampling
- LINEAR = 1#
Enum value to specify trilinear interpolation during sampling
- class RebuildInfo(
- kind,
- max_voxel_count,
- max_leaf_node_count,
- max_lower_node_count,
- max_upper_node_count,
Capacity metadata for a
Volumeallocated with rebuild support.The counts describe reserved storage, not the currently active topology. Use
Volume.get_active_stats()to query the current grid metadata.Create new instance of RebuildInfo(kind, max_voxel_count, max_leaf_node_count, max_lower_node_count, max_upper_node_count)
- Parameters:
- class ActiveStats(
- voxel_count,
- leaf_node_count,
- lower_node_count,
- upper_node_count,
Active topology statistics from the current
Volumegrid metadata.Create new instance of ActiveStats(voxel_count, leaf_node_count, lower_node_count, upper_node_count)
- get_tile_count()[source]#
Return the number of tiles (NanoVDB leaf nodes) of the volume.
- Return type:
- get_active_stats()[source]#
Return actual topology statistics from the current grid metadata.
For rebuildable volumes, this reports the current active topology rather than the reserved capacity returned by
get_rebuild_info(). For non-rebuildable volumes, these counts match the allocated grid topology.- Returns:
A
Volume.ActiveStatstuple containing the active voxel, leaf, lower, and upper node counts.- Return type:
- get_voxels(out=None)[source]#
Return the integer coordinates of all allocated voxels for this volume.
- class GridInfo(
- name,
- size_in_bytes,
- grid_index,
- grid_count,
- type_str,
- translation,
- transform_matrix,
Grid metadata
Create new instance of GridInfo(name, size_in_bytes, grid_index, grid_count, type_str, translation, transform_matrix)
- Parameters:
- property dtype: type[source]#
Type of the Volume’s values as a Warp type.
If the grid does not contain values (e.g. index grids) or if the NanoVDB type is not representable as a Warp type, returns
None.
- property is_index: bool[source]#
Whether this Volume contains an index grid, that is, a type of grid that does not explicitly store values but associates each voxel to linearized index.
- property is_rebuildable: bool[source]#
Whether this volume was allocated with persistent capacity for
rebuild().
- get_rebuild_info()[source]#
Return rebuild input kind and reserved capacity metadata.
- Returns:
A
Volume.RebuildInfotuple.kindis"tiles"for volumes created byallocate_by_tiles(),"voxels"for volumes created byallocate_by_voxels(), andNonefor volumes that cannot be rebuilt. Capacity fields are zero whenkindisNone.- Return type:
- get_feature_array_count()[source]#
Return the number of supplemental data arrays stored alongside the grid
- Return type:
- class FeatureArrayInfo(name, ptr, value_size, value_count, type_str)[source]#
Metadata for a supplemental data array
Create new instance of FeatureArrayInfo(name, ptr, value_size, value_count, type_str)
- get_feature_array_info(feature_index)[source]#
Return the metadata associated to the feature array at
feature_index.- Parameters:
feature_index (int)
- Return type:
- feature_array(feature_index, dtype=None)[source]#
Return one the grid’s feature data arrays as a Warp array.
- classmethod load_from_nvdb(file_or_buffer, device=None)[source]#
Create a
Volumeobject from a serialized NanoVDB file or in-memory buffer.
- save_to_nvdb(path, codec='none')[source]#
Serialize the
Volumeinto a NanoVDB (.nvdb) file.- Parameters:
path – File path where the
.nvdbfile will be saved.codec (Literal['none', 'zip', 'blosc']) –
Compression codec to use. Defaults to
"none". Available options:"none"- No compression"zip"- ZIP compression"blosc"- BLOSC compression (requiresbloscpackage)
- classmethod load_from_address(grid_ptr, buffer_size=0, device=None)[source]#
Create a new
Volumealiasing an in-memory grid buffer.In contrast to
load_from_nvdb()which should be used to load serialized NanoVDB grids, here the buffer must be uncompressed and must not contain file header information. If the passed address does not contain a NanoVDB grid, the behavior of this function is undefined.- Parameters:
grid_ptr (int) – Integer address of the start of the grid buffer.
buffer_size (int) – Size of the buffer, in bytes. If not provided, the size will be assumed to be that of the single grid starting at
grid_ptr.device – Device of the buffer and of the returned
Volume. If not provided, the current Warp device is assumed.
- Returns:
The newly created
Volume.- Raises:
RuntimeError – If
grid_ptris invalid (null pointer).RuntimeError – If a Warp Volume has already been created for this grid address.
- Return type:
- load_next_grid()[source]#
Create a new
Volumefor the next grid that is linked to by thisVolume.The existence of a next grid is determined by checking if there are more grids in the sequence (based on
grid_indexandgrid_countmetadata) and if there is sufficient buffer space remaining in thisVolume’s in-memory buffer.
- classmethod load_from_numpy(
- ndarray,
- min_world=(0.0, 0.0, 0.0),
- voxel_size=1.0,
- bg_value=0.0,
- device=None,
Create a
Volumeobject from a dense 3D NumPy array.This function is only supported for CUDA devices.
- Parameters:
min_world – The 3D coordinate of the lower corner of the volume.
voxel_size (int | float | list[float] | tuple[float, float, float]) – The size of each voxel in spatial coordinates. Can be a scalar for isotropic voxels or a 3-element sequence
(sx, sy, sz)for anisotropic voxels.bg_value – Background value
device (Device | str | None) – The CUDA device to create the volume on, e.g.:
"cuda"or"cuda:0".ndarray (ndarray)
- Returns:
A
warp.Volumeobject.- Return type:
- classmethod allocate(
- min,
- max,
- voxel_size,
- bg_value=0.0,
- translation=(0.0, 0.0, 0.0),
- points_in_world_space=False,
- device=None,
Allocate a new Volume based on the bounding box defined by min and max.
This function is only supported for CUDA devices.
Allocate a volume that is large enough to contain voxels [min[0], min[1], min[2]] - [max[0], max[1], max[2]], inclusive. If points_in_world_space is true, then min and max are first converted to index space using the given voxel size (per-axis for anisotropic volumes) and translation, and the volume is allocated with those.
The smallest unit of allocation is a dense tile of 8x8x8 voxels, the requested bounding box is rounded up to tiles, and the resulting tiles will be available in the new volume.
- Parameters:
min (list[int]) – Lower 3D coordinates of the bounding box in index space or world space, inclusive.
max (list[int]) – Upper 3D coordinates of the bounding box in index space or world space, inclusive.
voxel_size (int | float | list[float] | tuple[float, float, float]) – Voxel size(s) of the new volume. Can be a scalar for isotropic voxels or a 3-element sequence
(sx, sy, sz)for anisotropic voxels.bg_value – Value of unallocated voxels of the volume, also defines the volume’s type, a
warp.vec3volume is created if this is array-like, otherwise a float volume is createdtranslation – Translation between the index and world spaces.
device (Device | str | None) – The CUDA device to create the volume on, e.g.:
"cuda"or"cuda:0".
- Return type:
- REBUILD_LEAF_CAPACITY_EXCEEDED: ClassVar[int] = 1#
Rebuild produced more leaf nodes than the volume capacity.
- REBUILD_LOWER_CAPACITY_EXCEEDED: ClassVar[int] = 2#
Rebuild produced more lower internal nodes than the volume capacity.
- REBUILD_UPPER_CAPACITY_EXCEEDED: ClassVar[int] = 4#
Rebuild produced more upper internal nodes than the volume capacity.
- REBUILD_VOXEL_CAPACITY_EXCEEDED: ClassVar[int] = 8#
Rebuild produced more active voxels than the volume capacity.
- REBUILD_INVALID_INPUT: ClassVar[int] = 16#
Rebuild was called with invalid arguments or on a non-rebuildable volume.
- classmethod allocate_by_tiles(
- tile_points,
- voxel_size=None,
- bg_value=0.0,
- translation=(0.0, 0.0, 0.0),
- device=None,
- transform=None,
- rebuildable=False,
- max_tiles=None,
- max_lower_nodes=None,
- max_upper_nodes=None,
- status=None,
- point_mask=None,
Allocate a new
Volumewith active tiles for each pointtile_points.This function is supported on CPU and CUDA devices.
The smallest unit of allocation is a dense tile of 8x8x8 voxels. This is the primary method for allocating sparse volumes. It uses an array of points indicating the tiles that must be allocated.
- Example use cases:
tile_pointscan mark tiles directly in index space as in the case this method is called byallocate().tile_pointscan be a list of points used in a simulation that needs to transfer data to a volume.
If
rebuildableisTrueor any rebuild capacity argument is supplied, the returned volume reserves persistent storage and can be updated in place withrebuild(). The rebuild input kind is"tiles", so later rebuilds must provide tile points rather than voxel points. Useget_rebuild_info()to inspect reserved capacities andget_active_stats()to inspect the current active topology.Rebuildable CUDA volumes can be allocated during CUDA graph capture when CUDA memory-pool allocation is supported and enabled. Exact, non-rebuildable volume allocation is not graph-capture safe because determining the exact topology size requires device synchronization. Active-topology queries such as
get_active_stats()must also be performed outside graph capture.- Parameters:
tile_points (
warp.array) – Array of positions that define the tiles to be allocated. The array may use an integer scalar type (2D N-by-3 array ofwarp.int32or 1D array ofwarp.vec3ivalues), indicating index space positions, or a floating point scalar type (2D N-by-3 array ofwarp.float32or 1D array ofwarp.vec3fvalues), indicating world space positions. Repeated points per tile are allowed and will be efficiently deduplicated.voxel_size (int | float | list[float] | tuple[float, float, float] | None) – Voxel size(s) of the new volume. Ignored if
transformis given.bg_value – Value of unallocated voxels of the volume, also defines the volume’s type. An index volume will be created if
bg_valueisNone. Other supported grid types areint,float,vec3f, andvec4f.translation – Translation between the index and world spaces.
transform – Linear transform between the index and world spaces. If
None, deduced fromvoxel_size.rebuildable (bool) – Whether to allocate persistent capacity for rebuilds.
max_tiles (int | None) – Maximum number of NanoVDB leaf nodes reserved for rebuilds. Supplying this makes the volume rebuildable. Each tile can contain up to 512 voxels.
max_lower_nodes (int | None) – Maximum number of lower internal nodes reserved for rebuilds. Supplying this makes the volume rebuildable.
max_upper_nodes (int | None) – Maximum number of upper internal nodes reserved for rebuilds. Supplying this makes the volume rebuildable.
status (array | None) – Optional one-element
uint32array receivingVolume.REBUILD_*status flags from the initial build.Volume.REBUILD_SUCCESSmeans the requested topology fit in the reserved capacity.point_mask (array | None) – Optional
int32array with one entry per point. Points with a zero mask value are ignored.device (Device | str | None) – The device to create the volume on, e.g.
"cpu","cuda", or"cuda:0".
- Raises:
RuntimeError – If
tile_points,point_mask, orstatusis not a contiguous array of the required type and shape.RuntimeError – If
Volumecreation fails.ValueError – If neither
voxel_sizenortransformis provided.ValueError – If both
voxel_sizeandtransformare provided.ValueError – If a rebuild capacity is not positive or does not fit in
uint32.
- Return type:
- classmethod allocate_by_voxels(
- voxel_points,
- voxel_size=None,
- translation=(0.0, 0.0, 0.0),
- device=None,
- transform=None,
- rebuildable=False,
- max_active_voxels=None,
- max_leaf_nodes=None,
- max_lower_nodes=None,
- max_upper_nodes=None,
- status=None,
- point_mask=None,
Allocate a new
Volumewith an active voxel for each point invoxel_points.This function creates an index volume, a special kind of volume that does not store any explicit payload but encodes a linearized index for each active voxel, allowing to lookup and sample data from arbitrary external arrays.
If
rebuildableisTrueor any rebuild capacity argument is supplied, the returned volume reserves persistent storage and can be updated in place withrebuild(). The rebuild input kind is"voxels", so later rebuilds must provide voxel points rather than tile points. Useget_rebuild_info()to inspect reserved capacities andget_active_stats()to inspect the current active topology.Rebuildable CUDA volumes can be allocated during CUDA graph capture when CUDA memory-pool allocation is supported and enabled. Exact, non-rebuildable volume allocation is not graph-capture safe because determining the exact topology size requires device synchronization. Active-topology queries such as
get_active_stats()must also be performed outside graph capture.Unspecified node capacities use conservative sparse-grid defaults. In particular,
max_leaf_nodesdefaults tomax_active_voxelsbecause arbitrary voxel points can place one active voxel in each leaf node. For dense voxel sets, pass tighter node capacities explicitly to reduce memory use. Non-index volumes are allocated and rebuilt by tiles withallocate_by_tiles(), wheremax_tilesdirectly controls leaf capacity.- Parameters:
voxel_points (
warp.array) – Array of positions that define the voxels to be allocated. The array may use an integer scalar type (2D N-by-3 array ofwarp.int32or 1D array ofwarp.vec3ivalues), indicating index space positions, or a floating point scalar type (2D N-by-3 array ofwarp.float32or 1D array ofwarp.vec3fvalues), indicating world space positions. Repeated points per voxel are allowed and will be efficiently deduplicated.voxel_size (int | float | list[float] | tuple[float, float, float] | None) – Voxel size(s) of the new volume. Ignored if
transformis given.translation – Translation between the index and world spaces.
transform – Linear transform between the index and world spaces. If
None, deduced fromvoxel_size.rebuildable (bool) – Whether to allocate persistent capacity for rebuilds.
max_active_voxels (int | None) – Maximum number of active voxels reserved for rebuilds. Supplying this makes the volume rebuildable.
max_leaf_nodes (int | None) – Maximum number of NanoVDB leaf nodes reserved for rebuilds. Supplying this makes the volume rebuildable.
max_lower_nodes (int | None) – Maximum number of lower internal nodes reserved for rebuilds. Supplying this makes the volume rebuildable.
max_upper_nodes (int | None) – Maximum number of upper internal nodes reserved for rebuilds. Supplying this makes the volume rebuildable.
status (array | None) – Optional one-element
uint32array receivingVolume.REBUILD_*status flags from the initial build.Volume.REBUILD_SUCCESSmeans the requested topology fit in the reserved capacity.point_mask (array | None) – Optional
int32array with one entry per point. Points with a zero mask value are ignored.device (Device | str | None) – The device to create the volume on, e.g.
"cpu","cuda", or"cuda:0".
- Raises:
RuntimeError – If
voxel_points,point_mask, orstatusis not a contiguous array of the required type and shape.RuntimeError – If
Volumecreation fails.ValueError – If neither
voxel_sizenortransformis provided.ValueError – If both
voxel_sizeandtransformare provided.ValueError – If a rebuild capacity is not positive or does not fit in
uint32.
- Return type:
- rebuild(points, status=None, point_mask=None)[source]#
Rebuild this volume’s topology in place from
points.The volume must have been created with
rebuildable=Trueor explicit capacity arguments. The input kind must match the allocation method: volumes created byallocate_by_tiles()rebuild from tile points, and volumes created byallocate_by_voxels()rebuild from voxel points.Rebuilds preserve the volume’s transform, background value, grid type, and reserved capacity. Capacity does not grow automatically; pass
statusto detect whether the requested topology fit in the reserved storage.- Parameters:
points (array) – Contiguous array of tile or voxel positions. The array may be a 1D array of
vec3iorvec3fvalues, or a 2DN x 3array ofint32orfloat32values. Integer points are interpreted in index space, and floating-point points are interpreted in world space.status (array | None) – Optional one-element
uint32array receivingVolume.REBUILD_*status flags.Volume.REBUILD_SUCCESSmeans the requested topology fit in the reserved capacity.point_mask (array | None) – Optional
int32array with one entry per point. Points with a zero mask value are ignored.
- Returns:
The
statusarray if one was provided, otherwiseNone.- Raises:
RuntimeError – If the volume is not rebuildable.
RuntimeError – If
points,point_mask, orstatusis not a contiguous array of the required type and shape.
- Return type:
array | None