/[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 1078 - (show annotations)
Thu Apr 5 06:18:47 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 16209 byte(s)
Added and updated 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, VizType, ColorMode
11 from average import CellDataToPointData
12
13 # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
14 # public methods from the driver.
15 class Map(DataSetMapper, Actor3D):
16 """
17 Class that shows a scalar field on a domain surface. The domain surface
18 can either be colored or grey-scaled, depending on the lookup table used.
19 """
20
21 # The SOUTH_WEST default viewport is used when there is only one viewport.
22 # This saves the user from specifying the viewport when there is only one.
23 # If no lut is specified, the color scheme will be used.
24 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
25 lut = Lut.COLOR, cell_to_point = False, outline = True):
26 """
27 Initialise the Map.
28
29 @attention: The source can either be point or cell data. If the
30 source is cell data, a conversion to point data may or may not be
31 required, in order for the object to be rendered correctly.
32 If a conversion is needed, the 'cell_to_point' flag must be set to
33 'True', otherwise 'False' (which is the default).
34
35 @type scene: L{Scene <scene.Scene>} object
36 @param scene: Scene in which objects are to be rendered on
37 @type data_collector: L{DataCollector <datacollector.DataCollector>}
38 object
39 @param data_collector: Deal with source of data for vizualisation
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 cell_to_point: Boolean
45 @param cell_to_point: Converts cell data to point data (by averaging)
46 @type outline: Boolean
47 @param outline: Places an outline around the domain surface
48 """
49
50 # NOTE: Actor3D is inherited and there are two instances declared here.
51 # As a result, when methods from Actor3D is invoked from the driver,
52 # only the methods associated with the latest instance (which in this
53 # case is the Actor3D for the map) can be executed. Actor3D
54 # methods associated with Outline cannot be invoked from the driver.
55 # They can only be called within here, which is why Outline must
56 # be place before map as there is unlikely to be any changes
57 # made to the Outline's Actor3D.
58
59 # ----- Outline -----
60
61 if(outline == True):
62 outline = Outline(data_collector._getOutput())
63 DataSetMapper.__init__(self, outline._getOutput())
64
65 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
66 # Default outline color is black.
67 Actor3D.setColor(self, Color.BLACK)
68
69 # Default line width is 1.
70 Actor3D._setLineWidth(self, 1)
71 scene._addActor3D(viewport, Actor3D._getActor3D(self))
72
73 # ----- Map -----
74
75 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
76 # before DataSetMapper. If it is done after DataSetMapper, no effect
77 # will take place.
78 if(lut == Lut.COLOR): # Colored lookup table.
79 lookup_table = LookupTable()
80 lookup_table._setTableValue()
81 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
82 lookup_table = LookupTable()
83 lookup_table._setLookupTableToGreyScale()
84
85 if(cell_to_point == True): # Converts cell data to point data.
86 c2p = CellDataToPointData(data_collector._getOutput())
87 DataSetMapper.__init__(self, c2p._getOutput(),
88 lookup_table._getLookupTable())
89 elif(cell_to_point == False): # No conversion happens.
90 DataSetMapper.__init__(self, data_collector._getOutput(),
91 lookup_table._getLookupTable())
92
93 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
94
95 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
96 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
97
98 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
99 scene._addActor3D(viewport, Actor3D._getActor3D(self))
100
101
102 ###############################################################################
103
104
105 from transform import Transform
106 from plane import Plane
107 from cutter import Cutter
108
109 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
110 # to allow access to their public methods from the driver.
111 class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
112 """
113 This class works in a similar way to L{Map <map.Map>}, except that it
114 shows a scalar field on a plane. The plane can be translated and rotated
115 along the X, Y and Z axes.
116 """
117
118 # The SOUTH_WEST default viewport is used when there is only one viewport.
119 # This saves the user from specifying the viewport when there is only one.
120 # If no lut is specified, the color scheme will be used.
121 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
122 lut = Lut.COLOR, cell_to_point = False, outline = True):
123 """
124 Initialise the MapOnPlanceCut.
125
126 @attention: The source can either be point or cell data. If the
127 source is cell data, a conversion to point data may or may not be
128 required, in order for the object to be rendered correctly.
129 If a conversion is needed, the 'cell_to_point' flag must be set to
130 'True', otherwise 'False' (which is the default).
131
132 @type scene: L{Scene <scene.Scene>} object
133 @param scene: Scene in which objects are to be rendered on
134 @type data_collector: L{DataCollector <datacollector.DataCollector>}
135 object
136 @param data_collector: Deal with source of data for visualisation
137 @type viewport: L{Viewport <constant.Viewport>} constant
138 @param viewport: Viewport in which objects are to be rendered on
139 @type lut : L{Lut <constant.Lut>} constant
140 @param lut: Lookup table color scheme
141 @type cell_to_point: Boolean
142 @param cell_to_point: Converts cell data to point data (by averaging)
143 @type outline: Boolean
144 @param outline: Places an outline around the domain surface
145 """
146
147 # NOTE: Actor3D is inherited and there are two instances declared here.
148 # As a result, when methods from Actor3D is invoked from the driver,
149 # only the methods associated with the latest instance (which in this
150 # case is the Actor3D for the map) can be executed. Actor3D
151 # methods associated with Outline cannot be invoked from the driver.
152 # They can only be called within here, which is why Outline must
153 # be place before the map as there is unlikely to be any changes
154 # made to the Outline's Actor3D.
155
156 # ----- Outline -----
157
158 if(outline == True):
159 outline = Outline(data_collector._getOutput())
160 DataSetMapper.__init__(self, outline._getOutput())
161
162 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
163 # Default outline color is black.
164 Actor3D.setColor(self, Color.BLACK)
165 # Default line width is 1.
166
167 Actor3D._setLineWidth(self, 1)
168 scene._addActor3D(viewport, Actor3D._getActor3D(self))
169
170 # ----- Map on a plane -----
171
172 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
173 # before DataSetMapper. If it is done after DataSetMapper, no effect
174 # will take place.
175 if(lut == Lut.COLOR): # Colored lookup table.
176 lookup_table = LookupTable()
177 lookup_table._setTableValue()
178 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
179 lookup_table = LookupTable()
180 lookup_table._setLookupTableToGreyScale()
181
182 Transform.__init__(self)
183 Plane.__init__(self, Transform._getTransform(self))
184
185 if(cell_to_point == True): # Converts cell data to point data.
186 c2p = CellDataToPointData(data_collector._getOutput())
187 Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))
188 elif(cell_to_point == False): # No conversion happens.
189 Cutter.__init__(self, data_collector._getOutput(),
190 Plane._getPlane(self))
191
192 DataSetMapper.__init__(self, Cutter._getOutput(self),
193 lookup_table._getLookupTable())
194 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
195
196 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
197 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
198
199 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
200 scene._addActor3D(viewport, Actor3D._getActor3D(self))
201
202
203 ###############################################################################
204
205
206 from clipper import Clipper
207
208 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
209 # to allow access to their public methods from the driver.
210 class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
211 """
212 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
213 except that it shows a scalar field clipped using a plane.
214 """
215
216 # The SOUTH_WEST default viewport is used when there is only one viewport.
217 # This saves the user from specifying the viewport when there is only one.
218 # If no lut is specified, the color scheme will be used.
219 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
220 lut = Lut.COLOR, cell_to_point = False, outline = True):
221 """
222 Initialise the MapOnPlaneClip.
223
224 @attention: The source can either be point or cell data. If the
225 source is cell data, a conversion to point data may or may not be
226 required, in order for the object to be rendered correctly.
227 If a conversion is needed, the 'cell_to_point' flag must be set to
228 'True', otherwise 'False' (which is the default).
229
230 @type scene: L{Scene <scene.Scene>} object
231 @param scene: Scene in which objects are to be rendered on
232 @type data_collector: L{DataCollector <datacollector.DataCollector>}
233 object
234 @param data_collector: Deal with source of data for visualisation
235 @type viewport: L{Viewport <constant.Viewport>} constant
236 @param viewport: Viewport in which objects are to be rendered on
237 @type lut : L{Lut <constant.Lut>} constant
238 @param lut: Lookup table color scheme
239 @type cell_to_point: Boolean
240 @param cell_to_point: Converts cell data to point data (by averaging)
241 @type outline: Boolean
242 @param outline: Places an outline around the domain surface
243 """
244
245 # NOTE: Actor3D is inherited and there are two instances declared here.
246 # As a result, when methods from Actor3D is invoked from the driver,
247 # only the methods associated with the latest instance (which in this
248 # case is the Actor3D for the map) can be executed. Actor3D
249 # methods associated with Outline cannot be invoked from the driver.
250 # They can only be called within here, which is why Outline must
251 # be place before the map as there is unlikely to be any changes
252 # made to the Outline's Actor3D.
253
254 # ----- Outline -----
255
256 if(outline == True):
257 outline = Outline(data_collector._getOutput())
258 DataSetMapper.__init__(self, outline._getOutput())
259
260 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
261 # Default outline color is black.
262 Actor3D.setColor(self, Color.BLACK)
263
264 # Default line width is 1.
265 Actor3D._setLineWidth(self, 1)
266 scene._addActor3D(viewport, Actor3D._getActor3D(self))
267
268 # ----- Map on a clipped plane -----
269
270 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
271 # before DataSetMapper. If it is done after DataSetMapper, no effect
272 # will take place.
273 if(lut == Lut.COLOR): # Colored lookup table.
274 lookup_table = LookupTable()
275 lookup_table._setTableValue()
276 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
277 lookup_table = LookupTable()
278 lookup_table._setLookupTableToGreyScale()
279
280 Transform.__init__(self)
281 Plane.__init__(self, Transform._getTransform(self))
282
283 if(cell_to_point == True): # Converts cell data to point data.
284 c2p = CellDataToPointData(data_collector._getOutput())
285 Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self))
286 elif(cell_to_point == False): # No conversion happens.
287 Clipper.__init__(self, data_collector._getOutput(),
288 Plane._getPlane(self))
289
290 Clipper._setClipFunction(self)
291
292 DataSetMapper.__init__(self, Clipper._getOutput(self),
293 lookup_table._getLookupTable())
294 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
295
296 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
297 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
298
299 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
300 scene._addActor3D(viewport, Actor3D._getActor3D(self))
301
302
303 #############################################################################
304
305
306 # NOTE: DataSetMapper, Actor3D and Clipper were inherited
307 # to allow access to their public methods from the driver.
308 class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
309 """
310 This class works in a similar way to L{Map <map.Map>}, except that it
311 shows a scalar field clipped using a scalar value.
312 """
313
314 # The SOUTH_WEST default viewport is used when there is only one viewport.
315 # This saves the user from specifying the viewport when there is only one.
316 # If no lut is specified, the color scheme will be used.
317 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
318 lut = Lut.COLOR, cell_to_point = False, outline = True):
319 """
320 Initialise the MapOnScalarClip.
321
322 @attention: The source can either be point or cell data. If the
323 source is cell data, a conversion to point data may or may not be
324 required, in order for the object to be rendered correctly.
325 If a conversion is needed, the 'cell_to_point' flag must be set to
326 'True', otherwise 'False' (which is the default).
327
328 @type scene: L{Scene <scene.Scene>} object
329 @param scene: Scene in which objects are to be rendered on
330 @type data_collector: L{DataCollector <datacollector.DataCollector>}
331 object
332 @param data_collector: Deal with source of data for visualisation
333 @type viewport: L{Viewport <constant.Viewport>} constant
334 @param viewport: Viewport in which objects are to be rendered on
335 @type lut : L{Lut <constant.Lut>} constant
336 @param lut: Lookup table color scheme
337 @type cell_to_point: Boolean
338 @param cell_to_point: Converts cell data to point data (by averaging)
339 @type outline: Boolean
340 @param outline: Places an outline around the domain surface
341 """
342
343 # NOTE: Actor3D is inherited and there are two instances declared here.
344 # As a result, when methods from Actor3D is invoked from the driver,
345 # only the methods associated with the latest instance (which in this
346 # case is the Actor3D for the map) can be executed. Actor3D
347 # methods associated with Outline cannot be invoked from the driver.
348 # They can only be called within here, which is why Outline must
349 # be place before the map as there is unlikely to be any changes
350 # made to the Outline's Actor3D.
351
352 # ----- Outline -----
353
354 if(outline == True):
355 outline = Outline(data_collector._getOutput())
356 DataSetMapper.__init__(self, outline._getOutput())
357
358 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
359 # Default outline color is black.
360 Actor3D.setColor(self, Color.BLACK)
361
362 # Default line width is 1.
363 Actor3D._setLineWidth(self, 1)
364 scene._addActor3D(viewport, Actor3D._getActor3D(self))
365
366 # ----- Map clipped using a scalar value -----
367
368 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
369 # before DataSetMapper. If it is done after DataSetMapper, no effect
370 # will take place.
371 if(lut == Lut.COLOR): # Colored lookup table.
372 lookup_table = LookupTable()
373 lookup_table._setTableValue()
374 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
375 lookup_table = LookupTable()
376 lookup_table._setLookupTableToGreyScale()
377
378
379 if(cell_to_point == True): # Converts cell data to point data.
380 c2p = CellDataToPointData(data_collector._getOutput())
381 # None is used because a plane is not required when a scalar
382 # value is used to perform the clipping.
383 Clipper.__init__(self, c2p._getOutput(), None)
384 elif(cell_to_point == False): # No conversion happens.
385 Clipper.__init__(self, data_collector._getOutput(),None)
386
387 DataSetMapper.__init__(self, Clipper._getOutput(self),
388 lookup_table._getLookupTable())
389 DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
390
391 data_collector._paramForUpdatingMultipleSources(VizType.MAP,
392 ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))
393
394 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
395 scene._addActor3D(viewport, Actor3D._getActor3D(self))
396
397

  ViewVC Help
Powered by ViewVC 1.1.26