1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from mapper import DataSetMapper |
7 |
from actor import Actor3D |
8 |
from lookuptable import LookupTable |
9 |
from outline import Outline |
10 |
from constant import Viewport, Color, Lut, VizType, ColorMode |
11 |
from contourmodule import ContourModule |
12 |
from average import CellDataToPointData |
13 |
|
14 |
# NOTE: DataSetMapper, Actor3D and ContourModule were inherited to allow |
15 |
# access to their public methods from the driver. |
16 |
class Contour(DataSetMapper, Actor3D, ContourModule): |
17 |
""" |
18 |
Class that shows a scalar field by contour surfaces. The contour surfaces |
19 |
can either be colored or grey-scaled, depending on the lookup table used. |
20 |
This class can also be used to generate iso surfaces. |
21 |
""" |
22 |
|
23 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
24 |
# This saves the user from specifying the viewport when there is only one. |
25 |
# If no lut is specified, the color scheme will be used. |
26 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
27 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
28 |
""" |
29 |
Initialise the Contour. |
30 |
|
31 |
@attention: The source can either be point or cell data. If the |
32 |
source is cell data, a conversion to point data may or may not be |
33 |
required, in order for the object to be rendered correctly. |
34 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
35 |
'True', otherwise 'False' (which is the default). |
36 |
|
37 |
@type scene: L{Scene <scene.Scene>} object |
38 |
@param scene: Scene in which objects are to be rendered on |
39 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
40 |
object |
41 |
@param data_collector: Deal with source of data for visualisation |
42 |
@type viewport: L{Viewport <constant.Viewport>} constant |
43 |
@param viewport: Viewport in which objects are to be rendered on |
44 |
@type lut : L{Lut <constant.Lut>} constant |
45 |
@param lut: Lookup table color scheme |
46 |
@type cell_to_point: Boolean |
47 |
@param cell_to_point: Converts cell data to point data (by averaging) |
48 |
@type outline: Boolean |
49 |
@param outline: Places an outline around the domain surface |
50 |
""" |
51 |
|
52 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
53 |
# As a result, when methods from Actor3D is invoked from the driver, |
54 |
# only the methods associated with the latest instance (which in this |
55 |
# case is the Actor3D for the contour) can be executed. Actor3D |
56 |
# methods associated with Outline cannot be invoked from the driver. |
57 |
# They can only be called within here, which is why Outline must |
58 |
# be place before the contour as there is unlikely to be any changes |
59 |
# made to the Outline's Actor3D. |
60 |
|
61 |
# ----- Outline ----- |
62 |
|
63 |
if(outline == True): |
64 |
outline = Outline(data_collector._getOutput()) |
65 |
DataSetMapper.__init__(self, outline._getOutput()) |
66 |
|
67 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
68 |
# Default outline color is black. |
69 |
Actor3D.setColor(self, Color.BLACK) |
70 |
|
71 |
# Default line width is 1. |
72 |
Actor3D._setLineWidth(self, 1) |
73 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
74 |
|
75 |
# ----- Contour ----- |
76 |
|
77 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
78 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
79 |
# will take place. |
80 |
if(lut == Lut.COLOR): # Colored lookup table. |
81 |
lookup_table = LookupTable() |
82 |
lookup_table._setTableValue() |
83 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
84 |
lookup_table = LookupTable() |
85 |
lookup_table._setLookupTableToGreyScale() |
86 |
|
87 |
if(cell_to_point == True): # Converts cell data to point data. |
88 |
c2p = CellDataToPointData(data_collector._getOutput()) |
89 |
ContourModule.__init__(self, c2p._getOutput()) |
90 |
elif(cell_to_point == False): # No conversion happens. |
91 |
ContourModule.__init__(self, data_collector._getOutput()) |
92 |
|
93 |
# By default 10 contours are generated and the scalar range is based |
94 |
# on the scalar data range. |
95 |
ContourModule.generateContours(self, 10, |
96 |
data_collector._getScalarRange()[0], |
97 |
data_collector._getScalarRange()[1]) |
98 |
|
99 |
DataSetMapper.__init__(self, ContourModule._getOutput(self), |
100 |
lookup_table._getLookupTable()) |
101 |
DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) |
102 |
|
103 |
data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR, |
104 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
105 |
ContourModule._getContour(self)) |
106 |
|
107 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
108 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
109 |
|
110 |
|
111 |
############################################################################### |
112 |
|
113 |
|
114 |
from transform import Transform |
115 |
from plane import Plane |
116 |
from cutter import Cutter |
117 |
|
118 |
# NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter were |
119 |
# inherited to allow access to their public methods from the driver. |
120 |
class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform, |
121 |
Plane, Cutter): |
122 |
""" |
123 |
This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>}, |
124 |
except that it shows a scalar field by contour surfaces on a plane. |
125 |
""" |
126 |
|
127 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
128 |
# This saves the user from specifying the viewport when there is only one. |
129 |
# If no lut is specified, the color scheme will be used. |
130 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
131 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
132 |
|
133 |
""" |
134 |
Initialise the ContourOnPlaneCut. |
135 |
|
136 |
@attention: The source can either be point or cell data. If the |
137 |
source is cell data, a conversion to point data may or may not be |
138 |
required, in order for the object to be rendered correctly. |
139 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
140 |
'True', otherwise 'False' (which is the default). |
141 |
|
142 |
@type scene: L{Scene <scene.Scene>} object |
143 |
@param scene: Scene in which objects are to be rendered on |
144 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
145 |
object |
146 |
@param data_collector: Deal with source of data for visualisation |
147 |
@type viewport: L{Viewport <constant.Viewport>} constant |
148 |
@param viewport: Viewport in which objects are to be rendered on |
149 |
@type lut : L{Lut <constant.Lut>} constant |
150 |
@param lut: Lookup table color scheme |
151 |
@type cell_to_point: Boolean |
152 |
@param cell_to_point: Converts cell data to point data (by averaging) |
153 |
@type outline: Boolean |
154 |
@param outline: Places an outline around the domain surface |
155 |
""" |
156 |
|
157 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
158 |
# As a result, when methods from Actor3D is invoked from the driver, |
159 |
# only the methods associated with the latest instance (which in this |
160 |
# case is the Actor3D for the contour) can be executed. Actor3D |
161 |
# methods associated with Outline cannot be invoked from the driver. |
162 |
# They can only be called within here, which is why Outline must |
163 |
# be place before the contour as there is unlikely to be any changes |
164 |
# made to the Outline's Actor3D. |
165 |
|
166 |
# ----- Outline ----- |
167 |
|
168 |
if(outline == True): |
169 |
outline = Outline(data_collector._getOutput()) |
170 |
DataSetMapper.__init__(self, outline._getOutput()) |
171 |
|
172 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
173 |
# Default outline color is black. |
174 |
Actor3D.setColor(self, Color.BLACK) |
175 |
|
176 |
# Default line width is 1. |
177 |
Actor3D._setLineWidth(self, 1) |
178 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
179 |
|
180 |
# ----- Contour on a cut plane ----- |
181 |
|
182 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
183 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
184 |
# will take place. |
185 |
if(lut == Lut.COLOR): # Colored lookup table. |
186 |
lookup_table = LookupTable() |
187 |
lookup_table._setTableValue() |
188 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
189 |
lookup_table = LookupTable() |
190 |
lookup_table._setLookupTableToGreyScale() |
191 |
|
192 |
Transform.__init__(self) |
193 |
Plane.__init__(self, Transform._getTransform(self)) |
194 |
|
195 |
if(cell_to_point == True): # Converts cell data to point data. |
196 |
c2p = CellDataToPointData(data_collector._getOutput()) |
197 |
Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self)) |
198 |
elif(cell_to_point == False): # No conversion happens. |
199 |
Cutter.__init__(self, data_collector._getOutput(), |
200 |
Plane._getPlane(self)) |
201 |
|
202 |
ContourModule.__init__(self, Cutter._getOutput(self)) |
203 |
# By default 10 contours are generated and the scalar range is based |
204 |
# on the scalar data range. |
205 |
ContourModule.generateContours(self, 10, |
206 |
data_collector._getScalarRange()[0], |
207 |
data_collector._getScalarRange()[1]) |
208 |
|
209 |
DataSetMapper.__init__(self, ContourModule._getOutput(self), |
210 |
lookup_table._getLookupTable()) |
211 |
DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) |
212 |
|
213 |
data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR, |
214 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
215 |
ContourModule._getContour(self)) |
216 |
|
217 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
218 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
219 |
|
220 |
|
221 |
############################################################################### |
222 |
|
223 |
|
224 |
from clipper import Clipper |
225 |
|
226 |
# NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper |
227 |
# were inherited to allow access to their public methods from the driver. |
228 |
class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform, |
229 |
Plane, Clipper): |
230 |
""" |
231 |
This class works in a similar way to L{MapOnPlaneClip <map.MapOnPlaneClip>} |
232 |
, except that it shows a scalar field by contour surfaces clipped using |
233 |
a plane. |
234 |
""" |
235 |
|
236 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
237 |
# This saves the user from specifying the viewport when there is only one. |
238 |
# If no lut is specified, the color scheme will be used. |
239 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
240 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
241 |
|
242 |
""" |
243 |
Initialise the ContourOnPlaneClip. |
244 |
|
245 |
@attention: The source can either be point or cell data. If the |
246 |
source is cell data, a conversion to point data may or may not be |
247 |
required, in order for the object to be rendered correctly. |
248 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
249 |
'True', otherwise 'False' (which is the default). |
250 |
|
251 |
@type scene: L{Scene <scene.Scene>} object |
252 |
@param scene: Scene in which objects are to be rendered on |
253 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
254 |
object |
255 |
@param data_collector: Deal with source of data for visualisation |
256 |
@type viewport: L{Viewport <constant.Viewport>} constant |
257 |
@param viewport: Viewport in which objects are to be rendered on |
258 |
@type lut : L{Lut <constant.Lut>} constant |
259 |
@param lut: Lookup table color scheme |
260 |
@type cell_to_point: Boolean |
261 |
@param cell_to_point: Converts cell data to point data (by averaging) |
262 |
@type outline: Boolean |
263 |
@param outline: Places an outline around the domain surface |
264 |
""" |
265 |
|
266 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
267 |
# As a result, when methods from Actor3D is invoked from the driver, |
268 |
# only the methods associated with the latest instance (which in this |
269 |
# case is the Actor3D for the contour) can be executed. Actor3D |
270 |
# methods associated with Outline cannot be invoked from the driver. |
271 |
# They can only be called within here, which is why Outline must |
272 |
# be place before the contour as there is unlikely to be any changes |
273 |
# made to the Outline's Actor3D. |
274 |
|
275 |
# ----- Outline ----- |
276 |
|
277 |
if(outline == True): |
278 |
outline = Outline(data_collector._getOutput()) |
279 |
DataSetMapper.__init__(self, outline._getOutput()) |
280 |
|
281 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
282 |
# Default outline color is black. |
283 |
Actor3D.setColor(self, Color.BLACK) |
284 |
|
285 |
# Default line width is 1. |
286 |
Actor3D._setLineWidth(self, 1) |
287 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
288 |
|
289 |
# ----- Contour on a clipped plane ----- |
290 |
|
291 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
292 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
293 |
# will take place. |
294 |
if(lut == Lut.COLOR): # Colored lookup table. |
295 |
lookup_table = LookupTable() |
296 |
lookup_table._setTableValue() |
297 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
298 |
lookup_table = LookupTable() |
299 |
lookup_table._setLookupTableToGreyScale() |
300 |
|
301 |
Transform.__init__(self) |
302 |
Plane.__init__(self, Transform._getTransform(self)) |
303 |
|
304 |
if(cell_to_point == True): # Converts cell data to point data. |
305 |
c2p = CellDataToPointData(data_collector._getOutput()) |
306 |
Clipper.__init__(self, c2p._getOutput(), Plane._getPlane(self)) |
307 |
elif(cell_to_point == False): # No conversion happens. |
308 |
Clipper.__init__(self, data_collector._getOutput(), |
309 |
Plane._getPlane(self)) |
310 |
|
311 |
Clipper._setClipFunction(self) |
312 |
|
313 |
ContourModule.__init__(self, Clipper._getOutput(self)) |
314 |
# By default 10 contours are generated and the scalar range is based |
315 |
# on the scalar data range. |
316 |
ContourModule.generateContours(self, 10, |
317 |
data_collector._getScalarRange()[0], |
318 |
data_collector._getScalarRange()[1]) |
319 |
|
320 |
DataSetMapper.__init__(self, ContourModule._getOutput(self), |
321 |
lookup_table._getLookupTable()) |
322 |
DataSetMapper._setScalarRange(self, data_collector._getScalarRange()) |
323 |
|
324 |
data_collector._paramForUpdatingMultipleSources(VizType.CONTOUR, |
325 |
ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self), |
326 |
ContourModule._getContour(self)) |
327 |
|
328 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
329 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
330 |
|