Removed home-grown Profiling class, cProfile does a much better job.
[blender-addons-contrib.git] / geodesic_domes / geodesic_classes_271.py
1 #werkt from geodesic_domes.vefm_270 import *
2 from geodesic_domes.vefm_271 import mesh, vertex, edge, face
3
4 import math
5 from math import pi,acos,sin,cos,atan,tan,fabs, sqrt
6
7 def check_contains(cl,name , print_value = False):
8     dir_class = dir(cl)
9     for el in dir_class:
10         if el.startswith("_"):
11             pass
12         else:
13             if print_value:
14                 tmp = getattr(cl,el)
15                 print(name , " contains ==>",el," value = ", tmp)
16             else:
17                 print(name , " contains ==>",el)
18     print("\ncheck_contains finished\n\n")
19
20 class geodesic(mesh):
21     def __init__(self):
22         mesh.__init__(self)
23         self.PKHG_parameters = None
24 #        print("\n------ geodesic L11 PKHG_parameters",PKHG_parameters)
25         self.panels = []
26         self.vertsdone = []
27         self.skeleton = []                ## List of verts in the full skeleton edges.
28         self.vertskeleton = [] # config needs this member
29         self.edgeskeleton = [] # config needs this member
30         self.sphericalverts = []
31         self.a45 = pi * 0.25
32         self.a90 = pi * 0.5
33         self.a180 = pi
34         self.a270 = pi * 1.5
35         self.a360 = pi * 2
36         #define members here
37         #setparams  needs:
38         self.frequency = None
39         self.eccentricity = None
40         self.squish = None
41         self.radius = None
42         self.square = None
43         self.squarez = None
44         self.cart = None
45         self.shape = None
46         self.baselevel = None
47         self.faceshape = None
48         self.dualflag = None
49         self.rotxy = None
50         self.rotz = None
51         self.klass = None
52         self.sform = None
53         self.super = None
54         self.odd = None
55         #config needs
56         self.panelpoints = None
57         self.paneledges = None
58         self.reversepanel = None
59         self.edgelength = None
60         self.vertsdone = None
61         self.panels = []
62     
63 #PKHG because of unittest approach for a while the following three lines commentd
64 #PKHG do not understand the problems with the next three lines
65 #no does not work        self.setparameters()
66 #        self.makegeodesic()
67 #        self.connectivity()
68
69     def setparameters(self,params):
70         parameters = self.PKHG_parameters = params
71         self.frequency = parameters[0]    ## How many subdivisions - up to 20.
72         self.eccentricity = parameters[1]    ## Elliptical if >1.0.
73         self.squish = parameters[2]        ## Flattened if < 1.0.
74         self.radius = parameters[3]        ## Exactly what it says.
75         self.square = parameters[4]        ## Controls amount of superellipse in X/Y plane.
76         self.squarez = parameters[5]        ## Controls amount of superellipse in Z dimension.
77         self.cart = parameters[6]            ## Cuts out sphericalisation step.
78         self.shape = parameters[7]        ## Full sphere, dome, flatbase.
79         self.baselevel = parameters[8]        ## Where the base is cut on a flatbase dome.
80         self.faceshape = parameters[9]    ## Triangular, hexagonal, tri-hex.
81         self.dualflag = parameters[10]
82         self.rotxy = parameters[11]
83         self.rotz = parameters[12]
84         self.klass = parameters[13]
85         self.sform = parameters[14]
86         self.super = 0                    ## Toggles superellipse.
87         if self.square != 2.0 or self.squarez != 2.0:
88             self.super = 1
89         self.odd = 0                    ## Is the frequency odd. It matters for dome building.
90         if self.frequency % 2 != 0:
91             self.odd = 1
92
93     def makegeodesic(self):
94         self.vertedgefacedata() #PKHG only a pass 13okt11
95         self.config()                    ## Generate all the configuration information.
96         if self.klass:            
97             self.class2()
98         if self.faceshape == 1:
99             self.hexify()                ## Hexagonal faces
100         elif self.faceshape == 2:
101             self.starify()                ## Hex and Triangle faces
102         if self.dualflag:
103             self.dual()
104         if not self.cart:
105             self.sphericalize()    ##   Convert x,y,z positions into spherical u,v.
106         self.sphere2cartesian()    ##   Convert spherical uv back into cartesian x,y,z for final shape.
107         for i in range(len( self.verts)):
108             self.verts[i].index = i
109         for edg in self.edges:
110             edg.findvect()
111
112     def vertedgefacedata(self):
113         pass
114
115 #PKHG 23.1    def config(self, frequency = 1): #???PKHG frequency problem  20 oct.
116     def config(self): #???PKHG frequency problem  20 oct.
117 #PKHG_OK        print("\n20-11 >>>>>>>>>DBG geodesic_classes_270 config L117 called")
118         for i in range(len(self.vertskeleton)):
119             self.vertskeleton[i].index = i
120         for edges in self.edgeskeleton:
121 #???PKHG TODO            s = skeletonrow(self.frequency, edges, 0, self) #self a geodesic
122             s = skeletonrow(self.frequency, edges, 0, self) #self a geodesic
123             self.skeleton.append(s)
124         for i in range(len( self.verts)):
125             self.verts[i].index = i
126         for i in range(len(self.panelpoints)):
127             a = self.vertsdone[self.panelpoints[i][0]][1]
128             b = self.vertsdone[self.panelpoints[i][1]][1]
129             c = self.vertsdone[self.panelpoints[i][2]][1]
130             panpoints = [    self.verts[a],
131                         self.verts[b],
132                         self.verts[c]]
133             panedges = [    self.skeleton[self.paneledges[i][0]],
134                         self.skeleton[self.paneledges[i][1]],
135                         self.skeleton[self.paneledges[i][2]]    ]
136             reverseflag = 0
137             for flag in self.reversepanel:
138                 if flag == i:
139                     reverseflag = 1                     
140             p = panel(panpoints, panedges, reverseflag, self)
141 #PKHG_panels not used?!            self.panels.append(p)
142         
143     def sphericalize(self):
144         if self.shape == 2:
145             self.cutbasecomp()
146         for vert in(self.verts):
147 #PKHG test 20111030        
148 #            x = vert.x
149 #            y = vert.y
150 #            z = vert.z
151             x = vert.vector.x
152             y = vert.vector.y
153             z = vert.vector.z
154
155             u = self.usphericalise(x,y,z)
156             v = self.vsphericalise(x,y,z)
157             self.sphericalverts.append([u,v])
158
159     def sphere2cartesian(self):
160 #PKHG_TODOnot_now        check_contains(self,"sphereto self",True)
161         for i in range(len(self.verts)):
162             if self.cart:
163 #PKHG test 20111030                        
164 #                x = self.verts[i].x * self.radius * self.eccentricity
165 #                y = self.verts[i].y * self.radius
166 #                z = self.verts[i].z * self.radius * self.squish
167                 x = self.verts[i].vector.x * self.radius * self.eccentricity
168                 y = self.verts[i].vector.y * self.radius
169                 z = self.verts[i].vector.z * self.radius * self.squish
170             else:
171                 u = self.sphericalverts[i][0]
172                 v = self.sphericalverts[i][1]
173                 if self.squish != 1.0 or self.eccentricity>1.0:
174                     scalez = 1 / self.squish
175                     v = self.ellipsecomp(scalez,v)
176                     u = self.ellipsecomp(self.eccentricity,u)
177                 if self.super:
178                     r1 = self.superell(self.square,u,self.rotxy)
179                     r2 = self.superell(self.squarez,v,self.rotz)
180                 else:
181                     r1 = 1.0
182                     r2 = 1.0
183                 
184             #    print "sform",self.sform,"  u",u,"  v",v
185                 if self.sform[12]:                    
186                     r1 = r1 * self.superform(self.sform[0],self.sform[1],\
187                                              self.sform[2],self.sform[3],\
188                                              self.sform[14] + u,self.sform[4],\
189                                              self.sform[5],self.sform[16] * v)
190                 if self.sform[13]:
191                     r2 = r2 * self.superform(self.sform[6],self.sform[7],\
192                                              self.sform[8],self.sform[9],\
193                                              self.sform[15] + v,self.sform[10],\
194                                              self.sform[11],self.sform[17] * v)
195                 x,y,z = self.cartesian(u,v,r1,r2)
196 #PKHG test 20111030                        
197 #            self.verts[i].x = x
198 #            self.verts[i].y = y
199 #            self.verts[i].z = z
200             self.verts[i] = vertex((x,y,z))
201         
202     def usphericalise(self,x,y,z):
203         if y == 0.0:
204             if x>0:
205                 theta = 0.0
206             else:
207                 theta = self.a180
208         elif x == 0.0:
209             if y>0:
210                 theta = self.a90
211             else:
212                 theta = self.a270
213                 
214         else:
215             theta = atan(y / x)
216         if x < 0.0 and y < 0.0:
217             theta = theta + self.a180
218         elif x < 0.0 and y>0.0:
219             theta = theta + self.a180
220         u = theta
221         return u
222     
223     def vsphericalise(self,x,y,z) :
224         if z == 0.0:
225             phi = self.a90
226         else:
227             rho = sqrt(x ** 2 + y**2 + z**2)
228             phi = acos(z / rho)
229         v = phi
230         return v
231     def ellipsecomp(self,efactor,theta):
232         if theta == self.a90:
233             result = self.a90
234         elif theta == self.a270:
235             result = self.a270
236         else:
237             result = atan(tan(theta) / efactor**0.5)
238             if result>=0.0:
239                 x = result
240                 y = self.a180 + result
241                 if fabs(x - theta) <= fabs(y - theta):
242                     result = x
243                 else:
244                     result = y
245             else:
246                 x = self.a180 + result
247                 y = result
248             
249                 if fabs(x - theta) <= fabs(y - theta):
250                     result = x
251                 else:
252                     result = y
253         return result
254     def cutbasecomp(self):
255         pass
256
257     def cartesian(self,u,v,r1,r2):
258         x = r1 * cos(u) * r2 * sin(v) * self.radius * self.eccentricity
259         y = r1 * sin(u) * r2 * sin(v) * self.radius
260         z = r2 * cos(v) * self.radius * self.squish
261         return x,y,z
262 #     def connectivity(self):
263
264 #         self.dovertedge()
265 #         self.dovertface()
266 #         self.dofaceedge()
267
268 class edgerow:
269     def __init__(self, count, anchor, leftindex, rightindex, stepvector, endflag, parentgeo):
270         self.points = []
271         self.edges = []
272         ## Make a row of evenly spaced points.
273         for i in range(count + 1):
274             if i == 0:
275                 self.points.append(leftindex)
276             elif i == count and not endflag:
277                 self.points.append(rightindex)
278             else: #PKHG Vectors added!
279                 newpoint = anchor + (stepvector * i)
280                 vertcount = len(parentgeo.verts)
281                 self.points.append(vertcount)
282                 newpoint.index = vertcount
283                 parentgeo.verts.append(newpoint)
284         for i in range(count):
285             a = parentgeo.verts[self.points[i]]
286             b = parentgeo.verts[self.points[i + 1]]
287             line = edge(a,b)
288             self.edges.append(len(parentgeo.edges))
289             parentgeo.edges.append(line)
290
291 class skeletonrow:
292     def __init__(self, count, skeletonedge, shortflag, parentgeo):
293         self.points = []
294         self.edges = []
295         self.vect = skeletonedge.vect
296         self.step = skeletonedge.vect / float(count)
297         ## Make a row of evenly spaced points.
298         for i in range(count + 1):
299             vert1 = skeletonedge.a
300             vert2 = skeletonedge.b
301             if i == 0:
302                 if parentgeo.vertsdone[vert1.index][0]:
303                     self.points.append(parentgeo.vertsdone[vert1.index][1])
304                 else:
305 #PKHG test 20111030
306 #                    newpoint = vertex((vert1.x, vert1.y, vert1.z))
307                     newpoint = vertex(vert1.vector)
308                     vertcount = len(parentgeo.verts)
309                     self.points.append(vertcount)
310                     newpoint.index = vertcount
311                     parentgeo.vertsdone[vert1.index] = [1,vertcount]
312                     parentgeo.verts.append(newpoint)                    
313                     
314             elif i == count:
315                 if parentgeo.vertsdone[vert2.index][0]:
316                     self.points.append(parentgeo.vertsdone[vert2.index][1])
317                 else:
318 #PKHG test 20111030                    
319 #                    newpoint = vertex((vert2.x, vert2.y, vert2.z))
320                     newpoint = vertex(vert2.vector)
321                     vertcount = len(parentgeo.verts)
322                     self.points.append(vertcount)
323                     newpoint.index = vertcount
324                     parentgeo.vertsdone[vert2.index] = [1,vertcount]
325                     parentgeo.verts.append(newpoint)                    
326             else:
327                 newpoint = vertex(vert1.vector + (self.step * i)) #must be a vertex!
328                 vertcount = len(parentgeo.verts)
329                 self.points.append(vertcount)
330                 newpoint.index = vertcount
331                 parentgeo.verts.append(newpoint)
332         for i in range(count):
333             a = parentgeo.verts[self.points[i]]
334             b = parentgeo.verts[self.points[i + 1]]
335             line = edge(a,b)
336             self.edges.append(len(parentgeo.edges))
337             parentgeo.edges.append(line)
338
339 class facefill:
340     def __init__(self, upper, lower, reverseflag, parentgeo, finish):
341         for i in range(finish):
342             a,b,c = upper.points[i],lower.points[i + 1],lower.points[i]
343             if reverseflag:
344                 upface = face([parentgeo.verts[a],parentgeo.verts[c],parentgeo.verts[b]])
345             else:
346                 upface = face([parentgeo.verts[a],parentgeo.verts[b],parentgeo.verts[c]])
347             parentgeo.faces.append(upface)
348             if i == finish - 1:
349                 pass
350             else:
351                 d = upper.points[i + 1]
352                 if reverseflag:
353                     downface = face([parentgeo.verts[b],parentgeo.verts[d],parentgeo.verts[a]])
354                 else:
355                     downface = face([parentgeo.verts[b],parentgeo.verts[a],parentgeo.verts[d]])
356                 line = edge(parentgeo.verts[a],parentgeo.verts[b])
357                 line2 = edge(parentgeo.verts[d],parentgeo.verts[b])
358                 parentgeo.faces.append(downface)
359                 parentgeo.edges.append(line)
360                 parentgeo.edges.append(line2)
361 class panel:
362     def __init__(self, points, edges, reverseflag, parentgeo):
363         self.cardinal = points[0]
364         self.leftv = points[1]
365         self.rightv = points[2]
366         self.leftedge = edges[0]
367         self.rightedge = edges[1]
368         self.baseedge = edges[2]
369         self.rows=[]
370         self.orient(parentgeo,edges)
371         self.createrows(parentgeo)
372         self.createfaces(parentgeo,reverseflag)
373
374     def orient(self,parentgeo,edges):
375         if self.leftedge.points[0] != self.cardinal.index:
376             self.leftedge.points.reverse()
377             self.leftedge.vect.negative()
378         
379         if self.rightedge.points[0] != self.cardinal.index:
380             self.rightedge.points.reverse()
381             self.rightedge.vect.negative()
382         
383         if self.baseedge.points[0] != self.leftv.index:
384         
385             self.baseedge.points.reverse()
386             self.baseedge.vect.negative()
387
388     def createrows(self, parentgeo):
389         for i in range(len(self.leftedge.points)):
390             if i == parentgeo.frequency:
391                 newrow = self.baseedge
392             else:
393                 newrow = edgerow(i, parentgeo.verts[self.leftedge.points[i]], self.leftedge.points[i], self.rightedge.points[i], self.baseedge.step, 0, parentgeo )
394             self.rows.append(newrow)
395     def createfaces(self, parentgeo,reverseflag):
396         for i in range(len(self.leftedge.points) - 1):
397             facefill(self.rows[i], self.rows[i + 1], reverseflag, parentgeo, len(self.rows[i].points))
398 #############################
399 #############################
400
401 #for point on top?  YES!          
402 class tetrahedron(geodesic,mesh):
403     def __init__(self,parameter):
404         geodesic.__init__(mesh)
405         geodesic.setparameters(self,parameter)
406         self.set_vert_edge_skeleons()
407         
408     def set_vert_edge_skeleons(self):
409         self.vertskeleton=[        vertex(( 0.0 , 0.0 , 1.73205080757 )),
410                             vertex(( 0.0 , -1.63299316185 , -0.577350269185 )),
411                             vertex(( 1.41421356237 , 0.816496580927 , -0.57735026919 )),
412                             vertex(( -1.41421356237 , 0.816496580927 , -0.57735026919 ))    ]
413         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
414                             edge(self.vertskeleton[0],self.vertskeleton[2]),
415                             edge(self.vertskeleton[0],self.vertskeleton[3]),
416                             edge(self.vertskeleton[1],self.vertskeleton[2]),
417                             edge(self.vertskeleton[2],self.vertskeleton[3]),
418                             edge(self.vertskeleton[1],self.vertskeleton[3])    ]
419         
420 ### probably to be removed, other gui! : "#??? delete PKHG"
421         self.panelpoints=[[0,1,2],[0,2,3],[0,1,3],[1,2,3]]
422         self.paneledges=[[0,1,3],[1,2,4],[0,2,5],[3,5,4]]
423         self.reversepanel=[2,3]
424         self.edgelength=[]
425         self.vertsdone=[[0,0]] * len(self.vertskeleton)
426
427 #for edge on top? YES
428 class tetraedge(geodesic):
429     def __init__(self,parameter):
430         geodesic.__init__(mesh)
431         geodesic.setparameters(self,parameter)
432         self.set_vert_edge_skeleons()
433     def set_vert_edge_skeleons(self):
434         self.vertskeleton=[        vertex(( 0.0 , -1.41421356237 , 1.0 )),
435                             vertex(( 0.0 , 1.41421356237 , 1.0 )),
436                             vertex(( 1.41421356237 , 0.0 , -1.0 )),
437                             vertex(( -1.41421356237 , 0.0 , -1.0 ))    ]
438         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
439                             edge(self.vertskeleton[0],self.vertskeleton[2]),
440                             edge(self.vertskeleton[0],self.vertskeleton[3]),
441                             edge(self.vertskeleton[1],self.vertskeleton[3]),
442                             edge(self.vertskeleton[1],self.vertskeleton[2]),
443                             edge(self.vertskeleton[2],self.vertskeleton[3])    ]
444         for i in range(len(self.vertskeleton)):
445             self.vertskeleton[i].index = i
446         self.panelpoints=[[0,1,2],[1,2,3],[0,1,3],[0,2,3]]
447         self.paneledges=[[0,1,4],[4,3,5],[0,2,3],[1,2,5]]
448         self.reversepanel=[0,3]
449         self.edgelength=[]
450         self.vertsdone=[[0,0]] * len(self.vertskeleton)
451
452 #for face on top? YES
453 class tetraface(geodesic):
454     def __init__(self,parameter):
455         geodesic.__init__(mesh)
456         geodesic.setparameters(self,parameter)
457         self.set_vert_edge_skeleons()
458     def set_vert_edge_skeleons(self):
459         self.vertskeleton=[        vertex(( -1.41421356237 , -0.816496580927 , 0.57735026919 )),
460                             vertex(( 1.41421356237 , -0.816496580927 , 0.57735026919 )),
461                             vertex(( 0.0 , 1.63299316185 , 0.577350269185 )),
462                             vertex(( 0.0 , 0.0 , -1.73205080757 ))    ]
463         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
464                             edge(self.vertskeleton[2],self.vertskeleton[1]),
465                             edge(self.vertskeleton[2],self.vertskeleton[0]),
466                             edge(self.vertskeleton[0],self.vertskeleton[3]),
467                             edge(self.vertskeleton[1],self.vertskeleton[3]),
468                             edge(self.vertskeleton[2],self.vertskeleton[3])    ]
469         self.panelpoints=[[2,0,1],[0,1,3],[2,1,3],[2,0,3]]
470         self.paneledges=[[2,1,0],[0,3,4],[1,5,4],[2,5,3]]
471         self.reversepanel=[1,3]
472         self.edgelength=[]
473         self.vertsdone=[[0,0]] * len(self.vertskeleton)
474
475 class octahedron(geodesic):
476     def __init__(self,parameter):
477         geodesic.__init__(mesh)
478         geodesic.setparameters(self,parameter)
479         self.set_vert_edge_skeleons()
480     def set_vert_edge_skeleons(self):
481         self.vertskeleton=[        vertex((0.0,0.0,1.0)),
482                             vertex((0.0,1.0,0.0)),
483                             vertex((-1.0,0.0,0.0)),
484                             vertex((0.0,-1.0,0.0)),
485                             vertex((1.0,0.0,0.0)),
486                             vertex((0.0,0.0,-1.0))    ]
487         for i in range(len(self.vertskeleton)):
488             self.vertskeleton[i].index = i
489         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
490                             edge(self.vertskeleton[0],self.vertskeleton[2]),
491                             edge(self.vertskeleton[0],self.vertskeleton[3]),
492                             edge(self.vertskeleton[0],self.vertskeleton[4]),
493                             edge(self.vertskeleton[1],self.vertskeleton[2]),
494                             edge(self.vertskeleton[2],self.vertskeleton[3]),
495                             edge(self.vertskeleton[3],self.vertskeleton[4]),
496                             edge(self.vertskeleton[4],self.vertskeleton[1]),
497                             edge(self.vertskeleton[1],self.vertskeleton[5]),
498                             edge(self.vertskeleton[2],self.vertskeleton[5]),
499                             edge(self.vertskeleton[3],self.vertskeleton[5]),
500                             edge(self.vertskeleton[4],self.vertskeleton[5])    ]
501         self.panelpoints=[[0,1,2],[0,2,3],[0,3,4],[0,4,1],[1,2,5],[2,3,5],[3,4,5],[4,1,5]]
502         self.paneledges=[[0,1,4],[1,2,5],[2,3,6],[3,0,7],[4,8,9],[5,9,10],[6,10,11],[7,11,8]]
503         self.reversepanel=[4,5,6,7]
504         self.edgelength=[]
505         self.vertsdone=[[0,0]] * len(self.vertskeleton)
506 class octaedge(geodesic):
507     def __init__(self,parameter):
508         geodesic.__init__(mesh)
509         geodesic.setparameters(self,parameter)
510         self.set_vert_edge_skeleons()
511     def set_vert_edge_skeleons(self):
512         self.vertskeleton=[        vertex(( 0.0 , -0.707106781187 , 0.707106781187 )),
513                             vertex(( 0.0 , 0.707106781187 , 0.707106781187 )),
514                             vertex(( 1.0 , 0.0 , 0.0 )),
515                             vertex(( -1.0 , 0.0 , 0.0 )),
516                             vertex(( 0.0 , -0.707106781187 , -0.707106781187 )),
517                             vertex(( 0.0 , 0.707106781187 , -0.707106781187 ))    ]
518         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
519                             edge(self.vertskeleton[0],self.vertskeleton[4]),
520                             edge(self.vertskeleton[0],self.vertskeleton[2]),
521                             edge(self.vertskeleton[1],self.vertskeleton[2]),
522                                edge(self.vertskeleton[1],self.vertskeleton[5]),
523                             edge(self.vertskeleton[1],self.vertskeleton[3]),
524                             edge(self.vertskeleton[0],self.vertskeleton[3]),
525                             edge(self.vertskeleton[2],self.vertskeleton[4]),
526                                edge(self.vertskeleton[2],self.vertskeleton[5]),
527                             edge(self.vertskeleton[3],self.vertskeleton[5]),
528                             edge(self.vertskeleton[3],self.vertskeleton[4]),
529                             edge(self.vertskeleton[4],self.vertskeleton[5])    ]
530         self.panelpoints=[[0,1,2],[0,1,3],[0,2,4],[1,2,5],[1,3,5],[0,3,4],[2,4,5],[3,4,5]]
531         self.paneledges=[[0,2,3],[0,6,5],[2,1,7],[3,4,8],[5,4,9],[6,1,10],[7,8,11],[10,9,11]]
532         self.reversepanel=[0,2,4,7]
533         self.edgelength=[]
534         self.vertsdone=[[0,0]] * len(self.vertskeleton)
535 class octaface(geodesic):
536     def __init__(self,parameter):
537         geodesic.__init__(mesh)
538         geodesic.setparameters(self,parameter)
539         self.set_vert_edge_skeleons()
540     def set_vert_edge_skeleons(self):
541         self.vertskeleton=[        vertex(( 0.408248458663 , -0.707106781187 , 0.577350150255 )),
542                             vertex(( 0.408248458663 , 0.707106781187 , 0.577350150255 )),
543                             vertex(( -0.816496412728 , 0.0 , 0.577350507059 )),
544                             vertex(( -0.408248458663 , -0.707106781187 , -0.577350150255 )),
545                             vertex(( 0.816496412728 , 0.0 , -0.577350507059 )),
546                             vertex(( -0.408248458663 , 0.707106781187 , -0.577350150255 ))    ]
547         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
548                             edge(self.vertskeleton[2],self.vertskeleton[1]),
549                             edge(self.vertskeleton[2],self.vertskeleton[0]),
550                             edge(self.vertskeleton[0],self.vertskeleton[3]),
551                              edge(self.vertskeleton[0],self.vertskeleton[4]),
552                             edge(self.vertskeleton[1],self.vertskeleton[4]),
553                             edge(self.vertskeleton[1],self.vertskeleton[5]),
554                             edge(self.vertskeleton[2],self.vertskeleton[5]),
555                             edge(self.vertskeleton[2],self.vertskeleton[3]),
556                             edge(self.vertskeleton[3],self.vertskeleton[4]),
557                             edge(self.vertskeleton[4],self.vertskeleton[5]),
558                             edge(self.vertskeleton[3],self.vertskeleton[5])    ]
559         self.panelpoints=[[2,0,1],[0,3,4],[0,1,4],[1,4,5],[2,1,5],[2,3,5],[2,0,3],[3,4,5]]
560         self.paneledges=[[2,1,0],[3,4,9],[0,4,5],[5,6,10],[1,7,6],[8,7,11],[2,8,3],[9,11,10]]
561         self.reversepanel=[2,5,6,7]
562         self.edgelength=[]
563         self.vertsdone=[[0,0]] * len(self.vertskeleton)
564 class icosahedron(geodesic):
565     def __init__(self,parameter):
566         geodesic.__init__(mesh)
567         geodesic.setparameters(self,parameter)
568         self.set_vert_edge_skeleons()
569     def set_vert_edge_skeleons(self):
570         self.vertskeleton=[        vertex(( 0.0 , 0.0 , 0.587785252292 )),
571                             vertex(( 0.0 , -0.525731096637 , 0.262865587024 )),
572                             vertex(( 0.5 , -0.162459832634 , 0.262865565628 )),
573                             vertex(( 0.309016994375 , 0.425325419658 , 0.262865531009 )),
574                             vertex(( -0.309016994375 , 0.425325419658 , 0.262865531009 )),
575                             vertex(( -0.5 , -0.162459832634 , 0.262865565628 )),
576                             vertex(( 0.309016994375 , -0.425325419658 , -0.262865531009 )),
577                             vertex(( 0.5 , 0.162459832634 , -0.262865565628 )),
578                             vertex(( 0.0 , 0.525731096637 , -0.262865587024 )),
579                             vertex(( -0.5 , 0.162459832634 , -0.262865565628 )),
580                             vertex(( -0.309016994375 , -0.425325419658 , -0.262865531009 )),
581                             vertex(( 0.0 , 0.0 , -0.587785252292 ))    ]
582         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
583                             edge(self.vertskeleton[0],self.vertskeleton[2]),
584                             edge(self.vertskeleton[0],self.vertskeleton[3]),
585                             edge(self.vertskeleton[0],self.vertskeleton[4]),
586                             edge(self.vertskeleton[0],self.vertskeleton[5]),
587                             edge(self.vertskeleton[1],self.vertskeleton[2]),
588                             edge(self.vertskeleton[2],self.vertskeleton[3]),
589                             edge(self.vertskeleton[3],self.vertskeleton[4]),
590                             edge(self.vertskeleton[4],self.vertskeleton[5]),
591                             edge(self.vertskeleton[5],self.vertskeleton[1]),
592                             edge(self.vertskeleton[1],self.vertskeleton[6]),
593                             edge(self.vertskeleton[2],self.vertskeleton[6]),
594                             edge(self.vertskeleton[2],self.vertskeleton[7]),
595                             edge(self.vertskeleton[3],self.vertskeleton[7]),
596                             edge(self.vertskeleton[3],self.vertskeleton[8]),
597                             edge(self.vertskeleton[4],self.vertskeleton[8]),
598                             edge(self.vertskeleton[4],self.vertskeleton[9]),
599                             edge(self.vertskeleton[5],self.vertskeleton[9]),
600                             edge(self.vertskeleton[5],self.vertskeleton[10]),
601                             edge(self.vertskeleton[1],self.vertskeleton[10]),
602                             edge(self.vertskeleton[6],self.vertskeleton[7]),
603                             edge(self.vertskeleton[7],self.vertskeleton[8]),
604                             edge(self.vertskeleton[8],self.vertskeleton[9]),
605                             edge(self.vertskeleton[9],self.vertskeleton[10]),
606                             edge(self.vertskeleton[10],self.vertskeleton[6]),
607                             edge(self.vertskeleton[6],self.vertskeleton[11]),
608                             edge(self.vertskeleton[7],self.vertskeleton[11]),
609                             edge(self.vertskeleton[8],self.vertskeleton[11]),
610                             edge(self.vertskeleton[9],self.vertskeleton[11]),
611                             edge(self.vertskeleton[10],self.vertskeleton[11])    ]
612         self.panelpoints=[[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,1],[1,2,6],[2,6,7],[2,3,7],[3,7,8],[3,4,8],[4,8,9],[4,5,9],[5,9,10],[5,1,10],[1,10,6],[6,7,11],[7,8,11],[8,9,11],[9,10,11],[10,6,11]]
613         self.paneledges=[[0,1,5],[1,2,6],[2,3,7],[3,4,8],[4,0,9],[5,10,11],[11,12,20],[6,12,13],[13,14,21],[7,14,15],[15,16,22],[8,16,17],[17,18,23],[9,18,19],[19,10,24],[20,25,26],[21,26,27],[22,27,28],[23,28,29],[24,29,25]]
614         self.reversepanel=[5,7,9,11,13,15,16,17,18,19]
615         self.edgelength=[]
616         self.vertsdone=[[0,0]] * len(self.vertskeleton)
617 class icoedge(geodesic):
618     def __init__(self,parameter):
619         geodesic.__init__(mesh)
620         geodesic.setparameters(self,parameter)
621         self.set_vert_edge_skeleons()
622     def set_vert_edge_skeleons(self):
623         self.vertskeleton=[        vertex(( 0 , 0.309016994375 , 0.5 )),
624                             vertex(( 0 , -0.309016994375 , 0.5 )),
625                             vertex(( -0.5 , 0 , 0.309016994375 )),
626                             vertex(( 0.5 , 0 , 0.309016994375 )),
627                             vertex(( -0.309016994375 , -0.5 , 0 )),
628                             vertex(( 0.309016994375 , -0.5 , 0 )),
629                             vertex(( 0.309016994375 , 0.5 , 0 )),
630                             vertex(( -0.309016994375 , 0.5 , 0 )),
631                             vertex(( -0.5 , 0 , -0.309016994375 )),
632                             vertex(( 0.5 , 0 , -0.309016994375 )),
633                             vertex(( 0 , 0.309016994375 , -0.5 )),
634                             vertex(( 0 , -0.309016994375 , -0.5 ))    ]
635         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
636                             edge(self.vertskeleton[0],self.vertskeleton[7]),
637                             edge(self.vertskeleton[0],self.vertskeleton[2]),
638                             edge(self.vertskeleton[1],self.vertskeleton[2]),
639                             edge(self.vertskeleton[1],self.vertskeleton[4]),
640                             edge(self.vertskeleton[1],self.vertskeleton[5]),
641                             edge(self.vertskeleton[1],self.vertskeleton[3]),
642                             edge(self.vertskeleton[0],self.vertskeleton[3]),
643                             edge(self.vertskeleton[0],self.vertskeleton[6]),
644                             edge(self.vertskeleton[2],self.vertskeleton[7]),
645                             edge(self.vertskeleton[2],self.vertskeleton[8]),
646                             edge(self.vertskeleton[2],self.vertskeleton[4]),
647                             edge(self.vertskeleton[4],self.vertskeleton[5]),
648                             edge(self.vertskeleton[3],self.vertskeleton[5]),
649                             edge(self.vertskeleton[3],self.vertskeleton[9]),
650                             edge(self.vertskeleton[3],self.vertskeleton[6]),
651                             edge(self.vertskeleton[6],self.vertskeleton[7]),
652                             edge(self.vertskeleton[7],self.vertskeleton[10]),
653                             edge(self.vertskeleton[7],self.vertskeleton[8]),
654                             edge(self.vertskeleton[4],self.vertskeleton[8]),
655                             edge(self.vertskeleton[4],self.vertskeleton[11]),
656                             edge(self.vertskeleton[5],self.vertskeleton[11]),
657                             edge(self.vertskeleton[5],self.vertskeleton[9]),
658                             edge(self.vertskeleton[6],self.vertskeleton[9]),
659                             edge(self.vertskeleton[6],self.vertskeleton[10]),
660                             edge(self.vertskeleton[8],self.vertskeleton[10]),
661                             edge(self.vertskeleton[8],self.vertskeleton[11]),
662                             edge(self.vertskeleton[9],self.vertskeleton[11]),
663                             edge(self.vertskeleton[9],self.vertskeleton[10]),
664                             edge(self.vertskeleton[10],self.vertskeleton[11])    ]
665         self.panelpoints=[    [0,1,2],[0,1,3],[0,2,7],[1,2,4],[1,4,5],[1,3,5],[0,3,6],[0,6,7],[2,7,8],[2,4,8],
666                         [3,5,9],[3,6,9],[7,8,10],[4,8,11],[4,5,11],[5,9,11],[6,9,10],[6,7,10],[8,10,11],[9,10,11]]
667         self.paneledges=[[0,2,3],[0,7,6],[2,1,9],[3,4,11],[4,5,12],[6,5,13],[7,8,15],[8,1,16],[9,10,18],[11,10,19],
668                     [13,14,22],[15,14,23],[18,17,25],[19,20,26],[12,20,21],[22,21,27],[23,24,28],[16,24,17],[25,26,29],[28,27,29]]
669         self.reversepanel=[0,2,5,9,11,12,14,15,17,19]
670         self.edgelength=[]
671         self.vertsdone=[[0,0]] * len(self.vertskeleton)
672 class icoface(geodesic):
673     def __init__(self,parameter):
674         geodesic.__init__(mesh)
675         geodesic.setparameters(self,parameter)
676         self.set_vert_edge_skeleons()
677     def set_vert_edge_skeleons(self):
678         self.vertskeleton=[        vertex(( -0.17841104489 , 0.309016994375 , 0.46708617948 )),
679                             vertex(( -0.17841104489 , -0.309016994375 , 0.46708617948 )),
680                             vertex(( 0.35682208977 , 0.0 , 0.467086179484 )),
681                             vertex(( -0.57735026919 , 0.0 , 0.110264089705 )),
682                             vertex(( -0.288675134594 , -0.5 , -0.11026408971 )),
683                             vertex(( 0.288675134594 , -0.5 , 0.11026408971 )),
684                             vertex(( 0.57735026919 , 0.0 , -0.110264089705 )),
685                             vertex(( 0.288675134594 , 0.5 , 0.11026408971 )),
686                             vertex(( -0.288675134594 , 0.5 , -0.11026408971 )),
687                             vertex(( -0.35682208977 , 0.0 , -0.467086179484 )),
688                             vertex(( 0.17841104489 , -0.309016994375 , -0.46708617948 )),
689                             vertex(( 0.17841104489 , 0.309016994375 , -0.46708617948 ))    ]
690         self.edgeskeleton=[    edge(self.vertskeleton[0],self.vertskeleton[1]),
691                             edge(self.vertskeleton[2],self.vertskeleton[1]),
692                             edge(self.vertskeleton[2],self.vertskeleton[0]),
693                             edge(self.vertskeleton[0],self.vertskeleton[3]),
694                             edge(self.vertskeleton[1],self.vertskeleton[3]),
695                             edge(self.vertskeleton[1],self.vertskeleton[4]),
696                             edge(self.vertskeleton[1],self.vertskeleton[5]),
697                             edge(self.vertskeleton[2],self.vertskeleton[5]),
698                             edge(self.vertskeleton[2],self.vertskeleton[6]),
699                             edge(self.vertskeleton[2],self.vertskeleton[7]),
700                             edge(self.vertskeleton[0],self.vertskeleton[7]),
701                             edge(self.vertskeleton[0],self.vertskeleton[8]),
702                             edge(self.vertskeleton[3],self.vertskeleton[9]),
703                             edge(self.vertskeleton[3],self.vertskeleton[4]),
704                             edge(self.vertskeleton[5],self.vertskeleton[4]),
705                             edge(self.vertskeleton[5],self.vertskeleton[10]),
706                             edge(self.vertskeleton[5],self.vertskeleton[6]),
707                             edge(self.vertskeleton[7],self.vertskeleton[6]),
708                             edge(self.vertskeleton[7],self.vertskeleton[11]),
709                             edge(self.vertskeleton[7],self.vertskeleton[8]),
710                             edge(self.vertskeleton[3],self.vertskeleton[8]),
711                             edge(self.vertskeleton[4],self.vertskeleton[9]),
712                             edge(self.vertskeleton[4],self.vertskeleton[10]),
713                             edge(self.vertskeleton[6],self.vertskeleton[10]),
714                             edge(self.vertskeleton[6],self.vertskeleton[11]),
715                             edge(self.vertskeleton[8],self.vertskeleton[11]),
716                             edge(self.vertskeleton[8],self.vertskeleton[9]),
717                             edge(self.vertskeleton[9],self.vertskeleton[10]),
718                             edge(self.vertskeleton[11],self.vertskeleton[10]),
719                             edge(self.vertskeleton[11],self.vertskeleton[9])    ]
720         self.panelpoints=[[2,0,1],[0,1,3],[2,1,5],[2,0,7],[1,3,4],[1,5,4],[2,5,6],[2,7,6],[0,7,8],[0,3,8],[3,4,9],[5,4,10],[5,6,10],[7,6,11],[7,8,11],[3,8,9],[4,9,10],[6,11,10],[8,11,9],[11,9,10]]
721         self.paneledges=[[2,1,0],[0,3,4],[1,7,6],[2,9,10],[4,5,13],[6,5,14],[7,8,16],[9,8,17],[10,11,19],[3,11,20],
722                     [13,12,21],[14,15,22],[16,15,23],[17,18,24],[19,18,25],[20,12,26],[21,22,27],[24,23,28],[25,26,29],[29,28,27]]
723         self.reversepanel=[1,3,5,7,9,10,12,14,17,19]
724         self.edgelength=[]
725         self.vertsdone=[[0,0]] * len(self.vertskeleton)
726
727 ##???PKHG TODO this does not work yet ...
728 def creategeo(geo,polytype,orientation,parameters):
729     
730     if polytype == 'Tetrahedron':
731         if orientation == 'PointUp':
732             #return
733             #geo(parameters)
734 #            geo.setparameters()
735             my_tetrahedron = tetrahedron(geodesic)
736             my_tetrahedron.set_vert_edge_skeleons()
737             my_tetrahedron.config()            
738             check_contains(my_tetrahedron,"my_tetra",True)
739             vefm_add_object(geo)
740         elif orientation == 'EdgeUp':
741             geo = tetraedge(parameters)
742         else: # orientation==2:
743             geo=tetraface(parameters)
744     elif polytype == 'Octahedron':        # octahedron
745         if orientation == 'PointUp':
746             geo = octahedron(parameters)
747         elif orientation == 'EdgeUp':
748             geo = octaedge(parameters)
749         else: #if orientation==2:
750             geo = octaface(parameters)
751     elif polytype == 'Icosahedron':    # icosahedron
752         if orientation == 'PointUp':
753             geo = icosahedron(parameters)
754         elif orientation == 'EdgeUp':
755             geo = icoedge(parameters)
756         else: #if orientation==2:
757             geo = icoface(parameters)
758     return geo