/[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 988 - (show annotations)
Tue Feb 20 07:21:12 2007 UTC (12 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 14883 byte(s)
Both point and cell data should now work properly with Pyvisi. Some testing have been done but a more extensive test will be done at a later stage.
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 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 # be loaded automatically. If no lut is specified, the color scheme will
28 # be used.
29 def __init__(self, scene, data_collector, vector = None, scalar = None,
30 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
31 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
32
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 scalar: String
42 @param scalar: Scalar field to load from the source file
43 @type arrow: L{Arrow <constant.Arrow>} constant
44 @param arrow: Type of arrow (two dimensional or three dimensional)
45 @type color_mode: L{ColorMode <constant.ColorMode>} constant
46 @param color_mode: Type of color mode
47 @type viewport: L{Viewport <constant.Viewport>} constant
48 @param viewport: Viewport in which objects are to be rendered on
49 @type lut : L{Lut <constant.Lut>} constant
50 @param lut: Lookup table color scheme
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 if(vector != None):
81 data_collector._setActiveVector(vector)
82 elif(scalar != None):
83 data_collector._setActiveScalar(scalar)
84
85 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
86 # before DataSetMapper. If it is done after DataSetMapper, no effect
87 # will take place.
88 if(lut == Lut.COLOR): # Colored lookup table.
89 lookup_table = LookupTable()
90 lookup_table._setTableValue()
91 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
92 lookup_table = LookupTable()
93 lookup_table._setLookupTableToGreyScale()
94
95 StructuredPoints.__init__(self, data_collector._getOutput())
96 Probe.__init__(self, data_collector._getOutput(),
97 StructuredPoints._getStructuredPoints(self))
98
99 if(arrow == Arrow.TWO_D): # Use 2D arrows.
100 Arrow2D.__init__(self)
101 Glyph3D.__init__(self, Probe._getOutput(self),
102 Arrow2D._getOutput(self))
103 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
104 Arrow3D.__init__(self)
105 Glyph3D.__init__(self, Probe._getOutput(self),
106 Arrow3D._getOutput(self))
107
108 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
109 lookup_table._getLookupTable())
110
111 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
112 Glyph3D._setColorModeByVector(self)
113 Glyph3D._setRange(self, data_collector._getVectorRange())
114 DataSetMapper._setScalarRange(self,
115 data_collector._getVectorRange())
116 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
117 Glyph3D._setColorModeByScalar(self)
118 Glyph3D._setRange(self, data_collector._getVectorRange())
119 DataSetMapper._setScalarRange(self,
120 data_collector._getScalarRange())
121
122 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
123 scene._addActor3D(viewport, Actor3D._getActor3D(self))
124
125
126 ###############################################################################
127
128
129 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 # be loaded automatically. If no lut is specified, the color scheme will
146 # be used.
147 def __init__(self, scene, data_collector, vector = None, scalar = None,
148 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
149 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
150 """
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 scalar: String
159 @param scalar: Scalar field to load from the source file
160 @type arrow: L{Arrow <constant.Arrow>} constant
161 @param arrow: Type of arrow (two dimensional or three dimensional)
162 @type color_mode: L{ColorMode <constant.ColorMode>} constant
163 @param color_mode: Type of color mode
164 @type viewport: L{Viewport <constant.Viewport>} constant
165 @param viewport: Viewport in which objects are to be rendered on
166 @type lut : L{Lut <constant.Lut>} constant
167 @param lut: Lookup table color scheme
168 @type outline: Boolean
169 @param outline: Places an outline around the domain surface
170 """
171
172 # NOTE: Actor3D is inherited and there are two instances declared here.
173 # As a result, when methods from Actor3D is invoked from the driver,
174 # only the methods associated with the latest instance (which in this
175 # case is the Actor3D for the Velocity) can be executed. Actor3D
176 # methods associated with Outline cannot be invoked from the driver.
177 # They can only be called within here, which is why Outline must be
178 # place before Velocity as there is unlikely to be any changes
179 # made to the Outline's Actor3D.
180
181 # ----- Outline -----
182
183 if(outline == True):
184 outline = Outline(data_collector._getOutput())
185 DataSetMapper.__init__(self, outline._getOutput())
186
187 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
188 # Default outline color is black.
189 Actor3D.setColor(self, Color.BLACK)
190
191 # Default line width is 1.
192 Actor3D._setLineWidth(self, 1)
193 scene._addActor3D(viewport, Actor3D._getActor3D(self))
194
195 # ----- Velocity on a cut plane -----
196
197 if(vector != None):
198 data_collector._setActiveVector(vector)
199 elif(scalar != None):
200 data_collector._setActiveScalar(scalar)
201
202 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
203 # before DataSetMapper. If it is done after DataSetMapper, no effect
204 # will take place.
205 if(lut == Lut.COLOR): # Colored lookup table.
206 lookup_table = LookupTable()
207 lookup_table._setTableValue()
208 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
209 lookup_table = LookupTable()
210 lookup_table._setLookupTableToGreyScale()
211
212 Transform.__init__(self)
213 Plane.__init__(self, Transform._getTransform(self))
214
215 StructuredPoints.__init__(self, data_collector._getOutput())
216 Probe.__init__(self, data_collector._getOutput(),
217 StructuredPoints._getStructuredPoints(self))
218
219 Cutter.__init__(self, Probe._getOutput(self),
220 Plane._getPlane(self))
221
222 if(arrow == Arrow.TWO_D): # Use 2D arrows.
223 Arrow2D.__init__(self)
224 Glyph3D.__init__(self, Cutter._getOutput(self),
225 Arrow2D._getOutput(self))
226 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
227 Arrow3D.__init__(self)
228 Glyph3D.__init__(self, Cutter._getOutput(self),
229 Arrow3D._getOutput(self))
230
231 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
232 lookup_table._getLookupTable())
233
234 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
235 Glyph3D._setColorModeByVector(self)
236 Glyph3D._setRange(self, data_collector._getVectorRange())
237 DataSetMapper._setScalarRange(self,
238 data_collector._getVectorRange())
239 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
240 Glyph3D._setColorModeByScalar(self)
241 Glyph3D._setRange(self, data_collector._getVectorRange())
242 DataSetMapper._setScalarRange(self,
243 data_collector._getScalarRange())
244
245 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
246 scene._addActor3D(viewport, Actor3D._getActor3D(self))
247
248
249 ###############################################################################
250
251
252 from clipper import Clipper
253
254 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
255 # Clipper, StructuredPoints and Probe were inherited to allow access to
256 # their public methods from the driver.
257 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
258 Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
259 """
260 Class that show a vector field using arrows on a clipped plane.
261 """
262
263 # The SOUTH_WEST default viewport is used when there is only one viewport.
264 # This saves the user from specifying the viewport when there is only one.
265 # If no vector field is specified, the first encountered in the file will
266 # be loaded automatically. If no lut is specified, the color scheme will
267 # be used.
268 def __init__(self, scene, data_collector, vector = None, scalar = None,
269 arrow = Arrow.TWO_D, color_mode = ColorMode.VECTOR,
270 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
271 """
272 @type scene: L{Scene <scene.Scene>} object
273 @param scene: Scene in which objects are to be rendered on
274 @type data_collector: L{DataCollector <datacollector.DataCollector>}
275 object
276 @param data_collector: Deal with source of data for visualisation
277 @type vector: String
278 @param vector: Vector field to load from the source file
279 @type scalar: String
280 @param scalar: Scalar field to load from the source file
281 @type arrow: L{Arrow <constant.Arrow>} constant
282 @param arrow: Type of arrow (two dimensional or three dimensional)
283 @type color_mode: L{ColorMode <constant.ColorMode>} constant
284 @param color_mode: Type of color mode
285 @type viewport: L{Viewport <constant.Viewport>} constant
286 @param viewport: Viewport in which objects are to be rendered on
287 @type lut : L{Lut <constant.Lut>} constant
288 @param lut: Lookup table color scheme
289 @type outline: Boolean
290 @param outline: Places an outline around the domain surface
291 """
292
293 # NOTE: Actor3D is inherited and there are two instances declared here.
294 # As a result, when methods from Actor3D is invoked from the driver,
295 # only the methods associated with the latest instance (which in this
296 # case is the Actor3D for the Velocity) can be executed. Actor3D
297 # methods associated with Outline cannot be invoked from the driver.
298 # They can only be called within here, which is why Outline must be
299 # place before Velocity as there is unlikely to be any changes
300 # made to the Outline's Actor3D.
301
302 # ----- Outline -----
303
304 if(outline == True):
305 outline = Outline(data_collector._getOutput())
306 DataSetMapper.__init__(self, outline._getOutput())
307
308 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
309 # Default outline color is black.
310 Actor3D.setColor(self, Color.BLACK)
311
312 # Default line width is 1.
313 Actor3D._setLineWidth(self, 1)
314 scene._addActor3D(viewport, Actor3D._getActor3D(self))
315
316 # ----- Velocity on a clipped plane -----
317
318 if(vector != None):
319 data_collector._setActiveVector(vector)
320 elif(scalar != None):
321 data_collector._setActiveScalar(scalar)
322
323 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
324 # before DataSetMapper. If it is done after DataSetMapper, no effect
325 # will take place.
326 if(lut == Lut.COLOR): # Colored lookup table.
327 lookup_table = LookupTable()
328 lookup_table._setTableValue()
329 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
330 lookup_table = LookupTable()
331 lookup_table._setLookupTableToGreyScale()
332
333 Transform.__init__(self)
334 Plane.__init__(self, Transform._getTransform(self))
335
336 StructuredPoints.__init__(self, data_collector._getOutput())
337 Probe.__init__(self, data_collector._getOutput(),
338 StructuredPoints._getStructuredPoints(self))
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, data_collector._getOutput(),
345 Glyph3D.__init__(self, Probe._getOutput(self),
346 Arrow2D._getOutput(self))
347 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
348 Arrow3D.__init__(self)
349 Glyph3D.__init__(self, Probe._getOutput(self),
350 Arrow3D._getOutput(self))
351
352 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
353 # be incorrect.
354 Clipper.__init__(self, Glyph3D._getOutput(self),
355 Plane._getPlane(self))
356 Clipper._setClipFunction(self)
357
358 DataSetMapper.__init__(self, Clipper._getOutput(self),
359 lookup_table._getLookupTable())
360
361 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
362 Glyph3D._setColorModeByVector(self)
363 Glyph3D._setRange(self, data_collector._getVectorRange())
364 DataSetMapper._setScalarRange(self,
365 data_collector._getVectorRange())
366 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
367 Glyph3D._setColorModeByScalar(self)
368 Glyph3D._setRange(self, data_collector._getVectorRange())
369 DataSetMapper._setScalarRange(self,
370 data_collector._getScalarRange())
371
372 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
373 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26