This commit is contained in:
Stephen M. McQuay 2012-05-05 19:16:24 -06:00
commit 3e9299d4b7
4 changed files with 490 additions and 266 deletions

View File

@ -24,17 +24,24 @@ def cross(a, b):
k = a.x * b.y - a.y * b.x
return Vertex(i, j, k)
class Vertex(object):
'''
A vertex is a position along with other information such as color, normal
vector and texture coordinates.
'''
def __init__(self, polygon, x=0, y=0, z=0):
next_id
def __init__(self, polygon, parent_id=None, x=None, y=None, z=None, es=None):
'''
'''
self.polygon = polygon
self.parent_id = parent_id
self.x = x
self.y = y
self.z = z
self.edges = []
self.edge_ids = es or []
self.id = Vertex.next_id
Vertex.next_id += 1
def __eq__(self, other):
if(self.x == other.x and self.y == other.y and self.z == other.z):
@ -42,16 +49,12 @@ class Vertex(object):
else:
return False
def __repr__(self):
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 other + self
# return self.__add__(other)
def __mul__(self, other):
if isinstance(other, Vertex):
@ -73,32 +76,128 @@ class Vertex(object):
def __neg__(self):
return Vertex(-self.x, -self.y, -self.z)
def __unicode__(self):
d = {
'id': self.id,
'parent_id': self.parent_id,
'coords': [self.x, self.y, self.z]
}
return pprint.pformat(d)
__str__ = __unicode__
__repr__ = __unicode__
class Edge(object):
'''
'''
def __init__(self, polygon):
next_id = 0
def __init__(self, polygon, parent_id=None, vs=None, es=None, fs=None):
'''
'''
self.polygon = polygon
self.vertices = []
self.faces = []
self.edges = []
self.parent_id = parent_id
self.vertex_ids = vs or []
self.edge_ids = es or []
self.face_ids = fs or []
self.id = Edge.next_id
Edge.next_id += 1
def neighborFace(self, neighborFace):
def neighbor_face_id(self, neighbor_face_id):
'''Get neighboring face id
'''
if neighborFace == self.faces[0]:
return self.faces[1]
if neighbor_face_id == self.face_ids[0]:
return self.face_ids[1]
else:
return self.faces[0]
return self.face_ids[0]
def __unicode__(self):
d = {
'id': self.id,
'vertex_ids': self.vertex_ids,
'edge_ids': self.edge_ids,
'face_ids': self.face_ids,
}
return pprint.pformat(d)
__str__ = __unicode__
__repr__ = __unicode__
@property
def vertices(self):
return [self.polygon.vertex(v_id) for v_id in self.vertex_ids]
@property
def faces(self):
return [self.polygon.face(f_id) for f_id in self.face_ids]
def winged_edges_at_vertex(self, index):
edge_ids = []
for edge in self.edges:
if self.vertex_ids[index] in edge.vertex_ids:
edge_ids.append(edge.id)
return edge_ids
class Face(object):
'''
A face is a closed set of edges, in which a triangle face has three edges,
A face is a closed set of edges,
in which a triangle face has three edges,
and a quad face has four edges.
'''
def __init__(self, polygon):
next_id = 0
def __init__(self, polygon, parent_id=None, es=None):
'''
'''
self.polygon = polygon
self.edges = []
self.parent_id = parent_id
self.edge_ids = es or []
self.id = Face.next_id
Face.next_id += 1
def __unicode__(self):
d = {'id': self.id, 'edge_ids': self.edge_ids}
return pprint.pformat(d)
__str__ = __unicode__
__repr__ = __unicode__
def edge(self, edge_id):
return self.polygon.edge(edge_id)
@property
def edges(self):
return [self.polygon.edge(e_id) for e_id in self.edge_ids]
@property
def vertices(self):
vertices = []
for edge_id in self.edge_ids:
edge = self.polygon.edge(edge_id)
vertices.extend(edge.vertices)
return list(set(vertices))
@property
def centroid(self):
'''
'''
# gather all face vertex coords
face_vertices = self.vertices
xs = [vertex.x for vertex in face_vertices]
ys = [vertex.y for vertex in face_vertices]
zs = [vertex.z for vertex in face_vertices]
# average each vertex component
x = sum(xs) / len(xs)
y = sum(ys) / len(ys)
z = sum(zs) / len(zs)
return [x, y, z]
class Polygon(object):
'''
@ -109,6 +208,31 @@ class Polygon(object):
self.edges = es or []
self.faces = fs or []
def face(self, face_id):
for face in self.faces:
if face.id == face_id:
return face
return None
def edge(self, edge_id):
for edge in self.edges:
if edge.id == edge_id:
return edge
return None
def vertex(self, vertex_id):
for vertex in self.vertices:
if vertex.id == vertex_id:
return vertex
return None
def edge_ids_with_parent(self, parent_edge_id):
child_edge_ids = []
for edge in self.edges:
if edge.parent_id == parent_edge_id:
child_edge_ids.append(edge.id)
return child_edge_ids
def __unicode__(self):
d = {
'vertices': self.vertices,
@ -119,3 +243,4 @@ class Polygon(object):
__str__ = __unicode__
__repr__ = __unicode__

View File

@ -1,61 +1,101 @@
from surf.geometry import Vertex, Polygon
from surf.geometry import Vertex, Edge, Face, Polygon
from copy import deepcopy
import pprint
def mid_point(self):
vertex_objs = [self.polygon.vertices[v_id] for v_id in self.vertices]
def mid_point(edge):
vertex_objs = [edge.vertices[v_id] for v_id in edge.vertices]
return sum(vertex_objs, Vertex()) / len(self.vertices)
def sub_edges(self):
temp_p = Polygon()
temp_p.edges = [Edge(), Edge()]
temp_p.vertices =
# temp_p.vertices =
sub_edges[0].vertices = [self.vertices[0], self.edge_vertex]
sub_edges[1].vertices = [self.edge_vertex, self.vertices[1]]
return self.__sub_edges
def edge_vertex(self):
def centroid(face, poly):
'''
'''
# gather all face vertex coords
face_vertices = face.vertices
xs = [vertex.x for vertex in face_vertices]
ys = [vertex.y for vertex in face_vertices]
zs = [vertex.z for vertex in face_vertices]
# average each vertex component
x = sum(xs) / len(xs)
y = sum(ys) / len(ys)
z = sum(zs) / len(zs)
return Vertex(poly, x, y, z)
def edge_divide(edge, poly):
'''
Set each edge vertices to be the average of the two neighboring
face vertices and its two original end vertices.
'''
# two neighboring face vertices:
neighboringFaceVertices = [p.faces[f_id].centroid for f_id in self.faces]
neighboringFaceVertices.extend(self.vertices)
xs = [vertex.x for vertex in neighboringFaceVertices]
ys = [vertex.y for vertex in neighboringFaceVertices]
zs = [vertex.z for vertex in neighboringFaceVertices]
x = sum(xs) / len(xs)
y = sum(ys) / len(ys)
z = sum(zs) / len(zs)
self.__edge_vertex = Vertex(x, y, z)
self.__edge_vertex.edges.extend(self.__sub_edges)
return self.__edge_vertex
def centroid(self):
if not self.__centroid:
# gather all face vertex coords
face_vertices = list(set([vertex
for edge in self.edges for vertex in edge.vertices]))
xs = [vertex.x for vertex in face_vertices]
ys = [vertex.y for vertex in face_vertices]
zs = [vertex.z for vertex in face_vertices]
edge_ids = poly.edge_ids_with_parent(edge.id)
if edge_ids:
return edge_ids
else:
# otherwise split it
xs = []
ys = []
zs = []
for face in edge.faces:
centroid_v = centroid(face, None)
xs.append(centroid_v.x)
ys.append(centroid_v.y)
zs.append(centroid_v.z)
for vertex in edge.vertices:
xs.append(vertex.x)
ys.append(vertex.y)
zs.append(vertex.z)
# average each vertex component
x = sum(xs) / len(xs)
y = sum(ys) / len(ys)
z = sum(zs) / len(zs)
self.__centroid = Vertex(x, y, z)
return self.__centroid
e0 = Edge(poly)
e1 = Edge(poly)
edge_vertex = Vertex(poly, x, y, z)
edge_vertex.edge_ids = [e0.id, e1.id]
e0.vertex_ids = [edge.vertices[0].id, edge_vertex.id]
e1.vertex_ids = [edge_vertex.id, edge.vertices[1].id]
e0.edge_ids = edge.winged_edges_at_vertex(0)
e0.edge_ids.append(e1.id)
e1.edge_ids = edge.winged_edges_at_vertex(1)
e1.edge_ids.append(e0.id)
e0.parent_id = edge.id
e1.parent_id = edge.id
# add all these to the new polygon
poly.edge_ids.append(e0.id)
poly.edge_ids.append(e1.id)
poly.vertices.append(edge_vertex.id)
return e0.id, e1.id, edge_vertex.id
def sub_faces(self):
self.__setupSubDivisions()
return self.__sub_faces
setup_sub_divisions()
return sub_faces()
def interior_edges(self):
self.__setupSubDivisions()
setup_sub_divisions()
return self.__interior_edges
def __setupSubDivisions(self):
def setup_sub_divisions(polygon, face):
'''
v0 ev0 v1
*------e0-----*
@ -67,69 +107,86 @@ def __setupSubDivisions(self):
*------e2-----*
v3 ev2 v2
'''
if not self.__sub_faces:
# create empty sub_faces that will be filled with edge references
# below
# these need to at least exist so the interior edges have
# something to reference
self.__sub_faces = [Face() for edge in self.edges]
if not self.__interior_edges:
# set up empty edge objects to be filled below
self.__interior_edges = [Edge() for edge in self.edges]
# create empty sub_faces that will be filled with edge references
# below
# these need to at least exist so the interior edges have
# something to reference
# each interior edge connects the exterior edge vertex (mid-point)
# to the faceVertex (centroid)
for index in range(len(self.edges)):
prevIndex = (index - 1) % len(self.edges)
nextIndex = (index + 1) % len(self.edges)
# end vertices are face centroid and currEdge edge_vertex
self.__interior_edges[index].vertices = [
self.edges[index].edge_vertex, self.centroid
]
# wing edges are the current edge's sub_edges (ordered same as
# vertex order) and the prev and next interior edges
self.__interior_edges[index].edges = [
self.edges[index].sub_edges[0],
self.edges[index].sub_edges[1],
self.__interior_edges[prevIndex],
self.__interior_edges[nextIndex]
]
sub_faces = [Face(polygon) for edge in face.edge_ids]
# edge faces are the new sub_faces (current and next faces), the
# current will be define below
# and the next will be defined on the next iteration (or
# already defined on the last iteration)
self.__interior_edges[index].faces = [
self.__sub_faces[index],
self.__sub_faces[nextIndex]
]
# now reference the current edge back into the faces,
# and the edge.sub_edges, and the edge.edge_vertex
# set up empty edge objects to be filled below
interior_edges = [Edge(polygon) for edge in face.edge_ids]
# current subFace (same index as current interior edge)
# set its edges to reference the same edges used to setup the
# interior edge
# order will be pretty important on these steps...
self.__sub_faces[index].edges = [
self.edges[index].sub_edges[0],
self.__interior_edges[index],
self.__interior_edges[prevIndex],
self.edges[prevIndex].sub_edges[1]
]
# # each interior edge connects the exterior edge vertex (mid-point)
# # to the faceVertex (centroid)
# for edge_id in range(len(face.edges)):
# prevIndex = (edge_id - 1) % len(face.edges)
# nextIndex = (edge_id + 1) % len(face.edges)
# just set one of the vertex edges, the other belongs to
# another face and will get added when that face is run
self.edges[index].edge_vertex.edges.append(
self.__interior_edges[index])
# # end vertices are face centroid and currEdge edge_vertex
# interior_edges[edge_id].vertices = [
# face.edges[edge_id],
# edge_vertex, self.centroid
# ]
self.edges[index].sub_edges[0].faces.append(
self.__sub_faces[index])
self.edges[index].sub_edges[0].faces.append(
self.__sub_faces[index])
# # wing edges are the current edge's sub_edges (ordered same as
# # vertex order) and the prev and next interior edges
# self.__interior_edges[index].edges = [
# self.edges[index].sub_edges[0],
# self.edges[index].sub_edges[1],
# self.__interior_edges[prevIndex],
# self.__interior_edges[nextIndex]
# ]
# # edge faces are the new sub_faces (current and next faces), the
# # current will be define below
# # and the next will be defined on the next iteration (or
# # already defined on the last iteration)
# self.__interior_edges[index].faces = [
# self.__sub_faces[index],
# self.__sub_faces[nextIndex]
# ]
# # now reference the current edge back into the faces,
# # and the edge.sub_edges, and the edge.edge_vertex
# # current subFace (same index as current interior edge)
# # set its edges to reference the same edges used to setup the
# # interior edge
# # order will be pretty important on these steps...
# self.__sub_faces[index].edges = [
# self.edges[index].sub_edges[0],
# self.__interior_edges[index],
# self.__interior_edges[prevIndex],
# self.edges[prevIndex].sub_edges[1]
# ]
# # just set one of the vertex edges, the other belongs to
# # another face and will get added when that face is run
# self.edges[index].edge_vertex.edges.append(
# self.__interior_edges[index])
# self.edges[index].sub_edges[0].faces.append(
# self.__sub_faces[index])
# self.edges[index].sub_edges[0].faces.append(
# self.__sub_faces[index])
pass
def subdivide_face(poly, face):
# '''
# '''
# # find face centroid
# fc = face.centroid
# # find edge vertices
# for edge in face.edges:
# x, y, z = edge_mid_vertex(edge)
pass
def refine(poly):
'''
@ -147,64 +204,88 @@ def refine(poly):
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 = []
# create a new storage container for the items
new_poly = Polygon()
for face in poly.faces:
for subFace in face.sub_faces:
faces.append(subFace)
for edge in subFace.edges:
edges.append(edge)
for vertex in edge.vertices:
vertices.append(vertex)
# for now just test with the first face
start_face = poly.faces[0]
newVertices = []
for vertex in poly.vertices:
face_vertices = []
edge_mid_points = []
for edge in vertex.edges:
edge_mid_points.append(edge.mid_point)
for face in edge.faces:
face_vertices.append(face.centroid)
# go through the face vertices and add them to the new polygon
for vertex in start_face.vertices:
# truly, this needs to be a 'copy' of the vertex, I'll fix that later
new_poly.vertices.append(vertex)
f = sum(list(
set(face_vertices)), Vertex()) / len(list(set(face_vertices)))
r = sum(list(
set(edge_mid_points)), Vertex()) / len(list(set(edge_mid_points)))
p = vertex
n = len(vertex.edges)
v = (f + 2.0 * r + (n - 3.0) * p) / n
newVertices.append(v)
# find the face centroid
# and add the face centroid to the new polygon
start_centroid = centroid(start_face, new_poly)
new_poly.vertices.append(start_centroid)
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
# for each edge on the face,
for edge in start_face.edges:
# divide that edge into two new edges with an edge vertex
# set their parent object as the original edge
new_e0_id, new_e1_id, edge_v_id = edge_divide(edge, new_poly)
p.faces = faces
p.vertices = vertices
p.edges = edges
# create a new edge connecting the centroid to the edge_vertex
centroid_to_edge = Edge(new_poly)
new_poly.edges.append(centroid_to_edge)
# plotting these in excel seems to show the correct values (at first
# glace...)
# set the new edge's vertex references
centroid_to_edge.vertex_ids = [edge_v_id, start_centroid.id]
# 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)
# set the new edge's winged_edge references
centroid_to_edge.edge_ids = poly.edges ==> get edge by id not yet implemented... edge_v_id.edges
# set the edge vertex edge references
edge_v_id.edges.append(centroid_to_edge.id)
# set the centroid's edge reference
start_centroid.edge_ids.append(centroid_to_edge.id)
# now walk through the edges connected to the centroid
start_centroid.edges[0]
# need to get an adjacent edge, based on the the shared vertex of the
# original polygon... centroid to edge_vertex to shared point...
# start_face.neighbors
# f = sum(list(
# set(face_vertices)), Vertex()) / len(list(set(face_vertices)))
# r = sum(list(
# set(edge_mid_points)), Vertex()) / len(list(set(edge_mid_points)))
# 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)

View File

@ -2,7 +2,7 @@ from geometry import Vertex, Edge, Face, Polygon
def cube():
"""
'''
This function returns a populated Polygon object. The object is a cube with
a vertex at the origin, and another at (1, 1, 1).
@ -74,92 +74,86 @@ def cube():
v5 - e5, e9, e8
v6 - e2, e9, e10
v7 - e7, e10, e11
"""
'''
p = Polygon()
p.vertices.append(Vertex(p, 1.0, 1.0, 0.0))
p.vertices.append(Vertex(p, 1.0, 0.0, 0.0))
p.vertices.append(Vertex(p, 0.0, 1.0, 0.0))
p.vertices.append(Vertex(p, 0.0, 0.0, 0.0))
p.vertices.append(Vertex(p, 0.0, 1.0, 1.0))
p.vertices.append(Vertex(p, 1.0, 1.0, 1.0))
p.vertices.append(Vertex(p, 1.0, 0.0, 1.0))
p.vertices.append(Vertex(p, 0.0, 0.0, 1.0))
# setup vertices
p.vertices = [
Vertex(p, 0, 1.0, 1.0, 0.0),
Vertex(p, 1, 1.0, 0.0, 0.0),
Vertex(p, 2, 0.0, 1.0, 0.0),
Vertex(p, 3, 0.0, 0.0, 0.0),
Vertex(p, 4, 0.0, 1.0, 1.0),
Vertex(p, 5, 1.0, 1.0, 1.0),
Vertex(p, 6, 1.0, 0.0, 1.0),
Vertex(p, 7, 0.0, 0.0, 1.0)]
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.edges.append(Edge(p))
p.vertices[0].edge_ids = [0, 3, 4]
p.vertices[1].edge_ids = [0, 5, 1]
p.vertices[2].edge_ids = [1, 6, 2]
p.vertices[3].edge_ids = [2, 7, 3]
p.vertices[4].edge_ids = [4, 11, 8]
p.vertices[5].edge_ids = [5, 9, 8]
p.vertices[6].edge_ids = [6, 9, 10]
p.vertices[7].edge_ids = [7, 10, 11]
p.faces.append(Face(p))
p.faces.append(Face(p))
p.faces.append(Face(p))
p.faces.append(Face(p))
p.faces.append(Face(p))
p.faces.append(Face(p))
# setup edges
p.edges = [Edge(p, i) for i in range(12)]
p.vertices[0].edges = [0, 3, 4]
p.vertices[1].edges = [0, 5, 1]
p.vertices[2].edges = [1, 6, 2]
p.vertices[3].edges = [2, 7, 3]
p.vertices[4].edges = [4, 11, 8]
p.vertices[5].edges = [5, 9, 8]
p.vertices[6].edges = [6, 9, 10]
p.vertices[7].edges = [7, 10, 11]
# winged edges ordered by face, then by vertex reference
# setup edge end vertex ids
p.edges[0].vertex_ids = [0, 1]
p.edges[1].vertex_ids = [1, 2]
p.edges[2].vertex_ids = [2, 3]
p.edges[3].vertex_ids = [3, 0]
p.edges[4].vertex_ids = [0, 4]
p.edges[5].vertex_ids = [5, 1]
p.edges[6].vertex_ids = [2, 6]
p.edges[7].vertex_ids = [7, 3]
p.edges[8].vertex_ids = [4, 5]
p.edges[9].vertex_ids = [5, 6]
p.edges[10].vertex_ids = [7, 6]
p.edges[11].vertex_ids = [4, 7]
# face list
p.faces[0].edges = [0, 1, 2, 3]
p.faces[1].edges = [1, 5, 9, 6]
p.faces[2].edges = [2, 6, 10, 7]
p.faces[3].edges = [4, 3, 7, 11]
p.faces[4].edges = [8, 5, 0, 4]
p.faces[5].edges = [10, 9, 8, 11]
# setup edges winged edge ids
p.edges[0].edge_ids = [3, 1, 4, 5]
p.edges[1].edge_ids = [0, 2, 5, 6]
p.edges[2].edge_ids = [1, 3, 6, 7]
p.edges[3].edge_ids = [4, 7, 0, 2]
p.edges[4].edge_ids = [11, 3, 0, 8]
p.edges[5].edge_ids = [8, 0, 9, 1]
p.edges[6].edge_ids = [1, 9, 2, 10]
p.edges[7].edge_ids = [11, 3, 10, 2]
p.edges[8].edge_ids = [4, 5, 11, 9]
p.edges[9].edge_ids = [5, 6, 8, 10]
p.edges[10].edge_ids = [7, 6, 11, 9]
p.edges[11].edge_ids = [4, 7, 8, 10]
#winged edges ordered by face, then by vertex reference
p.edges[0].vertices = [0, 1]
p.edges[1].vertices = [1, 2]
p.edges[2].vertices = [2, 3]
p.edges[3].vertices = [3, 0]
p.edges[4].vertices = [0, 4]
p.edges[5].vertices = [5, 1]
p.edges[6].vertices = [2, 6]
p.edges[7].vertices = [7, 3]
p.edges[8].vertices = [4, 5]
p.edges[9].vertices = [5, 6]
p.edges[10].vertices = [7, 6]
p.edges[11].vertices = [4, 7]
p.edges[0].edges = [3, 1, 4, 5]
p.edges[1].edges = [0, 2, 5, 6]
p.edges[2].edges = [1, 3, 6, 7]
p.edges[3].edges = [4, 7, 0, 2]
p.edges[4].edges = [11, 3, 0, 8]
p.edges[5].edges = [8, 0, 9, 1]
p.edges[6].edges = [1, 9, 2, 10]
p.edges[7].edges = [11, 3, 10, 2]
p.edges[8].edges = [4, 5, 11, 9]
p.edges[9].edges = [5, 6, 8, 10]
p.edges[10].edges = [7, 6, 11, 9]
p.edges[11].edges = [4, 7, 8, 10]
p.edges[0].faces = [0, 4]
p.edges[1].faces = [0, 1]
p.edges[2].faces = [0, 2]
p.edges[3].faces = [3, 0]
p.edges[4].faces = [3, 4]
p.edges[5].faces = [4, 1]
p.edges[6].faces = [1, 2]
p.edges[7].faces = [3, 2]
p.edges[8].faces = [4, 5]
p.edges[9].faces = [1, 5]
p.edges[10].faces = [2, 5]
p.edges[11].faces = [3, 5]
# setup edge adjacent face ids
p.edges[0].face_ids = [0, 4]
p.edges[1].face_ids = [0, 1]
p.edges[2].face_ids = [0, 2]
p.edges[3].face_ids = [3, 0]
p.edges[4].face_ids = [3, 4]
p.edges[5].face_ids = [4, 1]
p.edges[6].face_ids = [1, 2]
p.edges[7].face_ids = [3, 2]
p.edges[8].face_ids = [4, 5]
p.edges[9].face_ids = [1, 5]
p.edges[10].face_ids = [2, 5]
p.edges[11].face_ids = [3, 5]
# setup faces
p.faces = [Face(p, i) for i in range(6)]
# setup face edge ids
p.faces[0].edge_ids = [0, 1, 2, 3]
p.faces[1].edge_ids = [1, 5, 9, 6]
p.faces[2].edge_ids = [2, 6, 10, 7]
p.faces[3].edge_ids = [4, 3, 7, 11]
p.faces[4].edge_ids = [8, 5, 0, 4]
p.faces[5].edge_ids = [10, 9, 8, 11]
# Polygon stores all the actual data.
# Every other class only stores indices to
@ -170,15 +164,15 @@ def cube():
# These are all the same vertex, just testing to make
# sure I did it right.
print p.vertices[1].x
edge_v_id = p.edges[1].vertices[0]
print p.vertices[edge_v_id].x
# print p.vertices[1].x
# edge_v_id = p.edges[1].vertex_ids[0]
# print p.vertices[edge_v_id].x
face_edge_id = p.faces[0].edges[1]
edge_v_id = p.edges[face_edge_id].vertices[0]
print p.vertices[edge_v_id].x
# face_edge_id = p.faces[0].edge_ids[1]
# edge_v_id = p.edges[face_edge_id].vertex_ids[0]
# print p.vertices[edge_v_id].x
return p
print cube()
# print cube()

24
test00.py Executable file
View File

@ -0,0 +1,24 @@
from surf.util2 import cube
from surf.subd import cc2
poly = cube()
# print poly
refined_poly = cc2.refine(poly)
# print refined_poly
#
#
# import pylab
# import mpl_toolkits.mplot3d.axes3d as p3
#
# 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()