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

Diff of /trunk/pyvisi/py_src/contour.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1147 by ksteube, Wed May 16 06:39:11 2007 UTC revision 1199 by jongui, Wed Jun 20 05:01:30 2007 UTC
# Line 1  Line 1 
1  """  """
2  @author: John NGUI  @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  """  """
9    
10    __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  import vtk  import vtk
22  from mapper import DataSetMapper  from mapper import DataSetMapper
23  from actor import Actor3D  from actor import Actor3D
24  from lookuptable import LookupTable  from lookuptable import LookupTable
25  from outline import Outline  from outline import Outline
26  from constant import Viewport, Color, Lut, VizType, ColorMode  from constant import Viewport, Color, Lut, ColorMode
27  from contourmodule import ContourModule  from contourmodule import ContourModule
28  from average import CellDataToPointData  from average import CellDataToPointData
29    
# Line 32  class Contour(DataSetMapper, Actor3D, Co Line 48  class Contour(DataSetMapper, Actor3D, Co
48          source is cell data, a conversion to point data may or may not be          source is cell data, a conversion to point data may or may not be
49          required, in order for the object to be rendered correctly.          required, in order for the object to be rendered correctly.
50          If a conversion is needed, the 'cell_to_point' flag must be set to          If a conversion is needed, the 'cell_to_point' flag must be set to
51          'True', otherwise 'False' (which is the default).          'True', otherwise 'False' (which is the default). On occasions, an
52            inaccurate object may be rendered from cell data even after conversion.
53    
54          @type scene: L{Scene <scene.Scene>} object          @type scene: L{Scene <scene.Scene>} object
55          @param scene: Scene in which objects are to be rendered on          @param scene: Scene in which objects are to be rendered on
# Line 49  class Contour(DataSetMapper, Actor3D, Co Line 66  class Contour(DataSetMapper, Actor3D, Co
66          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
67          """          """
68    
69          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
70          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
71          # only the methods associated with the latest instance (which in this          self.__lut = lut
72          # case is the Actor3D for the contour) can be executed. Actor3D          self.__cell_to_point = cell_to_point
73          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
74          # They can only be called within here, which is why Outline must          
75          # be place before the contour as there is unlikely to be any changes          self.__modified = True # Keeps track whether Contour has been modified.
76          # made to the Outline's Actor3D.          ContourModule.__init__(self)
77            DataSetMapper.__init__(self)
78            Actor3D.__init__(self)
79            scene._addVisualizationModules(self)
80    
81          # ----- Outline -----          # ----- Outline -----
82    
83          if(outline == True):          # NOTE: Changes cannot be made to the Outline's properties from the
84              outline = Outline(data_collector._getOutput())          # driver.
85              DataSetMapper.__init__(self, outline._getOutput())          if(self.__outline == True):
86                outline = Outline(self.__data_collector._getDataCollectorOutput())
87                mapper = DataSetMapper()
88                mapper._setupDataSetMapper(outline._getOutlineOutput())
89    
90              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
91                actor3D._setupActor3D(mapper._getDataSetMapper())
92              # Default outline color is black.              # Default outline color is black.
93              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
94    
95              # Default line width is 1.              # Default line width is 1.
96              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
97              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
98    
99          # ----- Contour -----          # ----- Contour -----
100    
101          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
102          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
103          # will take place.          # will take place.
104          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
105              lookup_table = LookupTable()              lookup_table = LookupTable()
106              lookup_table._setTableValue()              lookup_table._setTableValue()
107          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
108              lookup_table = LookupTable()              lookup_table = LookupTable()
109              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
110    
111          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
112              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
113              ContourModule.__init__(self, c2p._getOutput())                        self.__data_collector._getDataCollectorOutput())
114          elif(cell_to_point == False): # No conversion happens.                self._setupContourModule(c2p._getCellToPointOutput())  
115              ContourModule.__init__(self, data_collector._getOutput())            elif(self.__cell_to_point == False): # No conversion happens.  
116                self._setupContourModule(
117          # By default 10 contours are generated and the scalar range is based                      self.__data_collector._getDataCollectorOutput())    
         # on the scalar data range.  
         ContourModule.generateContours(self, 10,  
                 data_collector._getScalarRange()[0],  
                 data_collector._getScalarRange()[1])  
118    
119          DataSetMapper.__init__(self, ContourModule._getOutput(self),          self._setupDataSetMapper(self._getContourModuleOutput(),
120                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())  
121    
122          data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,          self._setupActor3D(self._getDataSetMapper())
123                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),          scene._addActor3D(self.__viewport, self._getActor3D())
124                  ContourModule._getContour(self))      
125        def _isModified(self):  
126            """
127            Return whether the Contour or DataCollector has been modified.
128    
129            @rtype: Boolean
130            @return: True or False
131            """
132    
133          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          return self.__modified or self.__data_collector._isModified()
134          scene._addActor3D(viewport, Actor3D._getActor3D(self))  
135        def _render(self, scene):
136            """
137            Render the contour.
138    
139            @type scene: L{Scene <scene.Scene>} object
140            @param scene: Scene in which objects are to be rendered on
141            """
142    
143            if (self._isModified() == True):
144                if(self.__data_collector._isScalarSet() == True):
145                    self.__data_collector._setActiveScalar()
146    
147                # By default 10 contours are generated and the scalar range is based
148                # on the scalar data range.
149                contours = 10
150                lower_range = self.__data_collector._getScalarRange()[0]
151                upper_range = self.__data_collector._getScalarRange()[1]
152    
153                if(self._isContoursSet() == True):
154                    contours = None
155                if(self._isLowerRangeSet() == True):
156                    lower_range = None
157                if(self._isUpperRangeSet() == True):
158                    upper_range = None
159    
160                self.generateContours(contours, lower_range, upper_range)
161                self._generateContours()
162                            
163                # self._isScalarRangeSet checks whether the scalar range has been
164                # specified by the user. If it has, then the scalar range
165                # read from the source will be ignored.
166                if(not(self._isScalarRangeSet())):
167                    self._setScalarRange(self.__data_collector._getScalarRange())
168                self.__modified = False
169    
170    
171  ###############################################################################  ###############################################################################
# Line 121  class ContourOnPlaneCut(DataSetMapper, A Line 181  class ContourOnPlaneCut(DataSetMapper, A
181          Plane, Cutter):          Plane, Cutter):
182      """      """
183      This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},      This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
184      except that it shows a scalar field by contour surfaces on a plane.      except that it shows a scalar field by contour surfaces cut using a plane.
185      """      """
186    
187      # The SOUTH_WEST default viewport is used when there is only one viewport.      # The SOUTH_WEST default viewport is used when there is only one viewport.
# Line 154  class ContourOnPlaneCut(DataSetMapper, A Line 214  class ContourOnPlaneCut(DataSetMapper, A
214          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
215          """          """
216    
217          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
218          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
219          # only the methods associated with the latest instance (which in this          self.__lut = lut
220          # case is the Actor3D for the contour) can be executed. Actor3D          self.__cell_to_point = cell_to_point
221          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
222          # They can only be called within here, which is why Outline must          
223          # be place before the contour as there is unlikely to be any changes          # Keeps track whether ContourOnPlaneCut has been modified.
224          # made to the Outline's Actor3D.          self.__modified = True      
225            Transform.__init__(self)
226          # ----- Outline -----          Plane.__init__(self)
227            Cutter.__init__(self)
228          if(outline == True):          ContourModule.__init__(self)
229              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
230              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
231            scene._addVisualizationModules(self)
232    
233            # ----- Outline -----
234    
235            # NOTE: Changes cannot be made to the Outline's properties from the
236            # driver.
237            if(self.__outline == True):
238                outline = Outline(self.__data_collector._getDataCollectorOutput())
239                mapper = DataSetMapper()
240                mapper._setupDataSetMapper(outline._getOutlineOutput())
241    
242              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
243                actor3D._setupActor3D(mapper._getDataSetMapper())
244              # Default outline color is black.              # Default outline color is black.
245              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
246    
247              # Default line width is 1.              # Default line width is 1.
248              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
249              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
250    
251          # ----- Contour on a cut plane -----          # ----- Contour on a cut plane -----
252    
253          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
254          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
255          # will take place.          # will take place.
256          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
257              lookup_table = LookupTable()              lookup_table = LookupTable()
258              lookup_table._setTableValue()              lookup_table._setTableValue()
259          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
260              lookup_table = LookupTable()              lookup_table = LookupTable()
261              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
262    
263          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
264    
265          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
266              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(self.__data_collector._getOutput())
267              Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))              self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
268          elif(cell_to_point == False): # No conversion happens.            elif(self.__cell_to_point == False): # No conversion happens.  
269              Cutter.__init__(self, data_collector._getOutput(),              self._setupCutter(self.__data_collector._getDataCollectorOutput(),
270                      Plane._getPlane(self))                      self._getPlane())
   
         ContourModule.__init__(self, Cutter._getOutput(self))  
         # By default 10 contours are generated and the scalar range is based  
         # on the scalar data range.  
         ContourModule.generateContours(self, 10,  
                 data_collector._getScalarRange()[0],  
                 data_collector._getScalarRange()[1])  
