simple plotting to see if it works.

This commit is contained in:
William Blattman 2012-03-18 17:52:24 -07:00
parent c6434469fb
commit a93c047a5d
1 changed files with 107 additions and 100 deletions

View File

@ -246,13 +246,11 @@ class Polygon(object):
it needs to average vertices with all adjoinging faces
'''
def __init__(self, vertices, edges, faces):
self.vertices = vertices
self.edges = edges
self.faces = faces
def __init__(self):
self.vertices = []
self.edges = []
self.faces = []
def __repr__(self):
return str([edge for edge in self.edges])
def catmullClarkRefine(self):
'''
For each face, add a face vertex
@ -264,26 +262,32 @@ class Polygon(object):
'''
# 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 self.faces:
for subFace in face.subFaces:
faces.append(subFace)
for edge in subFace.edges:
edges.append(edge)
for vertex in edge.vertices:
print vertex
vertices.append(vertex)
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 p
def createPolygon():
v = []
v.append(Vertex(0.0, 1.0, 0.0))
v.append(Vertex(1.0, 1.0, 0.0))
@ -363,24 +367,27 @@ e[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[
# print v[0].x
# print e[0].vertices[0].x
# print f[0].edges[0].vertices[0].x
p = Polygon()
p.vertices = v
p.edges = e
p.faces = f
return p
polygon = Polygon(v, e, f)
polygon.catmullClarkRefine()
polygon = createPolygon()
newPolygon = polygon.catmullClarkRefine()
from numpy import *
import pylab
import mpl_toolkits.mplot3d.axes3d as p3
# from numpy import *
# import pylab
# import mpl_toolkits.mplot3d.axes3d as p3
# fig = pylab.figure()
# ax = p3.Axes3D(fig)
# ax.plot_wireframe(xs, ys, zs)
# ax.set_xlabel('X')
# ax.set_ylabel('Y')
# ax.set_zlabel('Z')
# pylab.show()
# v4 = Vertex(4, 0, 0, 1)
# v5 = Vertex(5, 1, 0, 1)
# v6 = Vertex(6, 0, 1, 1)
# v7 = Vertex(7, 1, 1, 1)
fig = pylab.figure()
ax = p3.Axes3D(fig)
for edge in newPolygon.edges:
xs = [vertex.x for vertex in edge.vertices]
ys = [vertex.y for vertex in edge.vertices]
zs = [vertex.z for vertex in edge.vertices]
ax.plot_wireframe(xs, ys, zs)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
pylab.show()