1 |
|
2 |
######################################################## |
3 |
# |
4 |
# Copyright (c) 2003-2010 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-2010 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__="https://launchpad.net/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 |
|
34 |
from mapper import DataSetMapper |
35 |
from actor import Actor3D |
36 |
from lookuptable import LookupTable |
37 |
from outline import Outline |
38 |
from constant import Viewport, Color, Lut, ColorMode |
39 |
from contourmodule import ContourModule |
40 |
from average import CellDataToPointData |
41 |
from esys.escript import getMPISizeWorld |
42 |
if getMPISizeWorld()==1: import vtk |
43 |
|
44 |
# NOTE: DataSetMapper, Actor3D and ContourModule were inherited to allow |
45 |
# access to their public methods from the driver. |
46 |
class Contour(DataSetMapper, Actor3D, ContourModule): |
47 |
""" |
48 |
Class that shows a scalar field by contour surfaces. The contour surfaces |
49 |
can either be colored or grey-scaled, depending on the lookup table used. |
50 |
This class can also be used to generate iso surfaces. |
51 |
""" |
52 |
|
53 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
54 |
# This saves the user from specifying the viewport when there is only one. |
55 |
# If no lut is specified, the color scheme will be used. |
56 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
57 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
58 |
""" |
59 |
Initialise the Contour. |
60 |
|
61 |
:attention: The source can either be point or cell data. If the source is cell data, a conversion to point data may or may not be required, in order for the object to be rendered correctly. If a conversion is needed, the 'cell_to_point' flag must be set to 'True', otherwise 'False' (which is the default). On occasions, an inaccurate object may be rendered from cell data even after conversion. |
62 |
|
63 |
:type scene: `Scene` object |
64 |
:param scene: Scene in which objects are to be rendered on |
65 |
:type data_collector: `DataCollector` object |
66 |
:param data_collector: Deal with source of data for visualisation |
67 |
:type viewport: `Viewport` constant |
68 |
:param viewport: Viewport in which objects are to be rendered on |
69 |
:type lut: `Lut` constant |
70 |
:param lut: Lookup table color scheme |
71 |
:type cell_to_point: Boolean |
72 |
:param cell_to_point: Converts cell data to point data (by averaging) |
73 |
:type outline: Boolean |
74 |
:param outline: Places an outline around the domain surface |
75 |
""" |
76 |
|
77 |
self.__data_collector = data_collector |
78 |
self.__viewport = viewport |
79 |
self.__lut = lut |
80 |
self.__cell_to_point = cell_to_point |
81 |
self.__outline = outline |
82 |
|
83 |
self.__modified = True # Keeps track whether Contour has been modified. |
84 |
ContourModule.__init__(self) |
85 |
DataSetMapper.__init__(self) |
86 |
Actor3D.__init__(self) |
87 |
scene._addVisualizationModules(self) |
88 |
|
89 |
# ----- Outline ----- |
90 |
|
91 |
# NOTE: Changes cannot be made to the Outline's properties from the |
92 |
# driver. |
93 |
if(self.__outline == True): |
94 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
95 |
mapper = DataSetMapper() |
96 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
97 |
|
98 |
actor3D = Actor3D() |
99 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
100 |
# Default outline color is black. |
101 |
actor3D.setColor(Color.BLACK) |
102 |
|
103 |
# Default line width is 1. |
104 |
actor3D._setLineWidth(1) |
105 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
106 |
|
107 |
# ----- Contour ----- |
108 |
|
109 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
110 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
111 |
# will take place. |
112 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
113 |
lookup_table = LookupTable() |
114 |
lookup_table._setTableValue() |
115 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
116 |
lookup_table = LookupTable() |
117 |
lookup_table._setLookupTableToGreyScale() |
118 |
|
119 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
120 |
c2p = CellDataToPointData( |
121 |
self.__data_collector._getDataCollectorOutput()) |
122 |
self._setupContourModule(c2p._getCellToPointOutput()) |
123 |
elif(self.__cell_to_point == False): # No conversion happens. |
124 |
self._setupContourModule( |
125 |
self.__data_collector._getDataCollectorOutput()) |
126 |
|
127 |
self._setupDataSetMapper(self._getContourModuleOutput(), |
128 |
lookup_table._getLookupTable()) |
129 |
|
130 |
self._setupActor3D(self._getDataSetMapper()) |
131 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
132 |
|
133 |
def _isModified(self): |
134 |
""" |
135 |
Return whether the Contour or DataCollector has been modified. |
136 |
|
137 |
:rtype: Boolean |
138 |
:return: True or False |
139 |
""" |
140 |
|
141 |
return self.__modified or self.__data_collector._isModified() |
142 |
|
143 |
def _render(self, scene): |
144 |
""" |
145 |
Render the contour. |
146 |
|
147 |
:type scene: `Scene` object |
148 |
:param scene: Scene in which objects are to be rendered on |
149 |
""" |
150 |
|
151 |
if (self._isModified() == True): |
152 |
if(self.__data_collector._isScalarSet() == True): |
153 |
self.__data_collector._setActiveScalar() |
154 |
|
155 |
# By default 10 contours are generated and the scalar range is |
156 |
# based on the scalar data range. |
157 |
contours = 10 |
158 |
lower_range = self.__data_collector._getScalarRange()[0] |
159 |
upper_range = self.__data_collector._getScalarRange()[1] |
160 |
|
161 |
if(self._isContoursSet() == True): |
162 |
contours = None |
163 |
if(self._isLowerRangeSet() == True): |
164 |
lower_range = None |
165 |
if(self._isUpperRangeSet() == True): |
166 |
upper_range = None |
167 |
|
168 |
self.generateContours(contours, lower_range, upper_range) |
169 |
self._generateContours() |
170 |
|
171 |
# self._isScalarRangeSet checks whether the scalar range has been |
172 |
# specified by the user. If it has, then the scalar range |
173 |
# read from the source will be ignored. |
174 |
if(not(self._isScalarRangeSet())): |
175 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
176 |
self.__modified = False |
177 |
|
178 |
|
179 |
############################################################################### |
180 |
|
181 |
|
182 |
from transform import Transform |
183 |
from plane import Plane |
184 |
from cutter import Cutter |
185 |
|
186 |
# NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Cutter |
187 |
# were inherited to allow access to their public methods from the driver. |
188 |
class ContourOnPlaneCut(DataSetMapper, Actor3D, ContourModule, Transform, |
189 |
Plane, Cutter): |
190 |
""" |
191 |
This class works in a similar way to `MapOnPlaneCut`, |
192 |
except that it shows a scalar field by contour surfaces cut using a plane. |
193 |
""" |
194 |
|
195 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
196 |
# This saves the user from specifying the viewport when there is only one. |
197 |
# If no lut is specified, the color scheme will be used. |
198 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
199 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
200 |
|
201 |
""" |
202 |
Initialise the ContourOnPlaneCut. |
203 |
|
204 |
:attention: The source can either be point or cell data. If the source is cell data, a conversion to point data may or may not be required, in order for the object to be rendered correctly. If a conversion is needed, the 'cell_to_point' flag must be set to 'True', otherwise 'False' (which is the default). |
205 |
|
206 |
:type scene: `Scene` object |
207 |
:param scene: Scene in which objects are to be rendered on |
208 |
:type data_collector: `DataCollector` object |
209 |
:param data_collector: Deal with source of data for visualisation |
210 |
:type viewport: `Viewport` constant |
211 |
:param viewport: Viewport in which objects are to be rendered on |
212 |
:type lut: `Lut` constant |
213 |
:param lut: Lookup table color scheme |
214 |
:type cell_to_point: Boolean |
215 |
:param cell_to_point: Converts cell data to point data (by averaging) |
216 |
:type outline: Boolean |
217 |
:param outline: Places an outline around the domain surface |
218 |
""" |
219 |
|
220 |
self.__data_collector = data_collector |
221 |
self.__viewport = viewport |
222 |
self.__lut = lut |
223 |
self.__cell_to_point = cell_to_point |
224 |
self.__outline = outline |
225 |
|
226 |
# Keeps track whether ContourOnPlaneCut has been modified. |
227 |
self.__modified = True |
228 |
Transform.__init__(self) |
229 |
Plane.__init__(self) |
230 |
Cutter.__init__(self) |
231 |
ContourModule.__init__(self) |
232 |
DataSetMapper.__init__(self) |
233 |
Actor3D.__init__(self) |
234 |
scene._addVisualizationModules(self) |
235 |
|
236 |
# ----- Outline ----- |
237 |
|
238 |
# NOTE: Changes cannot be made to the Outline's properties from the |
239 |
# driver. |
240 |
if(self.__outline == True): |
241 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
242 |
mapper = DataSetMapper() |
243 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
244 |
|
245 |
actor3D = Actor3D() |
246 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
247 |
# Default outline color is black. |
248 |
actor3D.setColor(Color.BLACK) |
249 |
|
250 |
# Default line width is 1. |
251 |
actor3D._setLineWidth(1) |
252 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
253 |
|
254 |
# ----- Contour on a cut plane ----- |
255 |
|
256 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
257 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
258 |
# will take place. |
259 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
260 |
lookup_table = LookupTable() |
261 |
lookup_table._setTableValue() |
262 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
263 |
lookup_table = LookupTable() |
264 |
lookup_table._setLookupTableToGreyScale() |
265 |
|
266 |
self._setupPlane(self._getTransform()) |
267 |
|
268 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
269 |
c2p = CellDataToPointData(self.__data_collector._getOutput()) |
270 |
self._setupCutter(c2p._getCellToPointOutput(), self._getPlane()) |
271 |
elif(self.__cell_to_point == False): # No conversion happens. |
272 |
self._setupCutter(self.__data_collector._getDataCollectorOutput(), |
273 |
self._getPlane()) |
274 |
|
275 |
self._setupContourModule(self._getCutterOutput()) |
276 |
self._setupDataSetMapper(self._getContourModuleOutput(), |
277 |
lookup_table._getLookupTable()) |
278 |
|
279 |
self._setupActor3D(self._getDataSetMapper()) |
280 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
281 |
|
282 |
def _isModified(self): |
283 |
""" |
284 |
Return whether the ContourOnPlaneCut or DataCollector has been modified. |
285 |
|
286 |
:rtype: Boolean |
287 |
:return: True or False |
288 |
""" |
289 |
|
290 |
return self.__modified or self.__data_collector._isModified() |
291 |
|
292 |
def _render(self, scene): |
293 |
""" |
294 |
Render the contour cut using a plane. |
295 |
|
296 |
:type scene: `Scene` object |
297 |
:param scene: Scene in which objects are to be rendered on |
298 |
""" |
299 |
|
300 |
if (self._isModified() == True): |
301 |
if(self.__data_collector._isScalarSet() == True): |
302 |
self.__data_collector._setActiveScalar() |
303 |
|
304 |
# By default 10 contours are generated and the scalar range is based |
305 |
# on the scalar data range. |
306 |
contours = 10 |
307 |
lower_range = self.__data_collector._getScalarRange()[0] |
308 |
upper_range = self.__data_collector._getScalarRange()[1] |
309 |
|
310 |
if(self._isContoursSet() == True): |
311 |
contours = None |
312 |
if(self._isLowerRangeSet() == True): |
313 |
lower_range = None |
314 |
if(self._isUpperRangeSet() == True): |
315 |
upper_range = None |
316 |
|
317 |
self.generateContours(contours, lower_range, upper_range) |
318 |
self._generateContours() |
319 |
|
320 |
# self._isScalarRangeSet checks whether the scalar range has been |
321 |
# specified by the user. If it has, then the scalar range |
322 |
# read from the source will be ignored. |
323 |
if(not(self._isScalarRangeSet())): |
324 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
325 |
self.__modified = False |
326 |
|
327 |
|
328 |
############################################################################### |
329 |
|
330 |
|
331 |
from clipper import Clipper |
332 |
|
333 |
# NOTE: DataSetMapper, Actor3D, ContourModule, Transform, Plane and Clipper |
334 |
# were inherited to allow access to their public methods from the driver. |
335 |
class ContourOnPlaneClip(DataSetMapper, Actor3D, ContourModule, Transform, |
336 |
Plane, Clipper): |
337 |
""" |
338 |
This class works in a similar way to `MapOnPlaneClip` |
339 |
, except that it shows a scalar field by contour surfaces clipped using |
340 |
a plane. |
341 |
""" |
342 |
|
343 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
344 |
# This saves the user from specifying the viewport when there is only one. |
345 |
# If no lut is specified, the color scheme will be used. |
346 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
347 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
348 |
|
349 |
""" |
350 |
Initialise the ContourOnPlaneClip. |
351 |
|
352 |
:attention: The source can either be point or cell data. If the source is cell data, a conversion to point data may or may not be required, in order for the object to be rendered correctly. If a conversion is needed, the 'cell_to_point' flag must be set to 'True', otherwise 'False' (which is the default). |
353 |
|
354 |
:type scene: `Scene` object |
355 |
:param scene: Scene in which objects are to be rendered on |
356 |
:type data_collector: `DataCollector` object |
357 |
:param data_collector: Deal with source of data for visualisation |
358 |
:type viewport: `Viewport` constant |
359 |
:param viewport: Viewport in which objects are to be rendered on |
360 |
:type lut: `Lut` constant |
361 |
:param lut: Lookup table color scheme |
362 |
:type cell_to_point: Boolean |
363 |
:param cell_to_point: Converts cell data to point data (by averaging) |
364 |
:type outline: Boolean |
365 |
:param outline: Places an outline around the domain surface |
366 |
""" |
367 |
|
368 |
self.__data_collector = data_collector |
369 |
self.__viewport = viewport |
370 |
self.__lut = lut |
371 |
self.__cell_to_point = cell_to_point |
372 |
self.__outline = outline |
373 |
|
374 |
# Keeps track whether ContourOnPlaneClip has been modified. |
375 |
self.__modified = True |
376 |
Transform.__init__(self) |
377 |
Plane.__init__(self) |
378 |
Clipper.__init__(self) |
379 |
ContourModule.__init__(self) |
380 |
DataSetMapper.__init__(self) |
381 |
Actor3D.__init__(self) |
382 |
scene._addVisualizationModules(self) |
383 |
|
384 |
# ----- Outline ----- |
385 |
|
386 |
# NOTE: Changes cannot be made to the Outline's properties from the |
387 |
# driver. |
388 |
if(self.__outline == True): |
389 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
390 |
mapper = DataSetMapper() |
391 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
392 |
|
393 |
actor3D = Actor3D() |
394 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
395 |
# Default outline color is black. |
396 |
actor3D.setColor(Color.BLACK) |
397 |
|
398 |
# Default line width is 1. |
399 |
actor3D._setLineWidth(1) |
400 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
401 |
|
402 |
# ----- Contour on a clipped plane ----- |
403 |
|
404 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
405 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
406 |
# will take place. |
407 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
408 |
lookup_table = LookupTable() |
409 |
lookup_table._setTableValue() |
410 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
411 |
lookup_table = LookupTable() |
412 |
lookup_table._setLookupTableToGreyScale() |
413 |
|
414 |
self._setupPlane(self._getTransform()) |
415 |
|
416 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
417 |
c2p = CellDataToPointData( |
418 |
self.__data_collector._getDataCollectorOutput()) |
419 |
self._setupClipper(c2p._getCellToPointOutput(), self._getPlane()) |
420 |
elif(self.__cell_to_point == False): # No conversion happens. |
421 |
self._setupClipper(self.__data_collector._getDataCollectorOutput(), |
422 |
self._getPlane()) |
423 |
|
424 |
self._setClipFunction() |
425 |
self._setupContourModule(self._getClipperOutput()) |
426 |
|
427 |
self._setupDataSetMapper(self._getContourModuleOutput(), |
428 |
lookup_table._getLookupTable()) |
429 |
|
430 |
self._setupActor3D(self._getDataSetMapper()) |
431 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
432 |
|
433 |
def _isModified(self): |
434 |
""" |
435 |
Return whether the ContourOnPlaneClip or DataCollector has been |
436 |
modified. |
437 |
|
438 |
:rtype: Boolean |
439 |
:return: True or False |
440 |
""" |
441 |
|
442 |
return self.__modified or self.__data_collector._isModified() |
443 |
|
444 |
def _render(self, scene): |
445 |
""" |
446 |
Render the contour clip using a plane. |
447 |
|
448 |
:type scene: `Scene` object |
449 |
:param scene: Scene in which objects are to be rendered on |
450 |
""" |
451 |
|
452 |
if (self._isModified() == True): |
453 |
if(self.__data_collector._isScalarSet() == True): |
454 |
self.__data_collector._setActiveScalar() |
455 |
|
456 |
# By default 10 contours are generated and the scalar range is based |
457 |
# on the scalar data range. |
458 |
contours = 10 |
459 |
lower_range = self.__data_collector._getScalarRange()[0] |
460 |
upper_range = self.__data_collector._getScalarRange()[1] |
461 |
|
462 |
if(self._isContoursSet() == True): |
463 |
contours = None |
464 |
if(self._isLowerRangeSet() == True): |
465 |
lower_range = None |
466 |
if(self._isUpperRangeSet() == True): |
467 |
upper_range = None |
468 |
|
469 |
self.generateContours(contours, lower_range, upper_range) |
470 |
self._generateContours() |
471 |
|
472 |
# self._isScalarRangeSet checks whether the scalar range has been |
473 |
# specified by the user. If it has, then the scalar range |
474 |
# read from the source will be ignored. |
475 |
if(not(self._isScalarRangeSet())): |
476 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
477 |
self.__modified = False |
478 |
|
479 |
|