Updated file so that it could pass pep8/pyflakes

- left in borked state
This commit is contained in:
Stephen M. McQuay 2012-05-07 23:19:54 -06:00
parent ef9485f8a6
commit a083621d35

View File

@ -1,26 +1,22 @@
from surf.geometry import Vertex, Edge, Face, Polygon from surf.geometry import Vertex, Edge, Polygon
from copy import deepcopy
import pprint
def mid_point(edge):
vertex_objs = [edge.vertices[v_id] for v_id in edge.vertices]
return sum(vertex_objs, Vertex()) / len(self.vertices)
def sub_edges(self): def sub_edges(self):
temp_p = Polygon() temp_p = Polygon()
temp_p.edges = [Edge(), Edge()] temp_p.edges = [Edge(), Edge()]
# temp_p.vertices = # temp_p.vertices =
sub_edges[0].vertices = [self.vertices[0], self.edge_vertex] sub_edges[0].vertices = [self.vertices[0], self.edge_vertex]
sub_edges[1].vertices = [self.edge_vertex, self.vertices[1]] sub_edges[1].vertices = [self.edge_vertex, self.vertices[1]]
return self.__sub_edges return self.__sub_edges
def centroid(face, poly): def centroid(face, poly):
''' '''
''' '''
# gather all face vertex coords # gather all face vertex coords
face_vertices = face.vertices face_vertices = face.vertices
xs = [vertex.x for vertex in face_vertices] xs = [vertex.x for vertex in face_vertices]
ys = [vertex.y for vertex in face_vertices] ys = [vertex.y for vertex in face_vertices]
zs = [vertex.z for vertex in face_vertices] zs = [vertex.z for vertex in face_vertices]
@ -29,17 +25,17 @@ def centroid(face, poly):
x = sum(xs) / len(xs) x = sum(xs) / len(xs)
y = sum(ys) / len(ys) y = sum(ys) / len(ys)
z = sum(zs) / len(zs) z = sum(zs) / len(zs)
return Vertex(poly, x, y, z) return Vertex(poly, x, y, z)
def edge_divide(edge, poly): def edge_divide(edge, poly):
''' '''
Set each edge vertices to be the average of the two neighboring Set each edge vertices to be the average of the two neighboring
face vertices and its two original end vertices. face vertices and its two original end vertices.
''' '''
edge_ids = poly.edge_ids_with_parent(edge.id) edge_ids = poly.edge_ids_with_parent(edge.id)
if edge_ids: if edge_ids:
return edge_ids return edge_ids
else: else:
@ -52,49 +48,52 @@ def edge_divide(edge, poly):
xs.append(centroid_v.x) xs.append(centroid_v.x)
ys.append(centroid_v.y) ys.append(centroid_v.y)
zs.append(centroid_v.z) zs.append(centroid_v.z)
for vertex in edge.vertices: for vertex in edge.vertices:
xs.append(vertex.x) xs.append(vertex.x)
ys.append(vertex.y) ys.append(vertex.y)
zs.append(vertex.z) zs.append(vertex.z)
x = sum(xs) / len(xs) x = sum(xs) / len(xs)
y = sum(ys) / len(ys) y = sum(ys) / len(ys)
z = sum(zs) / len(zs) z = sum(zs) / len(zs)
e0 = Edge(poly) e0 = Edge(poly)
e1 = Edge(poly) e1 = Edge(poly)
edge_vertex = Vertex(poly, x, y, z) edge_vertex = Vertex(poly, x, y, z)
edge_vertex.edge_ids = [e0.id, e1.id] edge_vertex.edge_ids = [e0.id, e1.id]
e0.vertex_ids = [edge.vertices[0].id, edge_vertex.id] e0.vertex_ids = [edge.vertices[0].id, edge_vertex.id]
e1.vertex_ids = [edge_vertex.id, edge.vertices[1].id] e1.vertex_ids = [edge_vertex.id, edge.vertices[1].id]
e0.edge_ids = edge.winged_edges_at_vertex(0) e0.edge_ids = edge.winged_edges_at_vertex(0)
e0.edge_ids.append(e1.id) e0.edge_ids.append(e1.id)
e1.edge_ids = edge.winged_edges_at_vertex(1) e1.edge_ids = edge.winged_edges_at_vertex(1)
e1.edge_ids.append(e0.id) e1.edge_ids.append(e0.id)
e0.parent_id = edge.id e0.parent_id = edge.id
e1.parent_id = edge.id e1.parent_id = edge.id
# add all these to the new polygon # add all these to the new polygon
poly.edge_ids.append(e0.id) poly.edge_ids.append(e0.id)
poly.edge_ids.append(e1.id) poly.edge_ids.append(e1.id)
poly.vertices.append(edge_vertex.id) poly.vertices.append(edge_vertex.id)
return e0.id, e1.id, edge_vertex.id return e0.id, e1.id, edge_vertex.id
def sub_faces(self): def sub_faces(self):
setup_sub_divisions() setup_sub_divisions()
return sub_faces() return sub_faces()
def interior_edges(self): def interior_edges(self):
setup_sub_divisions() setup_sub_divisions()
return self.__interior_edges return self.__interior_edges
def setup_sub_divisions(polygon, face): def setup_sub_divisions(polygon, face):
''' '''
v0 ev0 v1 v0 ev0 v1
@ -107,19 +106,16 @@ def setup_sub_divisions(polygon, face):
*------e2-----* *------e2-----*
v3 ev2 v2 v3 ev2 v2
''' '''
# create empty sub_faces that will be filled with edge references # create empty sub_faces that will be filled with edge references
# below # below
# these need to at least exist so the interior edges have # these need to at least exist so the interior edges have
# something to reference # something to reference
sub_faces = [Face(polygon) for edge in face.edge_ids]
# sub_faces = [Face(polygon) for edge in face.edge_ids]
# set up empty edge objects to be filled below # set up empty edge objects to be filled below
interior_edges = [Edge(polygon) for edge in face.edge_ids] # interior_edges = [Edge(polygon) for edge in face.edge_ids]
# # each interior edge connects the exterior edge vertex (mid-point) # # each interior edge connects the exterior edge vertex (mid-point)
# # to the faceVertex (centroid) # # to the faceVertex (centroid)
@ -176,18 +172,20 @@ def setup_sub_divisions(polygon, face):
# self.__sub_faces[index]) # self.__sub_faces[index])
pass pass
def subdivide_face(poly, face): def subdivide_face(poly, face):
# ''' # '''
# ''' # '''
# # find face centroid # # find face centroid
# fc = face.centroid # fc = face.centroid
# # find edge vertices # # find edge vertices
# for edge in face.edges: # for edge in face.edges:
# x, y, z = edge_mid_vertex(edge) # x, y, z = edge_mid_vertex(edge)
pass pass
def refine(poly): def refine(poly):
''' '''
For each face, add a face vertex For each face, add a face vertex
@ -203,56 +201,52 @@ def refine(poly):
edges touching P, where each edge midvertex is the average of its two edges touching P, where each edge midvertex is the average of its two
endvertex vertices. Move each original vertex to the vertex endvertex vertices. Move each original vertex to the vertex
''' '''
# create a new storage container for the items # create a new storage container for the items
new_poly = Polygon() new_poly = Polygon()
# for now just test with the first face # for now just test with the first face
start_face = poly.faces[0] start_face = poly.faces[0]
# go through the face vertices and add them to the new polygon # go through the face vertices and add them to the new polygon
for vertex in start_face.vertices: for vertex in start_face.vertices:
# truly, this needs to be a 'copy' of the vertex, I'll fix that later # truly, this needs to be a 'copy' of the vertex, I'll fix that later
new_poly.vertices.append(vertex) new_poly.vertices.append(vertex)
# find the face centroid # find the face centroid
# and add the face centroid to the new polygon # and add the face centroid to the new polygon
start_centroid = centroid(start_face, new_poly) start_centroid = centroid(start_face, new_poly)
new_poly.vertices.append(start_centroid) new_poly.vertices.append(start_centroid)
# for each edge on the face, # for each edge on the face,
for edge in start_face.edges: for edge in start_face.edges:
# divide that edge into two new edges with an edge vertex # divide that edge into two new edges with an edge vertex
# set their parent object as the original edge # set their parent object as the original edge
new_e0_id, new_e1_id, edge_v_id = edge_divide(edge, new_poly) new_e0_id, new_e1_id, edge_v_id = edge_divide(edge, new_poly)
# create a new edge connecting the centroid to the edge_vertex # create a new edge connecting the centroid to the edge_vertex
centroid_to_edge = Edge(new_poly) centroid_to_edge = Edge(new_poly)
new_poly.edges.append(centroid_to_edge) new_poly.edges.append(centroid_to_edge)
# set the new edge's vertex references # set the new edge's vertex references
centroid_to_edge.vertex_ids = [edge_v_id, start_centroid.id] centroid_to_edge.vertex_ids = [edge_v_id, start_centroid.id]
# set the new edge's winged_edge references # set the new edge's winged_edge references
centroid_to_edge.edge_ids = poly.edges ==> get edge by id not yet implemented... edge_v_id.edges # centroid_to_edge.edge_ids = poly.edges ==> get edge by id not yet implemented... edge_v_id.edges
# set the edge vertex edge references # set the edge vertex edge references
edge_v_id.edges.append(centroid_to_edge.id) edge_v_id.edges.append(centroid_to_edge.id)
# set the centroid's edge reference # set the centroid's edge reference
start_centroid.edge_ids.append(centroid_to_edge.id) start_centroid.edge_ids.append(centroid_to_edge.id)
# now walk through the edges connected to the centroid # now walk through the edges connected to the centroid
start_centroid.edges[0] start_centroid.edges[0]
# need to get an adjacent edge, based on the the shared vertex of the # need to get an adjacent edge, based on the the shared vertex of the
# original polygon... centroid to edge_vertex to shared point... # original polygon... centroid to edge_vertex to shared point...
# start_face.neighbors # start_face.neighbors
# f = sum(list( # f = sum(list(
# set(face_vertices)), Vertex()) / len(list(set(face_vertices))) # set(face_vertices)), Vertex()) / len(list(set(face_vertices)))
# r = sum(list( # r = sum(list(