added real tests to the subd.cc.TestCC class

This commit is contained in:
Stephen M. McQuay
2012-05-15 23:51:48 -06:00
parent 71f99ba58d
commit 1a317781cf
3 changed files with 33 additions and 11 deletions
+17 -11
View File
@@ -11,7 +11,7 @@ def refine(mesh):
face_ids_for_v = defaultdict(list)
# TODO: not completely populated yet:
new_edges = list(mesh.edges)
new_edges = []
# TODO: must be populated:
new_faces = []
@@ -51,25 +51,26 @@ def refine(mesh):
# centroid == average
new_vertices.append(centroid(tmp_verts))
# For each face point, add an edge for every edge of the old face,
# connecting the new face point to each new edge point
for trunc_vid in xrange(len(new_vertices[f_vert_offset:e_vert_offset])):
# For each face point, add an edge connecting the new face point to each
# new edge point
new_face_vert_ids = new_vertices[f_vert_offset:e_vert_offset]
for trunc_vid in xrange(len(new_face_vert_ids)):
overall_vid = f_vert_offset + trunc_vid
for edge_vid in edge_vids_for_face[trunc_vid]:
new_edges.append([edge_vid, overall_vid])
# For each original point P, move the original point to a new location
for new_vid in xrange(f_vert_offset):
# Here we mimic the F, R, and P spelling in the wiki article
for old_vid in xrange(f_vert_offset):
# take the average F of all n face points for faces touching P ...
new_face_ids = face_ids_for_v[new_vid]
F_verts = []
for fid in new_face_ids:
F_verts.append(new_vertices[f_vert_offset + fid])
for old_fid in mesh.faces_for_vert[old_vid]:
F_verts.append(new_vertices[f_vert_offset + old_fid])
F = centroid(F_verts)
# and take the average R of all n edge midpoints for edges touching P
# wiki is wrong ... it should be the edge points, not midpoints ...
edges = [mesh.edges[eid] for eid in mesh.edges_for_vert[new_vid]]
edges = [mesh.edges[eid] for eid in mesh.edges_for_vert[old_vid]]
e_verts = []
for edge in edges:
e_verts.extend([mesh.vertices[vid] for vid in edge])
@@ -77,8 +78,13 @@ def refine(mesh):
# where each edge midpoint is the average of its two endpoint vertices.
# **Move** each original point to the point (or add it to new_verts)
new_vertex_point = (F + 2 * R + (len(edges) - 3) * new_vertices[new_vid]) / len(edges)
new_vertices[new_vid] = new_vertex_point
new_vertex_point = (F + 2 * R + (len(edges) - 3) * new_vertices[old_vid]) / len(edges)
new_vertices[old_vid] = new_vertex_point
# Connect each new Vertex point to the new edge points of all original
# edges incident on the original vertex.
for eid in mesh.edges_for_vert[old_vid]:
new_edges.append([old_vid, eid])
return PolygonMesh(vertices=new_vertices, edges=new_edges, faces=new_faces)
+15
View File
@@ -25,5 +25,20 @@ class TestCC(unittest.TestCase):
for i in xrange(len(a)):
self.assertAlmostEqual(a[i], b[i])
def test_vert_count(self):
p = PolygonMesh(**self.cube)
p2 = cc.refine(p)
self.assertEqual(len(p2.vertices), 26)
def test_edge_count(self):
p = PolygonMesh(**self.cube)
p2 = cc.refine(p)
self.assertEqual(len(p2.edges), 48)
def test_face_count(self):
p = PolygonMesh(**self.cube)
p2 = cc.refine(p)
self.assertEqual(len(p2.faces), 24)
if __name__ == '__main__':
unittest.main(verbosity=3)