/[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 996 - (show annotations)
Mon Feb 26 03:43:13 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 13592 byte(s)
Updated the drivers. Setting the active scalar/vector/tensor is now done in the DataCollector. i.e. 
dc = DataCollector(...)
dc.setFileName(...)
dc.setActiveScalar(...)

The use of setActiveScalar / setActiveVector / setActiveTensor have to be done after the setFileName.
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 lut is specified, the color scheme will be used.
27 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
28 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
29 lut = Lut.COLOR, outline = True):
30 """
31 @type scene: L{Scene <scene.Scene>} object
32 @param scene: Scene in which objects are to be rendered on
33 @type data_collector: L{DataCollector <datacollector.DataCollector>}
34 object
35 @param data_collector: Deal with source of data for visualisation
36 @type arrow: L{Arrow <constant.Arrow>} constant
37 @param arrow: Type of arrow (two dimensional or three dimensional)
38 @type color_mode: L{ColorMode <constant.ColorMode>} constant
39 @param color_mode: Type of color mode
40 @type viewport: L{Viewport <constant.Viewport>} constant
41 @param viewport: Viewport in which objects are to be rendered on
42 @type lut : L{Lut <constant.Lut>} constant
43 @param lut: Lookup table color scheme
44 @type outline: Boolean
45 @param outline: Places an outline around the domain surface
46 """
47
48 # NOTE: Actor3D is inherited and there are two instances declared here.
49 # As a result, when methods from Actor3D is invoked from the driver,
50 # only the methods associated with the latest instance (which in this
51 # case is the Actor3D for the Velocity) can be executed. Actor3D
52 # methods associated with Outline cannot be invoked from the driver.
53 # They can only be called within here, which is why Outline must be
54 # place before Velocity as there is unlikely to be any changes
55 # made to the Outline's Actor3D.
56
57 # ----- Outline -----
58
59 if(outline == True):
60 outline = Outline(data_collector._getOutput())
61 DataSetMapper.__init__(self, outline._getOutput())
62
63 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
64 # Default outline color is black.
65 Actor3D.setColor(self, Color.BLACK)
66
67 # Default line width is 1.
68 Actor3D._setLineWidth(self, 1)
69 scene._addActor3D(viewport, Actor3D._getActor3D(self))
70
71 # ----- Velocity -----
72
73 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
74 # before DataSetMapper. If it is done after DataSetMapper, no effect
75 # will take place.
76 if(lut == Lut.COLOR): # Colored lookup table.
77 lookup_table = LookupTable()
78 lookup_table._setTableValue()
79 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
80 lookup_table = LookupTable()
81 lookup_table._setLookupTableToGreyScale()
82
83 StructuredPoints.__init__(self, data_collector._getOutput())
84 Probe.__init__(self, data_collector._getOutput(),
85 StructuredPoints._getStructuredPoints(self))
86
87 if(arrow == Arrow.TWO_D): # Use 2D arrows.
88 Arrow2D.__init__(self)
89 Glyph3D.__init__(self, Probe._getOutput(self),
90 Arrow2D._getOutput(self))
91 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
92 Arrow3D.__init__(self)
93 Glyph3D.__init__(self, Probe._getOutput(self),
94 Arrow3D._getOutput(self))
95
96 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
97 lookup_table._getLookupTable())
98
99 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
100 Glyph3D._setColorModeByVector(self)
101 Glyph3D._setRange(self, data_collector._getVectorRange())
102 DataSetMapper._setScalarRange(self,
103 data_collector._getVectorRange())
104 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
105 Glyph3D._setColorModeByScalar(self)
106 Glyph3D._setRange(self, data_collector._getVectorRange())
107 DataSetMapper._setScalarRange(self,
108 data_collector._getScalarRange())
109
110 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
111 scene._addActor3D(viewport, Actor3D._getActor3D(self))
112
113
114 ###############################################################################
115
116
117 from transform import Transform
118 from plane import Plane
119 from cutter import Cutter
120
121 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
122 # Cutter, StructuredPoints and Probe were inherited to allow access to
123 # their public methods from the driver.
124 class VelocityOnPlaneCut(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
125 Glyph3D, Transform, Plane, Cutter, StructuredPoints, Probe):
126 """
127 Class that show a vector field using arrows on a plane.
128 """
129
130 # The SOUTH_WEST default viewport is used when there is only one viewport.
131 # This saves the user from specifying the viewport when there is only one.
132 # If no lut is specified, the color scheme willbe used.
133 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
134 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
135 lut = Lut.COLOR, outline = True):
136 """
137 @type scene: L{Scene <scene.Scene>} object
138 @param scene: Scene in which objects are to be rendered on
139 @type data_collector: L{DataCollector <datacollector.DataCollector>}
140 object
141 @param data_collector: Deal with source of data for visualisation
142 @type arrow: L{Arrow <constant.Arrow>} constant
143 @param arrow: Type of arrow (two dimensional or three dimensional)
144 @type color_mode: L{ColorMode <constant.ColorMode>} constant
145 @param color_mode: Type of color mode
146 @type viewport: L{Viewport <constant.Viewport>} constant
147 @param viewport: Viewport in which objects are to be rendered on
148 @type lut : L{Lut <constant.Lut>} constant
149 @param lut: Lookup table color scheme
150 @type outline: Boolean
151 @param outline: Places an outline around the domain surface
152 """
153
154 # NOTE: Actor3D is inherited and there are two instances declared here.
155 # As a result, when methods from Actor3D is invoked from the driver,
156 # only the methods associated with the latest instance (which in this
157 # case is the Actor3D for the Velocity) can be executed. Actor3D
158 # methods associated with Outline cannot be invoked from the driver.
159 # They can only be called within here, which is why Outline must be
160 # place before Velocity as there is unlikely to be any changes
161 # made to the Outline's Actor3D.
162
163 # ----- Outline -----
164
165 if(outline == True):
166 outline = Outline(data_collector._getOutput())
167 DataSetMapper.__init__(self, outline._getOutput())
168
169 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
170 # Default outline color is black.
171 Actor3D.setColor(self, Color.BLACK)
172
173 # Default line width is 1.
174 Actor3D._setLineWidth(self, 1)
175 scene._addActor3D(viewport, Actor3D._getActor3D(self))
176
177 # ----- Velocity on a cut plane -----
178
179 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
180 # before DataSetMapper. If it is done after DataSetMapper, no effect
181 # will take place.
182 if(lut == Lut.COLOR): # Colored lookup table.
183 lookup_table = LookupTable()
184 lookup_table._setTableValue()
185 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
186 lookup_table = LookupTable()
187 lookup_table._setLookupTableToGreyScale()
188
189 Transform.__init__(self)
190 Plane.__init__(self, Transform._getTransform(self))
191
192 StructuredPoints.__init__(self, data_collector._getOutput())
193 Probe.__init__(self, data_collector._getOutput(),
194 StructuredPoints._getStructuredPoints(self))
195
196 Cutter.__init__(self, Probe._getOutput(self),
197 Plane._getPlane(self))
198
199 if(arrow == Arrow.TWO_D): # Use 2D arrows.
200 Arrow2D.__init__(self)
201 Glyph3D.__init__(self, Cutter._getOutput(self),
202 Arrow2D._getOutput(self))
203 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
204 Arrow3D.__init__(self)
205 Glyph3D.__init__(self, Cutter._getOutput(self),
206 Arrow3D._getOutput(self))
207
208 DataSetMapper.__init__(self, Glyph3D._getOutput(self),
209 lookup_table._getLookupTable())
210
211 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
212 Glyph3D._setColorModeByVector(self)
213 Glyph3D._setRange(self, data_collector._getVectorRange())
214 DataSetMapper._setScalarRange(self,
215 data_collector._getVectorRange())
216 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
217 Glyph3D._setColorModeByScalar(self)
218 Glyph3D._setRange(self, data_collector._getVectorRange())
219 DataSetMapper._setScalarRange(self,
220 data_collector._getScalarRange())
221
222 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
223 scene._addActor3D(viewport, Actor3D._getActor3D(self))
224
225
226 ###############################################################################
227
228
229 from clipper import Clipper
230
231 # NOTE: DataSetMapper, Actor3D, Arrow2D, Arrow3D, Glyph3D, Transform, Plane,
232 # Clipper, StructuredPoints and Probe were inherited to allow access to
233 # their public methods from the driver.
234 class VelocityOnPlaneClip(DataSetMapper, Actor3D, Arrow2D, Arrow3D,
235 Glyph3D, Transform, Plane, Clipper, StructuredPoints, Probe):
236 """
237 Class that show a vector field using arrows on a clipped plane.
238 """
239
240 # The SOUTH_WEST default viewport is used when there is only one viewport.
241 # This saves the user from specifying the viewport when there is only one.
242 # If no lut is specified, the color scheme will be used.
243 def __init__(self, scene, data_collector, arrow = Arrow.TWO_D,
244 color_mode = ColorMode.VECTOR, viewport = Viewport.SOUTH_WEST,
245 lut = Lut.COLOR, outline = True):
246 """
247 @type scene: L{Scene <scene.Scene>} object
248 @param scene: Scene in which objects are to be rendered on
249 @type data_collector: L{DataCollector <datacollector.DataCollector>}
250 object
251 @param data_collector: Deal with source of data for visualisation
252 @type arrow: L{Arrow <constant.Arrow>} constant
253 @param arrow: Type of arrow (two dimensional or three dimensional)
254 @type color_mode: L{ColorMode <constant.ColorMode>} constant
255 @param color_mode: Type of color mode
256 @type viewport: L{Viewport <constant.Viewport>} constant
257 @param viewport: Viewport in which objects are to be rendered on
258 @type lut : L{Lut <constant.Lut>} constant
259 @param lut: Lookup table color scheme
260 @type outline: Boolean
261 @param outline: Places an outline around the domain surface
262 """
263
264 # NOTE: Actor3D is inherited and there are two instances declared here.
265 # As a result, when methods from Actor3D is invoked from the driver,
266 # only the methods associated with the latest instance (which in this
267 # case is the Actor3D for the Velocity) can be executed. Actor3D
268 # methods associated with Outline cannot be invoked from the driver.
269 # They can only be called within here, which is why Outline must be
270 # place before Velocity as there is unlikely to be any changes
271 # made to the Outline's Actor3D.
272
273 # ----- Outline -----
274
275 if(outline == True):
276 outline = Outline(data_collector._getOutput())
277 DataSetMapper.__init__(self, outline._getOutput())
278
279 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
280 # Default outline color is black.
281 Actor3D.setColor(self, Color.BLACK)
282
283 # Default line width is 1.
284 Actor3D._setLineWidth(self, 1)
285 scene._addActor3D(viewport, Actor3D._getActor3D(self))
286
287 # ----- Velocity on a clipped plane -----
288
289 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
290 # before DataSetMapper. If it is done after DataSetMapper, no effect
291 # will take place.
292 if(lut == Lut.COLOR): # Colored lookup table.
293 lookup_table = LookupTable()
294 lookup_table._setTableValue()
295 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
296 lookup_table = LookupTable()
297 lookup_table._setLookupTableToGreyScale()
298
299 Transform.__init__(self)
300 Plane.__init__(self, Transform._getTransform(self))
301
302 StructuredPoints.__init__(self, data_collector._getOutput())
303 Probe.__init__(self, data_collector._getOutput(),
304 StructuredPoints._getStructuredPoints(self))
305
306 # NOTE: Glyph3D must come before Clipper. Otherwise, the output will
307 # be incorrect.
308 if(arrow == Arrow.TWO_D): # Use 2D arrows.
309 Arrow2D.__init__(self)
310 #Glyph3D.__init__(self, data_collector._getOutput(),
311 Glyph3D.__init__(self, Probe._getOutput(self),
312 Arrow2D._getOutput(self))
313 elif(arrow == Arrow.THREE_D): # Use 3D arrows.
314 Arrow3D.__init__(self)
315 Glyph3D.__init__(self, Probe._getOutput(self),
316 Arrow3D._getOutput(self))
317
318 # NOTE: Clipper must come after Glyph3D. Otherwise, the output will
319 # be incorrect.
320 Clipper.__init__(self, Glyph3D._getOutput(self),
321 Plane._getPlane(self))
322 Clipper._setClipFunction(self)
323
324 DataSetMapper.__init__(self, Clipper._getOutput(self),
325 lookup_table._getLookupTable())
326
327 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
328 Glyph3D._setColorModeByVector(self)
329 Glyph3D._setRange(self, data_collector._getVectorRange())
330 DataSetMapper._setScalarRange(self,
331 data_collector._getVectorRange())
332 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
333 Glyph3D._setColorModeByScalar(self)
334 Glyph3D._setRange(self, data_collector._getVectorRange())
335 DataSetMapper._setScalarRange(self,
336 data_collector._getScalarRange())
337
338 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
339 scene._addActor3D(viewport, Actor3D._getActor3D(self))

  ViewVC Help
Powered by ViewVC 1.1.26