/[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 1043 - (show annotations)
Mon Mar 19 06:46:34 2007 UTC (13 years, 8 months ago) by jongui
File MIME type: text/x-python
File size: 15911 byte(s)
Map and Contour now able to display cell data correctly. At this stage, it appears that the probe filter cannot be applied on cell data as a segmentation fault will be thrown.
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 StructuredPoints
15 from average import CellDataToPointData
16
17 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, StructuredPoints and
18 # Probe were inherited to allow access to their public methods from the driver.
19 class Velocity(DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D,
20 StructuredPoints, Probe):
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 """
91 if(cell_to_point == True): # Converts cell data to point data.
92 print "YES..."
93 c2p = CellDataToPointData(data_collector._getOutput())
94 StructuredPoints.__init__(self, c2p._getOutput())
95 Probe.__init__(self, c2p._getOutput(),
96 StructuredPoints._getStructuredPoints(self))
97 elif(cell_to_point == False): # No conversion happens.
98 print "NO..."
99 StructuredPoints.__init__(self, data_collector._getOutput())
100 Probe.__init__(self, data_collector._getOutput(),
101 StructuredPoints._getStructuredPoints(self))
102 """
103 StructuredPoints.__init__(self, data_collector._getOutput())
104 Probe.__init__(self, data_collector._getOutput(),
105 StructuredPoints._getStructuredPoints(self))
106
107 if(arrow == Arrow.TWO_D): # Use 2D arrows.
108 Arrow2D.__init__(self)
109 Glyph3D.__init__(self, Probe._getOutput(self),
110 Arrow2D._getOutput(self))
111 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
112 Arrow3D.__init__(self)
113 #Glyph3D.__init__(self, data_collector._getOutput(),
114 Glyph3D.__init__(self, Probe._getOutput(self),
115 Arrow3D._getOutput(self))
116
117
118 #c2p = CellDataToPointData(Glyph3D._getOutput(self))
119 #DataSetMapper.__init__(self, c2p._getOutput(),
120 # lookup_table._getLookupTable())
121
122 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
123 lookup_table._getLookupTable())
124
125 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
126 Glyph3D._setColorModeByVector(self)
127 Glyph3D._setRange(self, data_collector._getVectorRange())
128 DataSetMapper._setScalarRange(self,
129 data_collector._getVectorRange())
130 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
131 ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
132 Glyph3D._getGlyph3D(self))
133
134 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
135 Glyph3D._setColorModeByScalar(self)
136 Glyph3D._setRange(self, data_collector._getScalarRange())
137 DataSetMapper._setScalarRange(self,
138 data_collector._getScalarRange())
139 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
140 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
141 Glyph3D._getGlyph3D(self))
142
143 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
144 scene._addActor3D(viewport, Actor3D._getActor3D(self))
145
146
147 ###############################################################################
148
149
150 from transform import Transform
151 from plane import Plane
152 from cutter import Cutter
153
154 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
155 # Cutter, StructuredPoints and Probe were inherited to allow access to
156 # their public methods from the driver.
157 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
158 Glyph3D, Transform, Plane, Cutter, StructuredPoints, Probe):
159 """
160 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
161 except that it shows a vector field using arrows on a plane.
162 """
163
164 # The SOUTH_WEST default viewport is used when there is only one viewport.
165 # This saves the user from specifying the viewport when there is only one.
166 # If no lut is specified, the color scheme willbe used.
167 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
168 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
169 lut = Lut.COLOR, outline = True):
170 """
171 @type scene: L{Scene <scene.Scene>} object
172 @param scene: Scene in which objects are to be rendered on
173 @type data_collector: L{DataCollector <datacollector.DataCollector>}
174 object
175 @param data_collector: Deal with source of data for visualisation
176 @type arrow: L{Arrow <constant.Arrow>} constant
177 @param arrow: Type of arrow (two dimensional or three dimensional)
178 @type color_mode: L{ColorMode <constant.ColorMode>} constant
179 @param color_mode: Type of color mode
180 @type viewport: L{Viewport <constant.Viewport>} constant
181 @param viewport: Viewport in which objects are to be rendered on
182 @type lut : L{Lut <constant.Lut>} constant
183 @param lut: Lookup table color scheme
184 @type outline: Boolean
185 @param outline: Places an outline around the domain surface
186 """
187
188 # NOTE: Actor3D is inherited and there are two instances declared here.
189 # As a result, when methods from Actor3D is invoked from the driver,
190 # only the methods associated with the latest instance (which in this
191 # case is the Actor3D for the Velocity) can be executed. Actor3D
192 # methods associated with Outline cannot be invoked from the driver.
193 # They can only be called within here, which is why Outline must be
194 # place before Velocity as there is unlikely to be any changes
195 # made to the Outline's Actor3D.
196
197 # ----- Outline -----
198
199 if(outline == True):
200 outline = Outline(data_collector._getOutput())
201 DataSetMapper.__init__(self, outline._getOutput())
202
203 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
204 # Default outline color is black.
205 Actor3D.setColor(self, Color.BLACK)
206
207 # Default line width is 1.
208 Actor3D._setLineWidth(self, 1)
209 scene._addActor3D(viewport, Actor3D._getActor3D(self))
210
211 # ----- Velocity on a cut plane -----
212
213 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
214 # before DataSetMapper. If it is done after DataSetMapper, no effect
215 # will take place.
216 if(lut == Lut.COLOR): # Colored lookup table.
217 lookup_table = LookupTable()
218 lookup_table._setTableValue()
219 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
220 lookup_table = LookupTable()
221 lookup_table._setLookupTableToGreyScale()
222
223 Transform.__init__(self)
224 Plane.__init__(self, Transform._getTransform(self))
225
226 StructuredPoints.__init__(self, data_collector._getOutput())
227 Probe.__init__(self, data_collector._getOutput(),
228 StructuredPoints._getStructuredPoints(self))
229
230 Cutter.__init__(self, Probe._getOutput(self),
231 Plane._getPlane(self))
232
233 if(arrow == Arrow.TWO_D): # Use 2D arrows.
234 Arrow2D.__init__(self)
235 Glyph3D.__init__(self, Cutter._getOutput(self),
236 Arrow2D._getOutput(self))
237 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
238 Arrow3D.__init__(self)
239 Glyph3D.__init__(self, Cutter._getOutput(self),
240 Arrow3D._getOutput(self))
241
242 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
243 lookup_table._getLookupTable())
244
245 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
246 Glyph3D._setColorModeByVector(self)
247 Glyph3D._setRange(self, data_collector._getVectorRange())
248 DataSetMapper._setScalarRange(self,
249 data_collector._getVectorRange())
250 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
251 ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
252 Glyph3D._getGlyph3D(self))
253
254 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
255 Glyph3D._setColorModeByScalar(self)
256 Glyph3D._setRange(self, data_collector._getScalarRange())
257 DataSetMapper._setScalarRange(self,
258 data_collector._getScalarRange())
259 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
260 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
261 Glyph3D._getGlyph3D(self))
262
263 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
264 scene._addActor3D(viewport, Actor3D._getActor3D(self))
265
266
267 ###############################################################################
268
269
270 from clipper import Clipper
271
272 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
273 # Clipper, StructuredPoints and Probe were inherited to allow access to
274 # their public methods from the driver.
275 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
276 Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
277 """
278 This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>}
279 , except that it shows a vector field using arrows clipped using a plane.
280 """
281
282 # The SOUTH_WEST default viewport is used when there is only one viewport.
283 # This saves the user from specifying the viewport when there is only one.
284 # If no lut is specified, the color scheme will be used.
285 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
286 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
287 lut = Lut.COLOR, outline = True):
288 """
289 @type scene: L{Scene <scene.Scene>} object
290 @param scene: Scene in which objects are to be rendered on
291 @type data_collector: L{DataCollector <datacollector.DataCollector>}
292 object
293 @param data_collector: Deal with source of data for visualisation
294 @type arrow: L{Arrow <constant.Arrow>} constant
295 @param arrow: Type of arrow (two dimensional or three dimensional)
296 @type color_mode: L{ColorMode <constant.ColorMode>} constant
297 @param color_mode: Type of color mode
298 @type viewport: L{Viewport <constant.Viewport>} constant
299 @param viewport: Viewport in which objects are to be rendered on
300 @type lut : L{Lut <constant.Lut>} constant
301 @param lut: Lookup table color scheme
302 @type outline: Boolean
303 @param outline: Places an outline around the domain surface
304 """
305
306 # NOTE: Actor3D is inherited and there are two instances declared here.
307 # As a result, when methods from Actor3D is invoked from the driver,
308 # only the methods associated with the latest instance (which in this
309 # case is the Actor3D for the Velocity) can be executed. Actor3D
310 # methods associated with Outline cannot be invoked from the driver.
311 # They can only be called within here, which is why Outline must be
312 # place before Velocity as there is unlikely to be any changes
313 # made to the Outline's Actor3D.
314
315 # ----- Outline -----
316
317 if(outline == True):
318 outline = Outline(data_collector._getOutput())
319 DataSetMapper.__init__(self, outline._getOutput())
320
321 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
322 # Default outline color is black.
323 Actor3D.setColor(self, Color.BLACK)
324
325 # Default line width is 1.
326 Actor3D._setLineWidth(self, 1)
327 scene._addActor3D(viewport, Actor3D._getActor3D(self))
328
329 # ----- Velocity on a clipped plane -----
330
331 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
332 # before DataSetMapper. If it is done after DataSetMapper, no effect
333 # will take place.
334 if(lut == Lut.COLOR): # Colored lookup table.
335 lookup_table = LookupTable()
336 lookup_table._setTableValue()
337 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
338 lookup_table = LookupTable()
339 lookup_table._setLookupTableToGreyScale()
340
341 Transform.__init__(self)
342 Plane.__init__(self, Transform._getTransform(self))
343
344 StructuredPoints.__init__(self, data_collector._getOutput())
345 Probe.__init__(self, data_collector._getOutput(),
346 StructuredPoints._getStructuredPoints(self))
347
348 # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
349 # be incorrect.
350 if(arrow == Arrow.TWO_D): # Use 2D arrows.
351 Arrow2D.__init__(self)
352 Glyph3D.__init__(self, Probe._getOutput(self),
353 Arrow2D._getOutput(self))
354 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
355 Arrow3D.__init__(self)
356 Glyph3D.__init__(self, Probe._getOutput(self),
357 Arrow3D._getOutput(self))
358
359 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
360 # be incorrect.
361 Clipper.__init__(self, Glyph3D._getOutput(self),
362 Plane._getPlane(self))
363 Clipper._setClipFunction(self)
364
365 DataSetMapper.__init__(self, Clipper._getOutput(self),
366 lookup_table._getLookupTable())
367
368 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
369 Glyph3D._setColorModeByVector(self)
370 Glyph3D._setRange(self, data_collector._getVectorRange())
371 DataSetMapper._setScalarRange(self,
372 data_collector._getVectorRange())
373 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
374 ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self),
375 Glyph3D._getGlyph3D(self))
376
377 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
378 Glyph3D._setColorModeByScalar(self)
379 Glyph3D._setRange(self, data_collector._getScalarRange())
380 DataSetMapper._setScalarRange(self,
381 data_collector._getScalarRange())
382 data_collector._paramForUpdatingMultipleSources(VizType.VELOCITY,
383 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),
384 Glyph3D._getGlyph3D(self))
385
386 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
387 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26