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