/[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 1197 by jongui, Mon Jun 18 02:08:34 2007 UTC
# Line 1  Line 1 
1  """  """
2  @author: John NGUI  @var __author__: name of author
3    @var __copyright__: copyrights
4    @var __license__: licence agreement
5    @var __url__: url entry point on documentation
6    @var __version__: version
7    @var __date__: date of the version
8  """  """
9    
10    __author__="John Ngui, john.ngui@uq.edu.au"
11    __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
12                        http://www.access.edu.au
13                    Primary Business: Queensland, Australia"""
14    __license__="""Licensed under the Open Software License version 3.0
15                 http://www.opensource.org/licenses/osl-3.0.php"""
16    __url__="http://www.iservo.edu.au/esys"
17    __version__="$Revision$"
18    __date__="$Date$"
19    
20    
21  import vtk  import vtk
22  from mapper import DataSetMapper  from mapper import DataSetMapper
23  from lookuptable import LookupTable  from lookuptable import LookupTable
24  from actor import Actor3D  from actor import Actor3D
25  from constant import Viewport, Color, Lut, ColorMode, VizType  from constant import Viewport, Color, Lut, ColorMode
26  from streamlinemodule import  StreamLineModule  from streamlinemodule import  StreamLineModule
27  from tube import Tube  from tube import Tube
28  from point import PointSource  from point import PointSource
29  from outline import Outline  from outline import Outline
30  from average import CellDataToPointData  from average import CellDataToPointData
31    from position import GlobalPosition
32    
33  # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube  were  # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube  were
34  # 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 73  class StreamLine(DataSetMapper, Actor3D,
73          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
74          """          """
75    
76          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
77          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
78          # only the methods associated with the latest instance (which in this          self.__color_mode = color_mode
79          # case is the Actor3D for the Tube) can be executed. Actor3D          self.__lut = lut
80          # methods associated with Outline cannot be invoked from the driver.          self.__cell_to_point = cell_to_point
81          # They can only be called within here, which is why Outline must be          self.__outline = outline
82          # place before Tube as there is unlikely to be any changes  
83          # made to the Outline's Actor3D.          # Keeps track whether Streamline has been modified.
84            self.__modified = True
85          # ----- Outline -----          PointSource.__init__(self)
86            StreamLineModule.__init__(self)
87          if(outline == True):          Tube.__init__(self)
88              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
89              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
90            scene._addVisualizationModules(self)
91    
92            # ----- Outline -----
93    
94            # NOTE: Changes cannot be made to the Outline's properties from the
95            # driver.
96            if(self.__outline == True):
97                outline = Outline(self.__data_collector._getDataCollectorOutput())
98                mapper = DataSetMapper()
99                mapper._setupDataSetMapper(outline._getOutlineOutput())
100    
101              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
102                actor3D._setupActor3D(mapper._getDataSetMapper())
103              # Default outline color is black.              # Default outline color is black.
104              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
105    
106              # Default line width is 1.              # Default line width is 1.
107              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
108              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
109    
110          # ----- Streamline -----          # ----- Streamline -----
111    
112          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
113          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
114          # will take place.          # will take place.
115          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
116              lookup_table = LookupTable()              lookup_table = LookupTable()
117              lookup_table._setTableValue()              lookup_table._setTableValue()
118          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
119              lookup_table = LookupTable()              lookup_table = LookupTable()
120              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
121    
122          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
123              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
124              PointSource.__init__(self, c2p._getOutput())                      self.__data_collector._getDataCollectorOutput())
125              StreamLineModule.__init__(self, c2p._getOutput(),              self._setupPointSource(c2p._getCellToPointOutput())
126                      PointSource._getOutput(self))              self._setupStreamLineModule(c2p._getCellToPointOutput(),
127          elif(cell_to_point == False): # No conversion happens.                      self._getPointSourceOutput())
128              PointSource.__init__(self, data_collector._getOutput())          elif(self.__cell_to_point == False): # No conversion happens.
129              StreamLineModule.__init__(self, data_collector._getOutput(),              self._setupPointSource(
130                      PointSource._getOutput(self))                      self.__data_collector._getDataCollectorOutput())
131                self._setupStreamLineModule(
132                        self.__data_collector._getDataCollectorOutput(),
133                        self._getPointSourceOutput())
134    
135          Tube.__init__(self, StreamLineModule._getOutput(self))          self._setupTube(self._getStreamLineModuleOutput())
136          DataSetMapper.__init__(self, Tube._getOutput(self),          self._setupDataSetMapper(self._getTubeOutput(),
137                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
138    
139          if(color_mode == ColorMode.VECTOR): # Color velocity by vector.          self._setupActor3D(self._getDataSetMapper())
140              DataSetMapper._setScalarVisibilityOn(self)          scene._addActor3D(self.__viewport, self._getActor3D())
141              StreamLineModule._setSpeedScalarsOn(self)  
142              DataSetMapper._setScalarRange(self,      def _isModified(self):  
143                      data_collector._getVectorRange())          """
144            Return whether the StreamLine or DataCollector has been modified.
145              data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE,  
146                      ColorMode.VECTOR, DataSetMapper._getDataSetMapper(self))          @rtype: Boolean
147            @return: True or False
148          elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.          """
149              DataSetMapper._setScalarVisibilityOn(self)  
150              StreamLineModule._setSpeedScalarsOff(self)          return self.__modified or self.__data_collector._isModified()
151              DataSetMapper._setScalarRange(self,  
152                      data_collector._getScalarRange())      def _render(self, scene):
153                        """
154              data_collector._paramForUpdatingMultipleSources(VizType.STREAMLINE,          Render the streamline.
155                      ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))  
156            @type scene: L{Scene <scene.Scene>} object
157            @param scene: Scene in which objects are to be rendered on
158            """
159    
160            if (self._isModified() == True):
161                if(self._isPointSourceCenterSet() != True):
162                    center = self.__data_collector._getCenter()
163                    center = GlobalPosition(center[0], center[1], center[2])
164                    self.setPointSourceCenter(center)
165    
166                self._setPointSourceCenter()    
167    
168                if(self.__data_collector._isScalarSet() == True):
169                    self.__data_collector._setActiveScalar()
170                if(self.__data_collector._isVectorSet() == True):
171                    self.__data_collector._setActiveVector()
172    
173                # Color streamline by vector.
174                if(self.__color_mode == ColorMode.VECTOR):              
175                    self._setScalarVisibilityOn()
176                    self._setSpeedScalarsOn()
177    
178                    # self._isScalarRangeSet checks whether the scalar range has
179                    # beenspecified by the user. If it has, then the scalar range
180                    # read from the source will be ignored.
181                    if(not(self._isScalarRangeSet())):
182                        self._setScalarRange(\
183                                self.__data_collector._getVectorRange())
184                # Color streamline by scalar.
185                elif(self.__color_mode == ColorMode.SCALAR):                
186                    self._setScalarVisibilityOn()
187                    self._setSpeedScalarsOff()
188    
189                    # self._isScalarRangeSet checks whether the scalar range has
190                    # beenspecified by the user. If it has, then the scalar range
191                    # read from the source will be ignored.
192                    if(not(self._isScalarRangeSet())):
193                        self._setScalarRange(\
194                                self.__data_collector._getScalarRange())
195    
196                self.__modified = False
197    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
198    

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

  ViewVC Help
Powered by ViewVC 1.1.26