271    
272          DataSetMapper.__init__(self, ContourModule._getOutput(self),          self._setupContourModule(self._getCutterOutput())
273            self._setupDataSetMapper(self._getContourModuleOutput(),
274                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
275    
276          data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,          self._setupActor3D(self._getDataSetMapper())
277                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),          scene._addActor3D(self.__viewport, self._getActor3D())
278                  ContourModule._getContour(self))      
279        def _isModified(self):  
280            """
281            Return whether the ContourOnPlaneCut or DataCollector has been modified.
282    
283          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          @rtype: Boolean
284          scene._addActor3D(viewport, Actor3D._getActor3D(self))          @return: True or False
285            """
286    
287            return self.__modified or self.__data_collector._isModified()
288    
289        def _render(self, scene):
290            """
291            Render the contour cut using a plane.
292    
293            @type scene: L{Scene <scene.Scene>} object
294            @param scene: Scene in which objects are to be rendered on
295            """
296    
297            if (self._isModified() == True):
298                if(self.__data_collector._isScalarSet() == True):
299                    self.__data_collector._setActiveScalar()
300    
301                # By default 10 contours are generated and the scalar range is based
302                # on the scalar data range.
303                contours = 10
304                lower_range = self.__data_collector._getScalarRange()[0]
305                upper_range = self.__data_collector._getScalarRange()[1]
306    
307                if(self._isContoursSet() == True):
308                    contours = None
309                if(self._isLowerRangeSet() == True):
310                    lower_range = None
311                if(self._isUpperRangeSet() == True):
312                    upper_range = None
313    
314                self.generateContours(contours, lower_range, upper_range)
315                self._generateContours()
316                            
317                # self._isScalarRangeSet checks whether the scalar range has been
318                # specified by the user. If it has, then the scalar range
319                # read from the source will be ignored.
320                if(not(self._isScalarRangeSet())):
321                    self._setScalarRange(self.__data_collector._getScalarRange())
322                self.__modified = False
323    
324    
325  ###############################################################################  ###############################################################################
# Line 263  class ContourOnPlaneClip(DataSetMapper, Line 367  class ContourOnPlaneClip(DataSetMapper,
367          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
368          """          """
369    
370          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
371          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
372          # only the methods associated with the latest instance (which in this          self.__lut = lut
373          # case is the Actor3D for the contour) can be executed. Actor3D          self.__cell_to_point = cell_to_point
374          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
375          # They can only be called within here, which is why Outline must          
376          # be place before the contour as there is unlikely to be any changes          # Keeps track whether ContourOnPlaneClip has been modified.
377          # made to the Outline's Actor3D.          self.__modified = True      
378            Transform.__init__(self)
379          # ----- Outline -----          Plane.__init__(self)
380            Clipper.__init__(self)
381          if(outline == True):          ContourModule.__init__(self)
382              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
383              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
384            scene._addVisualizationModules(self)
385    
386              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          # ----- Outline -----
387    
388            # NOTE: Changes cannot be made to the Outline's properties from the
389            # driver.
390            if(self.__outline == True):
391                outline = Outline(self.__data_collector._getDataCollectorOutput())
392                mapper = DataSetMapper()
393                mapper._setupDataSetMapper(outline._getOutlineOutput())
394    
395                actor3D = Actor3D()
396                actor3D._setupActor3D(mapper._getDataSetMapper())
397              # Default outline color is black.              # Default outline color is black.
398              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
399    
400              # Default line width is 1.              # Default line width is 1.
401              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
402              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
403    
404          # ----- Contour on a clipped plane -----          # ----- Contour on a clipped plane -----
405    
406          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
407          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
408          # will take place.          # will take place.
409          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
410              lookup_table = LookupTable()              lookup_table = LookupTable()
411              lookup_table._setTableValue()              lookup_table._setTableValue()
412          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
413              lookup_table = LookupTable()              lookup_table = LookupTable()
414              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
415    
416          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
417    
418          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
419              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
420              Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self))                      self.__data_collector._getDataCollectorOutput())
421          elif(cell_to_point == False): # No conversion happens.                self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
422              Clipper.__init__(self, data_collector._getOutput(),          elif(self.__cell_to_point == False): # No conversion happens.  
423                      Plane._getPlane(self))              self._setupClipper(self.__data_collector._getDataCollectorOutput(),
424                        self._getPlane())
         Clipper._setClipFunction(self)  
   
         ContourModule.__init__(self, Clipper._getOutput(self))  
         # By default 10 contours are generated and the scalar range is based  
         # on the scalar data range.  
         ContourModule.generateContours(self, 10,  
                 data_collector._getScalarRange()[0],  
                 data_collector._getScalarRange()[1])  
