/[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 1051 - (hide annotations)
Wed Mar 21 21:56:54 2007 UTC (14 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 15783 byte(s)
Velocity module does not work properly with all types of files yet.
1 jongui 1037 """
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, VizType
10     from arrow import Arrow2D, Arrow3D
11     from glyph import Glyph3D
12     from outline import Outline
13 jongui 1051 #from probe import Probe
14     from point import MaskPoints
15 jongui 1043 from average import CellDataToPointData
16 jongui 1037
17 jongui 1051 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D and
18     # MaskPoints were inherited to allow access to their public
19     # methods from the driver.
20     class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, MaskPoints):
21 jongui 1037 """
22     Class that shows a vector field using arrows. The arrows can either be
23     colored or grey-scaled, depending on the lookup table used. If the arrows
24     are colored, there are two possible coloring modes: (1) using vector data
25     or (2) using scalar data. Similarly, there are two possible types of
26     arrows: (1) using two-dimensional or (2) using three-dimensional.
27     """
28    
29     # The SOUTH_WEST default viewport is used when there is only one viewport.
30     # This saves the user from specifying the viewport when there is only one.
31     # If no lut is specified, the color scheme will be used.
32     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
33     color_mode = ColorMode.VECTOR, arrow = Arrow.TWO_D,
34 jongui 1043 lut = Lut.COLOR, cell_to_point = False, outline = True):
35 jongui 1037 """
36     @type scene: L{Scene <scene.Scene>} object
37     @param scene: Scene in which objects are to be rendered on
38     @type data_collector: L{DataCollector <datacollector.DataCollector>}
39     object
40     @param data_collector: Deal with source of data for visualisation
41     @type viewport: L{Viewport <constant.Viewport>} constant
42     @param viewport: Viewport in which objects are to be rendered on
43     @type color_mode: L{ColorMode <constant.ColorMode>} constant
44     @param color_mode: Type of color mode
45     @type arrow: L{Arrow <constant.Arrow>} constant
46     @param arrow: Type of arrow (two dimensional or three dimensional)
47     @type lut : L{Lut <constant.Lut>} constant
48     @param lut: Lookup table color scheme
49 jongui 1043 @type cell_to_point: Boolean
50     @param cell_to_point: Converts cell data to point data (by averaging)
51 jongui 1037 @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: Lookup table color mapping (color or grey scale) MUST be set
81     # before DataSetMapper. If it is done after DataSetMapper, no effect
82     # will take place.
83     if(lut == Lut.COLOR): # Colored lookup table.
84     lookup_table = LookupTable()
85     lookup_table._setTableValue()
86     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
87     lookup_table = LookupTable()
88     lookup_table._setLookupTableToGreyScale()
89 jongui 1051
90 jongui 1043 if(cell_to_point == True): # Converts cell data to point data.
91     c2p = CellDataToPointData(data_collector._getOutput())
92 jongui 1051 MaskPoints.__init__(self, c2p._getOutput())
93 jongui 1043 elif(cell_to_point == False): # No conversion happens.
94 jongui 1051 MaskPoints.__init__(self, data_collector._getOutput())
95    
96 jongui 1037 if(arrow == Arrow.TWO_D): # Use 2D arrows.
97     Arrow2D.__init__(self)
98 jongui 1051 Glyph3D.__init__(self, MaskPoints._getOutput(self),
99 jongui 1037 Arrow2D._getOutput(self))
100     elif(arrow == Arrow.THREE_D): # Use 3D arrows.
101     Arrow3D.__init__(self)
102 jongui 1051 Glyph3D.__init__(self, MaskPoints._getOutput(self),
103 jongui 1037 Arrow3D._getOutput(self))
104    
105     DataSetMapper.__init__(self, Glyph3D._getOutput(self),
106     lookup_table._getLookupTable())
107    
108     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
109     Glyph3D._setColorModeByVector(self)
110     Glyph3D._setRange(self, data_collector._getVectorRange())
111     DataSetMapper._setScalarRange(self,
112     data_collector._getVectorRange())
113     data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
114     ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
115     Glyph3D._getGlyph3D(self))
116    
117     elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
118     Glyph3D._setColorModeByScalar(self)
119     Glyph3D._setRange(self, data_collector._getScalarRange())
120     DataSetMapper._setScalarRange(self,
121     data_collector._getScalarRange())
122     data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
123     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
124     Glyph3D._getGlyph3D(self))
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 jongui 1051 # Cutter and MaskPoints were inherited to allow access to
139 jongui 1037 # their public methods from the driver.
140     class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
141 jongui 1051 Glyph3D, Transform, Plane, Cutter, MaskPoints):
142 jongui 1037 """
143     This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
144     except that it shows a vector field using arrows on a plane.
145     """
146    
147     # The SOUTH_WEST default viewport is used when there is only one viewport.
148     # This saves the user from specifying the viewport when there is only one.
149     # If no lut is specified, the color scheme willbe used.
150     def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
151     color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
152 jongui 1051 lut = Lut.COLOR, cell_to_point = False, outline = True):
153 jongui 1037 """
154     @type scene: L{Scene <scene.Scene>} object
155     @param scene: Scene in which objects are to be rendered on
156     @type data_collector: L{DataCollector <datacollector.DataCollector>}
157     object
158     @param data_collector: Deal with source of data for visualisation
159     @type arrow: L{Arrow <constant.Arrow>} constant
160     @param arrow: Type of arrow (two dimensional or three dimensional)
161     @type color_mode: L{ColorMode <constant.ColorMode>} constant
162     @param color_mode: Type of color mode
163     @type viewport: L{Viewport <constant.Viewport>} constant
164     @param viewport: Viewport in which objects are to be rendered on
165     @type lut : L{Lut <constant.Lut>} constant
166     @param lut: Lookup table color scheme
167 jongui 1051 @type cell_to_point: Boolean
168     @param cell_to_point: Converts cell data to point data (by averaging)
169 jongui 1037 @type outline: Boolean
170     @param outline: Places an outline around the domain surface
171     """
172    
173     # NOTE: Actor3D is inherited and there are two instances declared here.
174     # As a result, when methods from Actor3D is invoked from the driver,
175     # only the methods associated with the latest instance (which in this
176     # case is the Actor3D for the Velocity) can be executed. Actor3D
177     # methods associated with Outline cannot be invoked from the driver.
178     # They can only be called within here, which is why Outline must be
179     # place before Velocity as there is unlikely to be any changes
180     # made to the Outline's Actor3D.
181    
182     # ----- Outline -----
183    
184     if(outline == True):
185     outline = Outline(data_collector._getOutput())
186     DataSetMapper.__init__(self, outline._getOutput())
187    
188     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
189     # Default outline color is black.
190     Actor3D.setColor(self, Color.BLACK)
191    
192     # Default line width is 1.
193     Actor3D._setLineWidth(self, 1)
194     scene._addActor3D(viewport, Actor3D._getActor3D(self))
195    
196     # ----- Velocity on a cut plane -----
197    
198     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
199     # before DataSetMapper. If it is done after DataSetMapper, no effect
200     # will take place.
201     if(lut == Lut.COLOR): # Colored lookup table.
202     lookup_table = LookupTable()
203     lookup_table._setTableValue()
204     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
205     lookup_table = LookupTable()
206     lookup_table._setLookupTableToGreyScale()
207    
208     Transform.__init__(self)
209     Plane.__init__(self, Transform._getTransform(self))
210    
211 jongui 1051 if(cell_to_point == True): # Converts cell data to point data.
212     c2p = CellDataToPointData(data_collector._getOutput())
213     MaskPoints.__init__(self, c2p._getOutput())
214     elif(cell_to_point == False): # No conversion happens.
215     MaskPoints.__init__(self, data_collector._getOutput())
216    
217 jongui 1037
218     if(arrow == Arrow.TWO_D): # Use 2D arrows.
219     Arrow2D.__init__(self)
220 jongui 1051 #Glyph3D.__init__(self, Cutter._getOutput(self),
221     Glyph3D.__init__(self, MaskPoints._getOutput(self),
222 jongui 1037 Arrow2D._getOutput(self))
223     elif(arrow == Arrow.THREE_D): # Use 3D arrows.
224     Arrow3D.__init__(self)
225 jongui 1051 Glyph3D.__init__(self, MaskPoints._getOutput(self),
226 jongui 1037 Arrow3D._getOutput(self))
227    
228 jongui 1051 Cutter.__init__(self, Glyph3D._getOutput(self),
229     Plane._getPlane(self))
230    
231     DataSetMapper.__init__(self, Cutter._getOutput(self),
232 jongui 1037 lookup_table._getLookupTable())
233    
234     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
235     Glyph3D._setColorModeByVector(self)
236     Glyph3D._setRange(self, data_collector._getVectorRange())
237     DataSetMapper._setScalarRange(self,
238     data_collector._getVectorRange())
239 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
240     ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
241     Glyph3D._getGlyph3D(self))
242    
243 jongui 1037 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
244     Glyph3D._setColorModeByScalar(self)
245 jongui 1043 Glyph3D._setRange(self, data_collector._getScalarRange())
246 jongui 1037 DataSetMapper._setScalarRange(self,
247     data_collector._getScalarRange())
248 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
249     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
250     Glyph3D._getGlyph3D(self))
251 jongui 1037
252     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
253     scene._addActor3D(viewport, Actor3D._getActor3D(self))
254    
255    
256     ###############################################################################
257    
258    
259     from clipper import Clipper
260    
261     # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
262 jongui 1051 # Clipper and MaskPoints were inherited to allow access to
263 jongui 1037 # their public methods from the driver.
264     class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
265 jongui 1051 Glyph3D, Transform, Plane, Clipper, MaskPoints):
266 jongui 1037 """
267     This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
268     , except that it shows a vector field using arrows clipped using a 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 lut is specified, the color scheme will be used.
274     def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
275     color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
276 jongui 1051 lut = Lut.COLOR, cell_to_point = False, outline = True):
277 jongui 1037 """
278     @type scene: L{Scene <scene.Scene>} object
279     @param scene: Scene in which objects are to be rendered on
280     @type data_collector: L{DataCollector <datacollector.DataCollector>}
281     object
282     @param data_collector: Deal with source of data for visualisation
283     @type arrow: L{Arrow <constant.Arrow>} constant
284     @param arrow: Type of arrow (two dimensional or three dimensional)
285     @type color_mode: L{ColorMode <constant.ColorMode>} constant
286     @param color_mode: Type of color mode
287     @type viewport: L{Viewport <constant.Viewport>} constant
288     @param viewport: Viewport in which objects are to be rendered on
289     @type lut : L{Lut <constant.Lut>} constant
290     @param lut: Lookup table color scheme
291 jongui 1051 @type cell_to_point: Boolean
292     @param cell_to_point: Converts cell data to point data (by averaging)
293 jongui 1037 @type outline: Boolean
294     @param outline: Places an outline around the domain surface
295     """
296    
297     # NOTE: Actor3D is inherited and there are two instances declared here.
298     # As a result, when methods from Actor3D is invoked from the driver,
299     # only the methods associated with the latest instance (which in this
300     # case is the Actor3D for the Velocity) can be executed. Actor3D
301     # methods associated with Outline cannot be invoked from the driver.
302     # They can only be called within here, which is why Outline must be
303     # place before Velocity as there is unlikely to be any changes
304     # made to the Outline's Actor3D.
305    
306     # ----- Outline -----
307    
308     if(outline == True):
309     outline = Outline(data_collector._getOutput())
310     DataSetMapper.__init__(self, outline._getOutput())
311    
312     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
313     # Default outline color is black.
314     Actor3D.setColor(self, Color.BLACK)
315    
316     # Default line width is 1.
317     Actor3D._setLineWidth(self, 1)
318     scene._addActor3D(viewport, Actor3D._getActor3D(self))
319    
320     # ----- Velocity on a clipped plane -----
321    
322     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
323     # before DataSetMapper. If it is done after DataSetMapper, no effect
324     # will take place.
325     if(lut == Lut.COLOR): # Colored lookup table.
326     lookup_table = LookupTable()
327     lookup_table._setTableValue()
328     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
329     lookup_table = LookupTable()
330     lookup_table._setLookupTableToGreyScale()
331    
332     Transform.__init__(self)
333     Plane.__init__(self, Transform._getTransform(self))
334    
335 jongui 1051 if(cell_to_point == True): # Converts cell data to point data.
336     c2p = CellDataToPointData(data_collector._getOutput())
337     MaskPoints.__init__(self, c2p._getOutput())
338     elif(cell_to_point == False): # No conversion happens.
339     MaskPoints.__init__(self, data_collector._getOutput())
340 jongui 1037
341     # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
342     # be incorrect.
343     if(arrow == Arrow.TWO_D): # Use 2D arrows.
344     Arrow2D.__init__(self)
345 jongui 1051 Glyph3D.__init__(self, MaskPoints._getOutput(self),
346 jongui 1037 Arrow2D._getOutput(self))
347     elif(arrow == Arrow.THREE_D): # Use 3D arrows.
348     Arrow3D.__init__(self)
349 jongui 1051 Glyph3D.__init__(self, MaskPoints._getOutput(self),
350 jongui 1037 Arrow3D._getOutput(self))
351    
352     # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
353     # be incorrect.
354     Clipper.__init__(self, Glyph3D._getOutput(self),
355     Plane._getPlane(self))
356     Clipper._setClipFunction(self)
357    
358     DataSetMapper.__init__(self, Clipper._getOutput(self),
359     lookup_table._getLookupTable())
360    
361     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
362     Glyph3D._setColorModeByVector(self)
363     Glyph3D._setRange(self, data_collector._getVectorRange())
364     DataSetMapper._setScalarRange(self,
365     data_collector._getVectorRange())
366 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
367     ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
368     Glyph3D._getGlyph3D(self))
369    
370 jongui 1037 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
371     Glyph3D._setColorModeByScalar(self)
372 jongui 1043 Glyph3D._setRange(self, data_collector._getScalarRange())
373 jongui 1037 DataSetMapper._setScalarRange(self,
374     data_collector._getScalarRange())
375 jongui 1043 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
376     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
377     Glyph3D._getGlyph3D(self))
378 jongui 1037
379     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
380     scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26