/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 20576 byte(s)
Don't panic.
Updating copyright stamps

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

  ViewVC Help
Powered by ViewVC 1.1.26