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

  ViewVC Help
Powered by ViewVC 1.1.26