Skip to content

Commit 5cd13c0

Browse files
committed
Updated resources data path and added additional tests to ensure volume sampling is normalised.
1 parent 1369044 commit 5cd13c0

File tree

2 files changed

+82
-17
lines changed

2 files changed

+82
-17
lines changed

resources/data

Submodule data updated 49 files

src/render/tests/test_mesh.py

Lines changed: 81 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,35 +1337,100 @@ def test35_mesh_vcalls(variants_vec_rgb):
13371337

13381338

13391339
@fresolver_append_path
1340-
def test36_volume_sampling(variants_all_rgb):
1340+
def test36_correct_volume(variants_all_rgb):
1341+
objects_to_test = ["obj/cbox_smallbox.obj", "ply/bunny_watertight.ply"]
1342+
object_volumes = [4559445.0373, 1.6012674570083618]
1343+
for mesh_path, mesh_volume in zip(objects_to_test, object_volumes):
1344+
shape = mi.load_dict({
1345+
"type": "obj" if mesh_path.endswith("obj") else "ply",
1346+
"filename": f"resources/data/tests/{mesh_path}",
1347+
})
1348+
assert dr.allclose(shape.volume(), mesh_volume)
1349+
1350+
1351+
@pytest.mark.slow
1352+
@fresolver_append_path
1353+
def test37_volume_position_sampling_normalisation(variants_vec_rgb):
13411354
shape = mi.load_dict({
13421355
"type": "obj",
13431356
"filename": f"resources/data/tests/obj/cbox_smallbox.obj",
13441357
})
13451358

1359+
iter_count = 32
1360+
13461361
sampler = mi.load_dict({
1347-
"type": "independent",
1348-
"sample_count": 1
1362+
"type": "multijitter",
1363+
"sample_count": iter_count * 2
13491364
})
13501365

1351-
sampler.seed(0, 0 if "scalar" in variants_all_rgb else 256)
1352-
time = mi.Float(0.0)
1366+
sampler.seed(0, 131072)
13531367
active = mi.Mask(True)
1354-
sample = sampler.next_3d()
13551368

1356-
ps = shape.sample_position_volume(time, sample, active)
1369+
resulting_vol_pdfs = 0.0
1370+
1371+
for iter_num in range(iter_count):
1372+
ps = shape.sample_position_volume(mi.Float(0.0), sampler.next_3d(), active)
1373+
resulting_vol_pdfs = resulting_vol_pdfs + dr.select(ps.pdf != 0.0, shape.bbox().volume(), 0.0)
1374+
1375+
sum_pdf = dr.mean(resulting_vol_pdfs/iter_count, axis=None, mode="evaluated")
1376+
1377+
assert(dr.allclose(sum_pdf, shape.volume(), atol=32/(32*131072)**0.5))
1378+
1379+
1380+
@pytest.mark.slow
1381+
@fresolver_append_path
1382+
def test38_volume_direction_sampling_normalisation(variants_vec_rgb):
1383+
shape = mi.load_dict({
1384+
"type": "ply",
1385+
"filename": f"resources/data/tests/ply/bunny_watertight.ply",
1386+
})
1387+
1388+
iter_count = 32
1389+
1390+
for iter_index in range(33):
1391+
sampler = mi.load_dict({
1392+
"type": "multijitter",
1393+
"sample_count": iter_count * 2
1394+
})
1395+
1396+
sampler_offset = mi.load_dict({
1397+
"type": "multijitter",
1398+
"sample_count": 36
1399+
})
1400+
1401+
sampler.seed(iter_index, 131072)
1402+
sampler_offset.seed(iter_index + 64, 1)
1403+
active = mi.Mask(True)
1404+
1405+
bsphere = shape.bbox().bounding_sphere()
13571406

1358-
assert dr.allclose(dr.select(ps.pdf > 0.0, dr.rcp(shape.volume()), 0.0), ps.pdf)
1359-
assert dr.allclose(shape.pdf_position_volume(ps, active), ps.pdf)
1407+
resulting_line_pdfs = 0.0
13601408

1361-
bbox_center = mi.PositionSample3f()
1362-
bbox_center.time = time
1363-
bbox_center.p = shape.bbox().center()
1364-
bbox_center.n = mi.Vector3f([1.0, 0.0, 0.0])
1409+
if iter_index == 0:
1410+
ray_offset = mi.Vector3f(0.0, 0.0, 0.0)
1411+
else:
1412+
ray_offset = 4 * mi.warp.cube_to_uniform_sphere(sampler_offset.next_3d()) * bsphere.radius
1413+
for iter_num in range(iter_count):
1414+
ray = mi.Ray3f()
1415+
ray.o = bsphere.center + ray_offset
1416+
ray.d = mi.warp.square_to_uniform_sphere(sampler.next_2d())
1417+
pdf = mi.warp.square_to_uniform_sphere_pdf(ray.d)
1418+
1419+
test_si = dr.zeros(mi.SurfaceInteraction3f)
1420+
test_si.p = ray.o
1421+
test_si.time = 0.0
13651422

1366-
assert dr.allclose(shape.pdf_position_volume(bbox_center, active), dr.rcp(shape.volume()))
1367-
bbox_center.p = shape.bbox().center() + 5*dr.norm(shape.bbox().extents())*(shape.bbox().max - shape.bbox().center())
1368-
assert dr.allclose(shape.pdf_position_volume(bbox_center, active), 0.0)
13691423

1424+
if "scalar" in variants_vec_rgb:
1425+
test_ds = mi.DirectionSample3f()
1426+
else:
1427+
test_ds = dr.zeros(mi.DirectionSample3f)
1428+
test_ds.p = ray.o + bsphere.radius * 2 * ray.d
1429+
test_ds.time = 0.0
1430+
test_ds.d = ray.d
13701431

1432+
underlying_pdf = shape.pdf_direction_volume(test_si, test_ds, active)
1433+
resulting_line_pdfs = resulting_line_pdfs + (underlying_pdf / pdf)
13711434

1435+
sum_pdf = dr.mean(resulting_line_pdfs / iter_count, axis=None, mode="evaluated")
1436+
assert(dr.allclose(sum_pdf, 1.0, atol=32/(32*131072)**0.5))

0 commit comments

Comments
 (0)