/[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 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 21060 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 @var __author__: name of author
24 @var __copyright__: copyrights
25 @var __license__: licence agreement
26 @var __url__: url entry point on documentation
27 @var __version__: version
28 @var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 from mapper import DataSetMapper
35 from lookuptable import LookupTable
36 from actor import Actor3D
37 from constant import Viewport, Color, Arrow, ColorMode, Lut
38 from arrow import Arrow2D, Arrow3D
39 from glyph import Glyph3D
40 from outline import Outline
41 from point import MaskPoints
42 from average import CellDataToPointData
43 from esys.escript import getMPISizeWorld
44 if getMPISizeWorld()==1: import vtk
45
46 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D and
47 # MaskPoints were inherited to allow access to their public
48 # methods from the driver.
49 class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, MaskPoints):
50 """
51 Class that shows a vector field using arrows. The arrows can either be
52 colored or grey-scaled, depending on the lookup table used. If the arrows
53 are colored, there are two possible coloring modes, either using vector data
54 or scalar data. Similarly, there are two possible types of
55 arrows, either using two-dimensional or three-dimensional.
56 """
57
58 # The SOUTH_WEST default viewport is used when there is only one viewport.
59 # This saves the user from specifying the viewport when there is only one.
60 # If no lut is specified, the color scheme will be used.
61 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
62 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
63 lut = Lut.COLOR, cell_to_point = False, outline = True):
64 """
65 Initialise the Velocity.
66
67 @attention: The source can either be point or cell data. If the
68 source is cell data, a conversion to point data may or may not be
69 required, in order for the object to be rendered correctly.
70 If a conversion is needed, the 'cell_to_point' flag must be set to
71 'True', otherwise 'False' (which is the default). On occasions, an
72 inaccurate object may be rendered from cell data even after conversion.
73
74 @type scene: L{Scene <scene.Scene>} object
75 @param scene: Scene in which objects are to be rendered on
76 @type data_collector: L{DataCollector <datacollector.DataCollector>}
77 object
78 @param data_collector: Deal with source of data for visualisation
79 @type arrow: L{Arrow <constant.Arrow>} constant
80 @param arrow: Type of arrow (two dimensional or three dimensional)
81 @type color_mode: L{ColorMode <constant.ColorMode>} constant
82 @param color_mode: Type of color mode
83 @type viewport: L{Viewport <constant.Viewport>} constant
84 @param viewport: Viewport in which objects are to be rendered on
85 @type lut : L{Lut <constant.Lut>} constant
86 @param lut: Lookup table color scheme
87 @type cell_to_point: Boolean
88 @param cell_to_point: Converts cell data to point data (by averaging)
89 @type outline: Boolean
90 @param outline: Places an outline around the domain surface
91 """
92
93 self.__data_collector = data_collector
94 self.__arrow = arrow
95 self.__color_mode = color_mode
96 self.__viewport = viewport
97 self.__lut = lut
98 self.__cell_to_point = cell_to_point
99 self.__outline = outline
100
101 self.__modified = True # Keeps track whether Velocity has been modified.
102 MaskPoints.__init__(self)
103 Glyph3D.__init__(self)
104 DataSetMapper.__init__(self)
105 Actor3D.__init__(self)
106 scene._addVisualizationModules(self)
107
108 # ----- Outline -----
109
110 # NOTE: Changes cannot be made to the Outline's properties from the
111 # driver.
112 if(self.__outline == True):
113 outline = Outline(self.__data_collector._getDataCollectorOutput())
114 mapper = DataSetMapper()
115 mapper._setupDataSetMapper(outline._getOutlineOutput())
116
117 actor3D = Actor3D()
118 actor3D._setupActor3D(mapper._getDataSetMapper())
119 # Default outline color is black.
120 actor3D.setColor(Color.BLACK)
121
122 # Default line width is 1.
123 actor3D._setLineWidth(1)
124 scene._addActor3D(self.__viewport, actor3D._getActor3D())
125
126 # ----- Velocity -----
127
128 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
129 # before DataSetMapper. If it is done after DataSetMapper, no effect
130 # will take place.
131 if(self.__lut == Lut.COLOR): # Colored lookup table.
132 lookup_table = LookupTable()
133 lookup_table._setTableValue()
134 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
135 lookup_table = LookupTable()
136 lookup_table._setLookupTableToGreyScale()
137
138 if(self.__cell_to_point == True): # Converts cell data to point data.
139 c2p = CellDataToPointData(
140 self.__data_collector._getDataCollectorOutput())
141 self._setupMaskPoints(c2p._getCellToPointOutput())
142 elif(self.__cell_to_point == False): # No conversion happens.
143 self._setupMaskPoints(data_collector._getDataCollectorOutput())
144
145 if(self.__arrow == Arrow.TWO_D): # Use 2D arrows.
146 Arrow2D.__init__(self)
147 self._setupGlyph3D(self._getMaskPointsOutput(),
148 self._getArrow2DOutput())
149 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
150 Arrow3D.__init__(self)
151 self._setupGlyph3D(self._getMaskPointsOutput(),
152 self._getArrow3DOutput())
153
154 self._setupDataSetMapper(self._getGlyph3DOutput(),
155 lookup_table._getLookupTable())
156
157 self._setupActor3D(self._getDataSetMapper())
158 scene._addActor3D(self.__viewport, self._getActor3D())
159
160 def _isModified(self):
161 """
162 Return whether the Velocity or DataCollector has been modified.
163
164 @rtype: Boolean
165 @return: True or False
166 """
167
168 return self.__modified or self.__data_collector._isModified()
169
170 def _render(self, scene):
171 """
172 Render the velocity.
173
174 @type scene: L{Scene <scene.Scene>} object
175 @param scene: Scene in which objects are to be rendered on
176 """
177
178 if (self._isModified() == True):
179 if(self.__data_collector._isScalarSet() == True):
180 self.__data_collector._setActiveScalar()
181 if(self.__data_collector._isVectorSet() == True):
182 self.__data_collector._setActiveVector()
183
184 # Color velocity by vector.
185 if(self.__color_mode == ColorMode.VECTOR):
186 self._setColorModeByVector()
187
188 # self._isScalarRangeSet checks whether the scalar range has
189 # been specified by the user. If it has, then the scalar range
190 # read from the source will be ignored.
191 if(not(self._isScalarRangeSet())):
192 self._setRange(self.__data_collector._getVectorRange())
193 self._setScalarRange(\
194 self.__data_collector._getVectorRange())
195 else:
196 self._setRange(self._getDataSetMapperRange())
197
198 # Color velocity by scalar.
199 elif(self.__color_mode == ColorMode.SCALAR):
200 self._setColorModeByScalar()
201
202 # self._isScalarRangeSet checks whether the scalar range has
203 # been specified by the user. If it has, then the scalar range
204 # read from the source will be ignored.
205 if(not(self._isScalarRangeSet())):
206 self._setRange(self.__data_collector._getScalarRange())
207 self._setScalarRange(\
208 self.__data_collector._getScalarRange())
209 else:
210 self._setRange(self._getDataSetMapperRange())
211
212 self.__modified = False
213
214
215 ###############################################################################
216
217
218 from transform import Transform
219 from plane import Plane
220 from cutter import Cutter
221
222 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
223 # Cutter and MaskPoints were inherited to allow access to
224 # their public methods from the driver.
225 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
226 Glyph3D, Transform, Plane, Cutter, MaskPoints):
227 """
228 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
229 except that it shows a vector field using arrows cut using a plane.
230 """
231
232 # The SOUTH_WEST default viewport is used when there is only one viewport.
233 # This saves the user from specifying the viewport when there is only one.
234 # If no lut is specified, the color scheme willbe used.
235 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
236 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
237 lut = Lut.COLOR, cell_to_point = False, outline = True):
238 """
239 Initialise the VelocityOnPlaneCut.
240
241 @attention: The source can either be point or cell data. If the
242 source is cell data, a conversion to point data may or may not be
243 required, in order for the object to be rendered correctly.
244 If a conversion is needed, the 'cell_to_point' flag must be set to
245 'True', otherwise 'False' (which is the default). On occasions, an
246 inaccurate object may be rendered from cell data even after conversion.
247
248 @type scene: L{Scene <scene.Scene>} object
249 @param scene: Scene in which objects are to be rendered on
250 @type data_collector: L{DataCollector <datacollector.DataCollector>}
251 object
252 @param data_collector: Deal with source of data for visualisation
253 @type arrow: L{Arrow <constant.Arrow>} constant
254 @param arrow: Type of arrow (two dimensional or three dimensional)
255 @type color_mode: L{ColorMode <constant.ColorMode>} constant
256 @param color_mode: Type of color mode
257 @type viewport: L{Viewport <constant.Viewport>} constant
258 @param viewport: Viewport in which objects are to be rendered on
259 @type lut : L{Lut <constant.Lut>} constant
260 @param lut: Lookup table color scheme
261 @type cell_to_point: Boolean
262 @param cell_to_point: Converts cell data to point data (by averaging)
263 @type outline: Boolean
264 @param outline: Places an outline around the domain surface
265 """
266
267 self.__data_collector = data_collector
268 self.__arrow = arrow
269 self.__color_mode = color_mode
270 self.__viewport = viewport
271 self.__lut = lut
272 self.__cell_to_point = cell_to_point
273 self.__outline = outline
274
275 # Keeps track whether VelocityOnPlaneCut has been modified.
276 self.__modified = True
277 Transform.__init__(self)
278 Plane.__init__(self)
279 Cutter.__init__(self)
280 MaskPoints.__init__(self)
281 Glyph3D.__init__(self)
282 DataSetMapper.__init__(self)
283 Actor3D.__init__(self)
284 scene._addVisualizationModules(self)
285
286 # ----- Outline -----
287
288 # NOTE: Changes cannot be made to the Outline's properties from the
289 # driver.
290 if(self.__outline == True):
291 outline = Outline(self.__data_collector._getDataCollectorOutput())
292 mapper = DataSetMapper()
293 mapper._setupDataSetMapper(outline._getOutlineOutput())
294
295 actor3D = Actor3D()
296 actor3D._setupActor3D(mapper._getDataSetMapper())
297 # Default outline color is black.
298 actor3D.setColor(Color.BLACK)
299
300 # Default line width is 1.
301 actor3D._setLineWidth(1)
302 scene._addActor3D(self.__viewport, actor3D._getActor3D())
303
304 # ----- Velocity on a cut plane -----
305
306 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
307 # before DataSetMapper. If it is done after DataSetMapper, no effect
308 # will take place.
309 if(lut == Lut.COLOR): # Colored lookup table.
310 lookup_table = LookupTable()
311 lookup_table._setTableValue()
312 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
313 lookup_table = LookupTable()
314 lookup_table._setLookupTableToGreyScale()
315
316 self._setupPlane(self._getTransform())
317
318 if(self.__cell_to_point == True): # Converts cell data to point data.
319 c2p = CellDataToPointData(
320 self.__data_collector._getDataCollectorOutput())
321 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
322 elif(self.__cell_to_point == False): # No conversion happens.
323 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
324 self._getPlane())
325
326 self._setupMaskPoints(self._getCutterOutput())
327
328 if(self.__arrow == Arrow.TWO_D): # Use 2D arrows.
329 Arrow2D.__init__(self)
330 self._setupGlyph3D(self._getMaskPointsOutput(),
331 self._getArrow2DOutput())
332 elif(self.__arrow == Arrow.THREE_D): # Use 3D arrows.
333 Arrow3D.__init__(self)
334 self._setupGlyph3D(self._getMaskPointsOutput(),
335 self._getArrow3DOutput())
336
337 self._setupDataSetMapper(self._getGlyph3DOutput(),
338 lookup_table._getLookupTable())
339
340 self._setupActor3D(self._getDataSetMapper())
341 scene._addActor3D(self.__viewport, self._getActor3D())
342
343 def _isModified(self):
344 """
345 Return whether the VelocityOnPlaneCut or DataCollector has been
346 modified.
347
348 @rtype: Boolean
349 @return: True or False
350 """
351
352 return self.__modified or self.__data_collector._isModified()
353
354 def _render(self, scene):
355 """
356 Render the velocity cut using a plane.
357
358 @type scene: L{Scene <scene.Scene>} object
359 @param scene: Scene in which objects are to be rendered on
360 """
361
362 if (self._isModified() == True):
363 if(self.__data_collector._isVectorSet() == True):
364 self.__data_collector._setActiveVector()
365 # Color velocity by vector.
366 if(self.__color_mode == ColorMode.VECTOR):
367 self._setColorModeByVector()
368
369 # self._isScalarRangeSet checks whether the scalar range has
370 # been specified by the user. If it has, then the scalar range
371 # read from the source will be ignored.
372 if(not(self._isScalarRangeSet())):
373 self._setRange(self.__data_collector._getVectorRange())
374 self._setScalarRange(\
375 self.__data_collector._getVectorRange())
376 else:
377 self._setRange(self._getDataSetMapperRange())
378
379 # Color velocity by scalar.
380 elif(self.__color_mode == ColorMode.SCALAR):
381 self._setColorModeByScalar()
382
383 # self._isScalarRangeSet checks whether the scalar range has
384 # been specified by the user. If it has, then the scalar range
385 # read from the source will be ignored.
386 if(not(self._isScalarRangeSet())):
387 self._setRange(self.__data_collector._getScalarRange())
388 self._setScalarRange(\
389 self.__data_collector._getScalarRange())
390 else:
391 self._setRange(self._getDataSetMapperRange())
392
393 self.__modified = False
394
395
396 ###############################################################################
397
398
399 from clipper import Clipper
400
401 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
402 # Clipper and MaskPoints were inherited to allow access to
403 # their public methods from the driver.
404 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
405 Glyph3D, Transform, Plane, Clipper, MaskPoints):
406 """
407 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
408 , except that it shows a vector field using arrows clipped using a plane.
409 """
410
411 # The SOUTH_WEST default viewport is used when there is only one viewport.
412 # This saves the user from specifying the viewport when there is only one.
413 # If no lut is specified, the color scheme will be used.
414 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
415 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
416 lut = Lut.COLOR, cell_to_point = False, outline = True):
417 """
418 Initialise the VelocityOnPlaneClip.
419
420 @attention: The source can either be point or cell data. If the
421 source is cell data, a conversion to point data may or may not be
422 required, in order for the object to be rendered correctly.
423 If a conversion is needed, the 'cell_to_point' flag must be set to
424 'True', otherwise 'False' (which is the default). On occasions, an
425 inaccurate object may be rendered from cell data even after conversion.
426
427 @type scene: L{Scene <scene.Scene>} object
428 @param scene: Scene in which objects are to be rendered on
429 @type data_collector: L{DataCollector <datacollector.DataCollector>}
430 object
431 @param data_collector: Deal with source of data for visualisation
432 @type arrow: L{Arrow <constant.Arrow>} constant
433 @param arrow: Type of arrow (two dimensional or three dimensional)
434 @type color_mode: L{ColorMode <constant.ColorMode>} constant
435 @param color_mode: Type of color mode
436 @type viewport: L{Viewport <constant.Viewport>} constant
437 @param viewport: Viewport in which objects are to be rendered on
438 @type lut : L{Lut <constant.Lut>} constant
439 @param lut: Lookup table color scheme
440 @type cell_to_point: Boolean
441 @param cell_to_point: Converts cell data to point data (by averaging)
442 @type outline: Boolean
443 @param outline: Places an outline around the domain surface
444 """
445
446 self.__data_collector = data_collector
447 self.__arrow = arrow
448 self.__color_mode = color_mode
449 self.__viewport = viewport
450 self.__lut = lut
451 self.__cell_to_point = cell_to_point
452 self.__outline = outline
453
454 # Keeps track whether VelocityOnPlaneCut has been modified.
455 self.__modified = True
456 Transform.__init__(self)
457 Plane.__init__(self)
458 Clipper.__init__(self)
459 MaskPoints.__init__(self)
460 Glyph3D.__init__(self)
461 DataSetMapper.__init__(self)
462 Actor3D.__init__(self)
463 scene._addVisualizationModules(self)
464
465 # ----- Outline -----
466
467 # NOTE: Changes cannot be made to the Outline's properties from the
468 # driver.
469 if(self.__outline == True):
470 outline = Outline(self.__data_collector._getDataCollectorOutput())
471 mapper = DataSetMapper()
472 mapper._setupDataSetMapper(outline._getOutlineOutput())
473
474 actor3D = Actor3D()
475 actor3D._setupActor3D(mapper._getDataSetMapper())
476 # Default outline color is black.
477 actor3D.setColor(Color.BLACK)
478
479 # Default line width is 1.
480 actor3D._setLineWidth(1)
481 scene._addActor3D(self.__viewport, actor3D._getActor3D())
482
483 # ----- Velocity on a clipped plane -----
484
485 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
486 # before DataSetMapper. If it is done after DataSetMapper, no effect
487 # will take place.
488 if(self.__lut == Lut.COLOR): # Colored lookup table.
489 lookup_table = LookupTable()
490 lookup_table._setTableValue()
491 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
492 lookup_table = LookupTable()
493 lookup_table._setLookupTableToGreyScale()
494
495 self._setupPlane(self._getTransform())
496
497 if(self.__cell_to_point == True): # Converts cell data to point data.
498 c2p = CellDataToPointData(
499 self.__data_collector._getDataCollectorOutput())
500 self._setupMaskPoints(c2p._getCellToPointOutput())
501 elif(self.__cell_to_point == False): # No conversion happens.
502 self._setupMaskPoints(
503 self.__data_collector._getDataCollectorOutput())
504
505 # NOTE: Glyph3D must come before Clipper. Otherwise clipping may not
506 # work correctly.
507 if(self.__arrow == Arrow.TWO_D): # Use 2D arrows.
508 Arrow2D.__init__(self)
509 self._setupGlyph3D(self._getMaskPointsOutput(),
510 self._getArrow2DOutput())
511 elif(self.__arrow == Arrow.THREE_D): # Use 3D arrows.
512 Arrow3D.__init__(self)
513 self._setupGlyph3D(self._getMaskPointsOutput(),
514 self._getArrow3DOutput())
515
516 self._setupClipper(self._getGlyph3DOutput(), self._getPlane())
517 self._setClipFunction()
518
519 # NOTE: Clipper must come after Glyph. Otherwise clipping
520 # may not work correctly.
521 self._setupDataSetMapper(self._getClipperOutput(),
522 lookup_table._getLookupTable())
523
524 self._setupActor3D(self._getDataSetMapper())
525 scene._addActor3D(self.__viewport, self._getActor3D())
526
527 def _isModified(self):
528 """
529 Return whether the VelocityOnPlaneClip or DataCollector has been
530 modified.
531
532 @rtype: Boolean
533 @return: True or False
534 """
535
536 return self.__modified or self.__data_collector._isModified()
537
538 def _render(self, scene):
539 """
540 Render the velocity clip using a plane..
541
542 @type scene: L{Scene <scene.Scene>} object
543 @param scene: Scene in which objects are to be rendered on
544 """
545
546 if (self._isModified() == True):
547 if(self.__data_collector._isVectorSet() == True):
548 self.__data_collector._setActiveVector()
549 # Color velocity by vector.
550 if(self.__color_mode == ColorMode.VECTOR):
551 self._setColorModeByVector()
552
553 # self._isScalarRangeSet checks whether the scalar range has
554 # been specified by the user. If it has, then the scalar range
555 # read from the source will be ignored.
556 if(not(self._isScalarRangeSet())):
557 self._setRange(self.__data_collector._getVectorRange())
558 self._setScalarRange(\
559 self.__data_collector._getVectorRange())
560 else:
561 self._setRange(self._getDataSetMapperRange())
562
563 # Color velocity by scalar.
564 elif(self.__color_mode == ColorMode.SCALAR):
565 self._setColorModeByScalar()
566
567 # self._isScalarRangeSet checks whether the scalar range has
568 # been specified by the user. If it has, then the scalar range
569 # read from the source will be ignored.
570 if(not(self._isScalarRangeSet())):
571 self._setRange(self.__data_collector._getScalarRange())
572 self._setScalarRange(\
573 self.__data_collector._getScalarRange())
574 else:
575 self._setRange(self._getDataSetMapperRange())
576
577 self.__modified = False
578
579

  ViewVC Help
Powered by ViewVC 1.1.26