warp.Volume#
- class warp.Volume(*args, **kwargs)[source]#
-
Methods
__init__(data[, copy])Class representing a sparse grid.
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 active voxel for each pointvoxel_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 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.Returns the metadata associated with this Volume
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.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
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.
- CLOSEST = 0#
Enum value to specify nearest-neighbor interpolation during sampling
- LINEAR = 1#
Enum value to specify trilinear interpolation during sampling
- get_tile_count()[source]#
Return the number of tiles (NanoVDB leaf nodes) of the volume.
- 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
- 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.
- 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
- 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 – The size of each voxel in spatial coordinates.
bg_value – Background value
device – 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 with the given voxel size 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 (array-like) – Lower 3D coordinates of the bounding box in index space or world space, inclusive.
max (array-like) – Upper 3D coordinates of the bounding box in index space or world space, inclusive.
voxel_size (float) – Voxel size of the new volume.
bg_value (float or array-like) – 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 (array-like) – 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:
- classmethod allocate_by_tiles(
- tile_points,
- voxel_size=None,
- bg_value=0.0,
- translation=(0.0, 0.0, 0.0),
- device=None,
- transform=None,
Allocate a new
Volumewith active tiles for each pointtile_points.This function is only supported for 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.
- 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 (float or array-like) – Voxel size(s) of the new volume. Ignored if
transformis given.bg_value (array-like, scalar or None) – 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 (array-like) – Translation between the index and world spaces.
transform (array-like) – Linear transform between the index and world spaces. If
None, deduced fromvoxel_size.device (Device | str | None) – The CUDA device to create the volume on, e.g.
"cuda"or"cuda:0".
- Return type:
- classmethod allocate_by_voxels(
- voxel_points,
- voxel_size=None,
- translation=(0.0, 0.0, 0.0),
- device=None,
- transform=None,
Allocate a new
Volumewith active voxel for each pointvoxel_points.This function creates an index volume, a special kind of volume that does not any store any explicit payload but encodes a linearized index for each active voxel, allowing to lookup and sample data from arbitrary external arrays.
This function is only supported for CUDA devices.
- 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 tile are allowed and will be efficiently deduplicated.voxel_size (float or array-like) – Voxel size(s) of the new volume. Ignored if
transformis given.translation (array-like) – Translation between the index and world spaces.
transform (array-like) – Linear transform between the index and world spaces. If
None, deduced fromvoxel_size.device (Device | str | None) – The CUDA device to create the volume on, e.g.
"cuda"or"cuda:0".
- Raises:
RuntimeError – If the
deviceis not a CUDA device.RuntimeError – If
voxel_pointsis not a contiguous array of the correct type and shape.RuntimeError – If
Volumecreation fails.ValueError – If neither
voxel_sizenortransformis provided.ValueError – If both
voxel_sizeandtransformare provided.
- Return type: