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