/[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 943 - (hide annotations)
Mon Jan 29 07:22:43 2007 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 14705 byte(s)
new pyvisi files
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     class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, StructuredPoints, Probe):
19     """
20     Class that show a vector field using arrows.
21     """
22    
23     # The SOUTH_WEST default viewport is used when there is only one viewport.
24     # This saves the user from specifying the viewport when there is only one.
25     # If no vector field is specified, the first encountered in the file will
26     # be loaded automatically.
27     def __init__(self, scene, data_collector, vector = None,
28     viewport = Viewport.SOUTH_WEST, outline = True,
29     arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
30     lut = Lut.COLOR):
31    
32     """
33     @type scene: L{Scene <scene.Scene>} object
34     @param scene: Scene in which objects are to be rendered on
35     @type data_collector: L{DataCollector <datacollector.DataCollector>}
36     object
37     @param data_collector: Deal with source of data for visualisation
38     @type vector: String
39     @param vector: Vector field to load from the source file
40     @type viewport: L{Viewport <constant.Viewport>} constant
41     @param viewport: Viewport in which the object is to be rendered on
42     @type outline: Boolean
43     @param outline: Places an outline around the domain surface
44     @type arrow: L{Arrow <constant.Arrow>} constant
45     @param arrow: Type of arrow (two dimensional or three dimensional)
46     @type color_mode: L{ColorMode <constant.ColorMode>} constant
47     @param color_mode: Type of color mode
48     @type lut : L{Lut <constant.Lut>} constant
49     @param lut: Lookup table color scheme
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(Glyph3D._getOutput(self))
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     # Default line width is 1.
72     Actor3D._setLineWidth(self, 1)
73     scene._addActor3D(viewport, Actor3D._getActor3D(self))
74    
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    
96     if(arrow == Arrow.TWO_D): # Use 2D arrows.
97     Arrow2D.__init__(self)
98     #Glyph3D.__init__(self, data_collector._getOutput(),
99     Glyph3D.__init__(self, Probe._getOutput(self),
100     #Glyph3D.__init__(self, MaskPoints._getOutput(self),
101     Arrow2D._getOutput(self), data_collector._getScalarRange())
102     elif(arrow == Arrow.THREE_D): # Use 3D arrows.
103     Arrow3D.__init__(self)
104     #Glyph3D.__init__(self, data_collector._getOutput(),
105     Glyph3D.__init__(self, Probe._getOutput(self),
106     #Glyph3D.__init__(self, MaskPoints._getOutput(self),
107     Arrow3D._getOutput(self), data_collector._getScalarRange())
108    
109     DataSetMapper.__init__(self, Glyph3D._getOutput(self),
110     lookup_table._getLookupTable())
111    
112     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
113     Glyph3D._setColorModeByVector(self)
114     DataSetMapper._setScalarRange(self,
115     data_collector._getVectorRange())
116     elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
117     Glyph3D._setColorModeByScalar(self)
118     DataSetMapper._setScalarRange(self,
119     data_collector._getScalarRange())
120    
121     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
122     scene._addActor3D(viewport, Actor3D._getActor3D(self))
123    
124    
125     from transform import Transform
126     from plane import Plane
127     from cutter import Cutter
128    
129     # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
130     # Cutter, StructuredPoints and Probe were inherited to allow access to
131     # their public methods from the driver.
132     class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
133     Glyph3D, Transform, Plane, Cutter, StructuredPoints, Probe):
134     """
135     Class that show a vector field using arrows on a plane.
136     """
137    
138     # The SOUTH_WEST default viewport is used when there is only one viewport.
139     # This saves the user from specifying the viewport when there is only one.
140     # If no vector field is specified, the first encountered in the file will
141     # be loaded automatically.
142     def __init__(self, scene, data_collector, vector = None,
143     viewport = Viewport.SOUTH_WEST, outline = True,
144     arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR,
145     lut = Lut.COLOR):
146    
147     """
148     @type scene: L{Scene <scene.Scene>} object
149     @param scene: Scene in which objects are to be rendered on
150     @type data_collector: L{DataCollector <datacollector.DataCollector>}
151     object
152     @param data_collector: Deal with source of data for visualisation
153     @type vector: String
154     @param vector: Vector field to load from the source file
155     @type viewport: L{Viewport <constant.Viewport>} constant
156     @param viewport: Viewport in which the object is to be rendered on
157     @type outline: Boolean
158     @param outline: Places an outline around the domain surface
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 lut : L{Lut <constant.Lut>} constant
164     @param lut: Lookup table color scheme
165     """
166    
167     # NOTE: Actor3D is inherited and there are two instances declared here.
168     # As a result, when methods from Actor3D is invoked from the driver,
169     # only the methods associated with the latest instance (which in this
170     # case is the Actor3D for the Velocity) can be executed. Actor3D
171     # methods associated with Outline cannot be invoked from the driver.
172     # They can only be called within here, which is why Outline must be
173     # place before Velocity as there is unlikely to be any changes
174     # made to the Outline's Actor3D.
175    
176     # ----- Outline -----
177    
178     if(outline == True):
179     #outline = Outline(Glyph3D._getOutput(self))
180     outline = Outline(data_collector._getOutput())
181     DataSetMapper.__init__(self, outline._getOutput())
182    
183     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
184     # Default outline color is black.
185     Actor3D.setColor(self, Color.BLACK)
186     # Default line width is 1.
187     Actor3D._setLineWidth(self, 1)
188     scene._addActor3D(viewport, Actor3D._getActor3D(self))
189    
190    
191     # ----- Velocity on a cut plane -----
192    
193     if(vector != None):
194     data_collector._setActiveVector(vector)
195    
196     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
197     # before DataSetMapper. If it is done after DataSetMapper, no effect
198     # will take place.
199     if(lut == Lut.COLOR): # Colored lookup table.
200     lookup_table = LookupTable()
201     lookup_table._setTableValue()
202     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
203     lookup_table = LookupTable()
204     lookup_table._setLookupTableToGreyScale()
205    
206     Transform.__init__(self)
207     Plane.__init__(self, Transform._getTransform(self))
208    
209     StructuredPoints.__init__(self, data_collector._getOutput())
210     Probe.__init__(self, data_collector._getOutput(),
211     StructuredPoints._getStructuredPoints(self))
212    
213     Cutter.__init__(self, Probe._getOutput(self),
214     #Cutter.__init__(self, data_collector._getOutput(),
215     Plane._getPlane(self))
216    
217     if(arrow == Arrow.TWO_D): # Use 2D arrows.
218     Arrow2D.__init__(self)
219     Glyph3D.__init__(self, Cutter._getOutput(self),
220     #Arrow2D._getOutput(self), data_collector._getVectorRange())
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._getVectorRange())
226     Arrow3D._getOutput(self), data_collector._getScalarRange())
227    
228     DataSetMapper.__init__(self, Glyph3D._getOutput(self),
229     lookup_table._getLookupTable())
230    
231     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
232     Glyph3D._setColorModeByVector(self)
233     DataSetMapper._setScalarRange(self,
234     data_collector._getVectorRange())
235     elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
236     Glyph3D._setColorModeByScalar(self)
237     DataSetMapper._setScalarRange(self,
238     data_collector._getScalarRange())
239    
240     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
241     scene._addActor3D(viewport, Actor3D._getActor3D(self))
242    
243    
244     from clipper import Clipper
245    
246     # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
247     # Clipper, StructuredPoints and Probe were inherited to allow access to
248     # their public methods from the driver.
249     class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
250     Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
251     """
252     Class that show a vector field using arrows on a clipped plane.
253     """
254    
255     # The SOUTH_WEST default viewport is used when there is only one viewport.
256     # This saves the user from specifying the viewport when there is only one.
257     # If no vector field is specified, the first encountered in the file will
258     # be loaded automatically.
259     def __init__(self, scene, data_collector, vector = None,
260     viewport = Viewport.SOUTH_WEST, outline = True,
261     arrow = Arrow.THREE_D, color_mode = ColorMode.VECTOR,
262     lut = Lut.COLOR):
263    
264     """
265     @type scene: L{Scene <scene.Scene>} object
266     @param scene: Scene in which objects are to be rendered on
267     @type data_collector: L{DataCollector <datacollector.DataCollector>}
268     object
269     @param data_collector: Deal with source of data for visualisation
270     @type vector: String
271     @param vector: Vector field to load from the source file
272     @type viewport: L{Viewport <constant.Viewport>} constant
273     @param viewport: Viewport in which the object is to be rendered on
274     @type outline: Boolean
275     @param outline: Places an outline around the domain surface
276     @type arrow: L{Arrow <constant.Arrow>} constant
277     @param arrow: Type of arrow (two dimensional or three dimensional)
278     @type color_mode: L{ColorMode <constant.ColorMode>} constant
279     @param color_mode: Type of color mode
280     @type lut : L{Lut <constant.Lut>} constant
281     @param lut: Lookup table color scheme
282     """
283    
284     # NOTE: Actor3D is inherited and there are two instances declared here.
285     # As a result, when methods from Actor3D is invoked from the driver,
286     # only the methods associated with the latest instance (which in this
287     # case is the Actor3D for the Velocity) can be executed. Actor3D
288     # methods associated with Outline cannot be invoked from the driver.
289     # They can only be called within here, which is why Outline must be
290     # place before Velocity as there is unlikely to be any changes
291     # made to the Outline's Actor3D.
292    
293     # ----- Outline -----
294    
295     if(outline == True):
296     #outline = Outline(Glyph3D._getOutput(self))
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     # Default line width is 1.
304     Actor3D._setLineWidth(self, 1)
305     scene._addActor3D(viewport, Actor3D._getActor3D(self))
306    
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     #MaskPoints.__init__(self, data_collector._getOutput())
331    
332     # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
333     # be incorrect.
334     if(arrow == Arrow.TWO_D): # Use 2D arrows.
335     Arrow2D.__init__(self)
336     #Glyph3D.__init__(self, data_collector._getOutput(),
337     Glyph3D.__init__(self, Probe._getOutput(self),
338     #Glyph3D.__init__(self, MaskPoints._getOutput(self),
339     Arrow2D._getOutput(self), data_collector._getScalarRange())
340     elif(arrow == Arrow.THREE_D): # Use 3D arrows.
341     Arrow3D.__init__(self)
342     #Glyph3D.__init__(self, data_collector._getOutput(),
343     Glyph3D.__init__(self, Probe._getOutput(self),
344     #Glyph3D.__init__(self, MaskPoints._getOutput(self),
345     Arrow3D._getOutput(self), data_collector._getScalarRange())
346    
347    
348     # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
349     # be incorrect.
350     Clipper.__init__(self, Glyph3D._getOutput(self),
351     Plane._getPlane(self))
352     Clipper._setClipFunction(self)
353    
354     DataSetMapper.__init__(self, Clipper._getOutput(self),
355     lookup_table._getLookupTable())
356    
357     if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
358     Glyph3D._setColorModeByVector(self)
359     DataSetMapper._setScalarRange(self,
360     data_collector._getVectorRange())
361     elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
362     Glyph3D._setColorModeByScalar(self)
363     DataSetMapper._setScalarRange(self,
364     data_collector._getScalarRange())
365    
366     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
367     scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26