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

  ViewVC Help
Powered by ViewVC 1.1.26