warp-lang 1.0.2__py3-none-win_amd64.whl → 1.2.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +88 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3693 -3354
- warp/codegen.py +2925 -2792
- warp/config.py +40 -36
- warp/constants.py +49 -45
- warp/context.py +5409 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +381 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -277
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +145 -146
- warp/examples/benchmarks/benchmark_launches.py +293 -295
- warp/examples/browse.py +29 -29
- warp/examples/core/example_dem.py +232 -219
- warp/examples/core/example_fluid.py +291 -267
- warp/examples/core/example_graph_capture.py +142 -126
- warp/examples/core/example_marching_cubes.py +186 -174
- warp/examples/core/example_mesh.py +172 -155
- warp/examples/core/example_mesh_intersect.py +203 -193
- warp/examples/core/example_nvdb.py +174 -170
- warp/examples/core/example_raycast.py +103 -90
- warp/examples/core/example_raymarch.py +197 -178
- warp/examples/core/example_render_opengl.py +183 -141
- warp/examples/core/example_sph.py +403 -387
- warp/examples/core/example_torch.py +219 -181
- warp/examples/core/example_wave.py +261 -248
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +432 -389
- warp/examples/fem/example_burgers.py +262 -0
- warp/examples/fem/example_convection_diffusion.py +180 -168
- warp/examples/fem/example_convection_diffusion_dg.py +217 -209
- warp/examples/fem/example_deformed_geometry.py +175 -159
- warp/examples/fem/example_diffusion.py +199 -173
- warp/examples/fem/example_diffusion_3d.py +178 -152
- warp/examples/fem/example_diffusion_mgpu.py +219 -214
- warp/examples/fem/example_mixed_elasticity.py +242 -222
- warp/examples/fem/example_navier_stokes.py +257 -243
- warp/examples/fem/example_stokes.py +218 -192
- warp/examples/fem/example_stokes_transfer.py +263 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +258 -246
- warp/examples/optim/example_cloth_throw.py +220 -209
- warp/examples/optim/example_diffray.py +564 -536
- warp/examples/optim/example_drone.py +862 -835
- warp/examples/optim/example_inverse_kinematics.py +174 -168
- warp/examples/optim/example_inverse_kinematics_torch.py +183 -169
- warp/examples/optim/example_spring_cage.py +237 -231
- warp/examples/optim/example_trajectory.py +221 -199
- warp/examples/optim/example_walker.py +304 -293
- warp/examples/sim/example_cartpole.py +137 -129
- warp/examples/sim/example_cloth.py +194 -186
- warp/examples/sim/example_granular.py +122 -111
- warp/examples/sim/example_granular_collision_sdf.py +195 -186
- warp/examples/sim/example_jacobian_ik.py +234 -214
- warp/examples/sim/example_particle_chain.py +116 -105
- warp/examples/sim/example_quadruped.py +191 -180
- warp/examples/sim/example_rigid_chain.py +195 -187
- warp/examples/sim/example_rigid_contact.py +187 -177
- warp/examples/sim/example_rigid_force.py +125 -125
- warp/examples/sim/example_rigid_gyroscopic.py +107 -95
- warp/examples/sim/example_rigid_soft_contact.py +132 -122
- warp/examples/sim/example_soft_body.py +188 -177
- warp/fabric.py +337 -335
- warp/fem/__init__.py +61 -27
- warp/fem/cache.py +403 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +16 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +748 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +437 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/nanogrid.py +455 -0
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1684 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +179 -292
- warp/fem/space/basis_space.py +522 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +148 -267
- warp/fem/space/grid_3d_function_space.py +167 -306
- warp/fem/space/hexmesh_function_space.py +253 -352
- warp/fem/space/nanogrid_function_space.py +202 -0
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +261 -369
- warp/fem/space/restriction.py +161 -160
- warp/fem/space/shape/__init__.py +90 -15
- warp/fem/space/shape/cube_shape_function.py +728 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +224 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +153 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1081 -1025
- warp/native/builtin.h +1603 -1560
- warp/native/bvh.cpp +402 -398
- warp/native/bvh.cu +533 -525
- warp/native/bvh.h +430 -429
- warp/native/clang/clang.cpp +496 -464
- warp/native/crt.cpp +42 -32
- warp/native/crt.h +352 -335
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/exports.h +187 -0
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1545 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +292 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +6624 -4782
- warp/native/nanovdb/PNanoVDB.h +3390 -2553
- warp/native/noise.h +850 -850
- warp/native/quat.h +1112 -1085
- warp/native/rand.h +303 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1177 -1133
- warp/native/volume.cpp +529 -297
- warp/native/volume.cu +58 -32
- warp/native/volume.h +960 -538
- warp/native/volume_builder.cu +446 -425
- warp/native/volume_builder.h +34 -19
- warp/native/volume_impl.h +61 -0
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2949 -2828
- warp/native/warp.h +321 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3356 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1917 -1991
- warp/sim/integrator_xpbd.py +3288 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1289 -1227
- warp/stubs.py +2192 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +20 -22
- warp/tests/aux_test_grad_customs.py +21 -23
- warp/tests/aux_test_reference.py +9 -11
- warp/tests/aux_test_reference_reference.py +8 -10
- warp/tests/aux_test_square.py +15 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +237 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +155 -157
- warp/tests/test_arithmetic.py +1088 -1124
- warp/tests/test_array.py +2415 -2326
- warp/tests/test_array_reduce.py +148 -150
- warp/tests/test_async.py +666 -656
- warp/tests/test_atomic.py +139 -141
- warp/tests/test_bool.py +212 -149
- warp/tests/test_builtins_resolution.py +1290 -1292
- warp/tests/test_bvh.py +162 -171
- warp/tests/test_closest_point_edge_edge.py +227 -228
- warp/tests/test_codegen.py +562 -553
- warp/tests/test_compile_consts.py +217 -101
- warp/tests/test_conditional.py +244 -246
- warp/tests/test_copy.py +230 -215
- warp/tests/test_ctypes.py +630 -632
- warp/tests/test_dense.py +65 -67
- warp/tests/test_devices.py +89 -98
- warp/tests/test_dlpack.py +528 -529
- warp/tests/test_examples.py +403 -378
- warp/tests/test_fabricarray.py +952 -955
- warp/tests/test_fast_math.py +60 -54
- warp/tests/test_fem.py +1298 -1278
- warp/tests/test_fp16.py +128 -130
- warp/tests/test_func.py +336 -337
- warp/tests/test_generics.py +596 -571
- warp/tests/test_grad.py +885 -640
- warp/tests/test_grad_customs.py +331 -336
- warp/tests/test_hash_grid.py +208 -164
- warp/tests/test_import.py +37 -39
- warp/tests/test_indexedarray.py +1132 -1134
- warp/tests/test_intersect.py +65 -67
- warp/tests/test_jax.py +305 -307
- warp/tests/test_large.py +169 -164
- warp/tests/test_launch.py +352 -354
- warp/tests/test_lerp.py +217 -261
- warp/tests/test_linear_solvers.py +189 -171
- warp/tests/test_lvalue.py +419 -493
- warp/tests/test_marching_cubes.py +63 -65
- warp/tests/test_mat.py +1799 -1827
- warp/tests/test_mat_lite.py +113 -115
- warp/tests/test_mat_scalar_ops.py +2905 -2889
- warp/tests/test_math.py +124 -193
- warp/tests/test_matmul.py +498 -499
- warp/tests/test_matmul_lite.py +408 -410
- warp/tests/test_mempool.py +186 -190
- warp/tests/test_mesh.py +281 -324
- warp/tests/test_mesh_query_aabb.py +226 -241
- warp/tests/test_mesh_query_point.py +690 -702
- warp/tests/test_mesh_query_ray.py +290 -303
- warp/tests/test_mlp.py +274 -276
- warp/tests/test_model.py +108 -110
- warp/tests/test_module_hashing.py +111 -0
- warp/tests/test_modules_lite.py +36 -39
- warp/tests/test_multigpu.py +161 -163
- warp/tests/test_noise.py +244 -248
- warp/tests/test_operators.py +248 -250
- warp/tests/test_options.py +121 -125
- warp/tests/test_peer.py +131 -137
- warp/tests/test_pinned.py +76 -78
- warp/tests/test_print.py +52 -54
- warp/tests/test_quat.py +2084 -2086
- warp/tests/test_rand.py +324 -288
- warp/tests/test_reload.py +207 -217
- warp/tests/test_rounding.py +177 -179
- warp/tests/test_runlength_encode.py +188 -190
- warp/tests/test_sim_grad.py +241 -0
- warp/tests/test_sim_kinematics.py +89 -97
- warp/tests/test_smoothstep.py +166 -168
- warp/tests/test_snippet.py +303 -266
- warp/tests/test_sparse.py +466 -460
- warp/tests/test_spatial.py +2146 -2148
- warp/tests/test_special_values.py +362 -0
- warp/tests/test_streams.py +484 -473
- warp/tests/test_struct.py +708 -675
- warp/tests/test_tape.py +171 -148
- warp/tests/test_torch.py +741 -743
- warp/tests/test_transient_module.py +85 -87
- warp/tests/test_types.py +554 -659
- warp/tests/test_utils.py +488 -499
- warp/tests/test_vec.py +1262 -1268
- warp/tests/test_vec_lite.py +71 -73
- warp/tests/test_vec_scalar_ops.py +2097 -2099
- warp/tests/test_verify_fp.py +92 -94
- warp/tests/test_volume.py +961 -736
- warp/tests/test_volume_write.py +338 -265
- warp/tests/unittest_serial.py +38 -37
- warp/tests/unittest_suites.py +367 -359
- warp/tests/unittest_utils.py +434 -578
- warp/tests/unused_test_misc.py +69 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +563 -561
- warp/torch.py +321 -295
- warp/types.py +4941 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/METADATA +365 -400
- warp_lang-1.2.0.dist-info/RECORD +359 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp/examples/fem/example_convection_diffusion_dg0.py +0 -194
- warp/native/nanovdb/PNanoVDBWrite.h +0 -295
- warp_lang-1.0.2.dist-info/RECORD +0 -352
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.2.dist-info → warp_lang-1.2.0.dist-info}/top_level.txt +0 -0
warp/tests/test_volume.py
CHANGED
|
@@ -1,736 +1,961 @@
|
|
|
1
|
-
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
-
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
-
# and proprietary rights in and to this software, related documentation
|
|
4
|
-
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
-
# distribution of this software and related documentation without an express
|
|
6
|
-
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
-
|
|
8
|
-
import unittest
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect_eq(wp.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@wp.kernel
|
|
36
|
-
def test_volume_sample_closest_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
37
|
-
tid = wp.tid()
|
|
38
|
-
|
|
39
|
-
p = points[tid]
|
|
40
|
-
i = round(p[0])
|
|
41
|
-
j = round(p[1])
|
|
42
|
-
k = round(p[2])
|
|
43
|
-
expected = i * j * k
|
|
44
|
-
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
45
|
-
expected = 10.0
|
|
46
|
-
|
|
47
|
-
expect_eq(wp.volume_sample_f(volume, p, wp.Volume.CLOSEST), expected)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
expect_near(
|
|
87
|
-
expect_near(grad[
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@wp.kernel
|
|
100
|
-
def
|
|
101
|
-
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
102
|
-
):
|
|
103
|
-
tid = wp.tid()
|
|
104
|
-
p = points[tid]
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
i
|
|
174
|
-
j =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
p =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
tid = wp.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
tid = wp.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
grad_expected = np.array([y, x,
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
)
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
)
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
values_ref = np.
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
wp.
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
)
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
)
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
)
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
)
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
)
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1
|
+
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
+
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
+
# and proprietary rights in and to this software, related documentation
|
|
4
|
+
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
+
# distribution of this software and related documentation without an express
|
|
6
|
+
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
+
|
|
8
|
+
import unittest
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
import warp as wp
|
|
14
|
+
from warp.tests.unittest_utils import *
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# float volume tests
|
|
18
|
+
@wp.kernel
|
|
19
|
+
def test_volume_lookup_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
20
|
+
tid = wp.tid()
|
|
21
|
+
|
|
22
|
+
p = points[tid]
|
|
23
|
+
expected = p[0] * p[1] * p[2]
|
|
24
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
25
|
+
expected = 10.0
|
|
26
|
+
|
|
27
|
+
i = int(p[0])
|
|
28
|
+
j = int(p[1])
|
|
29
|
+
k = int(p[2])
|
|
30
|
+
|
|
31
|
+
expect_eq(wp.volume_lookup_f(volume, i, j, k), expected)
|
|
32
|
+
expect_eq(wp.volume_lookup(volume, i, j, k, dtype=wp.float32), expected)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@wp.kernel
|
|
36
|
+
def test_volume_sample_closest_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
37
|
+
tid = wp.tid()
|
|
38
|
+
|
|
39
|
+
p = points[tid]
|
|
40
|
+
i = round(p[0])
|
|
41
|
+
j = round(p[1])
|
|
42
|
+
k = round(p[2])
|
|
43
|
+
expected = i * j * k
|
|
44
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
45
|
+
expected = 10.0
|
|
46
|
+
|
|
47
|
+
expect_eq(wp.volume_sample_f(volume, p, wp.Volume.CLOSEST), expected)
|
|
48
|
+
expect_eq(wp.volume_sample(volume, p, wp.Volume.CLOSEST, dtype=wp.float32), expected)
|
|
49
|
+
|
|
50
|
+
q = wp.volume_index_to_world(volume, p)
|
|
51
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
52
|
+
expect_eq(p, q_inv)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@wp.kernel
|
|
56
|
+
def test_volume_sample_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
57
|
+
tid = wp.tid()
|
|
58
|
+
|
|
59
|
+
p = points[tid]
|
|
60
|
+
|
|
61
|
+
expected = p[0] * p[1] * p[2]
|
|
62
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
63
|
+
return # not testing against background values
|
|
64
|
+
|
|
65
|
+
expect_near(wp.volume_sample_f(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
66
|
+
expect_near(wp.volume_sample(volume, p, wp.Volume.LINEAR, dtype=wp.float32), expected, 2.0e-4)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@wp.kernel
|
|
70
|
+
def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
71
|
+
tid = wp.tid()
|
|
72
|
+
|
|
73
|
+
p = points[tid]
|
|
74
|
+
|
|
75
|
+
expected_val = p[0] * p[1] * p[2]
|
|
76
|
+
expected_gx = p[1] * p[2]
|
|
77
|
+
expected_gy = p[0] * p[2]
|
|
78
|
+
expected_gz = p[0] * p[1]
|
|
79
|
+
|
|
80
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
81
|
+
return # not testing against background values
|
|
82
|
+
|
|
83
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
84
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
85
|
+
|
|
86
|
+
expect_near(val, expected_val, 2.0e-4)
|
|
87
|
+
expect_near(grad[0], expected_gx, 2.0e-4)
|
|
88
|
+
expect_near(grad[1], expected_gy, 2.0e-4)
|
|
89
|
+
expect_near(grad[2], expected_gz, 2.0e-4)
|
|
90
|
+
|
|
91
|
+
val = wp.volume_sample_grad(volume, p, wp.Volume.LINEAR, grad, dtype=wp.float32)
|
|
92
|
+
|
|
93
|
+
expect_near(val, expected_val, 2.0e-4)
|
|
94
|
+
expect_near(grad[0], expected_gx, 2.0e-4)
|
|
95
|
+
expect_near(grad[1], expected_gy, 2.0e-4)
|
|
96
|
+
expect_near(grad[2], expected_gz, 2.0e-4)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@wp.kernel
|
|
100
|
+
def test_volume_sample_local_f_linear_values(
|
|
101
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
102
|
+
):
|
|
103
|
+
tid = wp.tid()
|
|
104
|
+
p = points[tid]
|
|
105
|
+
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@wp.kernel
|
|
109
|
+
def test_volume_sample_grad_local_f_linear_values(
|
|
110
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
111
|
+
):
|
|
112
|
+
tid = wp.tid()
|
|
113
|
+
p = points[tid]
|
|
114
|
+
|
|
115
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
116
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
117
|
+
if case_num == 0:
|
|
118
|
+
values[tid] = val
|
|
119
|
+
elif case_num == 1:
|
|
120
|
+
values[tid] = grad[0]
|
|
121
|
+
elif case_num == 2:
|
|
122
|
+
values[tid] = grad[1]
|
|
123
|
+
elif case_num == 3:
|
|
124
|
+
values[tid] = grad[2]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@wp.kernel
|
|
128
|
+
def test_volume_sample_world_f_linear_values(
|
|
129
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
130
|
+
):
|
|
131
|
+
tid = wp.tid()
|
|
132
|
+
q = points[tid]
|
|
133
|
+
p = wp.volume_world_to_index(volume, q)
|
|
134
|
+
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@wp.kernel
|
|
138
|
+
def test_volume_sample_grad_world_f_linear_values(
|
|
139
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
140
|
+
):
|
|
141
|
+
tid = wp.tid()
|
|
142
|
+
q = points[tid]
|
|
143
|
+
p = wp.volume_world_to_index(volume, q)
|
|
144
|
+
|
|
145
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
146
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
147
|
+
if case_num == 0:
|
|
148
|
+
values[tid] = val
|
|
149
|
+
elif case_num == 1:
|
|
150
|
+
values[tid] = grad[0]
|
|
151
|
+
elif case_num == 2:
|
|
152
|
+
values[tid] = grad[1]
|
|
153
|
+
elif case_num == 3:
|
|
154
|
+
values[tid] = grad[2]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# vec3f volume tests
|
|
158
|
+
@wp.kernel
|
|
159
|
+
def test_volume_lookup_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
160
|
+
tid = wp.tid()
|
|
161
|
+
|
|
162
|
+
p = points[tid]
|
|
163
|
+
expected = wp.vec3(
|
|
164
|
+
p[0] + 2.0 * p[1] + 3.0 * p[2], 4.0 * p[0] + 5.0 * p[1] + 6.0 * p[2], 7.0 * p[0] + 8.0 * p[1] + 9.0 * p[2]
|
|
165
|
+
)
|
|
166
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
167
|
+
expected = wp.vec3(10.8, -4.13, 10.26)
|
|
168
|
+
|
|
169
|
+
i = int(p[0])
|
|
170
|
+
j = int(p[1])
|
|
171
|
+
k = int(p[2])
|
|
172
|
+
|
|
173
|
+
expect_eq(wp.volume_lookup_v(volume, i, j, k), expected)
|
|
174
|
+
expect_eq(wp.volume_lookup(volume, i, j, k, dtype=wp.vec3), expected)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@wp.kernel
|
|
178
|
+
def test_volume_sample_closest_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
179
|
+
tid = wp.tid()
|
|
180
|
+
|
|
181
|
+
p = points[tid]
|
|
182
|
+
i = round(p[0])
|
|
183
|
+
j = round(p[1])
|
|
184
|
+
k = round(p[2])
|
|
185
|
+
expected = wp.vec3(i + 2.0 * j + 3.0 * k, 4.0 * i + 5.0 * j + 6.0 * k, 7.0 * i + 8.0 * j + 9.0 * k)
|
|
186
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
187
|
+
expected = wp.vec3(10.8, -4.13, 10.26)
|
|
188
|
+
|
|
189
|
+
expect_eq(wp.volume_sample_v(volume, p, wp.Volume.CLOSEST), expected)
|
|
190
|
+
expect_eq(wp.volume_sample(volume, p, wp.Volume.CLOSEST, dtype=wp.vec3), expected)
|
|
191
|
+
|
|
192
|
+
q = wp.volume_index_to_world(volume, p)
|
|
193
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
194
|
+
expect_eq(p, q_inv)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@wp.kernel
|
|
198
|
+
def test_volume_sample_linear_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
199
|
+
tid = wp.tid()
|
|
200
|
+
|
|
201
|
+
p = points[tid]
|
|
202
|
+
|
|
203
|
+
expected = wp.vec3(
|
|
204
|
+
p[0] + 2.0 * p[1] + 3.0 * p[2], 4.0 * p[0] + 5.0 * p[1] + 6.0 * p[2], 7.0 * p[0] + 8.0 * p[1] + 9.0 * p[2]
|
|
205
|
+
)
|
|
206
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
207
|
+
return # not testing against background values
|
|
208
|
+
|
|
209
|
+
expect_near(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
210
|
+
expect_near(wp.volume_sample(volume, p, wp.Volume.LINEAR, dtype=wp.vec3), expected, 2.0e-4)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
@wp.kernel
|
|
214
|
+
def test_volume_sample_grad_linear_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
215
|
+
tid = wp.tid()
|
|
216
|
+
|
|
217
|
+
p = points[tid]
|
|
218
|
+
|
|
219
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
220
|
+
return # not testing against background values
|
|
221
|
+
|
|
222
|
+
expected_val = wp.vec3(
|
|
223
|
+
p[0] + 2.0 * p[1] + 3.0 * p[2], 4.0 * p[0] + 5.0 * p[1] + 6.0 * p[2], 7.0 * p[0] + 8.0 * p[1] + 9.0 * p[2]
|
|
224
|
+
)
|
|
225
|
+
expected_grad = wp.mat33(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
|
|
226
|
+
|
|
227
|
+
grad = wp.mat33(0.0)
|
|
228
|
+
val = wp.volume_sample_grad(volume, p, wp.Volume.LINEAR, grad, dtype=wp.vec3)
|
|
229
|
+
|
|
230
|
+
expect_near(val, expected_val, 2.0e-4)
|
|
231
|
+
expect_near(grad[0], expected_grad[0], 2.0e-4)
|
|
232
|
+
expect_near(grad[1], expected_grad[1], 2.0e-4)
|
|
233
|
+
expect_near(grad[2], expected_grad[2], 2.0e-4)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
@wp.kernel
|
|
237
|
+
def test_volume_sample_local_v_linear_values(
|
|
238
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
239
|
+
):
|
|
240
|
+
tid = wp.tid()
|
|
241
|
+
p = points[tid]
|
|
242
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
243
|
+
values[tid] = wp.dot(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), ones)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
@wp.kernel
|
|
247
|
+
def test_volume_sample_world_v_linear_values(
|
|
248
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
249
|
+
):
|
|
250
|
+
tid = wp.tid()
|
|
251
|
+
q = points[tid]
|
|
252
|
+
p = wp.volume_world_to_index(volume, q)
|
|
253
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
254
|
+
values[tid] = wp.dot(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), ones)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# int32 volume tests
|
|
258
|
+
@wp.kernel
|
|
259
|
+
def test_volume_lookup_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
260
|
+
tid = wp.tid()
|
|
261
|
+
|
|
262
|
+
p = points[tid]
|
|
263
|
+
i = int(p[0])
|
|
264
|
+
j = int(p[1])
|
|
265
|
+
k = int(p[2])
|
|
266
|
+
expected = i * j * k
|
|
267
|
+
if abs(i) > 10 or abs(j) > 10 or abs(k) > 10:
|
|
268
|
+
expected = 10
|
|
269
|
+
|
|
270
|
+
expect_eq(wp.volume_lookup_i(volume, i, j, k), expected)
|
|
271
|
+
expect_eq(wp.volume_lookup(volume, i, j, k, dtype=wp.int32), expected)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
@wp.kernel
|
|
275
|
+
def test_volume_sample_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
276
|
+
tid = wp.tid()
|
|
277
|
+
|
|
278
|
+
p = points[tid]
|
|
279
|
+
i = round(p[0])
|
|
280
|
+
j = round(p[1])
|
|
281
|
+
k = round(p[2])
|
|
282
|
+
expected = int(i * j * k)
|
|
283
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
284
|
+
expected = 10
|
|
285
|
+
|
|
286
|
+
expect_eq(wp.volume_sample_i(volume, p), expected)
|
|
287
|
+
expect_eq(wp.volume_sample(volume, p, wp.Volume.CLOSEST, dtype=wp.int32), expected)
|
|
288
|
+
|
|
289
|
+
q = wp.volume_index_to_world(volume, p)
|
|
290
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
291
|
+
expect_eq(p, q_inv)
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
# Index/world transformation tests
|
|
295
|
+
@wp.kernel
|
|
296
|
+
def test_volume_index_to_world(
|
|
297
|
+
volume: wp.uint64,
|
|
298
|
+
points: wp.array(dtype=wp.vec3),
|
|
299
|
+
values: wp.array(dtype=wp.float32),
|
|
300
|
+
grad_values: wp.array(dtype=wp.vec3),
|
|
301
|
+
):
|
|
302
|
+
tid = wp.tid()
|
|
303
|
+
p = points[tid]
|
|
304
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
305
|
+
values[tid] = wp.dot(wp.volume_index_to_world(volume, p), ones)
|
|
306
|
+
grad_values[tid] = wp.volume_index_to_world_dir(volume, ones)
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
@wp.kernel
|
|
310
|
+
def test_volume_world_to_index(
|
|
311
|
+
volume: wp.uint64,
|
|
312
|
+
points: wp.array(dtype=wp.vec3),
|
|
313
|
+
values: wp.array(dtype=wp.float32),
|
|
314
|
+
grad_values: wp.array(dtype=wp.vec3),
|
|
315
|
+
):
|
|
316
|
+
tid = wp.tid()
|
|
317
|
+
p = points[tid]
|
|
318
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
319
|
+
values[tid] = wp.dot(wp.volume_world_to_index(volume, p), ones)
|
|
320
|
+
grad_values[tid] = wp.volume_world_to_index_dir(volume, ones)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
# Volume write tests
|
|
324
|
+
@wp.kernel
|
|
325
|
+
def test_volume_store_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)):
|
|
326
|
+
tid = wp.tid()
|
|
327
|
+
|
|
328
|
+
p = points[tid]
|
|
329
|
+
i = int(p[0])
|
|
330
|
+
j = int(p[1])
|
|
331
|
+
k = int(p[2])
|
|
332
|
+
|
|
333
|
+
wp.volume_store(volume, i, j, k, float(i + 100 * j + 10000 * k))
|
|
334
|
+
values[tid] = wp.volume_lookup_f(volume, i, j, k)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@wp.kernel
|
|
338
|
+
def test_volume_store_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.vec3)):
|
|
339
|
+
tid = wp.tid()
|
|
340
|
+
|
|
341
|
+
p = points[tid]
|
|
342
|
+
i = int(p[0])
|
|
343
|
+
j = int(p[1])
|
|
344
|
+
k = int(p[2])
|
|
345
|
+
|
|
346
|
+
wp.volume_store(volume, i, j, k, p)
|
|
347
|
+
values[tid] = wp.volume_lookup_v(volume, i, j, k)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
@wp.kernel
|
|
351
|
+
def test_volume_store_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.int32)):
|
|
352
|
+
tid = wp.tid()
|
|
353
|
+
|
|
354
|
+
p = points[tid]
|
|
355
|
+
i = int(p[0])
|
|
356
|
+
j = int(p[1])
|
|
357
|
+
k = int(p[2])
|
|
358
|
+
|
|
359
|
+
wp.volume_store(volume, i, j, k, i + 100 * j + 10000 * k)
|
|
360
|
+
values[tid] = wp.volume_lookup_i(volume, i, j, k)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
devices = get_test_devices()
|
|
364
|
+
rng = np.random.default_rng(101215)
|
|
365
|
+
|
|
366
|
+
# Note about the test grids:
|
|
367
|
+
# test_grid and test_int32_grid
|
|
368
|
+
# active region: [-10,10]^3
|
|
369
|
+
# values: v[i,j,k] = i * j * k
|
|
370
|
+
# voxel size: 0.25
|
|
371
|
+
#
|
|
372
|
+
# test_vec_grid
|
|
373
|
+
# active region: [-10,10]^3
|
|
374
|
+
# values: v[i,j,k] = (i + 2*j + 3*k, 4*i + 5*j + 6*k, 7*i + 8*j + 9*k)
|
|
375
|
+
# voxel size: 0.25
|
|
376
|
+
#
|
|
377
|
+
# torus
|
|
378
|
+
# index to world transformation:
|
|
379
|
+
# [0.1, 0, 0, 0]
|
|
380
|
+
# [0, 0, 0.1, 0]
|
|
381
|
+
# [0, 0.1, 0, 0]
|
|
382
|
+
# [1, 2, 3, 1]
|
|
383
|
+
# (-90 degrees rotation along X)
|
|
384
|
+
# voxel size: 0.1
|
|
385
|
+
volume_paths = {
|
|
386
|
+
"float": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
387
|
+
"int32": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_int32_grid.nvdb")),
|
|
388
|
+
"vec3f": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_vec_grid.nvdb")),
|
|
389
|
+
"index": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_index_grid.nvdb")),
|
|
390
|
+
"torus": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/torus.nvdb")),
|
|
391
|
+
"float_write": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
test_volume_tiles = (
|
|
395
|
+
np.array([[i, j, k] for i in range(-2, 2) for j in range(-2, 2) for k in range(-2, 2)], dtype=np.int32) * 8
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
volumes = {}
|
|
399
|
+
for value_type, path in volume_paths.items():
|
|
400
|
+
volumes[value_type] = {}
|
|
401
|
+
volume_data = open(path, "rb").read()
|
|
402
|
+
for device in devices:
|
|
403
|
+
try:
|
|
404
|
+
volume = wp.Volume.load_from_nvdb(volume_data, device)
|
|
405
|
+
except RuntimeError as e:
|
|
406
|
+
raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}') from e
|
|
407
|
+
|
|
408
|
+
volumes[value_type][device.alias] = volume
|
|
409
|
+
|
|
410
|
+
axis = np.linspace(-1, 1, 3)
|
|
411
|
+
point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def test_volume_sample_linear_f_gradient(test, device):
|
|
415
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
416
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
417
|
+
for test_case in points:
|
|
418
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
419
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
420
|
+
|
|
421
|
+
tape = wp.Tape()
|
|
422
|
+
with tape:
|
|
423
|
+
wp.launch(
|
|
424
|
+
test_volume_sample_local_f_linear_values,
|
|
425
|
+
dim=1,
|
|
426
|
+
inputs=[volumes["float"][device.alias].id, uvws, values],
|
|
427
|
+
device=device,
|
|
428
|
+
)
|
|
429
|
+
tape.backward(values)
|
|
430
|
+
|
|
431
|
+
x, y, z = test_case
|
|
432
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
433
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
434
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
435
|
+
|
|
436
|
+
tape = wp.Tape()
|
|
437
|
+
with tape:
|
|
438
|
+
wp.launch(
|
|
439
|
+
test_volume_sample_world_f_linear_values,
|
|
440
|
+
dim=1,
|
|
441
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values],
|
|
442
|
+
device=device,
|
|
443
|
+
)
|
|
444
|
+
tape.backward(values)
|
|
445
|
+
|
|
446
|
+
x, y, z = test_case
|
|
447
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
448
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
449
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
def test_volume_sample_grad_linear_f_gradient(test, device):
|
|
453
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
454
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
455
|
+
for test_case in points:
|
|
456
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
457
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
458
|
+
|
|
459
|
+
for case_num in range(4):
|
|
460
|
+
tape = wp.Tape()
|
|
461
|
+
with tape:
|
|
462
|
+
wp.launch(
|
|
463
|
+
test_volume_sample_grad_local_f_linear_values,
|
|
464
|
+
dim=1,
|
|
465
|
+
inputs=[volumes["float"][device.alias].id, uvws, values, case_num],
|
|
466
|
+
device=device,
|
|
467
|
+
)
|
|
468
|
+
tape.backward(values)
|
|
469
|
+
|
|
470
|
+
x, y, z = test_case
|
|
471
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
472
|
+
if case_num == 0:
|
|
473
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
474
|
+
elif case_num == 1:
|
|
475
|
+
grad_expected = np.array([0.0, z, y])
|
|
476
|
+
elif case_num == 2:
|
|
477
|
+
grad_expected = np.array([z, 0.0, x])
|
|
478
|
+
elif case_num == 3:
|
|
479
|
+
grad_expected = np.array([y, x, 0.0])
|
|
480
|
+
|
|
481
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
482
|
+
tape.zero()
|
|
483
|
+
|
|
484
|
+
for case_num in range(4):
|
|
485
|
+
tape = wp.Tape()
|
|
486
|
+
with tape:
|
|
487
|
+
wp.launch(
|
|
488
|
+
test_volume_sample_grad_world_f_linear_values,
|
|
489
|
+
dim=1,
|
|
490
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values, case_num],
|
|
491
|
+
device=device,
|
|
492
|
+
)
|
|
493
|
+
tape.backward(values)
|
|
494
|
+
|
|
495
|
+
x, y, z = test_case
|
|
496
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
497
|
+
if case_num == 0:
|
|
498
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
499
|
+
elif case_num == 1:
|
|
500
|
+
grad_expected = np.array([0.0, z, y]) / 0.25
|
|
501
|
+
elif case_num == 2:
|
|
502
|
+
grad_expected = np.array([z, 0.0, x]) / 0.25
|
|
503
|
+
elif case_num == 3:
|
|
504
|
+
grad_expected = np.array([y, x, 0.0]) / 0.25
|
|
505
|
+
|
|
506
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
507
|
+
tape.zero()
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def test_volume_sample_linear_v_gradient(test, device):
|
|
511
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
512
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
513
|
+
for test_case in points:
|
|
514
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
515
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
516
|
+
|
|
517
|
+
tape = wp.Tape()
|
|
518
|
+
with tape:
|
|
519
|
+
wp.launch(
|
|
520
|
+
test_volume_sample_local_v_linear_values,
|
|
521
|
+
dim=1,
|
|
522
|
+
inputs=[volumes["vec3f"][device.alias].id, uvws, values],
|
|
523
|
+
device=device,
|
|
524
|
+
)
|
|
525
|
+
tape.backward(values)
|
|
526
|
+
|
|
527
|
+
grad_expected = np.array([12.0, 15.0, 18.0])
|
|
528
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
529
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
530
|
+
|
|
531
|
+
tape = wp.Tape()
|
|
532
|
+
with tape:
|
|
533
|
+
wp.launch(
|
|
534
|
+
test_volume_sample_world_v_linear_values,
|
|
535
|
+
dim=1,
|
|
536
|
+
inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
|
|
537
|
+
device=device,
|
|
538
|
+
)
|
|
539
|
+
tape.backward(values)
|
|
540
|
+
|
|
541
|
+
grad_expected = np.array([12.0, 15.0, 18.0]) / 0.25
|
|
542
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
543
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def test_volume_transform_gradient(test, device):
|
|
547
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
548
|
+
grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
|
|
549
|
+
test_points = rng.uniform(-10.0, 10.0, size=(10, 3))
|
|
550
|
+
for test_case in test_points:
|
|
551
|
+
points = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
552
|
+
tape = wp.Tape()
|
|
553
|
+
with tape:
|
|
554
|
+
wp.launch(
|
|
555
|
+
test_volume_index_to_world,
|
|
556
|
+
dim=1,
|
|
557
|
+
inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
|
|
558
|
+
device=device,
|
|
559
|
+
)
|
|
560
|
+
tape.backward(values)
|
|
561
|
+
|
|
562
|
+
grad_computed = tape.gradients[points].numpy()
|
|
563
|
+
grad_expected = grad_values.numpy()
|
|
564
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
565
|
+
|
|
566
|
+
grad_computed = tape.gradients[points].numpy()
|
|
567
|
+
grad_expected = grad_values.numpy()
|
|
568
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
def test_volume_store(test, device):
|
|
572
|
+
values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
|
|
573
|
+
points = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
574
|
+
values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
|
|
575
|
+
wp.launch(
|
|
576
|
+
test_volume_store_f,
|
|
577
|
+
dim=len(point_grid),
|
|
578
|
+
inputs=[volumes["float_write"][device.alias].id, points, values],
|
|
579
|
+
device=device,
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
values_res = values.numpy()
|
|
583
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def test_volume_allocation_f(test, device):
|
|
587
|
+
bg_value = -123.0
|
|
588
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
589
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid]), bg_value)
|
|
590
|
+
|
|
591
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
592
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
593
|
+
values = wp.empty(len(points_np), dtype=wp.float32, device=device)
|
|
594
|
+
wp.launch(test_volume_store_f, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
595
|
+
|
|
596
|
+
values_res = values.numpy()
|
|
597
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def test_volume_allocation_v(test, device):
|
|
601
|
+
bg_value = (-1, 2.0, -3)
|
|
602
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
603
|
+
values_ref = np.append(point_grid, [bg_value], axis=0)
|
|
604
|
+
|
|
605
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
606
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
607
|
+
values = wp.empty(len(points_np), dtype=wp.vec3, device=device)
|
|
608
|
+
wp.launch(test_volume_store_v, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
609
|
+
|
|
610
|
+
values_res = values.numpy()
|
|
611
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
def test_volume_allocation_i(test, device):
|
|
615
|
+
bg_value = -123
|
|
616
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
617
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid], dtype=np.int32), bg_value)
|
|
618
|
+
|
|
619
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
620
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
621
|
+
values = wp.empty(len(points_np), dtype=wp.int32, device=device)
|
|
622
|
+
wp.launch(test_volume_store_i, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
623
|
+
|
|
624
|
+
values_res = values.numpy()
|
|
625
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def test_volume_introspection(test, device):
|
|
629
|
+
for volume_names in ("float", "vec3f"):
|
|
630
|
+
with test.subTest(volume_names=volume_names):
|
|
631
|
+
volume = volumes[volume_names][device.alias]
|
|
632
|
+
tiles_actual = volume.get_tiles().numpy()
|
|
633
|
+
tiles_sorted = tiles_actual[np.lexsort(tiles_actual.T[::-1])]
|
|
634
|
+
voxel_size = np.array(volume.get_voxel_size())
|
|
635
|
+
|
|
636
|
+
np.testing.assert_equal(test_volume_tiles, tiles_sorted)
|
|
637
|
+
np.testing.assert_equal([0.25] * 3, voxel_size)
|
|
638
|
+
|
|
639
|
+
voxel_count = volume.get_voxel_count()
|
|
640
|
+
voxels_actual = volume.get_voxels().numpy()
|
|
641
|
+
assert voxel_count == voxels_actual.shape[0]
|
|
642
|
+
|
|
643
|
+
# Voxel coordinates should be unique
|
|
644
|
+
voxels_unique = np.unique(voxels_actual, axis=0)
|
|
645
|
+
assert voxel_count == voxels_unique.shape[0]
|
|
646
|
+
|
|
647
|
+
# Get back tiles from voxels, should match get_tiles()
|
|
648
|
+
voxel_tiles = 8 * (voxels_unique // 8)
|
|
649
|
+
voxel_tiles_sorted = voxel_tiles[np.lexsort(voxel_tiles.T[::-1])]
|
|
650
|
+
voxel_tiles_unique = np.unique(voxel_tiles_sorted, axis=0)
|
|
651
|
+
|
|
652
|
+
np.testing.assert_equal(voxel_tiles_unique, tiles_sorted)
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def test_volume_multiple_grids(test, device):
|
|
656
|
+
volume = volumes["index"][device.alias]
|
|
657
|
+
|
|
658
|
+
volume_2 = volume.load_next_grid()
|
|
659
|
+
|
|
660
|
+
test.assertIsNotNone(volume_2)
|
|
661
|
+
|
|
662
|
+
test.assertNotEqual(volume.id, volume_2.id)
|
|
663
|
+
test.assertNotEqual(volume.get_voxel_count(), volume_2.get_voxel_count())
|
|
664
|
+
|
|
665
|
+
test.assertEqual(volume.get_grid_info().grid_count, volume_2.get_grid_info().grid_count)
|
|
666
|
+
test.assertEqual(volume.get_grid_info().grid_index + 1, volume_2.get_grid_info().grid_index)
|
|
667
|
+
|
|
668
|
+
volume_3 = volume_2.load_next_grid()
|
|
669
|
+
test.assertIsNone(volume_3)
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def test_volume_feature_array(test, device):
|
|
673
|
+
volume = volumes["index"][device.alias]
|
|
674
|
+
|
|
675
|
+
test.assertEqual(volume.get_feature_array_count(), 1)
|
|
676
|
+
|
|
677
|
+
array = volume.feature_array(0, dtype=wp.uint64)
|
|
678
|
+
test.assertEqual(array.device, device)
|
|
679
|
+
test.assertEqual(array.dtype, wp.uint64)
|
|
680
|
+
|
|
681
|
+
# fVDB convention, data starts with array ndim + shape
|
|
682
|
+
np.testing.assert_equal(array.numpy()[0:4], [3, volume.get_voxel_count(), 2, 3])
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
@wp.kernel
|
|
686
|
+
def fill_leaf_values_kernel(volume: wp.uint64, ijk: wp.array2d(dtype=wp.int32), values: wp.array(dtype=Any)):
|
|
687
|
+
tid = wp.tid()
|
|
688
|
+
|
|
689
|
+
i = ijk[tid, 0]
|
|
690
|
+
j = ijk[tid, 1]
|
|
691
|
+
k = ijk[tid, 2]
|
|
692
|
+
|
|
693
|
+
expect_eq(tid, wp.volume_lookup_index(volume, i, j, k))
|
|
694
|
+
|
|
695
|
+
values[tid] = wp.volume_lookup(volume, i, j, k, dtype=values.dtype)
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
@wp.kernel
|
|
699
|
+
def test_volume_sample_index_kernel(
|
|
700
|
+
volume: wp.uint64,
|
|
701
|
+
points: wp.array(dtype=wp.vec3),
|
|
702
|
+
values: wp.array(dtype=Any),
|
|
703
|
+
background: wp.array(dtype=Any),
|
|
704
|
+
sampled_values: wp.array(dtype=Any),
|
|
705
|
+
):
|
|
706
|
+
tid = wp.tid()
|
|
707
|
+
p = points[tid]
|
|
708
|
+
|
|
709
|
+
ref = wp.volume_sample(volume, p, wp.Volume.LINEAR, dtype=values.dtype)
|
|
710
|
+
sampled_values[tid] = wp.volume_sample_index(volume, p, wp.Volume.LINEAR, values, background[0])
|
|
711
|
+
expect_eq(sampled_values[tid], ref)
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
@wp.kernel
|
|
715
|
+
def test_volume_sample_grad_index_kernel(
|
|
716
|
+
volume: wp.uint64,
|
|
717
|
+
points: wp.array(dtype=wp.vec3),
|
|
718
|
+
values: wp.array(dtype=Any),
|
|
719
|
+
background: wp.array(dtype=Any),
|
|
720
|
+
sampled_values: wp.array(dtype=Any),
|
|
721
|
+
sampled_grads: wp.array(dtype=Any),
|
|
722
|
+
):
|
|
723
|
+
tid = wp.tid()
|
|
724
|
+
p = points[tid]
|
|
725
|
+
|
|
726
|
+
ref_grad = sampled_grads.dtype()
|
|
727
|
+
ref = wp.volume_sample_grad(volume, p, wp.Volume.LINEAR, ref_grad, dtype=values.dtype)
|
|
728
|
+
|
|
729
|
+
grad = type(ref_grad)()
|
|
730
|
+
sampled_values[tid] = wp.volume_sample_grad_index(volume, p, wp.Volume.LINEAR, values, background[0], grad)
|
|
731
|
+
expect_eq(sampled_values[tid], ref)
|
|
732
|
+
|
|
733
|
+
expect_eq(grad[0], ref_grad[0])
|
|
734
|
+
expect_eq(grad[1], ref_grad[1])
|
|
735
|
+
expect_eq(grad[2], ref_grad[2])
|
|
736
|
+
sampled_grads[tid] = grad
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def test_volume_sample_index(test, device):
|
|
740
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
741
|
+
points[0:10, 0] += 100.0 # ensure some points are over unallocated voxels
|
|
742
|
+
uvws = wp.array(points, dtype=wp.vec3, device=device)
|
|
743
|
+
|
|
744
|
+
bg_values = {
|
|
745
|
+
"float": 10.0,
|
|
746
|
+
"vec3f": wp.vec3(10.8, -4.13, 10.26),
|
|
747
|
+
}
|
|
748
|
+
grad_types = {
|
|
749
|
+
"float": wp.vec3,
|
|
750
|
+
"vec3f": wp.mat33,
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
for volume_names in ("float", "vec3f"):
|
|
754
|
+
with test.subTest(volume_names=volume_names):
|
|
755
|
+
volume = volumes[volume_names][device.alias]
|
|
756
|
+
|
|
757
|
+
ijk = volume.get_voxels()
|
|
758
|
+
|
|
759
|
+
values = wp.empty(shape=volume.get_voxel_count(), dtype=volume.dtype, device=device, requires_grad=True)
|
|
760
|
+
|
|
761
|
+
vid = wp.uint64(volume.id)
|
|
762
|
+
wp.launch(fill_leaf_values_kernel, dim=values.shape, inputs=[vid, ijk, values], device=device)
|
|
763
|
+
|
|
764
|
+
sampled_values = wp.empty(shape=points.shape[0], dtype=volume.dtype, device=device, requires_grad=True)
|
|
765
|
+
background = wp.array([bg_values[volume_names]], dtype=volume.dtype, device=device, requires_grad=True)
|
|
766
|
+
|
|
767
|
+
tape = wp.Tape()
|
|
768
|
+
with tape:
|
|
769
|
+
wp.launch(
|
|
770
|
+
test_volume_sample_index_kernel,
|
|
771
|
+
dim=points.shape[0],
|
|
772
|
+
inputs=[vid, uvws, values, background, sampled_values],
|
|
773
|
+
device=device,
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
sampled_values.grad.fill_(1.0)
|
|
777
|
+
tape.backward()
|
|
778
|
+
|
|
779
|
+
# test adjoint w.r.t voxel and background value arrays
|
|
780
|
+
# we should have sum(sampled_values) = sum(adj_values * values) + (adj_background * background)
|
|
781
|
+
sum_sampled_values = np.sum(sampled_values.numpy(), axis=0)
|
|
782
|
+
sum_values_adj = np.sum(values.numpy() * values.grad.numpy(), axis=0)
|
|
783
|
+
sum_background_adj = background.numpy()[0] * background.grad.numpy()[0]
|
|
784
|
+
|
|
785
|
+
np.testing.assert_allclose(sum_sampled_values, sum_values_adj + sum_background_adj, rtol=1.0e-3)
|
|
786
|
+
|
|
787
|
+
tape.reset()
|
|
788
|
+
|
|
789
|
+
sampled_grads = wp.empty(
|
|
790
|
+
shape=points.shape[0], dtype=grad_types[volume_names], device=device, requires_grad=True
|
|
791
|
+
)
|
|
792
|
+
|
|
793
|
+
with tape:
|
|
794
|
+
wp.launch(
|
|
795
|
+
test_volume_sample_grad_index_kernel,
|
|
796
|
+
dim=points.shape[0],
|
|
797
|
+
inputs=[vid, uvws, values, background, sampled_values, sampled_grads],
|
|
798
|
+
device=device,
|
|
799
|
+
)
|
|
800
|
+
|
|
801
|
+
sampled_values.grad.fill_(1.0)
|
|
802
|
+
tape.backward()
|
|
803
|
+
|
|
804
|
+
# we should have sum(sampled_values) = sum(adj_values * values) + (adj_background * background)
|
|
805
|
+
sum_sampled_values = np.sum(sampled_values.numpy(), axis=0)
|
|
806
|
+
sum_values_adj = np.sum(values.numpy() * values.grad.numpy(), axis=0)
|
|
807
|
+
sum_background_adj = background.numpy()[0] * background.grad.numpy()[0]
|
|
808
|
+
np.testing.assert_allclose(sum_sampled_values, sum_values_adj + sum_background_adj, rtol=1.0e-3)
|
|
809
|
+
|
|
810
|
+
tape.zero()
|
|
811
|
+
sampled_values.grad.fill_(0.0)
|
|
812
|
+
sampled_grads.grad.fill_(1.0)
|
|
813
|
+
tape.backward()
|
|
814
|
+
|
|
815
|
+
# we should have sum(sampled_grad, axes=(0, -1)) = sum(adj_values * values) + (adj_background * background)
|
|
816
|
+
sum_sampled_grads = np.sum(np.sum(sampled_grads.numpy(), axis=0), axis=-1)
|
|
817
|
+
sum_values_adj = np.sum(values.numpy() * values.grad.numpy(), axis=0)
|
|
818
|
+
sum_background_adj = background.numpy()[0] * background.grad.numpy()[0]
|
|
819
|
+
np.testing.assert_allclose(sum_sampled_grads, sum_values_adj + sum_background_adj, rtol=1.0e-3)
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
def test_volume_from_numpy(test, device):
|
|
823
|
+
# Volume.allocate_from_tiles() is only available with CUDA
|
|
824
|
+
mins = np.array([-3.0, -3.0, -3.0])
|
|
825
|
+
voxel_size = 0.2
|
|
826
|
+
maxs = np.array([3.0, 3.0, 3.0])
|
|
827
|
+
nums = np.ceil((maxs - mins) / (voxel_size)).astype(dtype=int)
|
|
828
|
+
center = np.array([0.0, 0.0, 0.0])
|
|
829
|
+
rad = 2.5
|
|
830
|
+
sphere_sdf_np = np.zeros(tuple(nums))
|
|
831
|
+
for x in range(nums[0]):
|
|
832
|
+
for y in range(nums[1]):
|
|
833
|
+
for z in range(nums[2]):
|
|
834
|
+
pos = mins + voxel_size * np.array([x, y, z])
|
|
835
|
+
dis = np.linalg.norm(pos - center)
|
|
836
|
+
sphere_sdf_np[x, y, z] = dis - rad
|
|
837
|
+
sphere_vdb = wp.Volume.load_from_numpy(sphere_sdf_np, mins, voxel_size, rad + 3.0 * voxel_size, device=device)
|
|
838
|
+
|
|
839
|
+
test.assertNotEqual(sphere_vdb.id, 0)
|
|
840
|
+
|
|
841
|
+
sphere_vdb_array = sphere_vdb.array()
|
|
842
|
+
test.assertEqual(sphere_vdb_array.dtype, wp.uint8)
|
|
843
|
+
test.assertIsNone(sphere_vdb_array.deleter)
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
class TestVolume(unittest.TestCase):
|
|
847
|
+
pass
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
add_function_test(
|
|
851
|
+
TestVolume, "test_volume_sample_linear_f_gradient", test_volume_sample_linear_f_gradient, devices=devices
|
|
852
|
+
)
|
|
853
|
+
add_function_test(
|
|
854
|
+
TestVolume, "test_volume_sample_grad_linear_f_gradient", test_volume_sample_grad_linear_f_gradient, devices=devices
|
|
855
|
+
)
|
|
856
|
+
add_function_test(
|
|
857
|
+
TestVolume, "test_volume_sample_linear_v_gradient", test_volume_sample_linear_v_gradient, devices=devices
|
|
858
|
+
)
|
|
859
|
+
add_function_test(TestVolume, "test_volume_transform_gradient", test_volume_transform_gradient, devices=devices)
|
|
860
|
+
add_function_test(TestVolume, "test_volume_store", test_volume_store, devices=devices)
|
|
861
|
+
add_function_test(
|
|
862
|
+
TestVolume, "test_volume_allocation_f", test_volume_allocation_f, devices=get_selected_cuda_test_devices()
|
|
863
|
+
)
|
|
864
|
+
add_function_test(
|
|
865
|
+
TestVolume, "test_volume_allocation_v", test_volume_allocation_v, devices=get_selected_cuda_test_devices()
|
|
866
|
+
)
|
|
867
|
+
add_function_test(
|
|
868
|
+
TestVolume, "test_volume_allocation_i", test_volume_allocation_i, devices=get_selected_cuda_test_devices()
|
|
869
|
+
)
|
|
870
|
+
add_function_test(TestVolume, "test_volume_introspection", test_volume_introspection, devices=devices)
|
|
871
|
+
add_function_test(
|
|
872
|
+
TestVolume, "test_volume_from_numpy", test_volume_from_numpy, devices=get_selected_cuda_test_devices()
|
|
873
|
+
)
|
|
874
|
+
add_function_test(TestVolume, "test_volume_multiple_grids", test_volume_multiple_grids, devices=devices)
|
|
875
|
+
add_function_test(TestVolume, "test_volume_feature_array", test_volume_feature_array, devices=devices)
|
|
876
|
+
add_function_test(TestVolume, "test_volume_sample_index", test_volume_sample_index, devices=devices)
|
|
877
|
+
|
|
878
|
+
points = {}
|
|
879
|
+
points_jittered = {}
|
|
880
|
+
for device in devices:
|
|
881
|
+
points_jittered_np = point_grid + rng.uniform(-0.5, 0.5, size=point_grid.shape)
|
|
882
|
+
points[device.alias] = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
883
|
+
points_jittered[device.alias] = wp.array(points_jittered_np, dtype=wp.vec3, device=device)
|
|
884
|
+
|
|
885
|
+
add_kernel_test(
|
|
886
|
+
TestVolume,
|
|
887
|
+
test_volume_lookup_f,
|
|
888
|
+
dim=len(point_grid),
|
|
889
|
+
inputs=[volumes["float"][device.alias].id, points[device.alias]],
|
|
890
|
+
devices=[device],
|
|
891
|
+
)
|
|
892
|
+
add_kernel_test(
|
|
893
|
+
TestVolume,
|
|
894
|
+
test_volume_sample_closest_f,
|
|
895
|
+
dim=len(point_grid),
|
|
896
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
897
|
+
devices=[device.alias],
|
|
898
|
+
)
|
|
899
|
+
add_kernel_test(
|
|
900
|
+
TestVolume,
|
|
901
|
+
test_volume_sample_linear_f,
|
|
902
|
+
dim=len(point_grid),
|
|
903
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
904
|
+
devices=[device.alias],
|
|
905
|
+
)
|
|
906
|
+
add_kernel_test(
|
|
907
|
+
TestVolume,
|
|
908
|
+
test_volume_sample_grad_linear_f,
|
|
909
|
+
dim=len(point_grid),
|
|
910
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
911
|
+
devices=[device.alias],
|
|
912
|
+
)
|
|
913
|
+
|
|
914
|
+
add_kernel_test(
|
|
915
|
+
TestVolume,
|
|
916
|
+
test_volume_lookup_v,
|
|
917
|
+
dim=len(point_grid),
|
|
918
|
+
inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
|
|
919
|
+
devices=[device.alias],
|
|
920
|
+
)
|
|
921
|
+
add_kernel_test(
|
|
922
|
+
TestVolume,
|
|
923
|
+
test_volume_sample_closest_v,
|
|
924
|
+
dim=len(point_grid),
|
|
925
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
926
|
+
devices=[device.alias],
|
|
927
|
+
)
|
|
928
|
+
add_kernel_test(
|
|
929
|
+
TestVolume,
|
|
930
|
+
test_volume_sample_linear_v,
|
|
931
|
+
dim=len(point_grid),
|
|
932
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
933
|
+
devices=[device.alias],
|
|
934
|
+
)
|
|
935
|
+
add_kernel_test(
|
|
936
|
+
TestVolume,
|
|
937
|
+
test_volume_sample_grad_linear_v,
|
|
938
|
+
dim=len(point_grid),
|
|
939
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
940
|
+
devices=[device.alias],
|
|
941
|
+
)
|
|
942
|
+
|
|
943
|
+
add_kernel_test(
|
|
944
|
+
TestVolume,
|
|
945
|
+
test_volume_lookup_i,
|
|
946
|
+
dim=len(point_grid),
|
|
947
|
+
inputs=[volumes["int32"][device.alias].id, points[device.alias]],
|
|
948
|
+
devices=[device.alias],
|
|
949
|
+
)
|
|
950
|
+
add_kernel_test(
|
|
951
|
+
TestVolume,
|
|
952
|
+
test_volume_sample_i,
|
|
953
|
+
dim=len(point_grid),
|
|
954
|
+
inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
|
|
955
|
+
devices=[device.alias],
|
|
956
|
+
)
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
if __name__ == "__main__":
|
|
960
|
+
wp.build.clear_kernel_cache()
|
|
961
|
+
unittest.main(verbosity=2)
|