/[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 1208 - (show annotations)
Mon Jul 2 04:46:10 2007 UTC (13 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 8803 byte(s)
Made some changes to the Carpet module. When 3D data is used, a cut will be performed using a plane before deformation occurs on the plane. However, if 2D data is used a cut will NOT be performed and deformation will instead occur immediately. 

Pyvisi distinguishes 2D from 3D data by retrieving the length of the z-axis. A 2D data will have a z-axis length of zero while a 3D data will have a z-axis length of non-zero. There are exceptions to these rules where some 2D data may have a non-zero z-axis length. However, such exceptions are not taken into account at this stage.

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

  ViewVC Help
Powered by ViewVC 1.1.26