diff options
author | Stan Seibert <stan@mtrr.org> | 2012-01-19 14:55:31 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
commit | 55921fc3012c547004f82b8a18d856bfa56a108e (patch) | |
tree | 10c52158786deb9d2b76c69c69f29814763badec | |
parent | 14309ab8618a80c7f67c7d80d43bbb4779f0bb2f (diff) | |
download | chroma-55921fc3012c547004f82b8a18d856bfa56a108e.tar.gz chroma-55921fc3012c547004f82b8a18d856bfa56a108e.tar.bz2 chroma-55921fc3012c547004f82b8a18d856bfa56a108e.zip |
Simple BVH construction passing the "smoke test"
-rw-r--r-- | chroma/bvh/simple.py | 11 | ||||
-rw-r--r-- | test/test_bvh_simple.py | 19 |
2 files changed, 22 insertions, 8 deletions
diff --git a/chroma/bvh/simple.py b/chroma/bvh/simple.py index 6c0e02b..6ce45e7 100644 --- a/chroma/bvh/simple.py +++ b/chroma/bvh/simple.py @@ -7,9 +7,10 @@ def make_simple_bvh(mesh, degree): world_coords, leaf_nodes, morton_codes = \ create_leaf_nodes(mesh, round_to_multiple=degree) - # rearrange in morton order + # rearrange in morton order. NOTE: morton_codes can be shorter than + # leaf_nodes if dummy padding nodes were added at the end! argsort = morton_codes.argsort() - leaf_nodes = leaf_nodes[argsort] + leaf_nodes[:len(argsort)] = leaf_nodes[argsort] assert len(leaf_nodes) % degree == 0 # Create parent layers @@ -23,9 +24,7 @@ def make_simple_bvh(mesh, degree): # How many nodes total? nodes, layer_bounds = concatenate_layers(layers) - for i, (layer_start, layer_end) in enumerate(zip(layer_bounds[:-1], - layer_bounds[1:])): - print i, node_area(nodes[layer_start:layer_end]) * world_coords.world_scale**2 - + return BVH(degree, world_coords, nodes, layer_bounds[:-1]) + diff --git a/test/test_bvh_simple.py b/test/test_bvh_simple.py index 20c0df5..9c0276e 100644 --- a/test/test_bvh_simple.py +++ b/test/test_bvh_simple.py @@ -1,14 +1,29 @@ import pycuda.autoinit import unittest from chroma.bvh import make_simple_bvh, BVH +from chroma.bvh.bvh import node_area import chroma.models import numpy as np #from numpy.testing import assert_array_max_ulp, assert_array_equal, \ # assert_approx_equal -def test_simple_bvh(): +def build_simple_bvh(degree): mesh = chroma.models.lionsolid() - bvh = make_simple_bvh(mesh, degree=2) + bvh = make_simple_bvh(mesh, degree) + + nodes = bvh.nodes + layer_bounds = np.append(bvh.layer_offsets, len(nodes)) + world_coords = bvh.world_coords + + for i, (layer_start, layer_end) in enumerate(zip(layer_bounds[:-1], + layer_bounds[1:])): + print i, node_area(nodes[layer_start:layer_end]) * world_coords.world_scale**2 + + assert isinstance(bvh, BVH) +def test_simple(): + yield build_simple_bvh, 2 + yield build_simple_bvh, 3 + yield build_simple_bvh, 4 |