/[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 1158 - (show annotations)
Tue May 22 04:24:01 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 18154 byte(s)
Made some changes to fix the memory leak problem. However, the problem still persists for run_escript_with_lazy_evaluation.py, run_streamline.py and run_streamline_with_lazy_evaluation.py.

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, 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 self.__data_collector = data_collector
51 self.__viewport = viewport
52 self.__lut = lut
53 self.__cell_to_point = cell_to_point
54 self.__outline = outline
55
56 self.__modified = True # Keeps track whether Map has been modified.
57 DataSetMapper.__init__(self)
58 Actor3D.__init__(self)
59 scene._addVisualizationModules(self)
60
61 # ----- Outline -----
62
63 # NOTE: Changes cannot be made to the Outline's properties from the
64 # driver.
65 if(self.__outline == True):
66 outline = Outline(self.__data_collector._getDataCollectorOutput())
67 mapper = DataSetMapper()
68 mapper._setupDataSetMapper(outline._getOutlineOutput())
69
70 actor3D = Actor3D()
71 actor3D._setupActor3D(mapper._getDataSetMapper())
72 # Default outline color is black.
73 actor3D.setColor(Color.BLACK)
74
75 # Default line width is 1.
76 actor3D._setLineWidth(1)
77 scene._addActor3D(self.__viewport, actor3D._getActor3D())
78
79 # ----- Map -----
80
81 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
82 # before DataSetMapper. If it is done after DataSetMapper, no effect
83 # will take place.
84 if(self.__lut == Lut.COLOR): # Colored lookup table.
85 lookup_table = LookupTable()
86 lookup_table._setTableValue()
87 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
88 lookup_table = LookupTable()
89 lookup_table._setLookupTableToGreyScale()
90
91 if(self.__cell_to_point == True): # Convert cell data to point data.
92 c2p = CellDataToPointData(
93 self.__data_collector._getDataCollectorOutput())
94 self._setupDataSetMapper(c2p._getCellToPointOutput(),
95 lookup_table._getLookupTable())
96 elif(self.__cell_to_point == False): # No conversion happens.
97 self._setupDataSetMapper(
98 self.__data_collector._getDataCollectorOutput(),
99 lookup_table._getLookupTable())
100
101 self._setupActor3D(self._getDataSetMapper())
102 scene._addActor3D(self.__viewport, self._getActor3D())
103
104 def _isModified(self):
105 """
106 Return whether the Map or DataCollector has been modified.
107
108 @rtype: Boolean
109 @return: True or False
110 """
111
112 return self.__modified or self.__data_collector._isModified()
113
114 def _render(self, scene):
115 """
116 Render the surface map.
117
118 @type scene: L{Scene <scene.Scene>} object
119 @param scene: Scene in which objects are to be rendered on
120 """
121
122 if (self._isModified() == True):
123 if(self.__data_collector._isScalarSet() == True):
124 self.__data_collector._setActiveScalar()
125 self._setScalarRange(self.__data_collector._getScalarRange())
126 self.__modified = False
127
128
129 ###############################################################################
130
131
132 from transform import Transform
133 from plane import Plane
134 from cutter import Cutter
135
136 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
137 # to allow access to their public methods from the driver.
138 class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
139 """
140 This class works in a similar way to L{Map <map.Map>}, except that it
141 shows a scalar field cut using a plane. The plane can be translated
142 and rotated along the X, Y and Z axes.
143 """
144
145 # The SOUTH_WEST default viewport is used when there is only one viewport.
146 # This saves the user from specifying the viewport when there is only one.
147 # If no lut is specified, the color scheme will be used.
148 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
149 lut = Lut.COLOR, cell_to_point = False, outline = True):
150 """
151 Initialise the MapOnPlanceCut.
152
153 @attention: The source can either be point or cell data. If the
154 source is cell data, a conversion to point data may or may not be
155 required, in order for the object to be rendered correctly.
156 If a conversion is needed, the 'cell_to_point' flag must be set to
157 'True', otherwise 'False' (which is the default).
158
159 @type scene: L{Scene <scene.Scene>} object
160 @param scene: Scene in which objects are to be rendered on
161 @type data_collector: L{DataCollector <datacollector.DataCollector>}
162 object
163 @param data_collector: Deal with source of data for visualisation
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 cell_to_point: Boolean
169 @param cell_to_point: Converts cell data to point data (by averaging)
170 @type outline: Boolean
171 @param outline: Places an outline around the domain surface
172 """
173
174 self.__data_collector = data_collector
175 self.__viewport = viewport
176 self.__lut = lut
177 self.__cell_to_point = cell_to_point
178 self.__outline = outline
179
180 # Keeps track whether MapOnPlaneCut has been modified.
181 self.__modified = True
182 Transform.__init__(self)
183 Plane.__init__(self)
184 Cutter.__init__(self)
185 DataSetMapper.__init__(self)
186 Actor3D.__init__(self)
187 scene._addVisualizationModules(self)
188
189 # ----- Outline -----
190
191 # NOTE: Changes cannot be made to the Outline's properties from the
192 # driver.
193 if(self.__outline == True):
194 outline = Outline(self.__data_collector._getDataCollectorOutput())
195 mapper = DataSetMapper()
196 mapper._setupDataSetMapper(outline._getOutlineOutput())
197
198 actor3D = Actor3D()
199 actor3D._setupActor3D(mapper._getDataSetMapper())
200 # Default outline color is black.
201 actor3D.setColor(Color.BLACK)
202
203 # Default line width is 1.
204 actor3D._setLineWidth(1)
205 scene._addActor3D(self.__viewport, actor3D._getActor3D())
206
207 # ----- Map on a plane -----
208 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
209 # before DataSetMapper. If it is done after DataSetMapper, no effect
210 # will take place.
211 if(self.__lut == Lut.COLOR): # Colored lookup table.
212 lookup_table = LookupTable()
213 lookup_table._setTableValue()
214 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
215 lookup_table = LookupTable()
216 lookup_table._setLookupTableToGreyScale()
217
218 self._setupPlane(self._getTransform())
219
220 if(self.__cell_to_point == True): # Converts cell data to point data.
221 c2p = CellDataToPointData(
222 self.__data_collector._getDataCollectorOutput())
223 self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
224 elif(self.__cell_to_point == False): # No conversion happens.
225 c2p = CellDataToPointData(
226 self.__data_collector._getDataCollectorOutput())
227 self._setupCutter(self.__data_collector._getDataCollectorOutput(),
228 self._getPlane())
229
230 self._setupDataSetMapper(self._getCutterOutput(),
231 lookup_table._getLookupTable())
232
233 self._setupActor3D(self._getDataSetMapper())
234 scene._addActor3D(self.__viewport, self._getActor3D())
235
236 def _isModified(self):
237 """
238 Return whether the MapOnPlaneCut or DataCollector has been modified.
239
240 @rtype: Boolean
241 @return: True or False
242 """
243
244 return self.__modified or self.__data_collector._isModified()
245
246 def _render(self, scene):
247 """
248 Render the surface map cut using a plane.
249
250 @type scene: L{Scene <scene.Scene>} object
251 @param scene: Scene in which objects are to be rendered on
252 """
253
254 if (self._isModified() == True):
255 if(self.__data_collector._isScalarSet() == True):
256 self.__data_collector._setActiveScalar()
257 self._setScalarRange(self.__data_collector._getScalarRange())
258 self.__modified = False
259
260
261 ###############################################################################
262
263
264 from clipper import Clipper
265
266 # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
267 # to allow access to their public methods from the driver.
268 class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
269 """
270 This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
271 except that it shows a scalar field clipped using a plane.
272 """
273
274 # The SOUTH_WEST default viewport is used when there is only one viewport.
275 # This saves the user from specifying the viewport when there is only one.
276 # If no lut is specified, the color scheme will be used.
277 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
278 lut = Lut.COLOR, cell_to_point = False, outline = True):
279 """
280 Initialise the MapOnPlaneClip.
281
282 @attention: The source can either be point or cell data. If the
283 source is cell data, a conversion to point data may or may not be
284 required, in order for the object to be rendered correctly.
285 If a conversion is needed, the 'cell_to_point' flag must be set to
286 'True', otherwise 'False' (which is the default).
287
288 @type scene: L{Scene <scene.Scene>} object
289 @param scene: Scene in which objects are to be rendered on
290 @type data_collector: L{DataCollector <datacollector.DataCollector>}
291 object
292 @param data_collector: Deal with source of data for visualisation
293 @type viewport: L{Viewport <constant.Viewport>} constant
294 @param viewport: Viewport in which objects are to be rendered on
295 @type lut : L{Lut <constant.Lut>} constant
296 @param lut: Lookup table color scheme
297 @type cell_to_point: Boolean
298 @param cell_to_point: Converts cell data to point data (by averaging)
299 @type outline: Boolean
300 @param outline: Places an outline around the domain surface
301 """
302
303 self.__data_collector = data_collector
304 self.__viewport = viewport
305 self.__lut = lut
306 self.__cell_to_point = cell_to_point
307 self.__outline = outline
308
309 # Keeps track whether MapOnPlaneClip has been modified.
310 self.__modified = True
311 Transform.__init__(self)
312 Plane.__init__(self)
313 Clipper.__init__(self)
314 DataSetMapper.__init__(self)
315 Actor3D.__init__(self)
316 scene._addVisualizationModules(self)
317
318 # ----- Outline -----
319
320 # NOTE: Changes cannot be made to the Outline's properties from the
321 # driver.
322 if(self.__outline == True):
323 outline = Outline(self.__data_collector._getDataCollectorOutput())
324 mapper = DataSetMapper()
325 mapper._setupDataSetMapper(outline._getOutlineOutput())
326
327 actor3D = Actor3D()
328 actor3D._setupActor3D(mapper._getDataSetMapper())
329 # Default outline color is black.
330 actor3D.setColor(Color.BLACK)
331
332 # Default line width is 1.
333 actor3D._setLineWidth(1)
334 scene._addActor3D(self.__viewport, actor3D._getActor3D())
335
336 # ----- Map on a clipped plane -----
337
338 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
339 # before DataSetMapper. If it is done after DataSetMapper, no effect
340 # will take place.
341 if(self.__lut == Lut.COLOR): # Colored lookup table.
342 lookup_table = LookupTable()
343 lookup_table._setTableValue()
344 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
345 lookup_table = LookupTable()
346 lookup_table._setLookupTableToGreyScale()
347
348 self._setupPlane(self._getTransform())
349
350 if(self.__cell_to_point == True): # Converts cell data to point data.
351 c2p = CellDataToPointData(data_collector._getDataCollectorOutput())
352 self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
353 elif(self.__cell_to_point == False): # No conversion happens.
354 self._setupClipper(data_collector._getDataCollectorOutput(),
355 self._getPlane())
356
357 self._setClipFunction()
358 self._setupDataSetMapper(self._getClipperOutput(),
359 lookup_table._getLookupTable())
360
361 self._setupActor3D(self._getDataSetMapper())
362 scene._addActor3D(self.__viewport, self._getActor3D())
363
364 def _isModified(self):
365 """
366 Return whether the MapOnPlaneClip or DataCollector has been modified.
367
368 @rtype: Boolean
369 @return: True or False
370 """
371
372 return self.__modified or self.__data_collector._isModified()
373
374 def _render(self, scene):
375 """
376 Render the surface map clip using a plane.
377
378 @type scene: L{Scene <scene.Scene>} object
379 @param scene: Scene in which objects are to be rendered on
380 """
381
382 if (self._isModified() == True):
383 if(self.__data_collector._isScalarSet() == True):
384 self.__data_collector._setActiveScalar()
385 self._setScalarRange(self.__data_collector._getScalarRange())
386 self.__modified = False
387
388
389 #############################################################################
390
391
392 # NOTE: DataSetMapper, Actor3D and Clipper were inherited
393 # to allow access to their public methods from the driver.
394 class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
395 """
396 This class works in a similar way to L{Map <map.Map>}, except that it
397 shows a scalar field clipped using a scalar value.
398 """
399
400 # The SOUTH_WEST default viewport is used when there is only one viewport.
401 # This saves the user from specifying the viewport when there is only one.
402 # If no lut is specified, the color scheme will be used.
403 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
404 lut = Lut.COLOR, cell_to_point = False, outline = True):
405 """
406 Initialise the MapOnScalarClip.
407
408 @attention: The source can either be point or cell data. If the
409 source is cell data, a conversion to point data may or may not be
410 required, in order for the object to be rendered correctly.
411 If a conversion is needed, the 'cell_to_point' flag must be set to
412 'True', otherwise 'False' (which is the default).
413
414 @type scene: L{Scene <scene.Scene>} object
415 @param scene: Scene in which objects are to be rendered on
416 @type data_collector: L{DataCollector <datacollector.DataCollector>}
417 object
418 @param data_collector: Deal with source of data for visualisation
419 @type viewport: L{Viewport <constant.Viewport>} constant
420 @param viewport: Viewport in which objects are to be rendered on
421 @type lut : L{Lut <constant.Lut>} constant
422 @param lut: Lookup table color scheme
423 @type cell_to_point: Boolean
424 @param cell_to_point: Converts cell data to point data (by averaging)
425 @type outline: Boolean
426 @param outline: Places an outline around the domain surface
427 """
428
429 self.__data_collector = data_collector
430 self.__viewport = viewport
431 self.__lut = lut
432 self.__cell_to_point = cell_to_point
433 self.__outline = outline
434
435 # Keeps track whether MapOnScalarClip has been modified.
436 self.__modified = True
437 Clipper.__init__(self)
438 DataSetMapper.__init__(self)
439 Actor3D.__init__(self)
440 scene._addVisualizationModules(self)
441
442 # ----- Outline -----
443
444 # NOTE: Changes cannot be made to the Outline's properties from the
445 # driver.
446 if(self.__outline == True):
447 outline = Outline(self.__data_collector._getDataCollectorOutput())
448 mapper = DataSetMapper()
449 mapper._setupDataSetMapper(outline._getOutlineOutput())
450
451 actor3D = Actor3D()
452 actor3D._setupActor3D(mapper._getDataSetMapper())
453 # Default outline color is black.
454 actor3D.setColor(Color.BLACK)
455
456 # Default line width is 1.
457 actor3D._setLineWidth(1)
458 scene._addActor3D(self.__viewport, actor3D._getActor3D())
459
460 # ----- Map clipped using a scalar value -----
461
462 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
463 # before DataSetMapper. If it is done after DataSetMapper, no effect
464 # will take place.
465 if(self.__lut == Lut.COLOR): # Colored lookup table.
466 lookup_table = LookupTable()
467 lookup_table._setTableValue()
468 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
469 lookup_table = LookupTable()
470 lookup_table._setLookupTableToGreyScale()
471
472 if(self.__cell_to_point == True): # Converts cell data to point data.
473 c2p = CellDataToPointData(
474 self.__data_collector._getDataCollectorOutput())
475 # None is used because a plane is not required when a scalar
476 # value is used to perform the clipping.
477 self._setupClipper(c2p._getDataCollectorOutput(), None)
478 elif(self.__cell_to_point == False): # No conversion happens.
479 self._setupClipper(
480 self.__data_collector._getDataCollectorOutput(),None)
481
482 self._setupDataSetMapper(self._getClipperOutput(),
483 lookup_table._getLookupTable())
484
485 self._setupActor3D(self._getDataSetMapper())
486 scene._addActor3D(self.__viewport, self._getActor3D())
487
488 def _isModified(self):
489 """
490 Return whether the MapOnScalarClip or DataCollector has been modified.
491
492 @rtype: Boolean
493 @return: True or False
494 """
495
496 return self.__modified or self.__data_collector._isModified()
497
498 def _render(self, scene):
499 """
500 Render the surface map clip using scalar data.
501
502 @type scene: L{Scene <scene.Scene>} object
503 @param scene: Scene in which objects are to be rendered on
504 """
505
506 if (self._isModified() == True):
507 if(self.__data_collector._isScalarSet() == True):
508 self.__data_collector._setActiveScalar()
509 self._setScalarRange(self.__data_collector._getScalarRange())
510 self.__modified = False
511
512
513

  ViewVC Help
Powered by ViewVC 1.1.26