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