Fixed bug in my CC implementation

- Wasn't calculating faces for a give original vert correctly
    - vertices generated by surf.subd.cc.refine look about right
    - still missing edge and face connectivity
This commit is contained in:
Stephen M. McQuay
2012-05-09 09:24:26 -06:00
parent ba1ec89c27
commit 198a7d7ca8
3 changed files with 33 additions and 14 deletions
+19 -13
View File
@@ -2,17 +2,18 @@ from collections import defaultdict
from surf.geometry import PolygonMesh, centroid
from pprint import pprint as pp # XXX
def refine(mesh):
new_vertices = list(mesh.vertices)
f_vert_offset = len(new_vertices)
edge_vids_for = defaultdict(list)
face_vids_for = defaultdict(list)
face_ids_for_v = defaultdict(list)
# TODO: not completely populated yet:
new_edges = list(mesh.edges)
# TODO: must be populated:
new_faces = []
# For each face, add a face point
@@ -26,6 +27,8 @@ def refine(mesh):
# below
new_face_point = mesh.centroid(cur_face)
new_vertices.append(new_face_point)
for i in cur_face:
face_ids_for_v[i].append(cur_face_id)
e_vert_offset = len(new_vertices)
@@ -41,7 +44,7 @@ def refine(mesh):
# Set each edge point to be the average of the two neighbouring, (very
# recently calculated) face points ...
tmp_verts.extend([new_vertices[f + f_vert_offset] for f in face_ids_for_edge])
# ... and its two original endpoints.
tmp_verts.extend([mesh.vertices[vid] for vid in cur_edge])
@@ -55,14 +58,18 @@ def refine(mesh):
for edge_vid in edge_vids_for[trunc_vid]:
new_edges.append([edge_vid, overall_vid])
# pp(new_edges)
# v_vert_offset = len(new_vertices)
# For each original point P
assert f_vert_offset == len(mesh.vertices)
for new_vid in xrange(f_vert_offset):
# take the average F of all n face points for faces touching P ...
F = centroid([mesh.vertices[vid] for vid in mesh.faces_for_vert[new_vid]])
print ">>>", F
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])
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 ...
@@ -74,18 +81,17 @@ def refine(mesh):
R = centroid(e_verts)
# 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)
v = (F + 2 * R + (len(edges) - 3) * new_vertices[new_vid]) / len(edges)
return None
new_vertex_point = (F + 2 * R + (len(edges) - 3) * new_vertices[new_vid]) / len(edges)
new_vertices.append(new_vertex_point)
return PolygonMesh(vertices=new_vertices, edges=new_edges, faces=new_faces)
if __name__ == '__main__':
import json
from surf.geometry import PolygonMesh
from surf.subd.cc import refine
cube = json.load(open('blender/samples/cube.json', 'r'))
p = PolygonMesh(**cube)
q = refine(p)
print q