warp.volume_lookup_index#

warp.volume_lookup_index(
id: uint64,
i: int32,
j: int32,
k: int32,
) int32#
  • Kernel

  • Python

Return the linear index associated with integer index-space coordinates i, j, k.

On NanoVDB OnIndex and OnIndexMask grids, active voxels have zero-based indices and inactive voxels return -1. On Index and IndexMask grids and on classical value grids, every slot in an allocated leaf has an index regardless of its active mask; coordinates outside allocated leaves return -1. For volumes whose indexable count fits in int32, nonnegative indices lie in [0, volume_voxel_count(id)). Guard against -1 before gathering from a per-voxel array. Not differentiable.

Parameters:
  • id – The id of a warp.Volume.

  • i – Voxel coordinate along the first index-space axis.

  • j – Voxel coordinate along the second index-space axis.

  • k – Voxel coordinate along the third index-space axis.

Returns:

The voxel’s linear index, or -1 when the coordinate is not indexable.

Example

@wp.kernel
def lookup_index(vid: wp.uint64, out: wp.array[wp.int32]):
    out[0] = wp.volume_lookup_index(vid, 1, 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)
out = wp.zeros(1, dtype=wp.int32)
wp.launch(lookup_index, dim=1, inputs=[volume.id], outputs=[out])
print(int(out.numpy()[0]))
1