/[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 1158 by jongui, Tue May 22 04:24:01 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._setScalarRange(self.__data_collector._getScalarRange())
147                self.__modified = False
148    
149    
150  ###############################################################################  ###############################################################################
# Line 121  class ContourOnPlaneCut(DataSetMapper, A Line 160  class ContourOnPlaneCut(DataSetMapper, A
160          Plane, Cutter):          Plane, Cutter):
161      """      """
162      This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},      This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>},
163      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.
164      """      """
165    
166      # 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 193  class ContourOnPlaneCut(DataSetMapper, A
193          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
194          """          """
195    
196          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
197          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
198          # only the methods associated with the latest instance (which in this          self.__lut = lut
199          # case is the Actor3D for the contour) can be executed. Actor3D          self.__cell_to_point = cell_to_point
200          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
201          # They can only be called within here, which is why Outline must          
202          # be place before the contour as there is unlikely to be any changes          # Keeps track whether ContourOnPlaneCut has been modified.
203          # made to the Outline's Actor3D.          self.__modified = True      
204            Transform.__init__(self)
205          # ----- Outline -----          Plane.__init__(self)
206            Cutter.__init__(self)
207          if(outline == True):          ContourModule.__init__(self)
208              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
209              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
210            scene._addVisualizationModules(self)
211    
212              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          # ----- Outline -----
213    
214            # 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    
221                actor3D = Actor3D()
222                actor3D._setupActor3D(mapper._getDataSetMapper())
223              # Default outline color is black.              # Default outline color is black.
224              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
225    
226              # Default line width is 1.              # Default line width is 1.
227              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
228              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
229    
230          # ----- Contour on a cut plane -----          # ----- Contour on a cut plane -----
231    
232          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
233          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
234          # will take place.          # will take place.
235          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
236              lookup_table = LookupTable()              lookup_table = LookupTable()
237              lookup_table._setTableValue()              lookup_table._setTableValue()
238          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
239              lookup_table = LookupTable()              lookup_table = LookupTable()
240              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
241    
242          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
243    
244          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
245              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(self.__data_collector._getOutput())
246              Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))              self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
247          elif(cell_to_point == False): # No conversion happens.            elif(self.__cell_to_point == False): # No conversion happens.  
248              Cutter.__init__(self, data_collector._getOutput(),              self._setupCutter(self.__data_collector._getDataCollectorOutput(),
249                      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])  
250    
251          DataSetMapper.__init__(self, ContourModule._getOutput(self),          self._setupContourModule(self._getCutterOutput())
252            self._setupDataSetMapper(self._getContourModuleOutput(),
253                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
254    
255          data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,          self._setupActor3D(self._getDataSetMapper())
256                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),          scene._addActor3D(self.__viewport, self._getActor3D())
257                  ContourModule._getContour(self))      
258        def _isModified(self):  
259            """
260            Return whether the ContourOnPlaneCut or DataCollector has been modified.
261    
262            @rtype: Boolean
263            @return: True or False
264            """
265    
266            return self.__modified or self.__data_collector._isModified()
267    
268        def _render(self, scene):
269            """
270            Render the contour cut using a plane.
271    
272            @type scene: L{Scene <scene.Scene>} object
273            @param scene: Scene in which objects are to be rendered on
274            """
275    
276          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          if (self._isModified() == True):
277          scene._addActor3D(viewport, Actor3D._getActor3D(self))              if(self.__data_collector._isScalarSet() == True):
278                    self.__data_collector._setActiveScalar()
279    
280                # By default 10 contours are generated and the scalar range is based
281                # on the scalar data range.
282                contours = 10
283                lower_range = self.__data_collector._getScalarRange()[0]
284                upper_range = self.__data_collector._getScalarRange()[1]
285    
286                if(self._isContoursSet() == True):
287                    contours = None
288                if(self._isLowerRangeSet() == True):
289                    lower_range = None
290                if(self._isUpperRangeSet() == True):
291                    upper_range = None
292    
293                self.generateContours(contours, lower_range, upper_range)
294                self._generateContours()
295                            
296                self._setScalarRange(self.__data_collector._getScalarRange())
297                self.__modified = False
298    
299    
300  ###############################################################################  ###############################################################################
# Line 263  class ContourOnPlaneClip(DataSetMapper, Line 342  class ContourOnPlaneClip(DataSetMapper,
342          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
343          """          """
344    
345          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
346          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
347          # only the methods associated with the latest instance (which in this          self.__lut = lut
348          # case is the Actor3D for the contour) can be executed. Actor3D          self.__cell_to_point = cell_to_point
349          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
350          # They can only be called within here, which is why Outline must          
351          # be place before the contour as there is unlikely to be any changes          # Keeps track whether ContourOnPlaneClip has been modified.
352          # made to the Outline's Actor3D.          self.__modified = True      
353            Transform.__init__(self)
354          # ----- Outline -----          Plane.__init__(self)
355            Clipper.__init__(self)
356          if(outline == True):          ContourModule.__init__(self)
357              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
358              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
359            scene._addVisualizationModules(self)
360    
361            # ----- Outline -----
362    
363            # NOTE: Changes cannot be made to the Outline's properties from the
364            # driver.
365            if(self.__outline == True):
366                outline = Outline(self.__data_collector._getDataCollectorOutput())
367                mapper = DataSetMapper()
368                mapper._setupDataSetMapper(outline._getOutlineOutput())
369    
370              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
371                actor3D._setupActor3D(mapper._getDataSetMapper())
372              # Default outline color is black.              # Default outline color is black.
373              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
374    
375              # Default line width is 1.              # Default line width is 1.
376              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
377              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
378    
379          # ----- Contour on a clipped plane -----          # ----- Contour on a clipped plane -----
380    
381          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
382          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
383          # will take place.          # will take place.
384          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
385              lookup_table = LookupTable()              lookup_table = LookupTable()
386              lookup_table._setTableValue()              lookup_table._setTableValue()
387          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
388              lookup_table = LookupTable()              lookup_table = LookupTable()
389              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
390    
391          Transform.__init__(self)              self._setupPlane(self._getTransform())
392          Plane.__init__(self, Transform._getTransform(self))  
393            if(self.__cell_to_point == True): # Converts cell data to point data.
394                c2p = CellDataToPointData(
395                        self.__data_collector._getDataCollectorOutput())
396                self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
397            elif(self.__cell_to_point == False): # No conversion happens.  
398                self._setupClipper(self.__data_collector._getDataCollectorOutput(),
399                        self._getPlane())
400    
401          if(cell_to_point == True): # Converts cell data to point data.          self._setClipFunction()
402              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])  
403    
404          DataSetMapper.__init__(self, ContourModule._getOutput(self),          self._setupDataSetMapper(self._getContourModuleOutput(),
405                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
406    
407          data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR,          self._setupActor3D(self._getDataSetMapper())
408                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self),          scene._addActor3D(self.__viewport, self._getActor3D())
409                  ContourModule._getContour(self))      
410        def _isModified(self):  
411            """
412            Return whether the ContourOnPlaneClip or DataCollector has been
413            modified.
414    
415            @rtype: Boolean
416            @return: True or False
417            """
418    
419            return self.__modified or self.__data_collector._isModified()
420    
421        def _render(self, scene):
422            """
423            Render the contour clip using a plane.
424    
425            @type scene: L{Scene <scene.Scene>} object
426            @param scene: Scene in which objects are to be rendered on
427            """
428    
429            if (self._isModified() == True):
430                if(self.__data_collector._isScalarSet() == True):
431                    self.__data_collector._setActiveScalar()
432    
433                # By default 10 contours are generated and the scalar range is based
434                # on the scalar data range.
435                contours = 10
436                lower_range = self.__data_collector._getScalarRange()[0]
437                upper_range = self.__data_collector._getScalarRange()[1]
438    
439                if(self._isContoursSet() == True):
440                    contours = None
441                if(self._isLowerRangeSet() == True):
442                    lower_range = None
443                if(self._isUpperRangeSet() == True):
444                    upper_range = None
445    
446                self.generateContours(contours, lower_range, upper_range)
447                self._generateContours()
448                            
449                self._setScalarRange(self.__data_collector._getScalarRange())
450                self.__modified = False
451    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
452    

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

  ViewVC Help
Powered by ViewVC 1.1.26