getting closer, its starting to look like it...

This commit is contained in:
William Blattman 2012-03-18 21:57:44 -07:00
parent a93c047a5d
commit 805edfe12f
1 changed files with 74 additions and 16 deletions

View File

@ -88,15 +88,33 @@ class Vertex(object):
''' '''
A vertex is a position along with other information such as color, normal vector and texture coordinates. A vertex is a position along with other information such as color, normal vector and texture coordinates.
''' '''
def __init__(self, x, y, z): def __init__(self, x=0, y=0, z=0):
self.x = x self.x = x
self.y = y self.y = y
self.z = z self.z = z
self.edges = [] self.edges = []
def __repr__(self): def __repr__(self):
return "<%.2f, %.2f, %.2f>" % (self.x, self.y, self.z) return "<%.2f, %.2f, %.2f>" % (self.x, self.y, self.z)
def __add__(self, other):
# for now just assume type(other) = Vertex... bad, I know
return Vertex(self.x + other.x, self.y + other.y, self.z + other.z)
def __radd__(self, other):
return self.__add__(other)
def __mul__(self, other):
# for now just assume type(other) = int or float
return Vertex(self.x * other, self.y * other, self.z * other)
def __rmul__(self, other):
return self.__mul__(other)
def __div__(self, other):
# same assumption as __mult__
return Vertex(self.x / other, self.y / other, self.z / other)
class Edge(object): class Edge(object):
''' '''
''' '''
@ -112,6 +130,9 @@ class Edge(object):
return self.faces[1] return self.faces[1]
else: else:
return self.faces[0] return self.faces[0]
def __getMidPoint(self):
return sum(self.vertices, Vertex())/len(self.vertices)
midPoint = property(fget=__getMidPoint)
def __getSubEdges(self): def __getSubEdges(self):
if not self.__subEdges: if not self.__subEdges:
@ -239,7 +260,7 @@ class Face(object):
self.edges[index].subEdges[0].faces.append(self.__subFaces[index]) self.edges[index].subEdges[0].faces.append(self.__subFaces[index])
self.edges[index].subEdges[0].faces.append(self.__subFaces[index]) self.edges[index].subEdges[0].faces.append(self.__subFaces[index])
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
@ -261,11 +282,17 @@ class Polygon(object):
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
''' '''
# 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() p = Polygon()
edges = [] edges = []
vertices = [] vertices = []
faces = [] faces = []
for face in self.faces: for face in self.faces:
for subFace in face.subFaces: for subFace in face.subFaces:
faces.append(subFace) faces.append(subFace)
@ -273,9 +300,39 @@ class Polygon(object):
edges.append(edge) edges.append(edge)
for vertex in edge.vertices: for vertex in edge.vertices:
vertices.append(vertex) vertices.append(vertex)
for vertex in self.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
# print v
vertex.x = v.x
vertex.y = v.y
vertex.z = v.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.faces = faces
p.vertices = vertices p.vertices = vertices
p.edges = edges p.edges = edges
# plotting these in excel seems to show the correct values (at first glace...) # plotting these in excel seems to show the correct values (at first glace...)
# so now what......... # so now what.........
@ -286,13 +343,14 @@ class Polygon(object):
# 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)
return p return p
def createPolygon(): def createPolygon():
v = [] v = []
v.append(Vertex(0.0, 1.0, 0.0)) v.append(Vertex(0.0, 1.0, 0.0))
v.append(Vertex(1.0, 1.0, 0.0)) v.append(Vertex(1.0, 1.0, 0.0))
v.append(Vertex(1.0, 0.0, 0.0)) v.append(Vertex(1.0, 0.0, 0.0))
v.append(Vertex(0.0, 0.0, 0.0)) v.append(Vertex(0.0, 0.0, 0.0))
v.append(Vertex(0.0, 1.0, 1.0)) v.append(Vertex(0.0, 1.0, 1.0))
v.append(Vertex(1.0, 1.0, 1.0)) v.append(Vertex(1.0, 1.0, 1.0))
v.append(Vertex(1.0, 0.0, 1.0)) v.append(Vertex(1.0, 0.0, 1.0))
@ -327,7 +385,7 @@ def createPolygon():
v[3].edges = [e[2], e[7], e[3]] v[3].edges = [e[2], e[7], e[3]]
v[4].edges = [e[4], e[11], e[8]] v[4].edges = [e[4], e[11], e[8]]
v[5].edges = [e[5], e[9], e[8]] v[5].edges = [e[5], e[9], e[8]]
v[6].edges = [e[2], e[9], e[10]] v[6].edges = [e[6], e[9], e[10]]
v[7].edges = [e[7], e[10], e[11]] v[7].edges = [e[7], e[10], e[11]]
# face list # face list
@ -339,16 +397,16 @@ def createPolygon():
f[5].edges = [e[10], e[9], e[8], e[11]] 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[2], v[3]], [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[1], e[3], e[6], e[7]]
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[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[0], v[4]], [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]]
e[8].vertices, e[8].faces, e[8].edges = [v[4], v[5]], [f[4], f[5]], [e[4], e[5], e[11], e[9]] e[8].vertices, e[8].faces, e[8].edges = [v[4], v[5]], [f[4], f[5]], [e[4], e[5], e[11], e[9]]
e[9].vertices, e[9].faces, e[9].edges = [v[5], v[6]], [f[1], f[5]], [e[5], e[6], e[8], e[10]] e[9].vertices, e[9].faces, e[9].edges = [v[5], v[6]], [f[1], f[5]], [e[5], e[6], e[8], e[10]]
e[10].vertices, e[10].faces, e[10].edges = [v[7], v[6]], [f[2], f[5]], [e[7], e[6], e[11], e[9]] e[10].vertices, e[10].faces, e[10].edges = [v[7], v[6]], [f[2], f[5]], [e[7], e[6], e[11], e[9]]
e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[7], e[8], e[10]] e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[7], e[8], e[10]]