/[escript]/trunk/pyvisi/py_src/map.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/map.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 947 - (show annotations)
Wed Jan 31 07:17:43 2007 UTC (12 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 13359 byte(s)
added some epydocs.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from mapper import DataSetMapper
7 from actor import Actor3D
8 from lookuptable import LookupTable
9 from outline import Outline
10 from constant import Viewport, Color, Lut
11
12 # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
13 # public methods from the driver.
14 class Map(DataSetMapper, Actor3D):
15 """
16 Class that shows a scalar field by color on a domain surface.
17 """
18
19 # The SOUTH_WEST default viewport is used when there is only one viewport.
20 # This saves the user from specifying the viewport when there is only one.
21 # If no scalar field is specified, the first encountered in the file will
22 # be loaded automatically.
23 def __init__(self, scene, data_collector, scalar = None,
24 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR,
25 outline = True):
26 """
27 @type scene: L{Scene <scene.Scene>} object
28 @param scene: Scene in which objects are to be rendered on
29 @type data_collector: L{DataCollector <datacollector.DataCollector>}
30 object
31 @param data_collector: Deal with source of data for visualisation
32 @type scalar: String
33 @param scalar: Scalar field to load from the source file
34 @type viewport: L{Viewport <constant.Viewport>} constant
35 @param viewport: Viewport in which the object is to be rendered on
36 @type lut : L{Lut <constant.Lut>} constant
37 @param lut: Lookup table color scheme
38 @type outline: Boolean
39 @param outline: Places an outline around the domain surface
40 """
41
42 # NOTE: Actor3D is inherited and there are two instances declared here.
43 # As a result, when methods from Actor3D is invoked from the driver,
44 # only the methods associated with the latest instance (which in this
45 # case is the Actor3D for the Surface map) can be executed. Actor3D
46 # methods associated with Outline cannot be invoked from the driver.
47 # They can only be called within here, which is why Outline must
48 # be place before Surface map as there is unlikely to be any changes
49 # made to the Outline's Actor3D.
50
51 # ----- Outline -----
52
53 if(outline == True):
54 outline = Outline(data_collector._getOutput())
55 DataSetMapper.__init__(self, outline._getOutput())
56
57 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
58 # Default outline color is black.
59 Actor3D.setColor(self, Color.BLACK)
60 # Default line width is 1.
61 Actor3D._setLineWidth(self, 1)
62 scene._addActor3D(viewport, Actor3D._getActor3D(self))
63
64 # ----- Surface map -----
65
66 if(scalar != None): # True only if a scalar field was specified.
67 data_collector._setActiveScalar(scalar)
68
69 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
70 # before DataSetMapper. If it is done after DataSetMapper, no effect
71 # will take place.
72 if(lut == Lut.COLOR): # Colored lookup table.
73 lookup_table = LookupTable()
74 lookup_table._setTableValue()
75 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
76 lookup_table = LookupTable()
77 lookup_table._setLookupTableToGreyScale()
78
79 DataSetMapper.__init__(self, data_collector._getOutput(),
80 lookup_table._getLookupTable())
81
82 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
83
84 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
85 scene._addActor3D(viewport, Actor3D._getActor3D(self))
86
87
88
89 from transform import Transform
90 from plane import Plane
91 from cutter import Cutter
92
93 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
94 # to allow access to their public methods from the driver.
95 class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
96 """
97 Class that show a scalar field on a plane.
98 """
99
100 # The SOUTH_WEST default viewport is used when there is only one viewport.
101 # This saves the user from specifying the viewport when there is only one.
102 # If no scalar field is specified, the first encountered in the file will
103 # be loaded automatically.
104 def __init__(self, scene, data_collector, scalar = None,
105 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
106
107 """
108 @type scene: L{Scene <scene.Scene>} object
109 @param scene: Scene in which objects are to be rendered on
110 @type data_collector: L{DataCollector <datacollector.DataCollector>}
111 object
112 @param data_collector: Deal with source of data for visualisation
113 @type scalar: String
114 @param scalar: Scalar field to load from the source file
115 @type viewport: L{Viewport <constant.Viewport>} constant
116 @param viewport: Viewport in which the object is to be rendered on
117 @type lut : L{Lut <constant.Lut>} constant
118 @param lut: Lookup table color scheme
119 @type outline: Boolean
120 @param outline: Places an outline around the domain surface
121 """
122
123 # NOTE: Actor3D is inherited and there are two instances declared here.
124 # As a result, when methods from Actor3D is invoked from the driver,
125 # only the methods associated with the latest instance (which in this
126 # case is the Actor3D for the map) can be executed. Actor3D
127 # methods associated with Outline cannot be invoked from the driver.
128 # They can only be called within here, which is why Outline must
129 # be place before the map as there is unlikely to be any changes
130 # made to the Outline's Actor3D.
131
132 # ----- Outline -----
133
134 if(outline == True):
135 #outline = Outline(Glyph3D._getOutput(self))
136 outline = Outline(data_collector._getOutput())
137 DataSetMapper.__init__(self, outline._getOutput())
138
139 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
140 # Default outline color is black.
141 Actor3D.setColor(self, Color.BLACK)
142 # Default line width is 1.
143 Actor3D._setLineWidth(self, 1)
144 scene._addActor3D(viewport, Actor3D._getActor3D(self))
145
146
147 # ----- Map on a plane -----
148
149 if(scalar != None):
150 data_collector._setActiveScalar(scalar)
151
152 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
153 # before DataSetMapper. If it is done after DataSetMapper, no effect
154 # will take place.
155 if(lut == Lut.COLOR): # Colored lookup table.
156 lookup_table = LookupTable()
157 lookup_table._setTableValue()
158 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
159 lookup_table = LookupTable()
160 lookup_table._setLookupTableToGreyScale()
161
162 Transform.__init__(self)
163 Plane.__init__(self, Transform._getTransform(self))
164
165 Cutter.__init__(self, data_collector._getOutput(),
166 Plane._getPlane(self))
167
168 DataSetMapper.__init__(self, Cutter._getOutput(self),
169 lookup_table._getLookupTable())
170
171 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
172
173 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
174 scene._addActor3D(viewport, Actor3D._getActor3D(self))
175
176
177
178 ###########################################################################
179
180
181
182 from clipper import Clipper
183
184 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
185 # to allow access to their public methods from the driver.
186 class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
187 """
188 Class that show a scalar field on a clipped plane.
189 """
190
191 # The SOUTH_WEST default viewport is used when there is only one viewport.
192 # This saves the user from specifying the viewport when there is only one.
193 # If no scalar field is specified, the first encountered in the file will
194 # be loaded automatically.
195 def __init__(self, scene, data_collector, scalar = None,
196 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
197
198 """
199 @type scene: L{Scene <scene.Scene>} object
200 @param scene: Scene in which objects are to be rendered on
201 @type data_collector: L{DataCollector <datacollector.DataCollector>}
202 object
203 @param data_collector: Deal with source of data for visualisation
204 @type scalar: String
205 @param scalar: Scalar field to load from the source file
206 @type viewport: L{Viewport <constant.Viewport>} constant
207 @param viewport: Viewport in which the object is to be rendered on
208 @type lut : L{Lut <constant.Lut>} constant
209 @param lut: Lookup table color scheme
210 @type outline: Boolean
211 @param outline: Places an outline around the domain surface
212 """
213
214 # NOTE: Actor3D is inherited and there are two instances declared here.
215 # As a result, when methods from Actor3D is invoked from the driver,
216 # only the methods associated with the latest instance (which in this
217 # case is the Actor3D for the map) can be executed. Actor3D
218 # methods associated with Outline cannot be invoked from the driver.
219 # They can only be called within here, which is why Outline must
220 # be place before the map as there is unlikely to be any changes
221 # made to the Outline's Actor3D.
222
223 # ----- Outline -----
224
225 if(outline == True):
226 #outline = Outline(Glyph3D._getOutput(self))
227 outline = Outline(data_collector._getOutput())
228 DataSetMapper.__init__(self, outline._getOutput())
229
230 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
231 # Default outline color is black.
232 Actor3D.setColor(self, Color.BLACK)
233 # Default line width is 1.
234 Actor3D._setLineWidth(self, 1)
235 scene._addActor3D(viewport, Actor3D._getActor3D(self))
236
237
238 # ----- Map on a clipped plane -----
239
240 if(scalar != None):
241 data_collector._setActiveScalar(scalar)
242
243 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
244 # before DataSetMapper. If it is done after DataSetMapper, no effect
245 # will take place.
246 if(lut == Lut.COLOR): # Colored lookup table.
247 lookup_table = LookupTable()
248 lookup_table._setTableValue()
249 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
250 lookup_table = LookupTable()
251 lookup_table._setLookupTableToGreyScale()
252
253 Transform.__init__(self)
254 Plane.__init__(self, Transform._getTransform(self))
255
256 Clipper.__init__(self, data_collector._getOutput(),
257 Plane._getPlane(self))
258 Clipper._setClipFunction(self)
259
260 DataSetMapper.__init__(self, Clipper._getOutput(self),
261 lookup_table._getLookupTable())
262
263 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
264
265 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
266 scene._addActor3D(viewport, Actor3D._getActor3D(self))
267
268
269
270 #############################################################################
271
272
273
274 # NOTE: DataSetMapper, Actor3D and Clipper were inherited
275 # to allow access to their public methods from the driver.
276 class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
277 """
278 Class that show a scalar field clipped using a scalar value.
279 """
280
281 # The SOUTH_WEST default viewport is used when there is only one viewport.
282 # This saves the user from specifying the viewport when there is only one.
283 # If no scalar field is specified, the first encountered in the file will
284 # be loaded automatically.
285 def __init__(self, scene, data_collector, scalar = None,
286 viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, outline = True):
287
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 scalar: String
295 @param scalar: Scalar field to load from the source file
296 @type viewport: L{Viewport <constant.Viewport>} constant
297 @param viewport: Viewport in which the object is to be rendered on
298 @type lut : L{Lut <constant.Lut>} constant
299 @param lut: Lookup table color scheme
300 @type outline: Boolean
301 @param outline: Places an outline around the domain surface
302 """
303
304 # NOTE: Actor3D is inherited and there are two instances declared here.
305 # As a result, when methods from Actor3D is invoked from the driver,
306 # only the methods associated with the latest instance (which in this
307 # case is the Actor3D for the map) can be executed. Actor3D
308 # methods associated with Outline cannot be invoked from the driver.
309 # They can only be called within here, which is why Outline must
310 # be place before the map as there is unlikely to be any changes
311 # made to the Outline's Actor3D.
312
313 # ----- Outline -----
314
315 if(outline == True):
316 #outline = Outline(Glyph3D._getOutput(self))
317 outline = Outline(data_collector._getOutput())
318 DataSetMapper.__init__(self, outline._getOutput())
319
320 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
321 # Default outline color is black.
322 Actor3D.setColor(self, Color.BLACK)
323 # Default line width is 1.
324 Actor3D._setLineWidth(self, 1)
325 scene._addActor3D(viewport, Actor3D._getActor3D(self))
326
327
328 # ----- Map clipped using a scalar value -----
329
330 if(scalar != None):
331 data_collector._setActiveScalar(scalar)
332
333 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
334 # before DataSetMapper. If it is done after DataSetMapper, no effect
335 # will take place.
336 if(lut == Lut.COLOR): # Colored lookup table.
337 lookup_table = LookupTable()
338 lookup_table._setTableValue()
339 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
340 lookup_table = LookupTable()
341 lookup_table._setLookupTableToGreyScale()
342
343 # None because a plane is not required when a scalar value is
344 # used to perform the clipping.
345 Clipper.__init__(self, data_collector._getOutput(), None)
346
347 DataSetMapper.__init__(self, Clipper._getOutput(self),
348 lookup_table._getLookupTable())
349
350 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
351
352 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
353 scene._addActor3D(viewport, Actor3D._getActor3D(self))
354
355

  ViewVC Help
Powered by ViewVC 1.1.26