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

Diff of /trunk/pyvisi/py_src/streamline.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 6  import vtk Line 6  import vtk
6  from mapper import DataSetMapper  from mapper import DataSetMapper
7  from lookuptable import LookupTable  from lookuptable import LookupTable
8  from actor import Actor3D  from actor import Actor3D
9  from constant import Viewport, Color, Lut, ColorMode, VizType  from constant import Viewport, Color, Lut, ColorMode
10  from streamlinemodule import  StreamLineModule  from streamlinemodule import  StreamLineModule
11  from tube import Tube  from tube import Tube
12  from point import PointSource  from point import PointSource
13  from outline import Outline  from outline import Outline
14  from average import CellDataToPointData  from average import CellDataToPointData
15    from position import GlobalPosition
16    
17  # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube  were  # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube  were
18  # inherited to allow access to their public methods from the driver.  # inherited to allow access to their public methods from the driver.
# Line 56  class StreamLine(DataSetMapper, Actor3D, Line 57  class StreamLine(DataSetMapper, Actor3D,
57          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
58          """          """
59    
60          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
61          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
62          # only the methods associated with the latest instance (which in this          self.__color_mode = color_mode
63          # case is the Actor3D for the Tube) can be executed. Actor3D          self.__lut = lut
64          # methods associated with Outline cannot be invoked from the driver.          self.__cell_to_point = cell_to_point
65          # They can only be called within here, which is why Outline must be          self.__outline = outline
66          # place before Tube as there is unlikely to be any changes  
67          # made to the Outline's Actor3D.          # Keeps track whether Streamline has been modified.
68            self.__modified = True
69          # ----- Outline -----          PointSource.__init__(self)
70            StreamLineModule.__init__(self)
71          if(outline == True):          Tube.__init__(self)
72              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
73              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
74            scene._addVisualizationModules(self)
75    
76            # ----- Outline -----
77    
78            # NOTE: Changes cannot be made to the Outline's properties from the
79            # driver.
80            if(self.__outline == True):
81                outline = Outline(self.__data_collector._getDataCollectorOutput())
82                mapper = DataSetMapper()
83                mapper._setupDataSetMapper(outline._getOutlineOutput())
84    
85              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
86                actor3D._setupActor3D(mapper._getDataSetMapper())
87              # Default outline color is black.              # Default outline color is black.
88              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
89    
90              # Default line width is 1.              # Default line width is 1.
91              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
92              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
93    
94          # ----- Streamline -----          # ----- Streamline -----
95    
96          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
97          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
98          # will take place.          # will take place.
99          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
100              lookup_table = LookupTable()              lookup_table = LookupTable()
101              lookup_table._setTableValue()              lookup_table._setTableValue()
102          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
103              lookup_table = LookupTable()              lookup_table = LookupTable()
104              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
105    
106          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
107              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
108              PointSource.__init__(self, c2p._getOutput())                      self.__data_collector._getDataCollectorOutput())
109              StreamLineModule.__init__(self, c2p._getOutput(),              self._setupPointSource(c2p._getCellToPointOutput())
110                      PointSource._getOutput(self))              self._setupStreamLineModule(c2p._getCellToPointOutput(),
111          elif(cell_to_point == False): # No conversion happens.                      self._getPointSourceOutput())
112              PointSource.__init__(self, data_collector._getOutput())          elif(self.__cell_to_point == False): # No conversion happens.
113              StreamLineModule.__init__(self, data_collector._getOutput(),              self._setupPointSource(
114                      PointSource._getOutput(self))                      self.__data_collector._getDataCollectorOutput())
115                self._setupStreamLineModule(
116                        self.__data_collector._getDataCollectorOutput(),
117                        self._getPointSourceOutput())
118    
119          Tube.__init__(self, StreamLineModule._getOutput(self))          self._setupTube(self._getStreamLineModuleOutput())
120          DataSetMapper.__init__(self, Tube._getOutput(self),          self._setupDataSetMapper(self._getTubeOutput(),
121                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
122    
123          if(color_mode == ColorMode.VECTOR): # Color velocity by vector.          self._setupActor3D(self._getDataSetMapper())
124              DataSetMapper._setScalarVisibilityOn(self)          scene._addActor3D(self.__viewport, self._getActor3D())
125              StreamLineModule._setSpeedScalarsOn(self)  
126              DataSetMapper._setScalarRange(self,      def _isModified(self):  
127                      data_collector._getVectorRange())          """
128            Return whether the StreamLine or DataCollector has been modified.
129              data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE,  
130                      ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self))          @rtype: Boolean
131            @return: True or False
132          elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.          """
133              DataSetMapper._setScalarVisibilityOn(self)  
134              StreamLineModule._setSpeedScalarsOff(self)          return self.__modified or self.__data_collector._isModified()
135              DataSetMapper._setScalarRange(self,  
136                      data_collector._getScalarRange())      def _render(self, scene):
137                        """
138              data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE,          Render the streamline.
139                      ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))  
140            @type scene: L{Scene <scene.Scene>} object
141            @param scene: Scene in which objects are to be rendered on
142            """
143    
144            if (self._isModified() == True):
145                if(self._isPointSourceCenterSet() != True):
146                    center = self.__data_collector._getCenter()
147                    center = GlobalPosition(center[0], center[1], center[2])
148                    self.setPointSourceCenter(center)
149    
150                self._setPointSourceCenter()    
151    
152                if(self.__data_collector._isScalarSet() == True):
153                    self.__data_collector._setActiveScalar()
154                if(self.__data_collector._isVectorSet() == True):
155                    self.__data_collector._setActiveVector()
156    
157                # Color streamline by vector.
158                if(self.__color_mode == ColorMode.VECTOR):              
159                    self._setScalarVisibilityOn()
160                    self._setSpeedScalarsOn()
161    
162                    # self._isScalarRangeSet checks whether the scalar range has
163                    # beenspecified by the user. If it has, then the scalar range
164                    # read from the source will be ignored.
165                    if(not(self._isScalarRangeSet())):
166                        self._setScalarRange(\
167                                self.__data_collector._getVectorRange())
168                # Color streamline by scalar.
169                elif(self.__color_mode == ColorMode.SCALAR):                
170                    self._setScalarVisibilityOn()
171                    self._setSpeedScalarsOff()
172    
173                    # self._isScalarRangeSet checks whether the scalar range has
174                    # beenspecified by the user. If it has, then the scalar range
175                    # read from the source will be ignored.
176                    if(not(self._isScalarRangeSet())):
177                        self._setScalarRange(\
178                                self.__data_collector._getScalarRange())
179    
180                self.__modified = False
181    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
182    

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

  ViewVC Help
Powered by ViewVC 1.1.26