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

  ViewVC Help
Powered by ViewVC 1.1.26