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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1211 - (hide annotations)
Wed Jul 4 05:16:46 2007 UTC (12 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 25190 byte(s)
- Fixed some minor bugs.
- Added a new feature called 'MapOnScalarClipWithRotation' that clips a two-dimensional data with a scalar value and subsequently rotating it to create a three-dimensional effect.
- Corresponding examples, test cases and documentation of the new module have also been added.
1 ksteube 1147 """
2 jongui 1197 @var __author__: name of author
3     @var __copyright__: copyrights
4     @var __license__: licence agreement
5     @var __url__: url entry point on documentation
6     @var __version__: version
7     @var __date__: date of the version
8 ksteube 1147 """
9    
10 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
11     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12     http://www.access.edu.au
13     Primary Business: Queensland, Australia"""
14     __license__="""Licensed under the Open Software License version 3.0
15     http://www.opensource.org/licenses/osl-3.0.php"""
16     __url__="http://www.iservo.edu.au/esys"
17     __version__="$Revision$"
18     __date__="$Date$"
19    
20    
21 ksteube 1147 import vtk
22     from mapper import DataSetMapper
23     from actor import Actor3D
24     from lookuptable import LookupTable
25     from outline import Outline
26 jongui 1148 from constant import Viewport, Color, Lut, ColorMode
27 ksteube 1147 from average import CellDataToPointData
28    
29     # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
30     # public methods from the driver.
31     class Map(DataSetMapper, Actor3D):
32     """
33     Class that shows a scalar field on a domain surface. The domain surface
34     can either be colored or grey-scaled, depending on the lookup table used.
35     """
36    
37     # The SOUTH_WEST default viewport is used when there is only one viewport.
38     # This saves the user from specifying the viewport when there is only one.
39     # If no lut is specified, the color scheme will be used.
40     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
41     lut = Lut.COLOR, cell_to_point = False, outline = True):
42     """
43     Initialise the Map.
44    
45     @attention: The source can either be point or cell data. If the
46     source is cell data, a conversion to point data may or may not be
47     required, in order for the object to be rendered correctly.
48     If a conversion is needed, the 'cell_to_point' flag must be set to
49 jongui 1199 'True', otherwise 'False' (which is the default). On occasions, an
50     inaccurate object may be rendered from cell data even after conversion.
51 ksteube 1147
52     @type scene: L{Scene <scene.Scene>} object
53     @param scene: Scene in which objects are to be rendered on
54     @type data_collector: L{DataCollector <datacollector.DataCollector>}
55     object
56     @param data_collector: Deal with source of data for vizualisation
57     @type viewport: L{Viewport <constant.Viewport>} constant
58     @param viewport: Viewport in which objects are to be rendered on
59     @type lut : L{Lut <constant.Lut>} constant
60     @param lut: Lookup table color scheme
61     @type cell_to_point: Boolean
62     @param cell_to_point: Converts cell data to point data (by averaging)
63     @type outline: Boolean
64     @param outline: Places an outline around the domain surface
65     """
66    
67     self.__data_collector = data_collector
68     self.__viewport = viewport
69     self.__lut = lut
70     self.__cell_to_point = cell_to_point
71     self.__outline = outline
72 jongui 1148
73     self.__modified = True # Keeps track whether Map has been modified.
74     DataSetMapper.__init__(self)
75     Actor3D.__init__(self)
76     scene._addVisualizationModules(self)
77 ksteube 1147
78 jongui 1148 # ----- Outline -----
79 ksteube 1147
80 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
81     # driver.
82     if(self.__outline == True):
83     outline = Outline(self.__data_collector._getDataCollectorOutput())
84     mapper = DataSetMapper()
85     mapper._setupDataSetMapper(outline._getOutlineOutput())
86 ksteube 1147
87 jongui 1148 actor3D = Actor3D()
88     actor3D._setupActor3D(mapper._getDataSetMapper())
89     # Default outline color is black.
90     actor3D.setColor(Color.BLACK)
91 ksteube 1147
92 jongui 1148 # Default line width is 1.
93     actor3D._setLineWidth(1)
94 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
95 ksteube 1147
96 jongui 1148 # ----- Map -----
97 ksteube 1147
98 jongui 1148 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
99     # before DataSetMapper. If it is done after DataSetMapper, no effect
100     # will take place.
101     if(self.__lut == Lut.COLOR): # Colored lookup table.
102     lookup_table = LookupTable()
103     lookup_table._setTableValue()
104     elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
105     lookup_table = LookupTable()
106     lookup_table._setLookupTableToGreyScale()
107 ksteube 1147
108 jongui 1148 if(self.__cell_to_point == True): # Convert cell data to point data.
109     c2p = CellDataToPointData(
110     self.__data_collector._getDataCollectorOutput())
111     self._setupDataSetMapper(c2p._getCellToPointOutput(),
112     lookup_table._getLookupTable())
113     elif(self.__cell_to_point == False): # No conversion happens.
114     self._setupDataSetMapper(
115     self.__data_collector._getDataCollectorOutput(),
116     lookup_table._getLookupTable())
117 ksteube 1147
118 jongui 1148 self._setupActor3D(self._getDataSetMapper())
119 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
120 jongui 1148
121     def _isModified(self):
122     """
123     Return whether the Map or DataCollector has been modified.
124 ksteube 1147
125 jongui 1148 @rtype: Boolean
126     @return: True or False
127     """
128 ksteube 1147
129 jongui 1148 return self.__modified or self.__data_collector._isModified()
130 ksteube 1147
131 jongui 1158 def _render(self, scene):
132 jongui 1148 """
133     Render the surface map.
134 jongui 1158
135     @type scene: L{Scene <scene.Scene>} object
136     @param scene: Scene in which objects are to be rendered on
137 jongui 1148 """
138 ksteube 1147
139 jongui 1148 if (self._isModified() == True):
140     if(self.__data_collector._isScalarSet() == True):
141     self.__data_collector._setActiveScalar()
142 jongui 1189
143     # self._isScalarRangeSet checks whether the scalar range has been
144     # specified by the user. If it has, then the scalar range
145     # read from the source will be ignored.
146     if(not(self._isScalarRangeSet())):
147     self._setScalarRange(self.__data_collector._getScalarRange())
148 ksteube 1147 self.__modified = False
149    
150    
151     ###############################################################################
152    
153    
154     from transform import Transform
155     from plane import Plane
156     from cutter import Cutter
157    
158     # NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited
159     # to allow access to their public methods from the driver.
160     class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
161     """
162     This class works in a similar way to L{Map <map.Map>}, except that it
163 jongui 1148 shows a scalar field cut using a plane. The plane can be translated
164     and rotated along the X, Y and Z axes.
165 ksteube 1147 """
166    
167     # The SOUTH_WEST default viewport is used when there is only one viewport.
168     # This saves the user from specifying the viewport when there is only one.
169     # If no lut is specified, the color scheme will be used.
170     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
171     lut = Lut.COLOR, cell_to_point = False, outline = True):
172     """
173     Initialise the MapOnPlanceCut.
174    
175     @attention: The source can either be point or cell data. If the
176     source is cell data, a conversion to point data may or may not be
177     required, in order for the object to be rendered correctly.
178     If a conversion is needed, the 'cell_to_point' flag must be set to
179 jongui 1199 'True', otherwise 'False' (which is the default). On occasions, an
180     inaccurate object may be rendered from cell data even after conversion.
181 ksteube 1147
182     @type scene: L{Scene <scene.Scene>} object
183     @param scene: Scene in which objects are to be rendered on
184     @type data_collector: L{DataCollector <datacollector.DataCollector>}
185     object
186     @param data_collector: Deal with source of data for visualisation
187     @type viewport: L{Viewport <constant.Viewport>} constant
188     @param viewport: Viewport in which objects are to be rendered on
189     @type lut : L{Lut <constant.Lut>} constant
190     @param lut: Lookup table color scheme
191     @type cell_to_point: Boolean
192     @param cell_to_point: Converts cell data to point data (by averaging)
193     @type outline: Boolean
194     @param outline: Places an outline around the domain surface
195     """
196    
197 jongui 1148 self.__data_collector = data_collector
198     self.__viewport = viewport
199     self.__lut = lut
200     self.__cell_to_point = cell_to_point
201     self.__outline = outline
202    
203     # Keeps track whether MapOnPlaneCut has been modified.
204     self.__modified = True
205     Transform.__init__(self)
206     Plane.__init__(self)
207     Cutter.__init__(self)
208     DataSetMapper.__init__(self)
209     Actor3D.__init__(self)
210     scene._addVisualizationModules(self)
211 ksteube 1147
212 jongui 1148 # ----- Outline -----
213 ksteube 1147
214 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
215     # driver.
216     if(self.__outline == True):
217     outline = Outline(self.__data_collector._getDataCollectorOutput())
218     mapper = DataSetMapper()
219     mapper._setupDataSetMapper(outline._getOutlineOutput())
220 ksteube 1147
221 jongui 1148 actor3D = Actor3D()
222     actor3D._setupActor3D(mapper._getDataSetMapper())
223 ksteube 1147 # Default outline color is black.
224 jongui 1148 actor3D.setColor(Color.BLACK)
225    
226 ksteube 1147 # Default line width is 1.
227 jongui 1148 actor3D._setLineWidth(1)
228 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
229 ksteube 1147
230     # ----- Map on a plane -----
231 jongui 1197
232 ksteube 1147 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
233     # before DataSetMapper. If it is done after DataSetMapper, no effect
234     # will take place.
235 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
236 ksteube 1147 lookup_table = LookupTable()
237     lookup_table._setTableValue()
238 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
239     lookup_table = LookupTable()
240 ksteube 1147 lookup_table._setLookupTableToGreyScale()
241    
242 jongui 1148 self._setupPlane(self._getTransform())
243 ksteube 1147
244 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
245     c2p = CellDataToPointData(
246     self.__data_collector._getDataCollectorOutput())
247     self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
248     elif(self.__cell_to_point == False): # No conversion happens.
249     c2p = CellDataToPointData(
250     self.__data_collector._getDataCollectorOutput())
251     self._setupCutter(self.__data_collector._getDataCollectorOutput(),
252     self._getPlane())
253 ksteube 1147
254 jongui 1148 self._setupDataSetMapper(self._getCutterOutput(),
255 ksteube 1147 lookup_table._getLookupTable())
256    
257 jongui 1148 self._setupActor3D(self._getDataSetMapper())
258 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
259 ksteube 1147
260 jongui 1148 def _isModified(self):
261     """
262     Return whether the MapOnPlaneCut or DataCollector has been modified.
263 ksteube 1147
264 jongui 1148 @rtype: Boolean
265     @return: True or False
266     """
267 ksteube 1147
268 jongui 1148 return self.__modified or self.__data_collector._isModified()
269    
270 jongui 1158 def _render(self, scene):
271 jongui 1148 """
272     Render the surface map cut using a plane.
273 jongui 1158
274     @type scene: L{Scene <scene.Scene>} object
275     @param scene: Scene in which objects are to be rendered on
276 jongui 1148 """
277    
278     if (self._isModified() == True):
279     if(self.__data_collector._isScalarSet() == True):
280     self.__data_collector._setActiveScalar()
281 jongui 1189 # self._isScalarRangeSet checks whether the scalar range has been
282     # specified by the user. If it has, then the scalar range
283     # read from the source will be ignored.
284     if(not(self._isScalarRangeSet())):
285     self._setScalarRange(self.__data_collector._getScalarRange())
286 jongui 1148 self.__modified = False
287    
288    
289 ksteube 1147 ###############################################################################
290    
291    
292     from clipper import Clipper
293    
294     # NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited
295     # to allow access to their public methods from the driver.
296     class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper):
297     """
298     This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
299     except that it shows a scalar field clipped using a plane.
300     """
301    
302     # The SOUTH_WEST default viewport is used when there is only one viewport.
303     # This saves the user from specifying the viewport when there is only one.
304     # If no lut is specified, the color scheme will be used.
305     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
306     lut = Lut.COLOR, cell_to_point = False, outline = True):
307     """
308     Initialise the MapOnPlaneClip.
309    
310     @attention: The source can either be point or cell data. If the
311     source is cell data, a conversion to point data may or may not be
312     required, in order for the object to be rendered correctly.
313     If a conversion is needed, the 'cell_to_point' flag must be set to
314 jongui 1199 'True', otherwise 'False' (which is the default). On occasions, an
315     inaccurate object may be rendered from cell data even after conversion.
316 ksteube 1147
317     @type scene: L{Scene <scene.Scene>} object
318     @param scene: Scene in which objects are to be rendered on
319     @type data_collector: L{DataCollector <datacollector.DataCollector>}
320     object
321     @param data_collector: Deal with source of data for visualisation
322     @type viewport: L{Viewport <constant.Viewport>} constant
323     @param viewport: Viewport in which objects are to be rendered on
324     @type lut : L{Lut <constant.Lut>} constant
325     @param lut: Lookup table color scheme
326     @type cell_to_point: Boolean
327     @param cell_to_point: Converts cell data to point data (by averaging)
328     @type outline: Boolean
329     @param outline: Places an outline around the domain surface
330     """
331    
332 jongui 1148 self.__data_collector = data_collector
333     self.__viewport = viewport
334     self.__lut = lut
335     self.__cell_to_point = cell_to_point
336     self.__outline = outline
337    
338     # Keeps track whether MapOnPlaneClip has been modified.
339     self.__modified = True
340     Transform.__init__(self)
341     Plane.__init__(self)
342     Clipper.__init__(self)
343     DataSetMapper.__init__(self)
344     Actor3D.__init__(self)
345     scene._addVisualizationModules(self)
346 ksteube 1147
347 jongui 1148 # ----- Outline -----
348 ksteube 1147
349 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
350     # driver.
351     if(self.__outline == True):
352     outline = Outline(self.__data_collector._getDataCollectorOutput())
353     mapper = DataSetMapper()
354     mapper._setupDataSetMapper(outline._getOutlineOutput())
355 ksteube 1147
356 jongui 1148 actor3D = Actor3D()
357     actor3D._setupActor3D(mapper._getDataSetMapper())
358 ksteube 1147 # Default outline color is black.
359 jongui 1148 actor3D.setColor(Color.BLACK)
360 ksteube 1147
361     # Default line width is 1.
362 jongui 1148 actor3D._setLineWidth(1)
363 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
364 ksteube 1147
365     # ----- Map on a clipped plane -----
366    
367     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
368     # before DataSetMapper. If it is done after DataSetMapper, no effect
369     # will take place.
370 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
371 ksteube 1147 lookup_table = LookupTable()
372     lookup_table._setTableValue()
373 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
374 ksteube 1147 lookup_table = LookupTable()
375     lookup_table._setLookupTableToGreyScale()
376    
377 jongui 1148 self._setupPlane(self._getTransform())
378 ksteube 1147
379 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
380     c2p = CellDataToPointData(data_collector._getDataCollectorOutput())
381     self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
382     elif(self.__cell_to_point == False): # No conversion happens.
383     self._setupClipper(data_collector._getDataCollectorOutput(),
384     self._getPlane())
385 ksteube 1147
386 jongui 1148 self._setClipFunction()
387     self._setupDataSetMapper(self._getClipperOutput(),
388 ksteube 1147 lookup_table._getLookupTable())
389    
390 jongui 1148 self._setupActor3D(self._getDataSetMapper())
391 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
392 ksteube 1147
393 jongui 1148 def _isModified(self):
394     """
395     Return whether the MapOnPlaneClip or DataCollector has been modified.
396 ksteube 1147
397 jongui 1148 @rtype: Boolean
398     @return: True or False
399     """
400 ksteube 1147
401 jongui 1148 return self.__modified or self.__data_collector._isModified()
402    
403 jongui 1158 def _render(self, scene):
404 jongui 1148 """
405     Render the surface map clip using a plane.
406 jongui 1158
407     @type scene: L{Scene <scene.Scene>} object
408     @param scene: Scene in which objects are to be rendered on
409 jongui 1148 """
410    
411     if (self._isModified() == True):
412     if(self.__data_collector._isScalarSet() == True):
413     self.__data_collector._setActiveScalar()
414 jongui 1189 # self._isScalarRangeSet checks whether the scalar range has been
415     # specified by the user. If it has, then the scalar range
416     # read from the source will be ignored.
417     if(not(self._isScalarRangeSet())):
418     self._setScalarRange(self.__data_collector._getScalarRange())
419 jongui 1148 self.__modified = False
420    
421    
422 ksteube 1147 #############################################################################
423    
424    
425     # NOTE: DataSetMapper, Actor3D and Clipper were inherited
426     # to allow access to their public methods from the driver.
427     class MapOnScalarClip(DataSetMapper, Actor3D, Clipper):
428     """
429     This class works in a similar way to L{Map <map.Map>}, except that it
430     shows a scalar field clipped using a scalar value.
431     """
432    
433     # The SOUTH_WEST default viewport is used when there is only one viewport.
434     # This saves the user from specifying the viewport when there is only one.
435     # If no lut is specified, the color scheme will be used.
436     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
437     lut = Lut.COLOR, cell_to_point = False, outline = True):
438     """
439     Initialise the MapOnScalarClip.
440    
441     @attention: The source can either be point or cell data. If the
442     source is cell data, a conversion to point data may or may not be
443     required, in order for the object to be rendered correctly.
444     If a conversion is needed, the 'cell_to_point' flag must be set to
445 jongui 1199 'True', otherwise 'False' (which is the default). On occasions, an
446     inaccurate object may be rendered from cell data even after conversion.
447 ksteube 1147
448     @type scene: L{Scene <scene.Scene>} object
449     @param scene: Scene in which objects are to be rendered on
450     @type data_collector: L{DataCollector <datacollector.DataCollector>}
451     object
452     @param data_collector: Deal with source of data for visualisation
453     @type viewport: L{Viewport <constant.Viewport>} constant
454     @param viewport: Viewport in which objects are to be rendered on
455     @type lut : L{Lut <constant.Lut>} constant
456     @param lut: Lookup table color scheme
457     @type cell_to_point: Boolean
458     @param cell_to_point: Converts cell data to point data (by averaging)
459     @type outline: Boolean
460     @param outline: Places an outline around the domain surface
461     """
462    
463 jongui 1148 self.__data_collector = data_collector
464     self.__viewport = viewport
465     self.__lut = lut
466     self.__cell_to_point = cell_to_point
467     self.__outline = outline
468    
469     # Keeps track whether MapOnScalarClip has been modified.
470     self.__modified = True
471     Clipper.__init__(self)
472     DataSetMapper.__init__(self)
473     Actor3D.__init__(self)
474     scene._addVisualizationModules(self)
475 ksteube 1147
476     # ----- Outline -----
477    
478 jongui 1148 # NOTE: Changes cannot be made to the Outline's properties from the
479     # driver.
480     if(self.__outline == True):
481     outline = Outline(self.__data_collector._getDataCollectorOutput())
482     mapper = DataSetMapper()
483     mapper._setupDataSetMapper(outline._getOutlineOutput())
484 ksteube 1147
485 jongui 1148 actor3D = Actor3D()
486     actor3D._setupActor3D(mapper._getDataSetMapper())
487     # Default outline color is black.
488     actor3D.setColor(Color.BLACK)
489 ksteube 1147
490 jongui 1148 # Default line width is 1.
491     actor3D._setLineWidth(1)
492 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
493 ksteube 1147
494     # ----- Map clipped using a scalar value -----
495    
496     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
497     # before DataSetMapper. If it is done after DataSetMapper, no effect
498     # will take place.
499 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
500 ksteube 1147 lookup_table = LookupTable()
501     lookup_table._setTableValue()
502 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
503 ksteube 1147 lookup_table = LookupTable()
504     lookup_table._setLookupTableToGreyScale()
505    
506 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
507     c2p = CellDataToPointData(
508     self.__data_collector._getDataCollectorOutput())
509 ksteube 1147 # None is used because a plane is not required when a scalar
510     # value is used to perform the clipping.
511 jongui 1211 self._setupClipper(c2p._getCellToPointOutput(), None)
512 jongui 1148 elif(self.__cell_to_point == False): # No conversion happens.
513     self._setupClipper(
514     self.__data_collector._getDataCollectorOutput(),None)
515 ksteube 1147
516 jongui 1148 self._setupDataSetMapper(self._getClipperOutput(),
517 ksteube 1147 lookup_table._getLookupTable())
518    
519 jongui 1148 self._setupActor3D(self._getDataSetMapper())
520 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
521 ksteube 1147
522 jongui 1148 def _isModified(self):
523     """
524     Return whether the MapOnScalarClip or DataCollector has been modified.
525 ksteube 1147
526 jongui 1148 @rtype: Boolean
527     @return: True or False
528     """
529 ksteube 1147
530 jongui 1148 return self.__modified or self.__data_collector._isModified()
531    
532 jongui 1158 def _render(self, scene):
533 jongui 1148 """
534     Render the surface map clip using scalar data.
535 jongui 1158
536     @type scene: L{Scene <scene.Scene>} object
537     @param scene: Scene in which objects are to be rendered on
538 jongui 1148 """
539    
540     if (self._isModified() == True):
541     if(self.__data_collector._isScalarSet() == True):
542     self.__data_collector._setActiveScalar()
543 jongui 1189 # self._isScalarRangeSet checks whether the scalar range has been
544     # specified by the user. If it has, then the scalar range
545     # read from the source will be ignored.
546     if(not(self._isScalarRangeSet())):
547     self._setScalarRange(self.__data_collector._getScalarRange())
548 jongui 1148 self.__modified = False
549    
550    
551 jongui 1211 ##############################################################################
552 jongui 1148
553 jongui 1211
554     from rotation import Rotation
555     from geometry import Geometry
556    
557     # NOTE: DataSetMapper, Actor3D, Clipper and Rotation were inherited
558     # to allow access to their public methods from the driver.
559     class MapOnScalarClipWithRotation(DataSetMapper, Actor3D, Clipper, Rotation):
560     """
561     This class works in a similar way to L{Map <map.Map>}, except that it
562     shows a 2D scalar field clipped using a scalar value and subsequently
563     rotated around the z-axis to create a 3D looking effect. This class should
564     only be used with 2D data sets and NOT 3D.
565     """
566    
567     # The SOUTH_WEST default viewport is used when there is only one viewport.
568     # This saves the user from specifying the viewport when there is only one.
569     # If no lut is specified, the color scheme will be used.
570     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
571     lut = Lut.COLOR, cell_to_point = False):
572     """
573     Initialise the MapOnScalarClipWithRotation.
574    
575     @attention: The source can either be point or cell data. If the
576     source is cell data, a conversion to point data may or may not be
577     required, in order for the object to be rendered correctly.
578     If a conversion is needed, the 'cell_to_point' flag must be set to
579     'True', otherwise 'False' (which is the default). On occasions, an
580     inaccurate object may be rendered from cell data even after conversion.
581    
582     @type scene: L{Scene <scene.Scene>} object
583     @param scene: Scene in which objects are to be rendered on
584     @type data_collector: L{DataCollector <datacollector.DataCollector>}
585     object
586     @param data_collector: Deal with source of data for visualisation
587     @type viewport: L{Viewport <constant.Viewport>} constant
588     @param viewport: Viewport in which objects are to be rendered on
589     @type lut : L{Lut <constant.Lut>} constant
590     @param lut: Lookup table color scheme
591     @type cell_to_point: Boolean
592     @param cell_to_point: Converts cell data to point data (by averaging)
593     """
594    
595     self.__data_collector = data_collector
596     self.__viewport = viewport
597     self.__lut = lut
598     self.__cell_to_point = cell_to_point
599    
600     # Keeps track whether MapOnScalarClipWithRotation has been modified.
601     self.__modified = True
602     Clipper.__init__(self)
603     Rotation.__init__(self)
604     DataSetMapper.__init__(self)
605     Actor3D.__init__(self)
606     scene._addVisualizationModules(self)
607    
608     def _isModified(self):
609     """
610     Return whether the MapOnScalarClipWithRotation or DataCollector has
611     been modified.
612    
613     @rtype: Boolean
614     @return: True or False
615     """
616    
617     return self.__modified or self.__data_collector._isModified()
618    
619     def _render(self, scene):
620     """
621     Render the surface map clip using scalar data and subsequently rotated.
622    
623     @type scene: L{Scene <scene.Scene>} object
624     @param scene: Scene in which objects are to be rendered on
625     """
626    
627     # This entire 'if' section had to be moved from the __init__ method
628     # due to the use of 'GetPoints().GetNumberOfPoints()'. A source
629     # (i.e. xml file) must be
630     # supplied before 'GetPoints().GetNumberOfPoints()' is able to return
631     # the correct value
632     # when executed. This is to accommodate for lazy evaluation.
633     if (self._isModified() == True):
634    
635     # Swaps the points from the y-axis to the z-axis and vice-versa.
636     # This is needed as VTK is only able to perform rotation along
637     # the z-axis.
638     output = self.__data_collector._getDataCollectorOutput()
639     num_points = output.GetPoints().GetNumberOfPoints()
640     for i in range (num_points):
641     point = output.GetPoints().GetPoint(i)
642     output.GetPoints().SetPoint(i, point[0], point[2], point[1])
643    
644     # --- Map clipped using a scalar value and subsequently rotated ---
645    
646     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
647     # before DataSetMapper. If it is done after DataSetMapper, no effect
648     # will take place.
649     if(self.__lut == Lut.COLOR): # Colored lookup table.
650     lookup_table = LookupTable()
651     lookup_table._setTableValue()
652     elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
653     lookup_table = LookupTable()
654     lookup_table._setLookupTableToGreyScale()
655    
656     if(self.__cell_to_point == True): #Converts cell data to point data.
657     c2p = CellDataToPointData(output)
658     # None is used because a plane is not required when a scalar
659     # value is used to perform the clipping.
660     self._setupClipper(c2p._getCellToPointOutput(), None)
661     elif(self.__cell_to_point == False): # No conversion happens.
662     self._setupClipper(output, None)
663    
664     geometry = Geometry(self._getClipperOutput())
665    
666     self._setupRotationExtrusionFilter(geometry._getGeometryOutput())
667     self._setupDataSetMapper(self._getRotationOutput(),
668     lookup_table._getLookupTable())
669    
670     self._setupActor3D(self._getDataSetMapper())
671     scene._addActor3D(self.__viewport, self._getActor3D())
672    
673     if(self.__data_collector._isScalarSet() == True):
674     self.__data_collector._setActiveScalar()
675     # self._isScalarRangeSet checks whether the scalar range has been
676     # specified by the user. If it has, then the scalar range
677     # read from the source will be ignored.
678     if(not(self._isScalarRangeSet())):
679     self._setScalarRange(self.__data_collector._getScalarRange())
680    
681     self.__modified = False
682    
683    
684    

  ViewVC Help
Powered by ViewVC 1.1.26