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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1158 - (hide annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 17979 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

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

  ViewVC Help
Powered by ViewVC 1.1.26