warp.volume_voxel_count#
- warp.volume_voxel_count(id: uint64) int32#
Kernel
Python
Return the number of indexable voxels in the volume given by
id.For NanoVDB
OnIndexandOnIndexMaskgrids, this is the active voxel count. ForIndexandIndexMaskgrids and for classical value grids, it is the number of allocated leaf nodes multiplied by 512, because every leaf slot is indexable. When the true count fits inint32, this is the required size of a per-voxelvoxel_dataarray (as used byvolume_sample_index()) and the exclusive upper bound of indices returned byvolume_lookup_index().The result is capped at
2**31 - 1. A larger volume cannot be fully represented by theseint32index APIs: lookup indices may overflow, and the capped count is not sufficient to allocate data for every underlying slot. Not differentiable.- Parameters:
id – The
idof awarp.Volume.- Returns:
The number of indexable voxels, capped at
2**31 - 1.
Example
@wp.kernel def count(vid: wp.uint64, out: wp.array[wp.int32]): out[0] = wp.volume_voxel_count(vid) volume = wp.Volume.load_from_numpy(np.zeros((2, 2, 2), dtype=np.float32), voxel_size=1.0, bg_value=0.0) out = wp.zeros(1, dtype=wp.int32) wp.launch(count, dim=1, inputs=[volume.id], outputs=[out]) print(int(out.numpy()[0]))
512