/[escript]/tags/trunk_2172_checkpoint/pyvisi/py_src/streamline.py
ViewVC logotype

Contents of /tags/trunk_2172_checkpoint/pyvisi/py_src/streamline.py

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26