425    
426          DataSetMapper.__init__(self, ContourModule._getOutput(self),          self._setClipFunction()
427            self._setupContourModule(self._getClipperOutput())
428    
429            self._setupDataSetMapper(self._getContourModuleOutput(),
430                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
431    
432          data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,          self._setupActor3D(self._getDataSetMapper())
433                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),          scene._addActor3D(self.__viewport, self._getActor3D())
434                  ContourModule._getContour(self))      
435        def _isModified(self):  
436            """
437            Return whether the ContourOnPlaneClip or DataCollector has been
438            modified.
439    
440            @rtype: Boolean
441            @return: True or False
442            """
443    
444            return self.__modified or self.__data_collector._isModified()
445    
446        def _render(self, scene):
447            """
448            Render the contour clip using a plane.
449    
450            @type scene: L{Scene <scene.Scene>} object
451            @param scene: Scene in which objects are to be rendered on
452            """
453    
454            if (self._isModified() == True):
455                if(self.__data_collector._isScalarSet() == True):
456                    self.__data_collector._setActiveScalar()
457    
458                # By default 10 contours are generated and the scalar range is based
459                # on the scalar data range.
460                contours = 10
461                lower_range = self.__data_collector._getScalarRange()[0]
462                upper_range = self.__data_collector._getScalarRange()[1]
463    
464                if(self._isContoursSet() == True):
465                    contours = None
466                if(self._isLowerRangeSet() == True):
467                    lower_range = None
468                if(self._isUpperRangeSet() == True):
469                    upper_range = None
470    
471                self.generateContours(contours, lower_range, upper_range)
472                self._generateContours()
473                            
474                # self._isScalarRangeSet checks whether the scalar range has been
475                # specified by the user. If it has, then the scalar range
476                # read from the source will be ignored.
477                if(not(self._isScalarRangeSet())):
478                    self._setScalarRange(self.__data_collector._getScalarRange())
479                self.__modified = False
480    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
481    

Legend:
Removed from v.1147  
changed lines
  Added in v.1199

  ViewVC Help
Powered by ViewVC 1.1.26