diff options
Diffstat (limited to 'geometry.py')
-rw-r--r-- | geometry.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/geometry.py b/geometry.py index 2c136a3..3a11daf 100644 --- a/geometry.py +++ b/geometry.py @@ -12,6 +12,14 @@ def compress(data, selectors): """ return (d for d, s in zip(data, selectors) if s) +def get_bounds(mesh): + """Returns the lower/upper bounds for `mesh`.""" + lower_bound = np.array([np.min(mesh[:,:,0]), np.min(mesh[:,:,1]), \ + np.min(mesh[:,:,2])]) + upper_bound = np.array([np.max(mesh[:,:,0]), np.max(mesh[:,:,1]), \ + np.max(mesh[:,:,2])]) + return lower_bound, upper_bound + class Leaf(object): """ Leaf object represents the last layer in the bounding volume hierarchy @@ -33,8 +41,7 @@ class Leaf(object): self.zvalue = zvalue self.mesh_idx = mesh_idx - self.lower_bound = np.array([np.min(mesh[:,:,0]), np.min(mesh[:,:,1]), np.min(mesh[:,:,2])]) - self.upper_bound = np.array([np.max(mesh[:,:,0]), np.max(mesh[:,:,1]), np.max(mesh[:,:,2])]) + self.lower_bound, self.upper_bound = get_bounds(mesh) self.size = mesh.shape[0] @@ -86,8 +93,7 @@ def morton_order(mesh, bits): bits of the quantized center coordinates of each triangle. Each coordinate axis is quantized into 2**bits bins. """ - lower_bound = np.array([np.min(mesh[:,:,0]), np.min(mesh[:,:,1]), np.min(mesh[:,:,2])]) - upper_bound = np.array([np.max(mesh[:,:,0]), np.max(mesh[:,:,1]), np.max(mesh[:,:,2])]) + lower_bound, upper_bound = get_bounds(mesh) max_value = 2**bits - 1 @@ -227,15 +233,15 @@ class Geometry(object): nodes.append(node) - self.lower_bound = np.empty((len(nodes),3)) - self.upper_bound = np.empty((len(nodes),3)) + self.lower_bounds = np.empty((len(nodes),3)) + self.upper_bounds = np.empty((len(nodes),3)) self.child_map = np.empty(len(nodes)) self.child_len = np.empty(len(nodes)) self.first_leaf = None for i, node in enumerate(nodes): - self.lower_bound[i] = node.lower_bound - self.upper_bound[i] = node.upper_bound + self.lower_bounds[i] = node.lower_bound + self.upper_bounds[i] = node.upper_bound self.child_len[i] = node.size |