Skip to content

Commit

Permalink
Merge branch 'GH-306' into 'main'
Browse files Browse the repository at this point in the history
Bugfix for 3D volume initialization (load_from_numpy)

Closes GH-306

See merge request omniverse/warp!716
  • Loading branch information
shi-eric committed Sep 4, 2024
2 parents 74b53df + 8362840 commit 8b8932c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 30 additions & 0 deletions warp/tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,33 @@ def test_volume_from_numpy(test, device):
test.assertIsNone(sphere_vdb_array.deleter)


def test_volume_from_numpy_3d(test, device):
# Volume.allocate_from_tiles() is only available with CUDA
mins = np.array([-3.0, -3.0, -3.0])
voxel_size = 0.2
maxs = np.array([3.0, 3.0, 3.0])
nums = np.ceil((maxs - mins) / (voxel_size)).astype(dtype=int)
centers = np.array([[-1.0, -1.0, -1.0], [0.0, 0.0, 0.0], [1.0, 1.0, 1.0]])
rad = 2.5
sphere_sdf_np = np.zeros(tuple(nums) + (3,))
for x in range(nums[0]):
for y in range(nums[1]):
for z in range(nums[2]):
for k in range(3):
pos = mins + voxel_size * np.array([x, y, z])
dis = np.linalg.norm(pos - centers[k])
sphere_sdf_np[x, y, z, k] = dis - rad
sphere_vdb = wp.Volume.load_from_numpy(
sphere_sdf_np, mins, voxel_size, (rad + 3.0 * voxel_size,) * 3, device=device
)

test.assertNotEqual(sphere_vdb.id, 0)

sphere_vdb_array = sphere_vdb.array()
test.assertEqual(sphere_vdb_array.dtype, wp.uint8)
test.assertIsNone(sphere_vdb_array.deleter)


def test_volume_aniso_transform(test, device):
# XY-rotation + z scale
transform = [
Expand Down Expand Up @@ -894,6 +921,9 @@ def test_volume_new_del(self):
add_function_test(
TestVolume, "test_volume_from_numpy", test_volume_from_numpy, devices=get_selected_cuda_test_devices()
)
add_function_test(
TestVolume, "test_volume_from_numpy_3d", test_volume_from_numpy_3d, devices=get_selected_cuda_test_devices()
)
add_function_test(
TestVolume, "test_volume_aniso_transform", test_volume_aniso_transform, devices=get_selected_cuda_test_devices()
)
Expand Down
5 changes: 3 additions & 2 deletions warp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3541,8 +3541,9 @@ def load_from_numpy(
)
if hasattr(bg_value, "__len__"):
# vec3, assuming the numpy array is 4D
padded_array = np.array((target_shape[0], target_shape[1], target_shape[2], 3), dtype=np.single)
padded_array[:, :, :, :] = np.array(bg_value)
padded_array = np.full(
shape=(target_shape[0], target_shape[1], target_shape[2], 3), fill_value=bg_value, dtype=np.single
)
padded_array[0 : ndarray.shape[0], 0 : ndarray.shape[1], 0 : ndarray.shape[2], :] = ndarray
else:
padded_amount = (
Expand Down

0 comments on commit 8b8932c

Please sign in to comment.