diff options
| author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-13 01:03:42 -0400 |
|---|---|---|
| committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-13 01:03:42 -0400 |
| commit | 519acb39bdb1df9869bb17bcc710108ac8c02983 (patch) | |
| tree | bc4fd6f165df09feb7fdc0b166d38df144ebc9a2 /zcurve.py | |
| parent | 6996620497d0e6382df8e1cb0d07f6746ac3b0f3 (diff) | |
| download | chroma-519acb39bdb1df9869bb17bcc710108ac8c02983.tar.gz chroma-519acb39bdb1df9869bb17bcc710108ac8c02983.tar.bz2 chroma-519acb39bdb1df9869bb17bcc710108ac8c02983.zip | |
added a bounding volume hierarchy
Diffstat (limited to 'zcurve.py')
| -rw-r--r-- | zcurve.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/zcurve.py b/zcurve.py new file mode 100644 index 0000000..5ef37f3 --- /dev/null +++ b/zcurve.py @@ -0,0 +1,25 @@ +import numpy as np +from itertools import chain + +def interleave(*args): + return int("".join(chain(*zip(*[bin(x)[2:].zfill(x.nbytes*8) for x in args]))), 2) + +def morton_order(mesh, dtype=np.uint8): + vertices = mesh.reshape(mesh.shape[0]*3, 3) + + upper_bound = np.max(vertices, axis=0) + lower_bound = np.min(vertices, axis=0) + + quantize = lambda x: dtype((x-lower_bound)*np.iinfo(dtype).max/(upper_bound-lower_bound)) + + zvalue = [] + for triangle in mesh: + center = np.mean(np.vstack((triangle[0], triangle[1], triangle[2])), axis=0) + zvalue.append(interleave(*quantize(center))) + + ordered_mesh = np.empty(mesh.shape) + + for i, idx in enumerate(zip(*sorted(zip(zvalue, range(len(zvalue)))))[-1]): + ordered_mesh[i] = mesh[idx] + + return ordered_mesh |
