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

Diff of /trunk/pyvisi/py_src/map.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 average import CellDataToPointData  from average import CellDataToPointData
12    
13  # NOTE: DataSetMapper and Actor3D were inherited to allow access to their  # NOTE: DataSetMapper and Actor3D were inherited to allow access to their
# Line 53  class Map(DataSetMapper, Actor3D): Line 53  class Map(DataSetMapper, Actor3D):
53          self.__lut = lut          self.__lut = lut
54          self.__cell_to_point = cell_to_point          self.__cell_to_point = cell_to_point
55          self.__outline = outline          self.__outline = outline
56            
57            self.__modified = True # Keeps track whether Map has been modified.
58            DataSetMapper.__init__(self)
59            Actor3D.__init__(self)
60            scene._addVisualizationModules(self)
61    
62          self.__modified = True          # ----- Outline -----
         scene._addModules(self)  
63    
64      def _render(self):          # NOTE: Changes cannot be made to the Outline's properties from the
65          if self.__modified == True:          # driver.
66              # NOTE: Actor3D is inherited and there are two instances declared here.          if(self.__outline == True):
67              # As a result, when methods from Actor3D is invoked from the driver,              outline = Outline(self.__data_collector._getDataCollectorOutput())
68              # only the methods associated with the latest instance (which in this              mapper = DataSetMapper()
69              # case is the Actor3D for the  map) can be executed. Actor3D              mapper._setupDataSetMapper(outline._getOutlineOutput())
70              # methods associated with Outline cannot be invoked from the driver.  
71              # They can only be called within here, which is why Outline must              actor3D = Actor3D()
72              # be place before map as there is unlikely to be any changes              actor3D._setupActor3D(mapper._getDataSetMapper())
73              # made to the Outline's Actor3D.              # Default outline color is black.
74                actor3D.setColor(Color.BLACK)
   
             # ----- Outline -----  
   
             if(self.__outline == True):  
                 outline = Outline(self.__data_collector._getOutput())  
                 DataSetMapper.__init__(self, outline._getOutput())  
   
                 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
                 # Default outline color is black.  
                 Actor3D.setColor(self, Color.BLACK)  
   
                 # Default line width is 1.  
                 Actor3D._setLineWidth(self, 1)  
                 self.__scene._addActor3D(self.__viewport, Actor3D._getActor3D(self))  
   
             # ----- Map -----  
   
             # NOTE: Lookup table color mapping (color or grey scale) MUST be set  
             # before DataSetMapper. If it is done after DataSetMapper, no effect  
             # will take place.  
             if(self.__lut == Lut.COLOR): # Colored lookup table.  
                 lookup_table = LookupTable()  
                 lookup_table._setTableValue()  
             elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.  
                 lookup_table = LookupTable()  
                 lookup_table._setLookupTableToGreyScale()  
   
             if(self.__cell_to_point == True): # Converts cell data to point data.  
                 c2p = CellDataToPointData(self.__data_collector._getOutput())  
                 DataSetMapper.__init__(self, c2p._getOutput(),  
                         lookup_table._getLookupTable())  
             elif(self.__cell_to_point == False): # No conversion happens.  
                 DataSetMapper.__init__(self, self.__data_collector._getOutput(),  
                         lookup_table._getLookupTable())  
75    
76              DataSetMapper._setScalarRange(self, self.__data_collector._getScalarRange())              # Default line width is 1.
77                actor3D._setLineWidth(1)
78                self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
79    
80              self.__data_collector._paramForUpdatingMultipleSources(VizType.MAP,          # ----- Map -----
                     ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))  
