Refactored into modules and test scripts.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
from surf.geometry import *
|
||||
|
||||
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.
|
||||
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
|
||||
'''
|
||||
|
||||
|
||||
# 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:
|
||||
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 = []
|
||||
for edge in vertex.edges:
|
||||
edgeMidPoints.append(edge.midPoint)
|
||||
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)))
|
||||
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
|
||||
# n = number of edges connecting to P
|
||||
|
||||
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.........
|
||||
# (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
|
||||
# n = face vertices or edge vertices (should be the same number)
|
||||
return Polygon(vertices, edges, faces)
|
||||
Reference in New Issue
Block a user