/[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 1809 - (show annotations)
Thu Sep 25 06:43:44 2008 UTC (11 years, 2 months ago) by ksteube
File MIME type: text/x-python
File size: 20999 byte(s)
Copyright updated in all python files

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

  ViewVC Help
Powered by ViewVC 1.1.26