From cfbde60480cddec2000726db75ebe8df3ae530ba Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Wed, 30 May 2012 22:57:56 -0600 Subject: [PATCH] added vertex calcs for simple butterfly --- surf/subd/butterfly.py | 55 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/surf/subd/butterfly.py b/surf/subd/butterfly.py index 2a5196c..3c4acfd 100644 --- a/surf/subd/butterfly.py +++ b/surf/subd/butterfly.py @@ -1,2 +1,55 @@ +from __future__ import division + +import sys + +from surf.geometry import PolygonMesh, Vertex + + +def _get_third_point(mesh, eid, fid): + evids = set(mesh.edges[eid]) + fvids = set(mesh.faces[fid]) + other_vid = fvids - evids + assert len(other_vid) == 1 + other_vid = other_vid.pop() + return other_vid + + +def _make_edge_point(mesh, eid): + final_vert = Vertex() + + a = 1 / 2 + b = 1 / 8 + c = -1 / 16 + + a_verts = [mesh.vertices[v] for v in mesh.edges[eid]] + for v in a_verts: + final_vert += a * v + + for fid in mesh.faces_for_edge[eid]: + other_vid = _get_third_point(mesh, eid, fid) + final_vert += b * mesh.vertices[other_vid] + + other_edges = [e for e in mesh.edges_for_face[fid] if e != eid] + for other_edge in other_edges: + wing_face = [f for f in mesh.faces_for_edge[other_edge] + if f != fid] + assert len(wing_face) == 1 + vid = _get_third_point(mesh, other_edge, wing_face[0]) + final_vert += c * mesh.vertices[vid] + + return final_vert + + def refine(mesh): - pass + new_verts = list(mesh.vertices) + + # TODO: + new_faces = [] + # TODO: + new_edges = [] + + for eid, verts_for_edge in enumerate(mesh.edges): + new_vert = _make_edge_point(mesh, eid) + new_verts.append(new_vert) + + return PolygonMesh(new_verts, new_faces, new_edges)