81    
82              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
83              self.__scene._addActor3D(self.__viewport, Actor3D._getActor3D(self))          # before DataSetMapper. If it is done after DataSetMapper, no effect
84            # will take place.
85            if(self.__lut == Lut.COLOR): # Colored lookup table.
86                lookup_table = LookupTable()
87                lookup_table._setTableValue()
88            elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
89                lookup_table = LookupTable()
90                lookup_table._setLookupTableToGreyScale()
91    
92            if(self.__cell_to_point == True): # Convert cell data to point data.
93                c2p = CellDataToPointData(
94                        self.__data_collector._getDataCollectorOutput())
95                self._setupDataSetMapper(c2p._getCellToPointOutput(),
96                        lookup_table._getLookupTable())
97            elif(self.__cell_to_point == False): # No conversion happens.
98                self._setupDataSetMapper(
99                        self.__data_collector._getDataCollectorOutput(),
100                        lookup_table._getLookupTable())
101    
102            self._setupActor3D(self._getDataSetMapper())
103            self.__scene._addActor3D(self.__viewport, self._getActor3D())
104        
105        def _isModified(self):  
106            """
107            Return whether the Map or DataCollector has been modified.
108    
109            @rtype: Boolean
110            @return: True or False
111            """
112    
113            return self.__modified or self.__data_collector._isModified()
114    
115        def _render(self):
116            """
117            Render the surface map.
118            """
119    
120            if (self._isModified() == True):
121                if(self.__data_collector._isScalarSet() == True):
122                    self.__data_collector._setActiveScalar()
123                self._setScalarRange(self.__data_collector._getScalarRange())
124              self.__modified = False              self.__modified = False
125    
126    
# Line 126  from cutter import Cutter Line 136  from cutter import Cutter
136  class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):  class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter):
137      """      """
138      This class works in a similar way to L{Map <map.Map>}, except that it      This class works in a similar way to L{Map <map.Map>}, except that it
139      shows a scalar field on a plane. The plane can be translated and rotated      shows a scalar field cut using a plane. The plane can be translated
140      along the X, Y and Z axes.      and rotated along the X, Y and Z axes.
141      """      """
142    
143      # 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 159  class MapOnPlaneCut(DataSetMapper, Actor Line 169  class MapOnPlaneCut(DataSetMapper, Actor
169          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
170          """          """
171    
172          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__scene = scene
173          # As a result, when methods from Actor3D is invoked from the driver,          self.__data_collector = data_collector
174          # only the methods associated with the latest instance (which in this          self.__viewport = viewport
175          # case is the Actor3D for the map) can be executed. Actor3D          self.__lut = lut
176          # methods associated with Outline cannot be invoked from the driver.          self.__cell_to_point = cell_to_point
177          # They can only be called within here, which is why Outline must          self.__outline = outline
178          # be place before the map as there is unlikely to be any changes          
179          # made to the Outline's Actor3D.          # Keeps track whether MapOnPlaneCut has been modified.
180            self.__modified = True
181          # ----- Outline -----          Transform.__init__(self)    
182            Plane.__init__(self)
183          if(outline == True):          Cutter.__init__(self)
184              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
185              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
186            scene._addVisualizationModules(self)
187    
188              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          # ----- Outline -----
189    
190            # NOTE: Changes cannot be made to the Outline's properties from the
191            # driver.
192            if(self.__outline == True):
193                outline = Outline(self.__data_collector._getDataCollectorOutput())
194                mapper = DataSetMapper()
195                mapper._setupDataSetMapper(outline._getOutlineOutput())
196    
197                actor3D = Actor3D()
198                actor3D._setupActor3D(mapper._getDataSetMapper())
199              # Default outline color is black.              # Default outline color is black.
200              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
             # Default line width is 1.  
201    
202              Actor3D._setLineWidth(self, 1)              # Default line width is 1.
203              scene._addActor3D(viewport, Actor3D._getActor3D(self))              actor3D._setLineWidth(1)
204                self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
205    
206          # ----- Map on a plane -----          # ----- Map on a plane -----
   
