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

  ViewVC Help
Powered by ViewVC 1.1.26