warp.volume_sample_index#
- warp.volume_sample_index( ) Any#
Kernel
Differentiable
Sample the volume given by
idat the index-space pointuvw, reading voxel values from a separatevoxel_dataarray.On NanoVDB
OnIndexandOnIndexMaskgrids, each active voxel maps to a linear index intovoxel_dataandbackgroundsupplies inactive voxels. OnIndexandIndexMaskgrids and on classical value grids, every slot in an allocated leaf maps tovoxel_dataregardless of its active mask;backgroundis used outside allocated leaves. This lets several fields share one topology. Seewarp.Volume.allocate_by_voxels()andvolume_lookup_index().uvwis in index space (voxel coordinates) and may be fractional. Sampling modes and boundary conventions matchvolume_sample(); useCLOSESTfor integer data. For floating-point scalar and vector data,LINEARis differentiable with respect touvw,voxel_data, andbackground. See the Volume sampling user-guide examples.- Parameters:
id – The
idof awarp.Volumeproviding the topology and voxel indices.uvw – Sampling location in index space (voxel coordinates); may be fractional.
sampling_mode –
warp.Volume.CLOSESTorwarp.Volume.LINEAR; useCLOSESTfor integer data.voxel_data – Per-voxel values indexed by each voxel’s linear index. For volumes whose indexable count fits in
int32, must hold at leastvolume_voxel_count()entries.warp.Volume.get_voxel_count()returns a host-side capacity that is safe for allocation but may exceed the live indexable count for rebuildable volumes. The array’s dtype must matchbackground.background – Value used for inactive voxels on
OnIndexandOnIndexMaskgrids and outside allocated leaves onIndexandIndexMaskgrids and classical value grids; its dtype must matchvoxel_data.
- Returns:
The sampled value, of the same dtype as
voxel_data.
Example
@wp.kernel def fill(vid: wp.uint64, d: wp.array[wp.float32]): i, j, k = wp.tid() idx = wp.volume_lookup_index(vid, i, j, k) if idx >= 0: d[idx] = wp.float32(i) * 10.0 @wp.kernel def sample(vid: wp.uint64, d: wp.array[wp.float32], out: wp.array[wp.float32]): out[0] = wp.volume_sample_index(vid, wp.vec3(0.5, 0.0, 0.0), wp.Volume.LINEAR, d, 0.0) voxels = wp.array([[0, 0, 0], [1, 0, 0]], dtype=wp.vec3i) volume = wp.Volume.allocate_by_voxels(voxels, voxel_size=1.0) data = wp.zeros(volume.get_voxel_count(), dtype=wp.float32) out = wp.zeros(1, dtype=wp.float32) wp.launch(fill, dim=(2, 1, 1), inputs=[volume.id, data]) wp.launch(sample, dim=1, inputs=[volume.id, data], outputs=[out]) print(round(float(out.numpy()[0]), 1))
5.0