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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 3 months ago) by gross
File MIME type: text/x-python
File size: 8312 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 from mapper import DataSetMapper
34 from lookuptable import LookupTable
35 from actor import Actor3D
36 from constant import Viewport, Color, Lut, WarpMode, ColorMode
37 from warp import Warp
38 from outline import Outline
39 from transform import Transform
40 from plane import Plane
41 from cutter import Cutter
42 from average import CellDataToPointData
43
44 # NOTE: DataSetMapper, Actor3D, Warp, Transform, Plane and Cutter were
45 # inherited to allow access to their public methods from the driver.
46 class Carpet(DataSetMapper, Actor3D, Warp, Transform, Plane, Cutter):
47 """
48 Class that shows a scalar field on a plane deformated along the normal.
49 """
50
51 # The SOUTH_WEST default viewport is used when there is only one viewport.
52 # This saves the user from specifying the viewport when there is only one.
53 # If no warp_mode is specified, the data will be deformated using scalar
54 # data. If no lut is specified, the color scheme will be used.
55 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
56 warp_mode = WarpMode.SCALAR, lut = Lut.COLOR,
57 cell_to_point = False, outline = True):
58 """
59 Initialise the Carpet.
60
61 @attention: The source can either be point or cell data. If the
62 source is cell data, a conversion to point data may or may not be
63 required, in order for the object to be rendered correctly.
64 If a conversion is needed, the 'cell_to_point' flag must be set to
65 'True', otherwise 'False' (which is the default). On occasions, an
66 inaccurate object may be rendered from cell data even after conversion.
67
68 @attention: When 3D data is used, a cut will be performed on the
69 scalar field using a
70 plane before deformation occurs on the plane. However, if 2D data is
71 used a cut will NOT be performed and deformation will instead occur
72 immediately on the scalar field. Pyvisi distinguishes 2D from 3D data
73 by retrieving the
74 length of the z-axis. A 2D data is assumed to have a z-axis length of
75 zero
76 while a 3D data is assumed to have a z-axis length of non-zero.
77 There are
78 exceptions to these rules where some 2D data may have a non-zero
79 z-axis length. However, such exceptions are not taken into account
80 at this stage.
81
82 @type scene: L{Scene <scene.Scene>} object
83 @param scene: Scene in which objects are to be rendered on
84 @type data_collector: L{DataCollector <datacollector.DataCollector>}
85 object
86 @param data_collector: Deal with source of data for visualisation
87 @type viewport: L{Viewport <constant.Viewport>} constant
88 @param viewport: Viewport in which objects are to be rendered on
89 @param warp_mode: L{WarpMode <constant.WarpMode>} constant
90 @type warp_mode: Mode in which to deform the scalar field
91 @type lut : L{Lut <constant.Lut>} constant
92 @param lut: Lookup table color scheme
93 @type cell_to_point: Boolean
94 @param cell_to_point: Converts cell data to point data (by averaging)
95 @type outline: Boolean
96 @param outline: Places an outline around the domain surface
97 """
98
99 self.__data_collector = data_collector
100 self.__viewport = viewport
101 self.__warp_mode = warp_mode
102 self.__lut = lut
103 self.__cell_to_point = cell_to_point
104 self.__outline = outline
105
106 # Keeps track whether Carpet has been modified.
107 self.__modified = True
108 Transform.__init__(self)
109 Plane.__init__(self)
110 Cutter.__init__(self)
111 Warp.__init__(self, self.__warp_mode)
112 DataSetMapper.__init__(self)
113 Actor3D.__init__(self)
114 scene._addVisualizationModules(self)
115
116 # ----- Outline -----
117
118 # NOTE: Changes cannot be made to the Outline's properties from the
119 # driver.
120 if(self.__outline == True):
121 outline = Outline(self.__data_collector._getDataCollectorOutput())
122 mapper = DataSetMapper()
123 mapper._setupDataSetMapper(outline._getOutlineOutput())
124
125 actor3D = Actor3D()
126 actor3D._setupActor3D(mapper._getDataSetMapper())
127 # Default outline color is black.
128 actor3D.setColor(Color.BLACK)
129
130 # Default line width is 1.
131 actor3D._setLineWidth(1)
132 scene._addActor3D(self.__viewport, actor3D._getActor3D())
133
134 # ----- Carpet -----
135
136 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
137 # before DataSetMapper. If it is done after DataSetMapper, no effect
138 # will take place.
139 if(self.__lut == Lut.COLOR): # Colored lookup table.
140 self.__lookup_table = LookupTable()
141 self.__lookup_table._setTableValue()
142 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
143 self.__lookup_table = LookupTable()
144 self.__lookup_table._setLookupTableToGreyScale()
145
146 self._setupPlane(self._getTransform())
147
148 def _isModified(self):
149 """
150 Return whether the Carpet or DataCollector has been modified.
151
152 @rtype: Boolean
153 @return: True or False
154 """
155
156 return self.__modified or self.__data_collector._isModified()
157
158 def _render(self, scene):
159 """
160 Render the carpet.
161
162 @type scene: L{Scene <scene.Scene>} object
163 @param scene: Scene in which objects are to be rendered on
164 """
165
166 # This entire 'if' section had to be moved from the __init__ method
167 # due to the use of 'GetBounds()'. A source (i.e. xml file) must be
168 # supplied before 'GetBounds()' is able to return the correct value
169 # when executed. This is to accommodate for lazy evaluation.
170 if(self.__modified):
171 # Get the bounds of the object in the form of
172 # (xmin, xmax, ymin, ymax, zmin, zmax).
173 bounds = \
174 self.__data_collector._getDataCollectorOutput().GetBounds()
175 # Length of the z-axis (max - min). Assumption is made that if the
176 # length of the z-axis is equal to zero, the the data set is 2D.
177 # Otherwise, the data set is 3D. However, there are exceptions
178 # to this rule as some 2D data sets may have a z-axis length
179 # of non-zero, but such exceptions are not taken into account here.
180 z_axis_length = bounds[5] - bounds[4]
181
182 if(self.__cell_to_point == True): #Convert cell data to point data.
183 c2p = CellDataToPointData(\
184 self.__data_collector._getDataCollectorOutput())
185 if(z_axis_length != 0): # A cutter is used for 3D data.
186 self._setupCutter(c2p._getCellToPointOutput(), \
187 self._getPlane())
188 self._setupWarp(self._getCutterOutput())
189 elif(z_axis_length == 0): # A cutter is not used for 2D data.
190 self._setupWarp(c2p._getCellToPointOutput())
191
192 elif(self.__cell_to_point == False): # No conversion happens.
193 if(z_axis_length != 0): # A cutter is used for 3D data.
194 self._setupCutter(\
195 self.__data_collector._getDataCollectorOutput(), \
196 self._getPlane())
197 self._setupWarp(self._getCutterOutput())
198 elif(z_axis_length == 0): # A cutter is not used for 2D data.
199 self._setupWarp(
200 self.__data_collector._getDataCollectorOutput())
201
202 self._setupDataSetMapper(self._getWarpOutput(),
203 self.__lookup_table._getLookupTable())
204
205 self._setupActor3D(self._getDataSetMapper())
206 scene._addActor3D(self.__viewport, self._getActor3D())
207
208
209 if (self._isModified() == True):
210 if(self.__data_collector._isScalarSet() == True):
211 self.__data_collector._setActiveScalar()
212
213 # self._isScalarRangeSet checks whether the scalar range has been
214 # specified by the user. If it has, then the scalar range
215 # read from the source will be ignored.
216 if(not(self._isScalarRangeSet())):
217 self._setScalarRange(self.__data_collector._getScalarRange())
218 self.__modified = False
219
220
221

  ViewVC Help
Powered by ViewVC 1.1.26