Cleaned up some pep8 violations
- changed camelCase variables to under_case
- wrapped lines that were longer than 80 chars
- used @property decorator
- changed the cc refine test to print before running refine
- refine seems to be destructive
This commit is contained in:
+35
-25
@@ -1,53 +1,63 @@
|
||||
from surf.geometry import Vertex, Polygon
|
||||
|
||||
|
||||
def refine(poly):
|
||||
'''
|
||||
For each face, add a face vertex
|
||||
Set each face vertex to be the centroid of all original vertices for the respective face.
|
||||
Set each face vertex to be the centroid of all original vertices for
|
||||
the respective face.
|
||||
For each edge, add an edge vertex.
|
||||
Set each edge vertex to be the average of the two neighbouring face vertices and its two original endvertices.
|
||||
For each face vertex, add an edge for every edge of the face, connecting the face vertex to each edge vertex for the face.
|
||||
For each original vertex P, take the average F of all n face vertices for faces touching P, and take the average R of all n edge midvertices for edges touching P, where each edge midvertex is the average of its two endvertex vertices. Move each original vertex to the vertex
|
||||
Set each edge vertex to be the average of the two neighbouring face
|
||||
vertices and its two original endvertices.
|
||||
For each face vertex, add an edge for every edge of the face, connecting
|
||||
the face vertex to each edge vertex for the face.
|
||||
For each original vertex P, take the average F of all n face vertices for
|
||||
faces touching P, and take the average R of all n edge midvertices for
|
||||
edges touching P, where each edge midvertex is the average of its two
|
||||
endvertex vertices. Move each original vertex to the vertex
|
||||
'''
|
||||
|
||||
|
||||
# each face knows how to subdivide and create a set of subfaces, including interior edges and setup their references correctly... <- not completely finished...
|
||||
|
||||
# each face knows how to subdivide and create a set of subfaces, including
|
||||
# interior edges and setup their references correctly... <- not completely
|
||||
# finished...
|
||||
p = Polygon()
|
||||
edges = []
|
||||
vertices = []
|
||||
faces = []
|
||||
|
||||
|
||||
for face in poly.faces:
|
||||
for subFace in face.subFaces:
|
||||
for subFace in face.sub_faces:
|
||||
faces.append(subFace)
|
||||
for edge in subFace.edges:
|
||||
edges.append(edge)
|
||||
for vertex in edge.vertices:
|
||||
vertices.append(vertex)
|
||||
|
||||
|
||||
newVertices = []
|
||||
for vertex in poly.vertices:
|
||||
faceVertices = []
|
||||
edgeMidPoints = []
|
||||
face_vertices = []
|
||||
edge_mid_points = []
|
||||
for edge in vertex.edges:
|
||||
edgeMidPoints.append(edge.midPoint)
|
||||
edge_mid_points.append(edge.mid_point)
|
||||
for face in edge.faces:
|
||||
faceVertices.append(face.centroid)
|
||||
|
||||
f = sum(list(set(faceVertices)), Vertex())/len(list(set(faceVertices)))
|
||||
r = sum(list(set(edgeMidPoints)), Vertex())/len(list(set(edgeMidPoints)))
|
||||
face_vertices.append(face.centroid)
|
||||
|
||||
f = sum(list(
|
||||
set(face_vertices)), Vertex()) / len(list(set(face_vertices)))
|
||||
r = sum(list(
|
||||
set(edge_mid_points)), Vertex()) / len(list(set(edge_mid_points)))
|
||||
p = vertex
|
||||
n = len(vertex.edges)
|
||||
v = (f + 2.0 * r + (n - 3.0) * p) / n
|
||||
newVertices.append(v)
|
||||
|
||||
|
||||
for vertex, newVertex in zip(poly.vertices, newVertices):
|
||||
vertex.x = newVertex.x
|
||||
vertex.y = newVertex.y
|
||||
vertex.z = newVertex.z
|
||||
# so now what.........
|
||||
# (F + 2R + (n-3) P) / n
|
||||
#
|
||||
#
|
||||
# F = average of all face vertices touching P
|
||||
# R = average of all edge vertices touching P
|
||||
# P original point
|
||||
@@ -56,13 +66,13 @@ def refine(poly):
|
||||
p.faces = faces
|
||||
p.vertices = vertices
|
||||
p.edges = edges
|
||||
|
||||
|
||||
# plotting these in excel seems to show the correct values (at first glace...)
|
||||
|
||||
# so now what.........
|
||||
|
||||
# plotting these in excel seems to show the correct values (at first
|
||||
# glace...)
|
||||
|
||||
# so now what.........
|
||||
# (F + 2R + (n-3) P) / n
|
||||
#
|
||||
#
|
||||
# F = average of all face vertices touching P
|
||||
# R = average of all edge vertices touching P
|
||||
# P original point
|
||||
|
||||
Reference in New Issue
Block a user