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