207          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
208          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
209          # will take place.          # will take place.
210          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
211              lookup_table = LookupTable()              lookup_table = LookupTable()
212              lookup_table._setTableValue()              lookup_table._setTableValue()
213          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
214              lookup_table = LookupTable()              lookup_table = LookupTable()
215              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
216    
217          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
218    
219          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
220              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
221              Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))                      self.__data_collector._getDataCollectorOutput())
222          elif(cell_to_point == False): # No conversion happens.              self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())
223              Cutter.__init__(self, data_collector._getOutput(),          elif(self.__cell_to_point == False): # No conversion happens.
224                  Plane._getPlane(self))              c2p = CellDataToPointData(
225                        self.__data_collector._getDataCollectorOutput())
226                self._setupCutter(self.__data_collector._getDataCollectorOutput(),
227                    self._getPlane())
228    
229          DataSetMapper.__init__(self, Cutter._getOutput(self),          self._setupDataSetMapper(self._getCutterOutput(),
230                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
231    
232          data_collector._paramForUpdatingMultipleSources(VizType.MAP,          self._setupActor3D(self._getDataSetMapper())
233                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))          self.__scene._addActor3D(self.__viewport, self._getActor3D())
234    
235        def _isModified(self):  
236            """
237            Return whether the MapOnPlaneCut or DataCollector has been modified.
238    
239            @rtype: Boolean
240            @return: True or False
241            """
242    
243            return self.__modified or self.__data_collector._isModified()
244    
245        def _render(self):
246            """
247            Render the surface map cut using a plane.
248            """
249    
250          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          if (self._isModified() == True):
251          scene._addActor3D(viewport, Actor3D._getActor3D(self))              if(self.__data_collector._isScalarSet() == True):
252                    self.__data_collector._setActiveScalar()
253                self._setScalarRange(self.__data_collector._getScalarRange())
254                self.__modified = False
255    
256    
257  ###############################################################################  ###############################################################################
# Line 257  class MapOnPlaneClip(DataSetMapper, Acto Line 296  class MapOnPlaneClip(DataSetMapper, Acto
296          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
297          """          """
298    
299          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__scene = scene
300          # As a result, when methods from Actor3D is invoked from the driver,          self.__data_collector = data_collector
301          # only the methods associated with the latest instance (which in this          self.__viewport = viewport
302          # case is the Actor3D for the map) can be executed. Actor3D          self.__lut = lut
303          # methods associated with Outline cannot be invoked from the driver.          self.__cell_to_point = cell_to_point
304          # They can only be called within here, which is why Outline must          self.__outline = outline
305          # be place before the map as there is unlikely to be any changes          
306          # made to the Outline's Actor3D.          # Keeps track whether MapOnPlaneClip has been modified.
307            self.__modified = True
308          # ----- Outline -----          Transform.__init__(self)    
309            Plane.__init__(self)
310          if(outline == True):          Clipper.__init__(self)
311              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
312              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
313            scene._addVisualizationModules(self)
314    
315            # ----- Outline -----
316    
317            # NOTE: Changes cannot be made to the Outline's properties from the
318            # driver.
319            if(self.__outline == True):
320                outline = Outline(self.__data_collector._getDataCollectorOutput())
321                mapper = DataSetMapper()
322                mapper._setupDataSetMapper(outline._getOutlineOutput())
323    
324              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
325                actor3D._setupActor3D(mapper._getDataSetMapper())
326              # Default outline color is black.              # Default outline color is black.
327              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
328    
329              # Default line width is 1.              # Default line width is 1.
330              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
331              scene._addActor3D(viewport, Actor3D._getActor3D(self))              self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
332    
333          # ----- Map on a clipped plane -----          # ----- Map on a clipped plane -----
334    
335          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
336          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
337          # will take place.          # will take place.
338          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
339              lookup_table = LookupTable()              lookup_table = LookupTable()
340              lookup_table._setTableValue()              lookup_table._setTableValue()
341          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
342              lookup_table = LookupTable()              lookup_table = LookupTable()
343              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
344    
345          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
346    
347          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
348              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(data_collector._getDataCollectorOutput())
349              Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self))              self._setupClipper(c2p._getCellToPointOutput(), self._getPlane())
350          elif(cell_to_point == False): # No conversion happens.          elif(self.__cell_to_point == False): # No conversion happens.
351              Clipper.__init__(self, data_collector._getOutput(),              self._setupClipper(data_collector._getDataCollectorOutput(),
352                      Plane._getPlane(self))                      self._getPlane())
353    
354          Clipper._setClipFunction(self)          self._setClipFunction()
355            self._setupDataSetMapper(self._getClipperOutput(),
         DataSetMapper.__init__(self, Clipper._getOutput(self),  
356                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
357    
358          data_collector._paramForUpdatingMultipleSources(VizType.MAP,          self._setupActor3D(self._getDataSetMapper())
359                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))          self.__scene._addActor3D(self.__viewport, self._getActor3D())
360    
361        def _isModified(self):  
362            """
363            Return whether the MapOnPlaneClip or DataCollector has been modified.
364    
365            @rtype: Boolean
366            @return: True or False
367            """
368    
369            return self.__modified or self.__data_collector._isModified()
370    
371          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))      def _render(self):
372          scene._addActor3D(viewport, Actor3D._getActor3D(self))          """
373            Render the surface map clip using a plane.
374            """
375    
376            if (self._isModified() == True):
377                if(self.__data_collector._isScalarSet() == True):
378                    self.__data_collector._setActiveScalar()
379                self._setScalarRange(self.__data_collector._getScalarRange())
380                self.__modified = False
381    
382    
383  #############################################################################  #############################################################################
# Line 355  class MapOnScalarClip(DataSetMapper, Act Line 420  class MapOnScalarClip(DataSetMapper, Act
420          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
421          """          """
422    
423          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__scene = scene
424          # As a result, when methods from Actor3D is invoked from the driver,          self.__data_collector = data_collector
425          # only the methods associated with the latest instance (which in this          self.__viewport = viewport
426          # case is the Actor3D for the map) can be executed. Actor3D          self.__lut = lut
427          # methods associated with Outline cannot be invoked from the driver.          self.__cell_to_point = cell_to_point
428          # They can only be called within here, which is why Outline must          self.__outline = outline
429          # be place before the map as there is unlikely to be any changes          
430          # made to the Outline's Actor3D.          # Keeps track whether MapOnScalarClip has been modified.
431            self.__modified = True
432            Clipper.__init__(self)
433            DataSetMapper.__init__(self)
434            Actor3D.__init__(self)
435            scene._addVisualizationModules(self)
436    
437          # ----- Outline -----          # ----- Outline -----
438    
439          if(outline == True):          # NOTE: Changes cannot be made to the Outline's properties from the
440              outline = Outline(data_collector._getOutput())          # driver.
441              DataSetMapper.__init__(self, outline._getOutput())          if(self.__outline == True):
442                outline = Outline(self.__data_collector._getDataCollectorOutput())
443          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              mapper = DataSetMapper()
444          # Default outline color is black.              mapper._setupDataSetMapper(outline._getOutlineOutput())
445          Actor3D.setColor(self, Color.BLACK)  
446                actor3D = Actor3D()
447          # Default line width is 1.              actor3D._setupActor3D(mapper._getDataSetMapper())
448          Actor3D._setLineWidth(self, 1)              # Default outline color is black.
449          scene._addActor3D(viewport, Actor3D._getActor3D(self))              actor3D.setColor(Color.BLACK)
450    
451                # Default line width is 1.
452                actor3D._setLineWidth(1)
453                self.__scene._addActor3D(self.__viewport, actor3D._getActor3D())
454    
455          # ----- Map clipped using a scalar value -----          # ----- Map clipped using a scalar value -----
456    
457          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
458          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
459          # will take place.          # will take place.
460          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
461              lookup_table = LookupTable()              lookup_table = LookupTable()
462              lookup_table._setTableValue()              lookup_table._setTableValue()
463          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
464              lookup_table = LookupTable()              lookup_table = LookupTable()
465              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
466    
467            if(self.__cell_to_point == True): # Converts cell data to point data.
468          if(cell_to_point == True): # Converts cell data to point data.              c2p = CellDataToPointData(
469              c2p = CellDataToPointData(data_collector._getOutput())                      self.__data_collector._getDataCollectorOutput())
470              # None is used because a plane is not required when a scalar              # None is used because a plane is not required when a scalar
471              # value is used to perform the clipping.              # value is used to perform the clipping.
472              Clipper.__init__(self, c2p._getOutput(), None)              self._setupClipper(c2p._getDataCollectorOutput(), None)
473          elif(cell_to_point == False): # No conversion happens.          elif(self.__cell_to_point == False): # No conversion happens.
474              Clipper.__init__(self, data_collector._getOutput(),None)              self._setupClipper(
475                        self.__data_collector._getDataCollectorOutput(),None)
476    
477          DataSetMapper.__init__(self, Clipper._getOutput(self),          self._setupDataSetMapper(self._getClipperOutput(),
478                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())    
479    
480          data_collector._paramForUpdatingMultipleSources(VizType.MAP,          self._setupActor3D(self._getDataSetMapper())
481                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))          self.__scene._addActor3D(self.__viewport, self._getActor3D())
482    
483        def _isModified(self):  
484            """
485            Return whether the MapOnScalarClip or DataCollector has been modified.
486    
487            @rtype: Boolean
488            @return: True or False
489            """
490    
491            return self.__modified or self.__data_collector._isModified()
492    
493        def _render(self):
494            """
495            Render the surface map clip using scalar data.
496            """
497    
498            if (self._isModified() == True):
499                if(self.__data_collector._isScalarSet() == True):
500                    self.__data_collector._setActiveScalar()
501                self._setScalarRange(self.__data_collector._getScalarRange())
502                self.__modified = False
503    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
504    
505    

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

  ViewVC Help
Powered by ViewVC 1.1.26