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

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

  ViewVC Help
Powered by ViewVC 1.1.26