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

Contents of /trunk/pyvisi/py_src/streamline.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 7634 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 @var __author__: name of author
24 @var __copyright__: copyrights
25 @var __license__: licence agreement
26 @var __url__: url entry point on documentation
27 @var __version__: version
28 @var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 from mapper import DataSetMapper
35 from lookuptable import LookupTable
36 from actor import Actor3D
37 from constant import Viewport, Color, Lut, ColorMode
38 from streamlinemodule import StreamLineModule
39 from tube import Tube
40 from point import PointSource
41 from outline import Outline
42 from average import CellDataToPointData
43 from position import GlobalPosition
44 from esys.escript import getMPISizeWorld
45 if getMPISizeWorld()==1: import vtk
46
47 # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were
48 # inherited to allow access to their public methods from the driver.
49 class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube):
50 """
51 Class that shows the direction of particles of a vector field using
52 streamlines.The streamlines can either be colored or grey-scaled,
53 depending on the lookup table used. If the streamlines are colored,
54 there are two possible coloring modes: (1) using vector data or (2)
55 using scalar data.
56 """
57
58 # The SOUTH_WEST default viewport is used when there is only one viewport.
59 # This saves the user from specifying the viewport when there is only one.
60 # If no lut is specified, the color scheme will be used.
61 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
62 color_mode = ColorMode.VECTOR, lut = Lut.COLOR, cell_to_point = False,
63 outline = True):
64 """
65 Initialise the StreamLine.
66
67 @attention: The source can either be point or cell data. If the
68 source is cell data, a conversion to point data may or may not be
69 required, in order for the object to be rendered correctly.
70 If a conversion is needed, the 'cell_to_point' flag must be set to
71 'True', otherwise 'False' (which is the default). On occasions, an
72 inaccurate object may be rendered from cell data even after conversion.
73
74 @type scene: L{Scene <scene.Scene>} object
75 @param scene: Scene in which objects are to be rendered on
76 @type data_collector: L{DataCollector <datacollector.DataCollector>}
77 object
78 @param data_collector: Deal with source of data for visualisation
79 @type viewport: L{Viewport <constant.Viewport>} constant
80 @param viewport: Viewport in which the object is to be rendered on
81 @type color_mode: L{ColorMode <constant.ColorMode>} constant
82 @param color_mode: Type of color mode
83 @type lut : L{Lut <constant.Lut>} constant
84 @param lut: Lookup table color scheme
85 @type cell_to_point: Boolean
86 @param cell_to_point: Converts cell data to point data (by averaging)
87 @type outline: Boolean
88 @param outline: Places an outline around the domain surface
89 """
90
91 self.__data_collector = data_collector
92 self.__viewport = viewport
93 self.__color_mode = color_mode
94 self.__lut = lut
95 self.__cell_to_point = cell_to_point
96 self.__outline = outline
97
98 # Keeps track whether Streamline has been modified.
99 self.__modified = True
100 PointSource.__init__(self)
101 StreamLineModule.__init__(self)
102 Tube.__init__(self)
103 DataSetMapper.__init__(self)
104 Actor3D.__init__(self)
105 scene._addVisualizationModules(self)
106
107 # ----- Outline -----
108
109 # NOTE: Changes cannot be made to the Outline's properties from the
110 # driver.
111 if(self.__outline == True):
112 outline = Outline(self.__data_collector._getDataCollectorOutput())
113 mapper = DataSetMapper()
114 mapper._setupDataSetMapper(outline._getOutlineOutput())
115
116 actor3D = Actor3D()
117 actor3D._setupActor3D(mapper._getDataSetMapper())
118 # Default outline color is black.
119 actor3D.setColor(Color.BLACK)
120
121 # Default line width is 1.
122 actor3D._setLineWidth(1)
123 scene._addActor3D(self.__viewport, actor3D._getActor3D())
124
125 # ----- Streamline -----
126
127 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
128 # before DataSetMapper. If it is done after DataSetMapper, no effect
129 # will take place.
130 if(self.__lut == Lut.COLOR): # Colored lookup table.
131 lookup_table = LookupTable()
132 lookup_table._setTableValue()
133 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
134 lookup_table = LookupTable()
135 lookup_table._setLookupTableToGreyScale()
136
137 if(self.__cell_to_point == True): # Converts cell data to point data.
138 c2p = CellDataToPointData(
139 self.__data_collector._getDataCollectorOutput())
140 self._setupPointSource(c2p._getCellToPointOutput())
141 self._setupStreamLineModule(c2p._getCellToPointOutput(),
142 self._getPointSourceOutput())
143 elif(self.__cell_to_point == False): # No conversion happens.
144 self._setupPointSource(
145 self.__data_collector._getDataCollectorOutput())
146 self._setupStreamLineModule(
147 self.__data_collector._getDataCollectorOutput(),
148 self._getPointSourceOutput())
149
150 self._setupTube(self._getStreamLineModuleOutput())
151 self._setupDataSetMapper(self._getTubeOutput(),
152 lookup_table._getLookupTable())
153
154 self._setupActor3D(self._getDataSetMapper())
155 scene._addActor3D(self.__viewport, self._getActor3D())
156
157 def _isModified(self):
158 """
159 Return whether the StreamLine or DataCollector has been modified.
160
161 @rtype: Boolean
162 @return: True or False
163 """
164
165 return self.__modified or self.__data_collector._isModified()
166
167 def _render(self, scene):
168 """
169 Render the streamline.
170
171 @type scene: L{Scene <scene.Scene>} object
172 @param scene: Scene in which objects are to be rendered on
173 """
174
175 if (self._isModified() == True):
176 if(self._isPointSourceCenterSet() != True):
177 center = self.__data_collector._getCenter()
178 center = GlobalPosition(center[0], center[1], center[2])
179 self.setPointSourceCenter(center)
180
181 self._setPointSourceCenter()
182
183 if(self.__data_collector._isScalarSet() == True):
184 self.__data_collector._setActiveScalar()
185 if(self.__data_collector._isVectorSet() == True):
186 self.__data_collector._setActiveVector()
187
188 # Color streamline by vector.
189 if(self.__color_mode == ColorMode.VECTOR):
190 self._setScalarVisibilityOn()
191 self._setSpeedScalarsOn()
192
193 # self._isScalarRangeSet checks whether the scalar range has
194 # beenspecified by the user. If it has, then the scalar range
195 # read from the source will be ignored.
196 if(not(self._isScalarRangeSet())):
197 self._setScalarRange(\
198 self.__data_collector._getVectorRange())
199 # Color streamline by scalar.
200 elif(self.__color_mode == ColorMode.SCALAR):
201 self._setScalarVisibilityOn()
202 self._setSpeedScalarsOff()
203
204 # self._isScalarRangeSet checks whether the scalar range has
205 # beenspecified by the user. If it has, then the scalar range
206 # read from the source will be ignored.
207 if(not(self._isScalarRangeSet())):
208 self._setScalarRange(\
209 self.__data_collector._getScalarRange())
210
211 self.__modified = False
212
213

  ViewVC Help
Powered by ViewVC 1.1.26