/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 7505 byte(s)
Don't panic.
Updating copyright stamps

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 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-2010 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 source is cell data, a conversion to point data may or may not be required, in order for the object to be rendered correctly. If a conversion is needed, the 'cell_to_point' flag must be set to 'True', otherwise 'False' (which is the default). On occasions, an inaccurate object may be rendered from cell data even after conversion.
68
69 :type scene: `Scene` object
70 :param scene: Scene in which objects are to be rendered on
71 :type data_collector: `DataCollector` object
72 :param data_collector: Deal with source of data for visualisation
73 :type viewport: `Viewport` constant
74 :param viewport: Viewport in which the object is to be rendered on
75 :type color_mode: `ColorMode` constant
76 :param color_mode: Type of color mode
77 :type lut: `Lut` constant
78 :param lut: Lookup table color scheme
79 :type cell_to_point: Boolean
80 :param cell_to_point: Converts cell data to point data (by averaging)
81 :type outline: Boolean
82 :param outline: Places an outline around the domain surface
83 """
84
85 self.__data_collector = data_collector
86 self.__viewport = viewport
87 self.__color_mode = color_mode
88 self.__lut = lut
89 self.__cell_to_point = cell_to_point
90 self.__outline = outline
91
92 # Keeps track whether Streamline has been modified.
93 self.__modified = True
94 PointSource.__init__(self)
95 StreamLineModule.__init__(self)
96 Tube.__init__(self)
97 DataSetMapper.__init__(self)
98 Actor3D.__init__(self)
99 scene._addVisualizationModules(self)
100
101 # ----- Outline -----
102
103 # NOTE: Changes cannot be made to the Outline's properties from the
104 # driver.
105 if(self.__outline == True):
106 outline = Outline(self.__data_collector._getDataCollectorOutput())
107 mapper = DataSetMapper()
108 mapper._setupDataSetMapper(outline._getOutlineOutput())
109
110 actor3D = Actor3D()
111 actor3D._setupActor3D(mapper._getDataSetMapper())
112 # Default outline color is black.
113 actor3D.setColor(Color.BLACK)
114
115 # Default line width is 1.
116 actor3D._setLineWidth(1)
117 scene._addActor3D(self.__viewport, actor3D._getActor3D())
118
119 # ----- Streamline -----
120
121 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
122 # before DataSetMapper. If it is done after DataSetMapper, no effect
123 # will take place.
124 if(self.__lut == Lut.COLOR): # Colored lookup table.
125 lookup_table = LookupTable()
126 lookup_table._setTableValue()
127 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
128 lookup_table = LookupTable()
129 lookup_table._setLookupTableToGreyScale()
130
131 if(self.__cell_to_point == True): # Converts cell data to point data.
132 c2p = CellDataToPointData(
133 self.__data_collector._getDataCollectorOutput())
134 self._setupPointSource(c2p._getCellToPointOutput())
135 self._setupStreamLineModule(c2p._getCellToPointOutput(),
136 self._getPointSourceOutput())
137 elif(self.__cell_to_point == False): # No conversion happens.
138 self._setupPointSource(
139 self.__data_collector._getDataCollectorOutput())
140 self._setupStreamLineModule(
141 self.__data_collector._getDataCollectorOutput(),
142 self._getPointSourceOutput())
143
144 self._setupTube(self._getStreamLineModuleOutput())
145 self._setupDataSetMapper(self._getTubeOutput(),
146 lookup_table._getLookupTable())
147
148 self._setupActor3D(self._getDataSetMapper())
149 scene._addActor3D(self.__viewport, self._getActor3D())
150
151 def _isModified(self):
152 """
153 Return whether the StreamLine or DataCollector has been modified.
154
155 :rtype: Boolean
156 :return: True or False
157 """
158
159 return self.__modified or self.__data_collector._isModified()
160
161 def _render(self, scene):
162 """
163 Render the streamline.
164
165 :type scene: `Scene` object
166 :param scene: Scene in which objects are to be rendered on
167 """
168
169 if (self._isModified() == True):
170 if(self._isPointSourceCenterSet() != True):
171 center = self.__data_collector._getCenter()
172 center = GlobalPosition(center[0], center[1], center[2])
173 self.setPointSourceCenter(center)
174
175 self._setPointSourceCenter()
176
177 if(self.__data_collector._isScalarSet() == True):
178 self.__data_collector._setActiveScalar()
179 if(self.__data_collector._isVectorSet() == True):
180 self.__data_collector._setActiveVector()
181
182 # Color streamline by vector.
183 if(self.__color_mode == ColorMode.VECTOR):
184 self._setScalarVisibilityOn()
185 self._setSpeedScalarsOn()
186
187 # self._isScalarRangeSet checks whether the scalar range has
188 # beenspecified by the user. If it has, then the scalar range
189 # read from the source will be ignored.
190 if(not(self._isScalarRangeSet())):
191 self._setScalarRange(\
192 self.__data_collector._getVectorRange())
193 # Color streamline by scalar.
194 elif(self.__color_mode == ColorMode.SCALAR):
195 self._setScalarVisibilityOn()
196 self._setSpeedScalarsOff()
197
198 # self._isScalarRangeSet checks whether the scalar range has
199 # beenspecified by the user. If it has, then the scalar range
200 # read from the source will be ignored.
201 if(not(self._isScalarRangeSet())):
202 self._setScalarRange(\
203 self.__data_collector._getScalarRange())
204
205 self.__modified = False
206
207

  ViewVC Help
Powered by ViewVC 1.1.26