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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1207 - (hide annotations)
Mon Jul 2 02:02:26 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 6915 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 ksteube 1147 """
2 jongui 1197 @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 ksteube 1147 """
9    
10 jongui 1197 __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 ksteube 1147 import vtk
22     from mapper import DataSetMapper
23     from lookuptable import LookupTable
24     from actor import Actor3D
25 jongui 1148 from constant import Viewport, Color, Lut, WarpMode, ColorMode
26 ksteube 1147 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 jongui 1199 'True', otherwise 'False' (which is the default). On occasions, an
55     inaccurate object may be rendered from cell data even after conversion.
56 ksteube 1147
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 jongui 1148 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 ksteube 1147
91     # ----- Outline -----
92    
93 jongui 1148 # 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 ksteube 1147
100 jongui 1148 actor3D = Actor3D()
101     actor3D._setupActor3D(mapper._getDataSetMapper())
102 ksteube 1147 # Default outline color is black.
103 jongui 1148 actor3D.setColor(Color.BLACK)
104 ksteube 1147
105     # Default line width is 1.
106 jongui 1148 actor3D._setLineWidth(1)
107 jongui 1158 scene._addActor3D(self.__viewport, actor3D._getActor3D())
108 ksteube 1147
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 jongui 1148 if(self.__lut == Lut.COLOR): # Colored lookup table.
115 ksteube 1147 lookup_table = LookupTable()
116     lookup_table._setTableValue()
117 jongui 1148 elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
118 ksteube 1147 lookup_table = LookupTable()
119     lookup_table._setLookupTableToGreyScale()
120    
121 jongui 1148 self._setupPlane(self._getTransform())
122 ksteube 1147
123 jongui 1207 # 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     # Length of the z-axis (max - min). Assumption is made that if the
127     # length of the z-axis is equal to zero, the the data set is 2D.
128     # Otherwise, the data set is 3D. However, there are exceptions to this
129     # rule as some 2D data sets may have a z-axis length of non-zero, but
130     # such exceptions are not taken into account here.
131     z_axis_length = bounds[5] - bounds[4]
132    
133 jongui 1148 if(self.__cell_to_point == True): # Converts cell data to point data.
134     c2p = CellDataToPointData(\
135     self.__data_collector._getDataCollectorOutput())
136 jongui 1207 if(z_axis_length != 0): # A cutter is used for 3D data.
137     self._setupCutter(c2p._getCellToPointOutput(), \
138     self._getPlane())
139     self._setupWarp(self._getCutterOutput())
140     elif(z_axis_length == 0): # A cutter is not used for 2D data.
141     self._setupWarp(c2p._getCellToPointOutput())
142 jongui 1148 elif(self.__cell_to_point == False): # No conversion happens.
143 jongui 1207 if(z_axis_length != 0): # A cutter is used for 3D data.
144     self._setupCutter(\
145     self.__data_collector._getDataCollectorOutput(), \
146     self._getPlane())
147     self._setupWarp(self._getCutterOutput())
148     elif(z_axis_length == 0): # A cutter is not used for 2D data.
149     self._setupWarp(
150     self.__data_collector._getDataCollectorOutput())
151 ksteube 1147
152 jongui 1148 self._setupDataSetMapper(self._getWarpOutput(),
153 ksteube 1147 lookup_table._getLookupTable())
154    
155 jongui 1148 self._setupActor3D(self._getDataSetMapper())
156 jongui 1158 scene._addActor3D(self.__viewport, self._getActor3D())
157 ksteube 1147
158 jongui 1148 def _isModified(self):
159     """
160     Return whether the Carpet or DataCollector has been modified.
161 ksteube 1147
162 jongui 1148 @rtype: Boolean
163     @return: True or False
164     """
165    
166     return self.__modified or self.__data_collector._isModified()
167    
168 jongui 1158 def _render(self, scene):
169 jongui 1148 """
170     Render the carpet.
171 jongui 1158
172     @type scene: L{Scene <scene.Scene>} object
173     @param scene: Scene in which objects are to be rendered on
174 jongui 1148 """
175    
176     if (self._isModified() == True):
177     if(self.__data_collector._isScalarSet() == True):
178     self.__data_collector._setActiveScalar()
179 jongui 1189
180     # self._isScalarRangeSet checks whether the scalar range has been
181     # specified by the user. If it has, then the scalar range
182     # read from the source will be ignored.
183     if(not(self._isScalarRangeSet())):
184     self._setScalarRange(self.__data_collector._getScalarRange())
185 jongui 1148 self.__modified = False
186    
187    

  ViewVC Help
Powered by ViewVC 1.1.26