0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022"""inherent from and intialize cvisual primitives to use as PyGeo drawing primitives; and create a primitive for
0023the drawing of a wireframe sphere"""
0024
0025try:
0026 import cvisual
0027except ImportError:
0028 import visual.cvisual as cvisual
0029
0030from pygeo.base.analytics.pygeomath import *
0031
0032PyGeoPrimtives=['frame','sphere','curve','label','convex','arrow','faces','pyramid','box','wiresphere']
0033
0034def cvisual_init(primitive,frame,**kws):
0035 for key, value in kws.iteritems():
0036 primitive.__setattr__(key, value)
0037 primitive._complete_init(primitive,primitive,
0038 True, cvisual.display.get_selected(), frame)
0039
0040
0041class sphere (cvisual.sphere):
0042 def __init__( self,frame=None,**kws):
0043 cvisual.sphere.__init__(self)
0044 cvisual_init(self,frame,**kws)
0045 pos = property( cvisual.sphere._get_pos, cvisual.sphere._set_pos, None)
0046 axis = property( cvisual.sphere._get_axis, cvisual.sphere._set_axis, None)
0047 up = property( cvisual.sphere._get_up, cvisual.sphere._set_up, None)
0048
0049
0050class curve (cvisual.curve):
0051 def __init__( self,frame=None,**kws):
0052 cvisual.curve.__init__(self)
0053 cvisual_init(self,frame,**kws)
0054 pos = property( cvisual.curve._get_pos, cvisual.curve._set_pos, None)
0055 color = property( cvisual.curve._get_color, cvisual.curve._set_color, None)
0056
0057
0058class frame (cvisual.frame):
0059 def __init__( self,frame=None,**kws):
0060 cvisual.frame.__init__(self)
0061 cvisual_init(self,frame,**kws)
0062 pos = property( cvisual.frame._get_pos, cvisual.frame._set_pos, None)
0063 axis = property( cvisual.frame._get_axis, cvisual.frame._set_axis, None)
0064 up = property( cvisual.frame._get_up, cvisual.frame._set_up, None)
0065
0066
0067class label (cvisual.label):
0068 def __init__( self, frame=None, **kws):
0069 cvisual.label.__init__(self)
0070 cvisual_init(self,frame,**kws)
0071 pos = property( cvisual.label._get_pos, cvisual.label._set_pos, None)
0072
0073
0074class convex( cvisual.convex):
0075 def __init__( self, frame=None, **kws):
0076 cvisual.convex.__init__(self)
0077 cvisual_init(self,frame,**kws)
0078 pos = property( cvisual.convex._get_pos, cvisual.convex._set_pos, None)
0079
0080
0081class arrow (cvisual.arrow):
0082 def __init__( self, frame=None, **kws):
0083 cvisual.arrow.__init__(self)
0084 cvisual_init(self,frame,**kws)
0085 pos = property( cvisual.primitive._get_pos, cvisual.primitive._set_pos, None)
0086 axis = property( cvisual.primitive._get_axis, cvisual.primitive._set_axis, None)
0087 up = property( cvisual.primitive._get_up, cvisual.primitive._set_up, None)
0088
0089
0090class faces( cvisual.faces):
0091 def __init__( self,frame=None,**kws):
0092 cvisual.faces.__init__(self)
0093 cvisual_init(self,frame,**kws)
0094 pos = property( cvisual.faces._get_pos, cvisual.faces._set_pos, None)
0095 normal = property( cvisual.faces._get_normal, cvisual.faces._set_normal, None)
0096 color = property( cvisual.faces._get_color, cvisual.faces._set_color, None)
0097
0098
0099class pyramid (cvisual.pyramid):
0100 def __init__( self,frame=None,**kws):
0101 cvisual.pyramid.__init__(self)
0102 cvisual_init(self,frame,**kws)
0103 pos = property( cvisual.pyramid._get_pos, cvisual.pyramid._set_pos, None)
0104 axis = property( cvisual.pyramid._get_axis, cvisual.pyramid._set_axis, None)
0105 up = property( cvisual.pyramid._get_up, cvisual.pyramid._set_up, None)
0106
0107class box (cvisual.box):
0108 def __init__( self, frame=None, **kws):
0109 cvisual.box.__init__(self)
0110 cvisual_init(self,frame,**kws)
0111 pos = property( cvisual.box._get_pos, cvisual.box._set_pos, None)
0112 axis = property( cvisual.box._get_axis, cvisual.box._set_axis, None)
0113 up = property( cvisual.box._get_up, cvisual.box._set_up, None)
0114
0115class wiresphere:
0116 def __init__(self,density):
0117 self.density=density
0118 self.stack_increment = PI /(density+1)
0119 self.slice_increment = PI /density
0120 def getstacks(self):
0121 stackAngle = self.stack_increment
0122 wireStack=[0]*self.density
0123 for i in range(self.density):
0124 sliceAngle = 0.0;
0125 newstack = [0]*self.density
0126 for j in range(self.density):
0127 newstackvect = (sin(stackAngle) * sin(sliceAngle),
0128 sin(stackAngle) * cos(sliceAngle),
0129 cos(stackAngle))
0130 newstack[j] = newstackvect
0131 sliceAngle -= self.slice_increment * 2.0
0132 newstack.append(newstack[0])
0133 wireStack[i] = newstack
0134 stackAngle +=self.stack_increment
0135 return array(wireStack,'d')
0136
0137 def getslices(self):
0138 sliceAngle = 0.0;
0139 wireSlice=[0]*self.density
0140 for i in range(self.density):
0141 stackAngle = 0.0
0142 newslice=[1]*(self.density+1)
0143 for j in range(self.density+1):
0144 newslicevect=vector(sin(stackAngle) * sin(sliceAngle),
0145 sin(stackAngle) * cos(sliceAngle),
0146 cos(stackAngle))
0147 newslice[j] =newslicevect
0148 stackAngle -= self.slice_increment
0149 wireSlice[i] = newslice
0150 sliceAngle += self.slice_increment * 2.0
0151 return array(wireSlice,'d')
0152
0153
0154__author__ = "Arthur Siegel <ajsiegel@optonline.com>"
0155__date__ = "$Date: 2006-02-02 $"
0156__revision__ = "$Revision: a1 $"
0157__url__ = "$URL: http://source.net/projects/pygeo $"
0158__copyright__ ="GPL <http://www.opensource.org/licenses/gpl-license.php>"