added real tests to the subd.cc.TestCC class
This commit is contained in:
parent
71f99ba58d
commit
1a317781cf
1
blender/samples/cube-blender-cc-1.json
Normal file
1
blender/samples/cube-blender-cc-1.json
Normal file
@ -0,0 +1 @@
|
||||
{"vertices": [[-1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0], [0.0, 0.0, 1.0], [-0.75, 0.0, 0.75], [-0.75, 0.75, 0.0], [-0.75, 0.0, -0.75], [-0.75, -0.75, 0.0], [0.0, 0.75, 0.75], [0.75, 0.75, 0.0], [0.0, 0.75, -0.75], [0.75, 0.0, 0.75], [0.75, -0.75, 0.0], [0.75, 0.0, -0.75], [0.0, -0.75, 0.75], [0.0, -0.75, -0.75], [-0.5555555820465088, -0.5555555820465088, -0.5555555820465088], [-0.5555555820465088, 0.5555555820465088, -0.5555555820465088], [0.5555555820465088, 0.5555555820465088, -0.5555555820465088], [0.5555555820465088, -0.5555555820465088, -0.5555555820465088], [-0.5555555820465088, -0.5555555820465088, 0.5555555820465088], [-0.5555555820465088, 0.5555555820465088, 0.5555555820465088], [0.5555555820465088, 0.5555555820465088, 0.5555555820465088], [0.5555555820465088, -0.5555555820465088, 0.5555555820465088]], "edges": [[0, 6], [0, 7], [0, 8], [0, 9], [1, 10], [1, 11], [1, 12], [1, 7], [2, 13], [2, 14], [2, 15], [2, 11], [3, 16], [3, 9], [3, 17], [3, 14], [4, 8], [4, 12], [4, 15], [4, 17], [5, 13], [5, 10], [5, 6], [5, 16], [22, 6], [6, 23], [23, 7], [7, 19], [19, 8], [8, 18], [18, 9], [9, 22], [23, 10], [10, 24], [24, 11], [11, 20], [20, 12], [12, 19], [24, 13], [13, 25], [25, 14], [14, 21], [21, 15], [15, 20], [25, 16], [16, 22], [18, 17], [17, 21]], "faces for edge": [[1, 0], [2, 1], [3, 2], [3, 0], [5, 4], [6, 5], [7, 6], [7, 4], [9, 8], [10, 9], [11, 10], [11, 8], [13, 12], [14, 13], [15, 14], [15, 12], [17, 16], [18, 17], [19, 18], [19, 16], [21, 20], [22, 21], [23, 22], [23, 20], [23, 0], [22, 1], [4, 1], [7, 2], [17, 2], [16, 3], [14, 3], [13, 0], [22, 4], [21, 5], [8, 5], [11, 6], [18, 6], [17, 7], [21, 8], [20, 9], [12, 9], [15, 10], [19, 10], [18, 11], [20, 12], [23, 13], [16, 14], [19, 15]], "faces": [[0, 9, 22, 6], [0, 6, 23, 7], [0, 7, 19, 8], [0, 8, 18, 9], [1, 7, 23, 10], [1, 10, 24, 11], [1, 11, 20, 12], [1, 12, 19, 7], [2, 11, 24, 13], [2, 13, 25, 14], [2, 14, 21, 15], [2, 15, 20, 11], [3, 14, 25, 16], [3, 16, 22, 9], [3, 9, 18, 17], [3, 17, 21, 14], [4, 17, 18, 8], [4, 8, 19, 12], [4, 12, 20, 15], [4, 15, 21, 17], [5, 16, 25, 13], [5, 13, 24, 10], [5, 10, 23, 6], [5, 6, 22, 16]], "edges for face": [[3, 31, 24, 0], [0, 25, 26, 1], [1, 27, 28, 2], [2, 29, 30, 3], [7, 26, 32, 4], [4, 33, 34, 5], [5, 35, 36, 6], [6, 37, 27, 7], [11, 34, 38, 8], [8, 39, 40, 9], [9, 41, 42, 10], [10, 43, 35, 11], [15, 40, 44, 12], [12, 45, 31, 13], [13, 30, 46, 14], [14, 47, 41, 15], [19, 46, 29, 16], [16, 28, 37, 17], [17, 36, 43, 18], [18, 42, 47, 19], [23, 44, 39, 20], [20, 38, 33, 21], [21, 32, 25, 22], [22, 24, 45, 23]], "edges for vert": [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23], [0, 22, 24, 25], [1, 7, 26, 27], [2, 16, 28, 29], [3, 13, 30, 31], [4, 21, 32, 33], [5, 11, 34, 35], [6, 17, 36, 37], [8, 20, 38, 39], [9, 15, 40, 41], [10, 18, 42, 43], [12, 23, 44, 45], [14, 19, 46, 47], [29, 30, 46], [27, 28, 37], [35, 36, 43], [41, 42, 47], [24, 31, 45], [25, 26, 32], [33, 34, 38], [39, 40, 44]], "faces for vert": [[1, 2, 3, 0], [5, 6, 7, 4], [9, 10, 11, 8], [13, 14, 15, 12], [17, 18, 19, 16], [21, 22, 23, 20], [0, 22, 23, 1], [1, 7, 4, 2], [2, 16, 17, 3], [3, 13, 14, 0], [4, 21, 22, 5], [5, 11, 8, 6], [6, 17, 18, 7], [8, 20, 21, 9], [9, 15, 12, 10], [10, 18, 19, 11], [12, 23, 20, 13], [14, 19, 16, 15], [16, 3, 14], [7, 2, 17], [11, 6, 18], [15, 10, 19], [0, 13, 23], [22, 1, 4], [21, 5, 8], [20, 9, 12]]}
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user