/[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 1199 - (show annotations)
Wed Jun 20 05:01:30 2007 UTC (12 years ago) by jongui
File MIME type: text/x-python
File size: 7179 byte(s)
- Updated the epydocs and guide.
Deleted redundant files and methods.
Tidied up the codes.
1 """
2 @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
22 from mapper import DataSetMapper
23 from lookuptable import LookupTable
24 from actor import Actor3D
25 from constant import Viewport, Color, Lut, ColorMode
26 from streamlinemodule import StreamLineModule
27 from tube import Tube
28 from point import PointSource
29 from outline import Outline
30 from average import CellDataToPointData
31 from position import GlobalPosition
32
33 # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were
34 # inherited to allow access to their public methods from the driver.
35 class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube):
36 """
37 Class that shows the direction of particles of a vector field using
38 streamlines.The streamlines can either be colored or grey-scaled,
39 depending on the lookup table used. If the streamlines are colored,
40 there are two possible coloring modes: (1) using vector data or (2)
41 using scalar data.
42 """
43
44 # The SOUTH_WEST default viewport is used when there is only one viewport.
45 # This saves the user from specifying the viewport when there is only one.
46 # If no lut is specified, the color scheme will be used.
47 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
48 color_mode = ColorMode.VECTOR, lut = Lut.COLOR, cell_to_point = False,
49 outline = True):
50 """
51 Initialise the StreamLine.
52
53 @attention: The source can either be point or cell data. If the
54 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.
56 If a conversion is needed, the 'cell_to_point' flag must be set to
57 '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
61 @param scene: Scene in which objects are to be rendered on
62 @type data_collector: L{DataCollector <datacollector.DataCollector>}
63 object
64 @param data_collector: Deal with source of data for visualisation
65 @type viewport: L{Viewport <constant.Viewport>} constant
66 @param viewport: Viewport in which the object is to be rendered on
67 @type color_mode: L{ColorMode <constant.ColorMode>} constant
68 @param color_mode: Type of color mode
69 @type lut : L{Lut <constant.Lut>} constant
70 @param lut: Lookup table color scheme
71 @type cell_to_point: Boolean
72 @param cell_to_point: Converts cell data to point data (by averaging)
73 @type outline: Boolean
74 @param outline: Places an outline around the domain surface
75 """
76
77 self.__data_collector = data_collector
78 self.__viewport = viewport
79 self.__color_mode = color_mode
80 self.__lut = lut
81 self.__cell_to_point = cell_to_point
82 self.__outline = outline
83
84 # Keeps track whether Streamline has been modified.
85 self.__modified = True
86 PointSource.__init__(self)
87 StreamLineModule.__init__(self)
88 Tube.__init__(self)
89 DataSetMapper.__init__(self)
90 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 = Actor3D()
103 actor3D._setupActor3D(mapper._getDataSetMapper())
104 # Default outline color is black.
105 actor3D.setColor(Color.BLACK)
106
107 # Default line width is 1.
108 actor3D._setLineWidth(1)
109 scene._addActor3D(self.__viewport, actor3D._getActor3D())
110
111 # ----- Streamline -----
112
113 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
114 # before DataSetMapper. If it is done after DataSetMapper, no effect
115 # will take place.
116 if(self.__lut == Lut.COLOR): # Colored lookup table.
117 lookup_table = LookupTable()
118 lookup_table._setTableValue()
119 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
120 lookup_table = LookupTable()
121 lookup_table._setLookupTableToGreyScale()
122
123 if(self.__cell_to_point == True): # Converts cell data to point data.
124 c2p = CellDataToPointData(
125 self.__data_collector._getDataCollectorOutput())
126 self._setupPointSource(c2p._getCellToPointOutput())
127 self._setupStreamLineModule(c2p._getCellToPointOutput(),
128 self._getPointSourceOutput())
129 elif(self.__cell_to_point == False): # No conversion happens.
130 self._setupPointSource(
131 self.__data_collector._getDataCollectorOutput())
132 self._setupStreamLineModule(
133 self.__data_collector._getDataCollectorOutput(),
134 self._getPointSourceOutput())
135
136 self._setupTube(self._getStreamLineModuleOutput())
137 self._setupDataSetMapper(self._getTubeOutput(),
138 lookup_table._getLookupTable())
139
140 self._setupActor3D(self._getDataSetMapper())
141 scene._addActor3D(self.__viewport, self._getActor3D())
142
143 def _isModified(self):
144 """
145 Return whether the StreamLine or DataCollector has been modified.
146
147 @rtype: Boolean
148 @return: True or False
149 """
150
151 return self.__modified or self.__data_collector._isModified()
152
153 def _render(self, scene):
154 """
155 Render the streamline.
156
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
199

  ViewVC Help
Powered by ViewVC 1.1.26