Package PyFoam :: Package Paraview :: Module SimpleSources
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Paraview.SimpleSources

  1  #  ICE Revision: $Id: /local/openfoam/Python/PyFoam/PyFoam/Paraview/SimpleSources.py 4714 2009-03-11T22:10:59.062514Z bgschaid  $  
  2  """ Simple sources 
  3   
  4  Builds and displays simple sources. Grants easy access to the actual source 
  5  and the representation objects""" 
  6   
  7  from paraview import servermanager 
  8   
  9  from PyFoam.Paraview import proxyManager as pm 
 10  from PyFoam.Paraview import renderView as rv 
 11  from PyFoam.Paraview import characteristicLength as lc 
 12  from PyFoam.Paraview import getCenter as gc 
 13  from PyFoam.Paraview import transformsModule as tm 
 14   
 15  from SourceBase import SourceBase 
 16   
 17  import math 
 18   
19 -class SimpleSource(SourceBase):
20 """Base class for the simple sources 21 22 The member src is the actual source object. 23 The member repr is the representation object""" 24
25 - def __init__(self,name,src):
26 """@param name: The name under which the thing should be displayed 27 @param src: the actual source proxy""" 28 SourceBase.__init__(self,src) 29 self.name = name 30 pm.RegisterProxy("sources",self.name,self.src) 31 self.repr=servermanager.CreateRepresentation(self.src,rv()) 32 pm.RegisterProxy("representations",self.name+"_repr",self.repr)
33
34 - def unregister(self):
35 """Unregister the Proxies, but keept the objects""" 36 pm.UnRegisterProxy("sources",self.name,self.src) 37 pm.UnRegisterProxy("representations",self.name+"_repr",self.repr)
38
39 - def __del__(self):
40 """Does not yet work properly""" 41 self.unregister() 42 del self.src 43 del self.repr
44
45 -class Sphere(SimpleSource):
46 """Displays a sphere""" 47
48 - def __init__(self,name,center,relRadius=0.01,absRadius=None):
49 """@param name: name under which the sphere should be displayed 50 @param center: the center of the sphere 51 @param relRadius: radius relative to the characteristic length 52 @param absRadius: absolute radius. Overrides relRadius if set""" 53 54 sphr=servermanager.sources.SphereSource() 55 sphr.Center=list(center) 56 if absRadius: 57 sphr.Radius=absRadius 58 else: 59 sphr.Radius=lc()*relRadius 60 61 SimpleSource.__init__(self,name,sphr)
62
63 -class Point(SimpleSource):
64 """Displays a point""" 65
66 - def __init__(self,name,center):
67 """@param name: name under which the point should be displayed 68 @param center: the center of the point""" 69 70 pt=servermanager.sources.PointSource() 71 pt.Center = list(center) 72 SimpleSource.__init__(self,name,pt)
73
74 -class Line(SimpleSource):
75 """Displays a line""" 76
77 - def __init__(self,name,pt1,pt2):
78 """@param name: name under which the line should be displayed 79 @param pt1: the start of the line 80 @param pt2: the end of the line""" 81 82 ln=servermanager.sources.LineSource() 83 ln.Point1 = list(pt1) 84 ln.Point2 = list(pt2) 85 SimpleSource.__init__(self,name,ln)
86
87 -class Plane(SimpleSource):
88 """Displays a plane""" 89
90 - def __init__(self,name,origin,pt1,pt2):
91 """@param name: name under which the plane should be displayed 92 @param origin: the origin of the plane 93 @param pt1: one point the plane spans to 94 @param pt2: the other point the plane spans to""" 95 96 pl=servermanager.sources.PlaneSource() 97 pl.Origin = list(origin) 98 pl.Point1 = list(pt1) 99 pl.Point2 = list(pt2) 100 SimpleSource.__init__(self,name,pl)
101
102 -class Cube(SimpleSource):
103 """Displays a cube""" 104
105 - def __init__(self,name,pt1,pt2):
106 """@param name: name under which the cube should be displayed 107 @param pt1: Point one that describes the box 108 @param pt2: Point two that describes the box""" 109 110 pt1=self.makeVector(pt1) 111 pt2=self.makeVector(pt2) 112 box=servermanager.sources.CubeSource() 113 box.Center=list(0.5*(pt1+pt2)) 114 diff=pt1-pt2 115 box.XLength=abs(diff[0]) 116 box.YLength=abs(diff[1]) 117 box.ZLength=abs(diff[2]) 118 119 SimpleSource.__init__(self,name,box)
120
121 -class STL(SimpleSource):
122 """Displays a STL-File""" 123
124 - def __init__(self,name,stlFile):
125 """@param name: name under which the surface should be displayed 126 @param stlFile: the STL-file""" 127 128 stl=servermanager.sources.stlreader() 129 stl.FileNames=[stlFile] 130 stl.UpdatePipeline() 131 132 SimpleSource.__init__(self,name,stl)
133
134 -class Text(SimpleSource):
135 """Displays a Vector-Text""" 136
137 - def __init__(self,name,text,scale=1,position=None):
138 """@param name: name under which the sphere should be displayed 139 @param text: the text that will be displayed 140 @param scale: the scaling of the text (in terms ofcharacterist length of the geometry 141 @param position: the actual position at which the object should be centered""" 142 143 txt=servermanager.sources.VectorText() 144 txt.Text=text 145 146 SimpleSource.__init__(self,name,txt) 147 148 if not position: 149 position=gc() 150 self.repr.Translate=list(position) 151 self.repr.Origin=list(position) 152 153 scale*=lc()/self.characteristicLength() 154 155 self.repr.Scale=(scale,scale,scale)
156
157 -class DirectedSource(SimpleSource):
158 """A Source that looks in a specific direction. 159 Assumes that the original base is located at (0 0 0)""" 160
161 - def __init__(self,name,src,base,tip):
162 """@param name: name under which the arrow will be displayed 163 @param src: The source objects 164 @param base: the base the arrow points away from 165 @param tip: the point the arrow points to""" 166 SimpleSource.__init__(self,name,src) 167 self.base=base 168 self.tip =tip 169 self.recalc()
170 # self.arrow=SimpleSource(name,ar) 171 # tf=servermanager.filters.TransformFilter(Input = ar) 172 # trafo=tm().Transform() 173 # trafo.Position = list(base) 174 # trafo.Scale = [abs(base-tip)]*3 175 # tf.Transform = trafo 176 177
178 - def recalc(self):
179 """Recalculate the orientation of the object according to the tip and 180 the base""" 181 diff=self.tip-self.base 182 r=abs(diff) 183 phi=math.acos(diff[0]/(r+1e-15))*180/math.pi 184 theta=math.atan2(diff[1],-diff[2])*180/math.pi 185 self.repr.Scale=[r]*3 186 self.repr.Position=list(self.base) 187 self.repr.Orientation=[theta,phi,0]
188
189 - def setBase(self,base):
190 """Reset the base point""" 191 self.base=base 192 self.recalc()
193
194 - def setTip(self,tip):
195 """Reset the tip point""" 196 self.tip=tip 197 self.recalc()
198
199 -class Arrow(DirectedSource):
200 """Displays a simple arrow""" 201
202 - def __init__(self,name,base,tip):
203 """@param name: name under which the arrow will be displayed 204 @param base: the base the arrow points away from 205 @param tip: the point the arrow points to""" 206 DirectedSource.__init__(self,name,servermanager.sources.ArrowSource(),base,tip)
207
208 -class Glyph(DirectedSource):
209 """Displays a simple glyph""" 210
211 - def __init__(self,name,base,tip):
212 """@param name: name under which the glyph will be displayed 213 @param base: the base the glyph points away from 214 @param tip: the point the glyph points to""" 215 DirectedSource.__init__(self,name,servermanager.sources.GlyphSource2D(),base,tip)
216