diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-15 18:35:41 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-15 18:35:41 -0400 |
commit | 2aa342458d1278487f9ca47ff0111e74b20d63ef (patch) | |
tree | 63f2bfbbc1f971525cf1f79c06e74d969484eaa2 /bvh.py | |
parent | 8ea783d053e817568b3e7d04f28a6fd2583f18cf (diff) | |
download | chroma-2aa342458d1278487f9ca47ff0111e74b20d63ef.tar.gz chroma-2aa342458d1278487f9ca47ff0111e74b20d63ef.tar.bz2 chroma-2aa342458d1278487f9ca47ff0111e74b20d63ef.zip |
cleanup. fixed tests
Diffstat (limited to 'bvh.py')
-rw-r--r-- | bvh.py | 47 |
1 files changed, 0 insertions, 47 deletions
@@ -1,47 +0,0 @@ -import numpy as np -from itertools import chain - -def compress(data, selectors): - return (d for d, s in zip(data, selectors) if s) - -class Leaf(object): - def __init__(self, mesh, mesh_idx, zvalue=None): - self.mesh_idx = mesh_idx - self.size = mesh.shape[0] - self.zvalue = zvalue - 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.center = (self.lower_bound + self.upper_bound)/2.0 - -class Node(object): - def __init__(self, children, zvalue=None): - self.size = len(children) - self.zvalue = zvalue - - lower_pts = np.array([child.lower_bound for child in children]) - upper_pts = np.array([child.upper_bound for child in children]) - - self.lower_bound = np.array([np.min(lower_pts[:,0]), np.min(lower_pts[:,1]), np.min(lower_pts[:,2])]) - self.upper_bound = np.array([np.max(upper_pts[:,0]), np.max(upper_pts[:,1]), np.max(upper_pts[:,2])]) - - self.children = children - - self.center = (self.lower_bound + self.upper_bound)/2.0 - -def interleave(*args): - return int("".join(chain(*zip(*[bin(x)[2:].zfill(x.nbytes*8) for x in args]))), 2) - -def morton_order(mesh, bits=8): - 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])]) - - def quantize(x): - return np.uint64((x-lower_bound)*bits/(upper_bound-lower_bound)) - - zvalues = np.empty(mesh.shape[0], dtype=np.uint64) - for i, triangle in enumerate(mesh): - zvalues[i] = interleave(*quantize(np.mean(triangle, axis=0))) - - order = np.array(zip(*sorted(zip(zvalues, range(len(zvalues)))))[-1]) - - return order, zvalues |