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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1029 - (show annotations)
Wed Mar 14 05:01:13 2007 UTC (12 years, 4 months ago) by jongui
File MIME type: text/x-python
File size: 14009 byte(s)
Fixed problems in relation to updates propagating when multiple files/sources are read.
1 """
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,
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 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
109 Glyph3D._setColorModeByScalar(self)
110 Glyph3D._setRange(self, data_collector._getVectorRange())
111 DataSetMapper._setScalarRange(self,
112 data_collector._getScalarRange())
113
114 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
115 scene._addActor3D(viewport, Actor3D._getActor3D(self))
116
117
118 ###############################################################################
119
120
121 from transform import Transform
122 from plane import Plane
123 from cutter import Cutter
124
125 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
126 # Cutter, StructuredPoints and Probe were inherited to allow access to
127 # their public methods from the driver.
128 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
129 Glyph3D, Transform, Plane, Cutter, StructuredPoints, Probe):
130 """
131 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
132 except that it shows a vector field using arrows on a plane.
133 """
134
135 # The SOUTH_WEST default viewport is used when there is only one viewport.
136 # This saves the user from specifying the viewport when there is only one.
137 # If no lut is specified, the color scheme willbe used.
138 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
139 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
140 lut = Lut.COLOR, outline = True):
141 """
142 @type scene: L{Scene <scene.Scene>} object
143 @param scene: Scene in which objects are to be rendered on
144 @type data_collector: L{DataCollector <datacollector.DataCollector>}
145 object
146 @param data_collector: Deal with source of data for visualisation
147 @type arrow: L{Arrow <constant.Arrow>} constant
148 @param arrow: Type of arrow (two dimensional or three dimensional)
149 @type color_mode: L{ColorMode <constant.ColorMode>} constant
150 @param color_mode: Type of color mode
151 @type viewport: L{Viewport <constant.Viewport>} constant
152 @param viewport: Viewport in which objects are to be rendered on
153 @type lut : L{Lut <constant.Lut>} constant
154 @param lut: Lookup table color scheme
155 @type outline: Boolean
156 @param outline: Places an outline around the domain surface
157 """
158
159 # NOTE: Actor3D is inherited and there are two instances declared here.
160 # As a result, when methods from Actor3D is invoked from the driver,
161 # only the methods associated with the latest instance (which in this
162 # case is the Actor3D for the Velocity) can be executed. Actor3D
163 # methods associated with Outline cannot be invoked from the driver.
164 # They can only be called within here, which is why Outline must be
165 # place before Velocity as there is unlikely to be any changes
166 # made to the Outline's Actor3D.
167
168 # ----- Outline -----
169
170 if(outline == True):
171 outline = Outline(data_collector._getOutput())
172 DataSetMapper.__init__(self, outline._getOutput())
173
174 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
175 # Default outline color is black.
176 Actor3D.setColor(self, Color.BLACK)
177
178 # Default line width is 1.
179 Actor3D._setLineWidth(self, 1)
180 scene._addActor3D(viewport, Actor3D._getActor3D(self))
181
182 # ----- Velocity on a cut plane -----
183
184 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
185 # before DataSetMapper. If it is done after DataSetMapper, no effect
186 # will take place.
187 if(lut == Lut.COLOR): # Colored lookup table.
188 lookup_table = LookupTable()
189 lookup_table._setTableValue()
190 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
191 lookup_table = LookupTable()
192 lookup_table._setLookupTableToGreyScale()
193
194 Transform.__init__(self)
195 Plane.__init__(self, Transform._getTransform(self))
196
197 StructuredPoints.__init__(self, data_collector._getOutput())
198 Probe.__init__(self, data_collector._getOutput(),
199 StructuredPoints._getStructuredPoints(self))
200
201 Cutter.__init__(self, Probe._getOutput(self),
202 Plane._getPlane(self))
203
204 if(arrow == Arrow.TWO_D): # Use 2D arrows.
205 Arrow2D.__init__(self)
206 Glyph3D.__init__(self, Cutter._getOutput(self),
207 Arrow2D._getOutput(self))
208 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
209 Arrow3D.__init__(self)
210 Glyph3D.__init__(self, Cutter._getOutput(self),
211 Arrow3D._getOutput(self))
212
213 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
214 lookup_table._getLookupTable())
215
216 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
217 Glyph3D._setColorModeByVector(self)
218 Glyph3D._setRange(self, data_collector._getVectorRange())
219 DataSetMapper._setScalarRange(self,
220 data_collector._getVectorRange())
221 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
222 Glyph3D._setColorModeByScalar(self)
223 Glyph3D._setRange(self, data_collector._getVectorRange())
224 DataSetMapper._setScalarRange(self,
225 data_collector._getScalarRange())
226
227 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
228 scene._addActor3D(viewport, Actor3D._getActor3D(self))
229
230
231 ###############################################################################
232
233
234 from clipper import Clipper
235
236 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
237 # Clipper, StructuredPoints and Probe were inherited to allow access to
238 # their public methods from the driver.
239 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
240 Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
241 """
242 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
243 , except that it shows a vector field using arrows clipped using a plane.
244 """
245
246 # The SOUTH_WEST default viewport is used when there is only one viewport.
247 # This saves the user from specifying the viewport when there is only one.
248 # If no lut is specified, the color scheme will be used.
249 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
250 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
251 lut = Lut.COLOR, outline = True):
252 """
253 @type scene: L{Scene <scene.Scene>} object
254 @param scene: Scene in which objects are to be rendered on
255 @type data_collector: L{DataCollector <datacollector.DataCollector>}
256 object
257 @param data_collector: Deal with source of data for visualisation
258 @type arrow: L{Arrow <constant.Arrow>} constant
259 @param arrow: Type of arrow (two dimensional or three dimensional)
260 @type color_mode: L{ColorMode <constant.ColorMode>} constant
261 @param color_mode: Type of color mode
262 @type viewport: L{Viewport <constant.Viewport>} constant
263 @param viewport: Viewport in which objects are to be rendered on
264 @type lut : L{Lut <constant.Lut>} constant
265 @param lut: Lookup table color scheme
266 @type outline: Boolean
267 @param outline: Places an outline around the domain surface
268 """
269
270 # NOTE: Actor3D is inherited and there are two instances declared here.
271 # As a result, when methods from Actor3D is invoked from the driver,
272 # only the methods associated with the latest instance (which in this
273 # case is the Actor3D for the Velocity) can be executed. Actor3D
274 # methods associated with Outline cannot be invoked from the driver.
275 # They can only be called within here, which is why Outline must be
276 # place before Velocity as there is unlikely to be any changes
277 # made to the Outline's Actor3D.
278
279 # ----- Outline -----
280
281 if(outline == True):
282 outline = Outline(data_collector._getOutput())
283 DataSetMapper.__init__(self, outline._getOutput())
284
285 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
286 # Default outline color is black.
287 Actor3D.setColor(self, Color.BLACK)
288
289 # Default line width is 1.
290 Actor3D._setLineWidth(self, 1)
291 scene._addActor3D(viewport, Actor3D._getActor3D(self))
292
293 # ----- Velocity on a clipped plane -----
294
295 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
296 # before DataSetMapper. If it is done after DataSetMapper, no effect
297 # will take place.
298 if(lut == Lut.COLOR): # Colored lookup table.
299 lookup_table = LookupTable()
300 lookup_table._setTableValue()
301 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
302 lookup_table = LookupTable()
303 lookup_table._setLookupTableToGreyScale()
304
305 Transform.__init__(self)
306 Plane.__init__(self, Transform._getTransform(self))
307
308 StructuredPoints.__init__(self, data_collector._getOutput())
309 Probe.__init__(self, data_collector._getOutput(),
310 StructuredPoints._getStructuredPoints(self))
311
312 # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
313 # be incorrect.
314 if(arrow == Arrow.TWO_D): # Use 2D arrows.
315 Arrow2D.__init__(self)
316 Glyph3D.__init__(self, Probe._getOutput(self),
317 Arrow2D._getOutput(self))
318 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
319 Arrow3D.__init__(self)
320 Glyph3D.__init__(self, Probe._getOutput(self),
321 Arrow3D._getOutput(self))
322
323 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
324 # be incorrect.
325 Clipper.__init__(self, Glyph3D._getOutput(self),
326 Plane._getPlane(self))
327 Clipper._setClipFunction(self)
328
329 DataSetMapper.__init__(self, Clipper._getOutput(self),
330 lookup_table._getLookupTable())
331
332 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
333 Glyph3D._setColorModeByVector(self)
334 Glyph3D._setRange(self, data_collector._getVectorRange())
335 DataSetMapper._setScalarRange(self,
336 data_collector._getVectorRange())
337 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
338 Glyph3D._setColorModeByScalar(self)
339 Glyph3D._setRange(self, data_collector._getVectorRange())
340 DataSetMapper._setScalarRange(self,
341 data_collector._getScalarRange())
342
343 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
344 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26