simple plotting to see if it works.
This commit is contained in:
parent
c6434469fb
commit
a93c047a5d
207
geometry.py
207
geometry.py
@ -246,13 +246,11 @@ class Polygon(object):
|
|||||||
it needs to average vertices with all adjoinging faces
|
it needs to average vertices with all adjoinging faces
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, vertices, edges, faces):
|
def __init__(self):
|
||||||
self.vertices = vertices
|
self.vertices = []
|
||||||
self.edges = edges
|
self.edges = []
|
||||||
self.faces = faces
|
self.faces = []
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return str([edge for edge in self.edges])
|
|
||||||
def catmullClarkRefine(self):
|
def catmullClarkRefine(self):
|
||||||
'''
|
'''
|
||||||
For each face, add a face vertex
|
For each face, add a face vertex
|
||||||
@ -264,123 +262,132 @@ 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...
|
# 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 face in self.faces:
|
||||||
for subFace in face.subFaces:
|
for subFace in face.subFaces:
|
||||||
|
faces.append(subFace)
|
||||||
for edge in subFace.edges:
|
for edge in subFace.edges:
|
||||||
|
edges.append(edge)
|
||||||
for vertex in edge.vertices:
|
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...)
|
# plotting these in excel seems to show the correct values (at first glace...)
|
||||||
|
|
||||||
|
# so now what.........
|
||||||
# so now what.........
|
|
||||||
|
|
||||||
# (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)
|
||||||
|
return p
|
||||||
|
|
||||||
v = []
|
|
||||||
v.append(Vertex(0.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(0.0, 0.0, 0.0))
|
|
||||||
v.append(Vertex(0.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(0.0, 0.0, 1.0))
|
|
||||||
|
|
||||||
e = []
|
def createPolygon():
|
||||||
e.append(Edge())
|
v = []
|
||||||
e.append(Edge())
|
v.append(Vertex(0.0, 1.0, 0.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(1.0, 1.0, 0.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(1.0, 0.0, 0.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(0.0, 0.0, 0.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(0.0, 1.0, 1.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(1.0, 1.0, 1.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(1.0, 0.0, 1.0))
|
||||||
e.append(Edge())
|
v.append(Vertex(0.0, 0.0, 1.0))
|
||||||
e.append(Edge())
|
|
||||||
e.append(Edge())
|
|
||||||
e.append(Edge())
|
|
||||||
|
|
||||||
f = []
|
e = []
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
f.append(Face())
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
e.append(Edge())
|
||||||
|
|
||||||
# vertex list
|
f = []
|
||||||
v[0].edges = [e[0], e[3], e[4]]
|
f.append(Face())
|
||||||
v[1].edges = [e[0], e[5], e[1]]
|
f.append(Face())
|
||||||
v[2].edges = [e[1], e[6], e[2]]
|
f.append(Face())
|
||||||
v[3].edges = [e[2], e[7], e[3]]
|
f.append(Face())
|
||||||
v[4].edges = [e[4], e[11], e[8]]
|
f.append(Face())
|
||||||
v[5].edges = [e[5], e[9], e[8]]
|
f.append(Face())
|
||||||
v[6].edges = [e[2], e[9], e[10]]
|
|
||||||
v[7].edges = [e[7], e[10], e[11]]
|
|
||||||
|
|
||||||
# face list
|
# vertex list
|
||||||
f[0].edges = [e[0], e[1], e[2], e[3]]
|
v[0].edges = [e[0], e[3], e[4]]
|
||||||
f[1].edges = [e[1], e[5], e[9], e[6]]
|
v[1].edges = [e[0], e[5], e[1]]
|
||||||
f[2].edges = [e[2], e[6], e[10], e[7]]
|
v[2].edges = [e[1], e[6], e[2]]
|
||||||
f[3].edges = [e[4], e[3], e[7], e[11]]
|
v[3].edges = [e[2], e[7], e[3]]
|
||||||
f[4].edges = [e[8], e[5], e[0], e[4]]
|
v[4].edges = [e[4], e[11], e[8]]
|
||||||
f[5].edges = [e[10], e[9], e[8], e[11]]
|
v[5].edges = [e[5], e[9], e[8]]
|
||||||
|
v[6].edges = [e[2], e[9], e[10]]
|
||||||
|
v[7].edges = [e[7], e[10], e[11]]
|
||||||
|
|
||||||
#winged edges ordered by face, then by vertex reference
|
# face list
|
||||||
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]]
|
f[0].edges = [e[0], e[1], e[2], e[3]]
|
||||||
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]]
|
f[1].edges = [e[1], e[5], e[9], 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]]
|
f[2].edges = [e[2], e[6], e[10], 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]]
|
f[3].edges = [e[4], e[3], e[7], e[11]]
|
||||||
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]]
|
f[4].edges = [e[8], e[5], e[0], e[4]]
|
||||||
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]]
|
f[5].edges = [e[10], e[9], e[8], e[11]]
|
||||||
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[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[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]]
|
|
||||||
|
|
||||||
# just to prove to myself that the objects are the same, this is what years of pass by value have done to me...
|
#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[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[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[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[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[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[11].vertices, e[11].faces, e[11].edges = [v[4], v[7]], [f[3], f[5]], [e[4], e[7], e[8], e[10]]
|
||||||
|
|
||||||
# print id(v[0].x)
|
# just to prove to myself that the objects are the same, this is what years of pass by value have done to me...
|
||||||
# print id(e[0].vertices[0].x)
|
|
||||||
# print id(f[0].edges[0].vertices[0].x)
|
|
||||||
|
|
||||||
# v[0].x = 9
|
# print id(v[0].x)
|
||||||
|
# print id(e[0].vertices[0].x)
|
||||||
|
# print id(f[0].edges[0].vertices[0].x)
|
||||||
|
|
||||||
# print id(v[0].x)
|
# v[0].x = 9
|
||||||
# print id(e[0].vertices[0].x)
|
|
||||||
# print id(f[0].edges[0].vertices[0].x)
|
|
||||||
|
|
||||||
# print v[0].x
|
# print id(v[0].x)
|
||||||
# print e[0].vertices[0].x
|
# print id(e[0].vertices[0].x)
|
||||||
# print f[0].edges[0].vertices[0].x
|
# print id(f[0].edges[0].vertices[0].x)
|
||||||
|
|
||||||
polygon = Polygon(v, e, f)
|
# print v[0].x
|
||||||
polygon.catmullClarkRefine()
|
# 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 = createPolygon()
|
||||||
|
newPolygon = polygon.catmullClarkRefine()
|
||||||
|
|
||||||
# from numpy import *
|
from numpy import *
|
||||||
# import pylab
|
import pylab
|
||||||
# import mpl_toolkits.mplot3d.axes3d as p3
|
import mpl_toolkits.mplot3d.axes3d as p3
|
||||||
|
|
||||||
# fig = pylab.figure()
|
fig = pylab.figure()
|
||||||
# ax = p3.Axes3D(fig)
|
ax = p3.Axes3D(fig)
|
||||||
# ax.plot_wireframe(xs, ys, zs)
|
for edge in newPolygon.edges:
|
||||||
# ax.set_xlabel('X')
|
xs = [vertex.x for vertex in edge.vertices]
|
||||||
# ax.set_ylabel('Y')
|
ys = [vertex.y for vertex in edge.vertices]
|
||||||
# ax.set_zlabel('Z')
|
zs = [vertex.z for vertex in edge.vertices]
|
||||||
# pylab.show()
|
ax.plot_wireframe(xs, ys, zs)
|
||||||
|
ax.set_xlabel('X')
|
||||||
# v4 = Vertex(4, 0, 0, 1)
|
ax.set_ylabel('Y')
|
||||||
# v5 = Vertex(5, 1, 0, 1)
|
ax.set_zlabel('Z')
|
||||||
# v6 = Vertex(6, 0, 1, 1)
|
pylab.show()
|
||||||
# v7 = Vertex(7, 1, 1, 1)
|
|
Loading…
Reference in New Issue
Block a user