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

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

  ViewVC Help
Powered by ViewVC 1.1.26