/[escript]/trunk/pyvisi/py_src/velocity.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/velocity.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 949 - (show annotations)
Fri Feb 2 05:33:05 2007 UTC (12 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 14232 byte(s)
Fixed some more bugs and added more epydocs. Testing remains outstanding.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from mapper import DataSetMapper
7 from lookuptable import LookupTable
8 from actor import Actor3D
9 from constant import Viewport, Color, Arrow, ColorMode, Lut
10 from arrow import Arrow2D, Arrow3D
11 from glyph import Glyph3D
12 from outline import Outline
13 from probe import Probe
14 from point import StructuredPoints
15
16 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, StructuredPoints and
17 # Probe were inherited to allow access to their public methods from the driver.
18 class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D,
19 StructuredPoints, Probe):
20 """
21 Class that show a vector field using arrows.
22 """
23
24 # The SOUTH_WEST default viewport is used when there is only one viewport.
25 # This saves the user from specifying the viewport when there is only one.
26 # If no vector field is specified, the first encountered in the file will
27 # be loaded automatically. If no lut is specified, the color scheme will
28 # be used.
29 def __init__(self, scene, data_collector, vector = None,
30 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
31 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
32
33 """
34 @type scene: L{Scene <scene.Scene>} object
35 @param scene: Scene in which objects are to be rendered on
36 @type data_collector: L{DataCollector <datacollector.DataCollector>}
37 object
38 @param data_collector: Deal with source of data for visualisation
39 @type vector: String
40 @param vector: Vector field to load from the source file
41 @type arrow: L{Arrow <constant.Arrow>} constant
42 @param arrow: Type of arrow (two dimensional or three dimensional)
43 @type color_mode: L{ColorMode <constant.ColorMode>} constant
44 @param color_mode: Type of color mode
45 @type viewport: L{Viewport <constant.Viewport>} constant
46 @param viewport: Viewport in which objects are to be rendered on
47 @type lut : L{Lut <constant.Lut>} constant
48 @param lut: Lookup table color scheme
49 @type outline: Boolean
50 @param outline: Places an outline around the domain surface
51 """
52
53 # NOTE: Actor3D is inherited and there are two instances declared here.
54 # As a result, when methods from Actor3D is invoked from the driver,
55 # only the methods associated with the latest instance (which in this
56 # case is the Actor3D for the Velocity) can be executed. Actor3D
57 # methods associated with Outline cannot be invoked from the driver.
58 # They can only be called within here, which is why Outline must be
59 # place before Velocity as there is unlikely to be any changes
60 # made to the Outline's Actor3D.
61
62 # ----- Outline -----
63
64 if(outline == True):
65 outline = Outline(data_collector._getOutput())
66 DataSetMapper.__init__(self, outline._getOutput())
67
68 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
69 # Default outline color is black.
70 Actor3D.setColor(self, Color.BLACK)
71
72 # Default line width is 1.
73 Actor3D._setLineWidth(self, 1)
74 scene._addActor3D(viewport, Actor3D._getActor3D(self))
75
76 # ----- Velocity -----
77
78 if(vector != None):
79 data_collector._setActiveVector(vector)
80
81 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
82 # before DataSetMapper. If it is done after DataSetMapper, no effect
83 # will take place.
84 if(lut == Lut.COLOR): # Colored lookup table.
85 lookup_table = LookupTable()
86 lookup_table._setTableValue()
87 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
88 lookup_table = LookupTable()
89 lookup_table._setLookupTableToGreyScale()
90
91 StructuredPoints.__init__(self, data_collector._getOutput())
92 Probe.__init__(self, data_collector._getOutput(),
93 StructuredPoints._getStructuredPoints(self))
94
95 if(arrow == Arrow.TWO_D): # Use 2D arrows.
96 Arrow2D.__init__(self)
97 Glyph3D.__init__(self, Probe._getOutput(self),
98 Arrow2D._getOutput(self), data_collector._getScalarRange())
99 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
100 Arrow3D.__init__(self)
101 Glyph3D.__init__(self, Probe._getOutput(self),
102 Arrow3D._getOutput(self), data_collector._getScalarRange())
103
104 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
105 lookup_table._getLookupTable())
106
107 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
108 Glyph3D._setColorModeByVector(self)
109 DataSetMapper._setScalarRange(self,
110 data_collector._getVectorRange())
111 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
112 Glyph3D._setColorModeByScalar(self)
113 DataSetMapper._setScalarRange(self,
114 data_collector._getScalarRange())
115
116 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
117 scene._addActor3D(viewport, Actor3D._getActor3D(self))
118
119
120 ###############################################################################
121
122
123 from transform import Transform
124 from plane import Plane
125 from cutter import Cutter
126
127 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
128 # Cutter, StructuredPoints and Probe were inherited to allow access to
129 # their public methods from the driver.
130 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
131 Glyph3D, Transform, Plane, Cutter, StructuredPoints, Probe):
132 """
133 Class that show a vector field using arrows on a plane.
134 """
135
136 # The SOUTH_WEST default viewport is used when there is only one viewport.
137 # This saves the user from specifying the viewport when there is only one.
138 # If no vector field is specified, the first encountered in the file will
139 # be loaded automatically. If no lut is specified, the color scheme will
140 # be used.
141 def __init__(self, scene, data_collector, vector = None,
142 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
143 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
144 """
145 @type scene: L{Scene <scene.Scene>} object
146 @param scene: Scene in which objects are to be rendered on
147 @type data_collector: L{DataCollector <datacollector.DataCollector>}
148 object
149 @param data_collector: Deal with source of data for visualisation
150 @type vector: String
151 @param vector: Vector field to load from the source file
152 @type arrow: L{Arrow <constant.Arrow>} constant
153 @param arrow: Type of arrow (two dimensional or three dimensional)
154 @type color_mode: L{ColorMode <constant.ColorMode>} constant
155 @param color_mode: Type of color mode
156 @type viewport: L{Viewport <constant.Viewport>} constant
157 @param viewport: Viewport in which objects are to be rendered on
158 @type lut : L{Lut <constant.Lut>} constant
159 @param lut: Lookup table color scheme
160 @type outline: Boolean
161 @param outline: Places an outline around the domain surface
162 """
163
164 # NOTE: Actor3D is inherited and there are two instances declared here.
165 # As a result, when methods from Actor3D is invoked from the driver,
166 # only the methods associated with the latest instance (which in this
167 # case is the Actor3D for the Velocity) can be executed. Actor3D
168 # methods associated with Outline cannot be invoked from the driver.
169 # They can only be called within here, which is why Outline must be
170 # place before Velocity as there is unlikely to be any changes
171 # made to the Outline's Actor3D.
172
173 # ----- Outline -----
174
175 if(outline == True):
176 outline = Outline(data_collector._getOutput())
177 DataSetMapper.__init__(self, outline._getOutput())
178
179 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
180 # Default outline color is black.
181 Actor3D.setColor(self, Color.BLACK)
182
183 # Default line width is 1.
184 Actor3D._setLineWidth(self, 1)
185 scene._addActor3D(viewport, Actor3D._getActor3D(self))
186
187 # ----- Velocity on a cut plane -----
188
189 if(vector != None):
190 data_collector._setActiveVector(vector)
191
192 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
193 # before DataSetMapper. If it is done after DataSetMapper, no effect
194 # will take place.
195 if(lut == Lut.COLOR): # Colored lookup table.
196 lookup_table = LookupTable()
197 lookup_table._setTableValue()
198 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
199 lookup_table = LookupTable()
200 lookup_table._setLookupTableToGreyScale()
201
202 Transform.__init__(self)
203 Plane.__init__(self, Transform._getTransform(self))
204
205 StructuredPoints.__init__(self, data_collector._getOutput())
206 Probe.__init__(self, data_collector._getOutput(),
207 StructuredPoints._getStructuredPoints(self))
208
209 Cutter.__init__(self, Probe._getOutput(self),
210 Plane._getPlane(self))
211
212 if(arrow == Arrow.TWO_D): # Use 2D arrows.
213 Arrow2D.__init__(self)
214 Glyph3D.__init__(self, Cutter._getOutput(self),
215 Arrow2D._getOutput(self), data_collector._getScalarRange())
216 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
217 Arrow3D.__init__(self)
218 Glyph3D.__init__(self, Cutter._getOutput(self),
219 Arrow3D._getOutput(self), data_collector._getScalarRange())
220
221 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
222 lookup_table._getLookupTable())
223
224 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
225 Glyph3D._setColorModeByVector(self)
226 DataSetMapper._setScalarRange(self,
227 data_collector._getVectorRange())
228 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
229 Glyph3D._setColorModeByScalar(self)
230 DataSetMapper._setScalarRange(self,
231 data_collector._getScalarRange())
232
233 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
234 scene._addActor3D(viewport, Actor3D._getActor3D(self))
235
236
237 ###############################################################################
238
239
240 from clipper import Clipper
241
242 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
243 # Clipper, StructuredPoints and Probe were inherited to allow access to
244 # their public methods from the driver.
245 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
246 Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
247 """
248 Class that show a vector field using arrows on a clipped plane.
249 """
250
251 # The SOUTH_WEST default viewport is used when there is only one viewport.
252 # This saves the user from specifying the viewport when there is only one.
253 # If no vector field is specified, the first encountered in the file will
254 # be loaded automatically. If no lut is specified, the color scheme will
255 # be used.
256 def __init__(self, scene, data_collector, vector = None,
257 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
258 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
259 """
260 @type scene: L{Scene <scene.Scene>} object
261 @param scene: Scene in which objects are to be rendered on
262 @type data_collector: L{DataCollector <datacollector.DataCollector>}
263 object
264 @param data_collector: Deal with source of data for visualisation
265 @type vector: String
266 @param vector: Vector field to load from the source file
267 @type arrow: L{Arrow <constant.Arrow>} constant
268 @param arrow: Type of arrow (two dimensional or three dimensional)
269 @type color_mode: L{ColorMode <constant.ColorMode>} constant
270 @param color_mode: Type of color mode
271 @type viewport: L{Viewport <constant.Viewport>} constant
272 @param viewport: Viewport in which objects are to be rendered on
273 @type lut : L{Lut <constant.Lut>} constant
274 @param lut: Lookup table color scheme
275 @type outline: Boolean
276 @param outline: Places an outline around the domain surface
277 """
278
279 # NOTE: Actor3D is inherited and there are two instances declared here.
280 # As a result, when methods from Actor3D is invoked from the driver,
281 # only the methods associated with the latest instance (which in this
282 # case is the Actor3D for the Velocity) can be executed. Actor3D
283 # methods associated with Outline cannot be invoked from the driver.
284 # They can only be called within here, which is why Outline must be
285 # place before Velocity as there is unlikely to be any changes
286 # made to the Outline's Actor3D.
287
288 # ----- Outline -----
289
290 if(outline == True):
291 outline = Outline(data_collector._getOutput())
292 DataSetMapper.__init__(self, outline._getOutput())
293
294 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
295 # Default outline color is black.
296 Actor3D.setColor(self, Color.BLACK)
297
298 # Default line width is 1.
299 Actor3D._setLineWidth(self, 1)
300 scene._addActor3D(viewport, Actor3D._getActor3D(self))
301
302 # ----- Velocity on a clipped plane -----
303
304 if(vector != None):
305 data_collector._setActiveVector(vector)
306
307 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
308 # before DataSetMapper. If it is done after DataSetMapper, no effect
309 # will take place.
310 if(lut == Lut.COLOR): # Colored lookup table.
311 lookup_table = LookupTable()
312 lookup_table._setTableValue()
313 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
314 lookup_table = LookupTable()
315 lookup_table._setLookupTableToGreyScale()
316
317 Transform.__init__(self)
318 Plane.__init__(self, Transform._getTransform(self))
319
320 StructuredPoints.__init__(self, data_collector._getOutput())
321 Probe.__init__(self, data_collector._getOutput(),
322 StructuredPoints._getStructuredPoints(self))
323
324 # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
325 # be incorrect.
326 if(arrow == Arrow.TWO_D): # Use 2D arrows.
327 Arrow2D.__init__(self)
328 #Glyph3D.__init__(self, data_collector._getOutput(),
329 Glyph3D.__init__(self, Probe._getOutput(self),
330 Arrow2D._getOutput(self), data_collector._getScalarRange())
331 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
332 Arrow3D.__init__(self)
333 Glyph3D.__init__(self, Probe._getOutput(self),
334 Arrow3D._getOutput(self), data_collector._getScalarRange())
335
336 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
337 # be incorrect.
338 Clipper.__init__(self, Glyph3D._getOutput(self),
339 Plane._getPlane(self))
340 Clipper._setClipFunction(self)
341
342 DataSetMapper.__init__(self, Clipper._getOutput(self),
343 lookup_table._getLookupTable())
344
345 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
346 Glyph3D._setColorModeByVector(self)
347 DataSetMapper._setScalarRange(self,
348 data_collector._getVectorRange())
349 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
350 Glyph3D._setColorModeByScalar(self)
351 DataSetMapper._setScalarRange(self,
352 data_collector._getScalarRange())
353
354 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
355 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26