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

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

  ViewVC Help
Powered by ViewVC 1.1.26