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

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

  ViewVC Help
Powered by ViewVC 1.1.26