summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chroma/bvh/bvh.py14
-rw-r--r--chroma/bvh/grid.py4
-rw-r--r--chroma/bvh/simple.py2
3 files changed, 12 insertions, 8 deletions
diff --git a/chroma/bvh/bvh.py b/chroma/bvh/bvh.py
index e8c128b..1c26088 100644
--- a/chroma/bvh/bvh.py
+++ b/chroma/bvh/bvh.py
@@ -196,8 +196,12 @@ class BVH(object):
'''Returns the number of nodes in this BVH'''
return len(self.nodes)
-def node_area(nodes):
- '''Returns the area of a list of nodes in fixed point units.'''
+def node_areas(nodes):
+ '''Returns the areas of each node in an array of nodes in fixed point units.
+
+ ``nodes``: ndarray(dtype=uint4)
+ array of packed BVH nodes
+ '''
unpacked = unpack_nodes(nodes)
delta = np.empty(shape=len(nodes),
dtype=[('x', float), ('y', float), ('z', float)])
@@ -207,7 +211,7 @@ def node_area(nodes):
half_area = delta['x']*delta['y'] + delta['y']*delta['z'] \
+ delta['z']*delta['x']
- return 2.0 * half_area.sum()
+ return 2.0 * half_area
class BVHLayerSlice(object):
'''A single layer in a bounding volume hierarchy represented as a slice
@@ -232,9 +236,9 @@ class BVHLayerSlice(object):
def area_fixed(self):
'''Return the surface area of all the nodes in this layer in
fixed point units.'''
- return node_area(self.nodes)
+ return node_areas(self.nodes).sum()
def area(self):
'''Return the surface area of all the nodes in this layer in world
units.'''
- return self.area_fixed() * self.world_coords.world_scale**2
+ return self.area_fixed().sum() * self.world_coords.world_scale**2
diff --git a/chroma/bvh/grid.py b/chroma/bvh/grid.py
index 0b36a2f..5392976 100644
--- a/chroma/bvh/grid.py
+++ b/chroma/bvh/grid.py
@@ -1,4 +1,4 @@
-from chroma.bvh.bvh import BVH, node_area
+from chroma.bvh.bvh import BVH, node_areas
from chroma.gpu.bvh import create_leaf_nodes
def make_recursive_grid_bvh(mesh, bits=11):
@@ -23,6 +23,6 @@ def make_recursive_grid_bvh(mesh, bits=11):
morton_codes[argsort]
- print node_area(leaf_nodes) * world_coords.world_scale**2
+ print node_areas(leaf_nodes).sum() * world_coords.world_scale**2
diff --git a/chroma/bvh/simple.py b/chroma/bvh/simple.py
index 6ce45e7..f87f6d8 100644
--- a/chroma/bvh/simple.py
+++ b/chroma/bvh/simple.py
@@ -1,4 +1,4 @@
-from chroma.bvh.bvh import BVH, node_area
+from chroma.bvh.bvh import BVH
from chroma.gpu.bvh import create_leaf_nodes, merge_nodes, concatenate_layers
def make_simple_bvh(mesh, degree):