some more changes to the geometry tests, and some notes on what todo

This commit is contained in:
William Blattman 2012-03-17 23:18:32 -07:00
parent f9179f972c
commit 66593129e6

View File

@ -95,18 +95,23 @@ class Vertex(object):
self.edges = [] self.edges = []
def __repr__(self): def __repr__(self):
return "<%.2f, %.2f, %.2f>, faces: %s" % (self.x, self.y, self.z, [edge.id for edge in self.edges]) return "<%.2f, %.2f, %.2f>" % (self.x, self.y, self.z)
class Edge(object): class Edge(object):
''' '''
''' '''
def __init__(self): def __init__(self):
self.id = 0
self.vertices = [] self.vertices = []
self.faces = [] self.faces = []
self.edges = [] self.edges = []
def createEdgeVertex(self): def neighborFace(self, neighborFace):
if neighborFace == self.faces[0]:
return self.faces[1]
else:
return self.faces[0]
def edgeVertex(self):
''' '''
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.
@ -134,7 +139,7 @@ class Face(object):
''' '''
def __init__(self): def __init__(self):
self.edges = [] self.edges = []
def __getCentroid(self): def __getCentroid(self):
# gather all vertex coords # gather all vertex coords
faceVertices = self.__getFaceVertices() faceVertices = self.__getFaceVertices()
@ -151,8 +156,9 @@ class Face(object):
centroid = property(fget=__getCentroid) centroid = property(fget=__getCentroid)
def __getFaceVertices(self): def __getFaceVertices(self):
return list(set([vertex for edge in self.edges for vertex in edge.vertices])) return list([vertex for edge in self.edges for vertex in edge.vertices])
vertices = property(fget=__getFaceVertices)
class Polygon(object): class Polygon(object):
''' '''
Face splitting should happend on the polygon level(?). It doesn't make sense to split just one face since Face splitting should happend on the polygon level(?). It doesn't make sense to split just one face since
@ -164,31 +170,41 @@ class Polygon(object):
self.edges = edges self.edges = edges
self.faces = faces self.faces = faces
def __getFaceNeighbors(self, testFace):
for face in self.faces:
testFace.isNeighbor(face)
def catmullClarkRefine(self): def catmullClarkRefine(self):
''' '''
1. For each face, add a face vertex 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.
2. For each edge, add an edge vertex. 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. Set each edge vertex to be the average of the two neighbouring face vertices and its two original endvertices.
3. 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 face vertex, add an edge for every edge of the face, connecting the face vertex to each edge vertex for the face.
4. 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 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
''' '''
# 1 # this calculates and returns the averaged vertex point
faceVertex = self.faces[0].centroid print self.faces[0].edges[0].edgeVertex()
# 2 # this returns a vertex at the face centroid
edgeVertices = [edge.createEdgeVertex() for edge in self.faces[0].edges] print self.faces[0].centroid
# 3 # this will get to the first neighborFace...
# each face knows its faceVertex, and all of its edgeVertices
neighborFace = self.faces[0].edges[0].neighborFace(self.faces[0])
print neighborFace.centroid
# so now what.........
# 4
# (F + 2R + (n-3) P) / n # (F + 2R + (n-3) P) / n
# #
# F = average of all face vertices touching P # F = average of all face vertices touching P
# R = average of all edge vertices touching P # R = average of all edge vertices touching P
# P original point # P original point
# n = face vertices or edge vertices (should be the same number) # n = face vertices or edge vertices (should be the same number)
v = [] v = []
v.append(Vertex(0.0, 1.0, 0.0)) v.append(Vertex(0.0, 1.0, 0.0))
@ -243,9 +259,9 @@ f[5].edges = [e[10], e[9], e[8], e[11]]
#winged edges ordered by face, then by vertex reference #winged edges ordered by face, then by vertex reference
e[0].vertices, e[0].faces, e[0].edges = [v[0], v[1]], [f[0], f[4]], [e[3], e[1], e[4], e[5]] e[0].vertices, e[0].faces, e[0].edges = [v[0], v[1]], [f[0], f[4]], [e[3], e[1], e[4], e[5]]
e[1].vertices, e[1].faces, e[1].edges = [v[1], v[2]], [f[0], f[1]], [e[0], e[2], e[5], e[6]] e[1].vertices, e[1].faces, e[1].edges = [v[1], v[2]], [f[0], f[1]], [e[0], e[2], e[5], e[6]]
e[2].vertices, e[2].faces, e[2].edges = [v[3], v[2]], [f[0], f[2]], [e[3], e[7], e[1], e[6]] e[2].vertices, e[2].faces, e[2].edges = [v[2], v[3]], [f[0], f[2]], [e[3], e[7], e[1], e[6]]
e[3].vertices, e[3].faces, e[3].edges = [v[0], v[3]], [f[3], f[0]], [e[4], e[7], e[0], e[2]] e[3].vertices, e[3].faces, e[3].edges = [v[3], v[0]], [f[3], f[0]], [e[4], e[7], e[0], e[2]]
e[4].vertices, e[4].faces, e[4].edges = [v[4], v[0]], [f[3], f[4]], [e[11], e[3], e[0], e[8]] e[4].vertices, e[4].faces, e[4].edges = [v[0], v[4]], [f[3], f[4]], [e[11], e[3], e[0], e[8]]
e[5].vertices, e[5].faces, e[5].edges = [v[5], v[1]], [f[4], f[1]], [e[8], e[0], e[9], e[1]] e[5].vertices, e[5].faces, e[5].edges = [v[5], v[1]], [f[4], f[1]], [e[8], e[0], e[9], e[1]]
e[6].vertices, e[6].faces, e[6].edges = [v[2], v[6]], [f[1], f[2]], [e[1], e[9], e[2], e[10]] e[6].vertices, e[6].faces, e[6].edges = [v[2], v[6]], [f[1], f[2]], [e[1], e[9], e[2], e[10]]
e[7].vertices, e[7].faces, e[7].edges = [v[7], v[3]], [f[3], f[2]], [e[11], e[3], e[10], e[2]] e[7].vertices, e[7].faces, e[7].edges = [v[7], v[3]], [f[3], f[2]], [e[11], e[3], e[10], e[2]]