From 9a37d67ae73f9b4ee40f67380925c627a6212641 Mon Sep 17 00:00:00 2001 From: William Blattman Date: Sat, 14 Apr 2012 19:35:05 -0700 Subject: [PATCH] nothing --- surf/__init__.pyc | Bin 0 -> 140 bytes surf/geometry.py | 181 ++++------------------------------------- surf/geometry.pyc | Bin 0 -> 4979 bytes surf/subd/__init__.pyc | Bin 0 -> 145 bytes surf/subd/cc.py | 130 +++++++++++++++++++++++++++++ surf/util.py | 171 +++++++++++++++++++++----------------- surf/util.pyc | Bin 0 -> 4923 bytes test00.py | 24 ++++++ 8 files changed, 270 insertions(+), 236 deletions(-) create mode 100755 surf/__init__.pyc create mode 100755 surf/geometry.pyc create mode 100755 surf/subd/__init__.pyc create mode 100755 surf/util.pyc create mode 100755 test00.py diff --git a/surf/__init__.pyc b/surf/__init__.pyc new file mode 100755 index 0000000000000000000000000000000000000000..6b6222e9368f37bb55e6032d1822524a2b94726e GIT binary patch literal 140 zcmZSn%*z!Yk?Wt#00oRd+5w1*S%5?e14FO|NW@PANHCxg#il?pXRDad;?$zznDWe= zoTQw@l9HH!qWrAX6BPKpRGcU6wK3=b&vV;Su(f1#JldhH(z$N(+fhkJ!q)i#6Hx{}jG!?od^kEw_lo0zlxZ5{2f3&8sn~&4MU~3SU<>tL2 z-!a|NZrV}Ni@U}#n|+h-nzGnm8}66frd#CJo(5xSD&<{}Z%7$yh}pQMF(m_IfFYm* z1*BlypRW!B!PbG?AjpT916&2<4M5qH9-t=xZve0b>1nA%z}*09FUXBWbNqLc^SzH>sCUa73t-7=nA3BgY&NVRb13(^u5jTm@ z6px6|Y{*cc`r=;^?4fG>xllO|GRz12{X7c;@F5){Mm z#0?016s1{OMv>-biy+EtRbPo33PwRh`CDKn&aTu$Ulli`$3=>Fq{l^vU-cj&I%Pw3 zrmQig6=o=PzZe-Y#oc&dO`8IQ$3dh|P@akMjJhZ?kD}-@ILoH;u6qr?OF;P4YQKvH z+`ZD=B??eq^#Zlh5ee7rGA8|eY3wC5d4Qt_e2bJ6L-r+Aut#C{B_nx(e1Q z@kNwM{Jx|rDO>7pxLR$0tG+s z`7+}HrxJuYz9uJ0v*zZ7BM>;w;D9?VS$mQ6xhx6#hvek37rqY>o?boB+sJ!yrbn51 zGDNa7NOb!{b3;G9b|9IxWT@kC%xoEFUE|PYpF~-2kmDqw*QQxH1$x;+_kApOrzrA5 z4lkE-C3v~Zo4~-i#qMYjMPFcl%hO(YC%og{Y44KXns|HdAWRu`u7aJ$ULxuCJO(rKmk!I$;$WGGvd$9BnwU*=v}Kpxwh$)v>O6sa2w;a$xXibSk0f zM>0Lj;^jh>B4C@d9eS`E>fp-Kk#b$k`K>8+X43xlR$ip2H(6EdG!fgeIF(W{B?9a2 zZ2t)CMAed-kKezGcW0vZWi0vtkE>jQlirdqWn-w(8GbksGxy7kvVfwtMr7FIH z>RvzIPFdCKvPk2sKQQhU9(Uz-VN5ksmScGz>qnzFnM~^Cqr%N`RetR!^|`^Id(rie zI67y#lKf42H0@{^Q>@3u6<-GI>@ej@zmE50(vie?&s|g~jC?52Ee*+d_xuN_$OZ1t zlM5m4JucnMDKn>V2_&5-S2=)lhJLBq3VJ)Y>l%F;PBP(%(#iH6sY0laT9mZ zNe&9INO*~a(1a3(T-@Cs2;81UMF!E`PtQ&a_!{xR5POKHx{?3E8*ndB-am6ItFS7mq@AboVC`cRidq?`lJpU4w0Tpcf)iw*^wl~^pwm( z-RkrkWob80aDoo8aCLJGyhVJE`|Irmil|BIOe85{J}}B05skzU>`5*=nv_TUlOd{SAAu(AEF| literal 0 HcmV?d00001 diff --git a/surf/subd/__init__.pyc b/surf/subd/__init__.pyc new file mode 100755 index 0000000000000000000000000000000000000000..d3b74f0ec10a25a40052c8ef7c5d2c4a78aa19bc GIT binary patch literal 145 zcmZSn%*z!Yk?Wt#00oRd+5w1*S%5?e14FO|NW@PANHCxg#a2KuXRDad;?$zznDWe= zoTQw@l9HH!qWrAX61ISBCiHVQT%*!l^kJl@xEa3oZx5>> K16fiG#0&t%z9B>a literal 0 HcmV?d00001 diff --git a/surf/subd/cc.py b/surf/subd/cc.py index 4b73e54..cd7de8e 100644 --- a/surf/subd/cc.py +++ b/surf/subd/cc.py @@ -1,5 +1,135 @@ from surf.geometry import Vertex, Polygon +def mid_point(self): + vertex_objs = [self.polygon.vertices[v_id] for v_id in self.vertices] + return sum(vertex_objs, Vertex()) / len(self.vertices) + +def sub_edges(self): + temp_p = Polygon() + temp_p.edges = [Edge(), Edge()] + 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): + ''' + 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] + + # 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 + +def sub_faces(self): + self.__setupSubDivisions() + return self.__sub_faces + +def interior_edges(self): + self.__setupSubDivisions() + return self.__interior_edges + +def __setupSubDivisions(self): + ''' + v0 ev0 v1 + *------e0-----* + | | | + | | | + ev3 e|11----f5----e|1 ev1 + | | | + | | | + *------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] + + # 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] + ] + + # 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]) def refine(poly): ''' diff --git a/surf/util.py b/surf/util.py index cfbb84a..53f607a 100644 --- a/surf/util.py +++ b/surf/util.py @@ -1,4 +1,4 @@ -from surf.geometry import Vertex, Edge, Face, Polygon +from geometry import Vertex, Edge, Face, Polygon def cube(): @@ -75,85 +75,110 @@ def cube(): 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)) - 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)) + 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)) - 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)) + 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)) - e = [] - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - e.append(Edge()) - - f = [] - f.append(Face()) - f.append(Face()) - f.append(Face()) - f.append(Face()) - f.append(Face()) - f.append(Face()) - - # vertex list - v[0].edges = [e[0], e[3], e[4]] - v[1].edges = [e[0], e[5], e[1]] - v[2].edges = [e[1], e[6], e[2]] - v[3].edges = [e[2], e[7], e[3]] - v[4].edges = [e[4], e[11], e[8]] - v[5].edges = [e[5], e[9], e[8]] - v[6].edges = [e[6], e[9], e[10]] - v[7].edges = [e[7], e[10], e[11]] + 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] # face list - f[0].edges = [e[0], e[1], e[2], e[3]] - f[1].edges = [e[1], e[5], e[9], e[6]] - f[2].edges = [e[2], e[6], e[10], e[7]] - f[3].edges = [e[4], e[3], e[7], e[11]] - f[4].edges = [e[8], e[5], e[0], e[4]] - f[5].edges = [e[10], e[9], e[8], e[11]] + 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] #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[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[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]] + 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] - # just to prove to myself that the objects are the same, this is what years of pass by value have done to me... + # Polygon stores all the actual data. + # Every other class only stores indices to + # the original data. This could be slightly + # dangerous if any items get appended to the + # list of objects or the indices get changed. + + + # 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 + + 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 - # print id(v[0].x) - # print id(e[0].vertices[0].x) - # print id(f[0].edges[0].vertices[0].x) + return p - # 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 v[0].x - # print e[0].vertices[0].x - # print f[0].edges[0].vertices[0].x - return Polygon(v, e, f) +print cube() diff --git a/surf/util.pyc b/surf/util.pyc new file mode 100755 index 0000000000000000000000000000000000000000..d1bc6dd8b8f82320656a79f69ce99c32240122d7 GIT binary patch literal 4923 zcmd^D%Wm6N5WUpH57|yOMS%bXN_3?LP9XZ7CP)heeV~graM~^m1BNVKDm3&kM2d+4 zW|e+SKcHXHRX?RbKcGEl=JFxOHtH7brnE)z&dfb?=FE_m)%<;<^J{nxm!}x6Dz?cwxi*Xv|UD*tU6V%$Hw_cY8PF7IrsMyLPwcUU0Xh?l$X2twp*2 zKkJg{uzX2}|IUi>4qGN{o1x4g<`I^ACosXWWWwc|V_6-`CR{P$YR$2#j#U$Oh*m+h z)X_HKnhDoyj%h=Bs~x8&9WxGMz?&9qYU zxoWTj$$;6Z`CLKZ4Iz*c`ASSz)4E_HE2JxZt}LKQSquAIWx{jV5Qd`iy%T6I)GI5w z!K&4iv1A3S?5bkPN4iEPWh|M%svRt?m_a-VWUK- zTkn(z(6+=~Q!A=K(TcA6IW^>srGtCfFNv11#3n4zva(-TR{cT|P#D8mV!D1|02LWy zSo&PQ&`WGW%P{Sw&-DxW-~b&AW9f6lsF>(>J)fILsf=U4QQJrLz(Oj+{jh*Z4dFup zDDKieDhVGj;l8wwdTM3${&Vt?=F+rruG9*~Wk;wUtO8P5she8sxKs>QFo9Mj0=0tm z(iBrAMW|<^K8kR8t`wner6#b-FjU#7hT_&^sl$@oR+w58dbWbU-uxSiy10ZDqP+23 zNbc1_fCit7d{dN_H*VhcqI;Kr)AJQ$IzEo?UdD+Z%_oC2o=*IkP3N;o;`jaY>G^!r zPi^SC&jtSU^vn*@huC4=wU4cRe=t9_{;N2BDR_N9lMfkwKlM{a&f;M_+4TF95U(jr zGrGFLrqADxA9iFLsT4=HQ(W;q+kGd%zyE-TJ&?Ei@A~sPKz?h#&4ocEXPaL^;N1iZ zq_ezNG05_uS`_8D3U;&tIon=+v0JNcF8}`Z4hX1w9PP^%UdMWt&)y} zy3HTm5*l!Sod<%Q9Q$JQn+MYl(_hU3c#-+y}+9XFdOc|D?AWZ1$c?#w?&A zs2R4@&?_UhbxUQ~DKG+uv0GpihP?u#Fzgo?Fi74A|LpjqI7xLyTDG_8TRe*F7GB$G zCp)q2!uAL+odnDU?2OyPE8xa`-9WN-2kULx=nT|B()IubB5}ix+R0rJ2+siQ5Z9}C zGQ?BY;{US*PtVZKusXf)Nqv)#)CpJaAv?1X{F8x|t=v;pXIWi_oLTVLkMJJtJXV6N zmSpw8W?5|pTejum5HDO=DS2!4mepq{u#7`|Rd5wYF(mIc@DLyM5XXEJh8k=sTWXWR zp2071ct{144H^vYjLU8={sk^{e63pNJ_AyI31JB>}FUeRBMLVrR+mt9Udz#Yd;~ z`1x$gk4(vNGM`Bvxj3Gu@#x|Cg?#(M4^J#N`H5&>uX-QqPosE$-@EdsQL{Ggc?&9Qpv_0UeoHl1CFzM`sVDZMzPVwFn&M5+}a VJsD5K`N%$HZxU+uQFHa@KLH_mN&Nr- literal 0 HcmV?d00001 diff --git a/test00.py b/test00.py new file mode 100755 index 0000000..0a03945 --- /dev/null +++ b/test00.py @@ -0,0 +1,24 @@ +from surf.util import cube +from surf.subd import cc + +polygon = cube() +print polygon + +refined_poly = cc.refine(polygon) +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()