/[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 1053 - (show annotations)
Thu Mar 22 01:14:43 2007 UTC (14 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 15755 byte(s)
Removed the use of StructuredPointsProbe and replaced it with MaskPoints in the Velocity module. StructuredPointsProbe does NOT work well in all instances.
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, 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 MaskPoints
15 from average import CellDataToPointData
16
17 # 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 """
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 lut = Lut.COLOR, cell_to_point = False, outline = True):
35 """
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 @type cell_to_point: Boolean
50 @param cell_to_point: Converts cell data to point data (by averaging)
51 @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
90 if(cell_to_point == True): # Converts cell data to point data.
91 c2p = CellDataToPointData(data_collector._getOutput())
92 MaskPoints.__init__(self, c2p._getOutput())
93 elif(cell_to_point == False): # No conversion happens.
94 MaskPoints.__init__(self, data_collector._getOutput())
95
96 if(arrow == Arrow.TWO_D): # Use 2D arrows.
97 Arrow2D.__init__(self)
98 Glyph3D.__init__(self, MaskPoints._getOutput(self),
99 Arrow2D._getOutput(self))
100 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
101 Arrow3D.__init__(self)
102 Glyph3D.__init__(self, MaskPoints._getOutput(self),
103 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 # Cutter and MaskPoints were inherited to allow access to
139 # their public methods from the driver.
140 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
141 Glyph3D, Transform, Plane, Cutter, MaskPoints):
142 """
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 lut = Lut.COLOR, cell_to_point = False, outline = True):
153 """
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 @type cell_to_point: Boolean
168 @param cell_to_point: Converts cell data to point data (by averaging)
169 @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 if(cell_to_point == True): # Converts cell data to point data.
212 c2p = CellDataToPointData(data_collector._getOutput())
213 Cutter.__init__(self, c2p._getOutput(),
214 Plane._getPlane(self))
215 elif(cell_to_point == False): # No conversion happens.
216 Cutter.__init__(self, data_collector._getOutput(),
217 Plane._getPlane(self))
218
219 MaskPoints.__init__(self, Cutter._getOutput(self))
220
221 if(arrow == Arrow.TWO_D): # Use 2D arrows.
222 Arrow2D.__init__(self)
223 Glyph3D.__init__(self, MaskPoints._getOutput(self),
224 Arrow2D._getOutput(self))
225 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
226 Arrow3D.__init__(self)
227 Glyph3D.__init__(self, MaskPoints._getOutput(self),
228 Arrow3D._getOutput(self))
229
230 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
231 lookup_table._getLookupTable())
232
233 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
234 Glyph3D._setColorModeByVector(self)
235 Glyph3D._setRange(self, data_collector._getVectorRange())
236 DataSetMapper._setScalarRange(self,
237 data_collector._getVectorRange())
238 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
239 ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
240 Glyph3D._getGlyph3D(self))
241
242 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
243 Glyph3D._setColorModeByScalar(self)
244 Glyph3D._setRange(self, data_collector._getScalarRange())
245 DataSetMapper._setScalarRange(self,
246 data_collector._getScalarRange())
247 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
248 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
249 Glyph3D._getGlyph3D(self))
250
251 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
252 scene._addActor3D(viewport, Actor3D._getActor3D(self))
253
254
255 ###############################################################################
256
257
258 from clipper import Clipper
259
260 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
261 # Clipper and MaskPoints were inherited to allow access to
262 # their public methods from the driver.
263 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
264 Glyph3D, Transform, Plane, Clipper, MaskPoints):
265 """
266 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
267 , except that it shows a vector field using arrows clipped using a plane.
268 """
269
270 # The SOUTH_WEST default viewport is used when there is only one viewport.
271 # This saves the user from specifying the viewport when there is only one.
272 # If no lut is specified, the color scheme will be used.
273 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
274 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
275 lut = Lut.COLOR, cell_to_point = False, outline = True):
276 """
277 @type scene: L{Scene <scene.Scene>} object
278 @param scene: Scene in which objects are to be rendered on
279 @type data_collector: L{DataCollector <datacollector.DataCollector>}
280 object
281 @param data_collector: Deal with source of data for visualisation
282 @type arrow: L{Arrow <constant.Arrow>} constant
283 @param arrow: Type of arrow (two dimensional or three dimensional)
284 @type color_mode: L{ColorMode <constant.ColorMode>} constant
285 @param color_mode: Type of color mode
286 @type viewport: L{Viewport <constant.Viewport>} constant
287 @param viewport: Viewport in which objects are to be rendered on
288 @type lut : L{Lut <constant.Lut>} constant
289 @param lut: Lookup table color scheme
290 @type cell_to_point: Boolean
291 @param cell_to_point: Converts cell data to point data (by averaging)
292 @type outline: Boolean
293 @param outline: Places an outline around the domain surface
294 """
295
296 # NOTE: Actor3D is inherited and there are two instances declared here.
297 # As a result, when methods from Actor3D is invoked from the driver,
298 # only the methods associated with the latest instance (which in this
299 # case is the Actor3D for the Velocity) can be executed. Actor3D
300 # methods associated with Outline cannot be invoked from the driver.
301 # They can only be called within here, which is why Outline must be
302 # place before Velocity as there is unlikely to be any changes
303 # made to the Outline's Actor3D.
304
305 # ----- Outline -----
306
307 if(outline == True):
308 outline = Outline(data_collector._getOutput())
309 DataSetMapper.__init__(self, outline._getOutput())
310
311 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
312 # Default outline color is black.
313 Actor3D.setColor(self, Color.BLACK)
314
315 # Default line width is 1.
316 Actor3D._setLineWidth(self, 1)
317 scene._addActor3D(viewport, Actor3D._getActor3D(self))
318
319 # ----- Velocity on a clipped plane -----
320
321 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
322 # before DataSetMapper. If it is done after DataSetMapper, no effect
323 # will take place.
324 if(lut == Lut.COLOR): # Colored lookup table.
325 lookup_table = LookupTable()
326 lookup_table._setTableValue()
327 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
328 lookup_table = LookupTable()
329 lookup_table._setLookupTableToGreyScale()
330
331 Transform.__init__(self)
332 Plane.__init__(self, Transform._getTransform(self))
333
334 if(cell_to_point == True): # Converts cell data to point data.
335 c2p = CellDataToPointData(data_collector._getOutput())
336 MaskPoints.__init__(self, c2p._getOutput())
337 elif(cell_to_point == False): # No conversion happens.
338 MaskPoints.__init__(self, data_collector._getOutput())
339
340 # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
341 # be incorrect.
342 if(arrow == Arrow.TWO_D): # Use 2D arrows.
343 Arrow2D.__init__(self)
344 Glyph3D.__init__(self, MaskPoints._getOutput(self),
345 Arrow2D._getOutput(self))
346 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
347 Arrow3D.__init__(self)
348 Glyph3D.__init__(self, MaskPoints._getOutput(self),
349 Arrow3D._getOutput(self))
350
351 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
352 # be incorrect.
353 Clipper.__init__(self, Glyph3D._getOutput(self),
354 Plane._getPlane(self))
355 Clipper._setClipFunction(self)
356
357 DataSetMapper.__init__(self, Clipper._getOutput(self),
358 lookup_table._getLookupTable())
359
360 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
361 Glyph3D._setColorModeByVector(self)
362 Glyph3D._setRange(self, data_collector._getVectorRange())
363 DataSetMapper._setScalarRange(self,
364 data_collector._getVectorRange())
365 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
366 ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
367 Glyph3D._getGlyph3D(self))
368
369 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
370 Glyph3D._setColorModeByScalar(self)
371 Glyph3D._setRange(self, data_collector._getScalarRange())
372 DataSetMapper._setScalarRange(self,
373 data_collector._getScalarRange())
374 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
375 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
376 Glyph3D._getGlyph3D(self))
377
378 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
379 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26