diff options
author | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-12 18:50:18 -0400 |
---|---|---|
committer | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-12 18:50:18 -0400 |
commit | 56f17469d6e86b78f68ece3bce41d1a50a58b657 (patch) | |
tree | 8d3dd35ea4dc168509d19c90aae046b69a5d42ad | |
parent | 332ec7a527857cc8c5f92c16ee94326b4cbfcbe1 (diff) | |
download | chroma-56f17469d6e86b78f68ece3bce41d1a50a58b657.tar.gz chroma-56f17469d6e86b78f68ece3bce41d1a50a58b657.tar.bz2 chroma-56f17469d6e86b78f68ece3bce41d1a50a58b657.zip |
speedup Mesh.remove_duplicate_vertices()
-rw-r--r-- | geometry.py | 13 | ||||
-rw-r--r-- | make.py | 3 |
2 files changed, 4 insertions, 12 deletions
diff --git a/geometry.py b/geometry.py index 9ef49bc..b08de54 100644 --- a/geometry.py +++ b/geometry.py @@ -39,16 +39,9 @@ class Mesh(object): return np.min(self.vertices, axis=0), np.max(self.vertices, axis=0) def remove_duplicate_vertices(self): - unique_vertices = list(unique_everseen(map(tuple, self.vertices))) - - if len(unique_vertices) == len(self.vertices): - return - - for i in range(len(self.triangles)): - for j in range(3): - self.triangles[i,j] = unique_vertices.index(tuple(self.vertices[self.triangles[i,j]])) - - self.vertices = np.array(unique_vertices) + unique_vertices, inverse = np.unique(self.vertices.view([('', self.vertices.dtype)]*self.vertices.shape[1]), return_inverse=True) + self.vertices = unique_vertices.view(self.vertices.dtype).reshape((unique_vertices.shape[0], self.vertices.shape[1])) + self.triangles = np.vectorize(lambda i: inverse[i])(self.triangles) def assemble(self, key=slice(None), group=True): if group: @@ -55,8 +55,7 @@ def segmented_cylinder(radius, height=2, theta=np.pi/32, n=50): y = np.concatenate(([-height/2.0] * n, np.linspace(-height/2.0, height/2.0, n, endpoint=False), [height/2.0] * (n+1))) - #return x,y - return rotate_extrude(x, y, theta, remove_duplicate_vertices=False) + return rotate_extrude(x, y, theta) def sphere(radius=1, theta=np.pi/32): profile_angles = np.arange(-np.pi/2, np.pi/2+theta, theta) |