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 average import CellDataToPointData |
41 |
|
42 |
# NOTE: DataSetMapper and Actor3D were inherited to allow access to their |
43 |
# public methods from the driver. |
44 |
class Map(DataSetMapper, Actor3D): |
45 |
""" |
46 |
Class that shows a scalar field on a domain surface. The domain surface |
47 |
can either be colored or grey-scaled, depending on the lookup table used. |
48 |
""" |
49 |
|
50 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
51 |
# This saves the user from specifying the viewport when there is only one. |
52 |
# If no lut is specified, the color scheme will be used. |
53 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
54 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
55 |
""" |
56 |
Initialise the Map. |
57 |
|
58 |
@attention: The source can either be point or cell data. If the |
59 |
source is cell data, a conversion to point data may or may not be |
60 |
required, in order for the object to be rendered correctly. |
61 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
62 |
'True', otherwise 'False' (which is the default). On occasions, an |
63 |
inaccurate object may be rendered from cell data even after conversion. |
64 |
|
65 |
@type scene: L{Scene <scene.Scene>} object |
66 |
@param scene: Scene in which objects are to be rendered on |
67 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
68 |
object |
69 |
@param data_collector: Deal with source of data for vizualisation |
70 |
@type viewport: L{Viewport <constant.Viewport>} constant |
71 |
@param viewport: Viewport in which objects are to be rendered on |
72 |
@type lut : L{Lut <constant.Lut>} constant |
73 |
@param lut: Lookup table color scheme |
74 |
@type cell_to_point: Boolean |
75 |
@param cell_to_point: Converts cell data to point data (by averaging) |
76 |
@type outline: Boolean |
77 |
@param outline: Places an outline around the domain surface |
78 |
""" |
79 |
|
80 |
self.__data_collector = data_collector |
81 |
self.__viewport = viewport |
82 |
self.__lut = lut |
83 |
self.__cell_to_point = cell_to_point |
84 |
self.__outline = outline |
85 |
|
86 |
self.__modified = True # Keeps track whether Map has been modified. |
87 |
DataSetMapper.__init__(self) |
88 |
Actor3D.__init__(self) |
89 |
scene._addVisualizationModules(self) |
90 |
|
91 |
# ----- Outline ----- |
92 |
|
93 |
# NOTE: Changes cannot be made to the Outline's properties from the |
94 |
# driver. |
95 |
if(self.__outline == True): |
96 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
97 |
mapper = DataSetMapper() |
98 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
99 |
|
100 |
actor3D = Actor3D() |
101 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
102 |
# Default outline color is black. |
103 |
actor3D.setColor(Color.BLACK) |
104 |
|
105 |
# Default line width is 1. |
106 |
actor3D._setLineWidth(1) |
107 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
108 |
|
109 |
# ----- Map ----- |
110 |
|
111 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
112 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
113 |
# will take place. |
114 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
115 |
lookup_table = LookupTable() |
116 |
lookup_table._setTableValue() |
117 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
118 |
lookup_table = LookupTable() |
119 |
lookup_table._setLookupTableToGreyScale() |
120 |
|
121 |
if(self.__cell_to_point == True): # Convert cell data to point data. |
122 |
c2p = CellDataToPointData( |
123 |
self.__data_collector._getDataCollectorOutput()) |
124 |
self._setupDataSetMapper(c2p._getCellToPointOutput(), |
125 |
lookup_table._getLookupTable()) |
126 |
elif(self.__cell_to_point == False): # No conversion happens. |
127 |
self._setupDataSetMapper( |
128 |
self.__data_collector._getDataCollectorOutput(), |
129 |
lookup_table._getLookupTable()) |
130 |
|
131 |
self._setupActor3D(self._getDataSetMapper()) |
132 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
133 |
|
134 |
def _isModified(self): |
135 |
""" |
136 |
Return whether the Map or DataCollector has been modified. |
137 |
|
138 |
@rtype: Boolean |
139 |
@return: True or False |
140 |
""" |
141 |
|
142 |
return self.__modified or self.__data_collector._isModified() |
143 |
|
144 |
def _render(self, scene): |
145 |
""" |
146 |
Render the surface map. |
147 |
|
148 |
@type scene: L{Scene <scene.Scene>} object |
149 |
@param scene: Scene in which objects are to be rendered on |
150 |
""" |
151 |
|
152 |
if (self._isModified() == True): |
153 |
if(self.__data_collector._isScalarSet() == True): |
154 |
self.__data_collector._setActiveScalar() |
155 |
|
156 |
# self._isScalarRangeSet checks whether the scalar range has been |
157 |
# specified by the user. If it has, then the scalar range |
158 |
# read from the source will be ignored. |
159 |
if(not(self._isScalarRangeSet())): |
160 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
161 |
self.__modified = False |
162 |
|
163 |
|
164 |
############################################################################### |
165 |
|
166 |
|
167 |
from transform import Transform |
168 |
from plane import Plane |
169 |
from cutter import Cutter |
170 |
|
171 |
# NOTE: DataSetMapper, Actor3D, Transform, Plane and Cutter were inherited |
172 |
# to allow access to their public methods from the driver. |
173 |
class MapOnPlaneCut(DataSetMapper, Actor3D, Transform, Plane, Cutter): |
174 |
""" |
175 |
This class works in a similar way to L{Map <map.Map>}, except that it |
176 |
shows a scalar field cut using a plane. The plane can be translated |
177 |
and rotated along the X, Y and Z axes. |
178 |
""" |
179 |
|
180 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
181 |
# This saves the user from specifying the viewport when there is only one. |
182 |
# If no lut is specified, the color scheme will be used. |
183 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
184 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
185 |
""" |
186 |
Initialise the MapOnPlanceCut. |
187 |
|
188 |
@attention: The source can either be point or cell data. If the |
189 |
source is cell data, a conversion to point data may or may not be |
190 |
required, in order for the object to be rendered correctly. |
191 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
192 |
'True', otherwise 'False' (which is the default). On occasions, an |
193 |
inaccurate object may be rendered from cell data even after conversion. |
194 |
|
195 |
@type scene: L{Scene <scene.Scene>} object |
196 |
@param scene: Scene in which objects are to be rendered on |
197 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
198 |
object |
199 |
@param data_collector: Deal with source of data for visualisation |
200 |
@type viewport: L{Viewport <constant.Viewport>} constant |
201 |
@param viewport: Viewport in which objects are to be rendered on |
202 |
@type lut : L{Lut <constant.Lut>} constant |
203 |
@param lut: Lookup table color scheme |
204 |
@type cell_to_point: Boolean |
205 |
@param cell_to_point: Converts cell data to point data (by averaging) |
206 |
@type outline: Boolean |
207 |
@param outline: Places an outline around the domain surface |
208 |
""" |
209 |
|
210 |
self.__data_collector = data_collector |
211 |
self.__viewport = viewport |
212 |
self.__lut = lut |
213 |
self.__cell_to_point = cell_to_point |
214 |
self.__outline = outline |
215 |
|
216 |
# Keeps track whether MapOnPlaneCut has been modified. |
217 |
self.__modified = True |
218 |
Transform.__init__(self) |
219 |
Plane.__init__(self) |
220 |
Cutter.__init__(self) |
221 |
DataSetMapper.__init__(self) |
222 |
Actor3D.__init__(self) |
223 |
scene._addVisualizationModules(self) |
224 |
|
225 |
# ----- Outline ----- |
226 |
|
227 |
# NOTE: Changes cannot be made to the Outline's properties from the |
228 |
# driver. |
229 |
if(self.__outline == True): |
230 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
231 |
mapper = DataSetMapper() |
232 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
233 |
|
234 |
actor3D = Actor3D() |
235 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
236 |
# Default outline color is black. |
237 |
actor3D.setColor(Color.BLACK) |
238 |
|
239 |
# Default line width is 1. |
240 |
actor3D._setLineWidth(1) |
241 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
242 |
|
243 |
# ----- Map on a plane ----- |
244 |
|
245 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
246 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
247 |
# will take place. |
248 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
249 |
lookup_table = LookupTable() |
250 |
lookup_table._setTableValue() |
251 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
252 |
lookup_table = LookupTable() |
253 |
lookup_table._setLookupTableToGreyScale() |
254 |
|
255 |
self._setupPlane(self._getTransform()) |
256 |
|
257 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
258 |
c2p = CellDataToPointData( |
259 |
self.__data_collector._getDataCollectorOutput()) |
260 |
self._setupCutter(c2p._getCellToPointOutput(), self._getPlane()) |
261 |
elif(self.__cell_to_point == False): # No conversion happens. |
262 |
c2p = CellDataToPointData( |
263 |
self.__data_collector._getDataCollectorOutput()) |
264 |
self._setupCutter(self.__data_collector._getDataCollectorOutput(), |
265 |
self._getPlane()) |
266 |
|
267 |
self._setupDataSetMapper(self._getCutterOutput(), |
268 |
lookup_table._getLookupTable()) |
269 |
|
270 |
self._setupActor3D(self._getDataSetMapper()) |
271 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
272 |
|
273 |
def _isModified(self): |
274 |
""" |
275 |
Return whether the MapOnPlaneCut or DataCollector has been modified. |
276 |
|
277 |
@rtype: Boolean |
278 |
@return: True or False |
279 |
""" |
280 |
|
281 |
return self.__modified or self.__data_collector._isModified() |
282 |
|
283 |
def _render(self, scene): |
284 |
""" |
285 |
Render the surface map cut using a plane. |
286 |
|
287 |
@type scene: L{Scene <scene.Scene>} object |
288 |
@param scene: Scene in which objects are to be rendered on |
289 |
""" |
290 |
|
291 |
if (self._isModified() == True): |
292 |
if(self.__data_collector._isScalarSet() == True): |
293 |
self.__data_collector._setActiveScalar() |
294 |
# self._isScalarRangeSet checks whether the scalar range has been |
295 |
# specified by the user. If it has, then the scalar range |
296 |
# read from the source will be ignored. |
297 |
if(not(self._isScalarRangeSet())): |
298 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
299 |
self.__modified = False |
300 |
|
301 |
|
302 |
############################################################################### |
303 |
|
304 |
|
305 |
from clipper import Clipper |
306 |
|
307 |
# NOTE: DataSetMapper, Actor3D, Transform, Plane and Clipper were inherited |
308 |
# to allow access to their public methods from the driver. |
309 |
class MapOnPlaneClip(DataSetMapper, Actor3D, Transform, Plane, Clipper): |
310 |
""" |
311 |
This class works in a similar way to L{MapOnPlaneCut <map.MapOnPlaneCut>}, |
312 |
except that it shows a scalar field clipped using a plane. |
313 |
""" |
314 |
|
315 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
316 |
# This saves the user from specifying the viewport when there is only one. |
317 |
# If no lut is specified, the color scheme will be used. |
318 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
319 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
320 |
""" |
321 |
Initialise the MapOnPlaneClip. |
322 |
|
323 |
@attention: The source can either be point or cell data. If the |
324 |
source is cell data, a conversion to point data may or may not be |
325 |
required, in order for the object to be rendered correctly. |
326 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
327 |
'True', otherwise 'False' (which is the default). On occasions, an |
328 |
inaccurate object may be rendered from cell data even after conversion. |
329 |
|
330 |
@type scene: L{Scene <scene.Scene>} object |
331 |
@param scene: Scene in which objects are to be rendered on |
332 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
333 |
object |
334 |
@param data_collector: Deal with source of data for visualisation |
335 |
@type viewport: L{Viewport <constant.Viewport>} constant |
336 |
@param viewport: Viewport in which objects are to be rendered on |
337 |
@type lut : L{Lut <constant.Lut>} constant |
338 |
@param lut: Lookup table color scheme |
339 |
@type cell_to_point: Boolean |
340 |
@param cell_to_point: Converts cell data to point data (by averaging) |
341 |
@type outline: Boolean |
342 |
@param outline: Places an outline around the domain surface |
343 |
""" |
344 |
|
345 |
self.__data_collector = data_collector |
346 |
self.__viewport = viewport |
347 |
self.__lut = lut |
348 |
self.__cell_to_point = cell_to_point |
349 |
self.__outline = outline |
350 |
|
351 |
# Keeps track whether MapOnPlaneClip has been modified. |
352 |
self.__modified = True |
353 |
Transform.__init__(self) |
354 |
Plane.__init__(self) |
355 |
Clipper.__init__(self) |
356 |
DataSetMapper.__init__(self) |
357 |
Actor3D.__init__(self) |
358 |
scene._addVisualizationModules(self) |
359 |
|
360 |
# ----- Outline ----- |
361 |
|
362 |
# NOTE: Changes cannot be made to the Outline's properties from the |
363 |
# driver. |
364 |
if(self.__outline == True): |
365 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
366 |
mapper = DataSetMapper() |
367 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
368 |
|
369 |
actor3D = Actor3D() |
370 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
371 |
# Default outline color is black. |
372 |
actor3D.setColor(Color.BLACK) |
373 |
|
374 |
# Default line width is 1. |
375 |
actor3D._setLineWidth(1) |
376 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
377 |
|
378 |
# ----- Map on a clipped plane ----- |
379 |
|
380 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
381 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
382 |
# will take place. |
383 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
384 |
lookup_table = LookupTable() |
385 |
lookup_table._setTableValue() |
386 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
387 |
lookup_table = LookupTable() |
388 |
lookup_table._setLookupTableToGreyScale() |
389 |
|
390 |
self._setupPlane(self._getTransform()) |
391 |
|
392 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
393 |
c2p = CellDataToPointData(data_collector._getDataCollectorOutput()) |
394 |
self._setupClipper(c2p._getCellToPointOutput(), self._getPlane()) |
395 |
elif(self.__cell_to_point == False): # No conversion happens. |
396 |
self._setupClipper(data_collector._getDataCollectorOutput(), |
397 |
self._getPlane()) |
398 |
|
399 |
self._setClipFunction() |
400 |
self._setupDataSetMapper(self._getClipperOutput(), |
401 |
lookup_table._getLookupTable()) |
402 |
|
403 |
self._setupActor3D(self._getDataSetMapper()) |
404 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
405 |
|
406 |
def _isModified(self): |
407 |
""" |
408 |
Return whether the MapOnPlaneClip or DataCollector has been modified. |
409 |
|
410 |
@rtype: Boolean |
411 |
@return: True or False |
412 |
""" |
413 |
|
414 |
return self.__modified or self.__data_collector._isModified() |
415 |
|
416 |
def _render(self, scene): |
417 |
""" |
418 |
Render the surface map clip using a plane. |
419 |
|
420 |
@type scene: L{Scene <scene.Scene>} object |
421 |
@param scene: Scene in which objects are to be rendered on |
422 |
""" |
423 |
|
424 |
if (self._isModified() == True): |
425 |
if(self.__data_collector._isScalarSet() == True): |
426 |
self.__data_collector._setActiveScalar() |
427 |
# self._isScalarRangeSet checks whether the scalar range has been |
428 |
# specified by the user. If it has, then the scalar range |
429 |
# read from the source will be ignored. |
430 |
if(not(self._isScalarRangeSet())): |
431 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
432 |
self.__modified = False |
433 |
|
434 |
|
435 |
############################################################################# |
436 |
|
437 |
|
438 |
# NOTE: DataSetMapper, Actor3D and Clipper were inherited |
439 |
# to allow access to their public methods from the driver. |
440 |
class MapOnScalarClip(DataSetMapper, Actor3D, Clipper): |
441 |
""" |
442 |
This class works in a similar way to L{Map <map.Map>}, except that it |
443 |
shows a scalar field clipped using a scalar value. |
444 |
""" |
445 |
|
446 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
447 |
# This saves the user from specifying the viewport when there is only one. |
448 |
# If no lut is specified, the color scheme will be used. |
449 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
450 |
lut = Lut.COLOR, cell_to_point = False, outline = True): |
451 |
""" |
452 |
Initialise the MapOnScalarClip. |
453 |
|
454 |
@attention: The source can either be point or cell data. If the |
455 |
source is cell data, a conversion to point data may or may not be |
456 |
required, in order for the object to be rendered correctly. |
457 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
458 |
'True', otherwise 'False' (which is the default). On occasions, an |
459 |
inaccurate object may be rendered from cell data even after conversion. |
460 |
|
461 |
@type scene: L{Scene <scene.Scene>} object |
462 |
@param scene: Scene in which objects are to be rendered on |
463 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
464 |
object |
465 |
@param data_collector: Deal with source of data for visualisation |
466 |
@type viewport: L{Viewport <constant.Viewport>} constant |
467 |
@param viewport: Viewport in which objects are to be rendered on |
468 |
@type lut : L{Lut <constant.Lut>} constant |
469 |
@param lut: Lookup table color scheme |
470 |
@type cell_to_point: Boolean |
471 |
@param cell_to_point: Converts cell data to point data (by averaging) |
472 |
@type outline: Boolean |
473 |
@param outline: Places an outline around the domain surface |
474 |
""" |
475 |
|
476 |
self.__data_collector = data_collector |
477 |
self.__viewport = viewport |
478 |
self.__lut = lut |
479 |
self.__cell_to_point = cell_to_point |
480 |
self.__outline = outline |
481 |
|
482 |
# Keeps track whether MapOnScalarClip has been modified. |
483 |
self.__modified = True |
484 |
Clipper.__init__(self) |
485 |
DataSetMapper.__init__(self) |
486 |
Actor3D.__init__(self) |
487 |
scene._addVisualizationModules(self) |
488 |
|
489 |
# ----- Outline ----- |
490 |
|
491 |
# NOTE: Changes cannot be made to the Outline's properties from the |
492 |
# driver. |
493 |
if(self.__outline == True): |
494 |
outline = Outline(self.__data_collector._getDataCollectorOutput()) |
495 |
mapper = DataSetMapper() |
496 |
mapper._setupDataSetMapper(outline._getOutlineOutput()) |
497 |
|
498 |
actor3D = Actor3D() |
499 |
actor3D._setupActor3D(mapper._getDataSetMapper()) |
500 |
# Default outline color is black. |
501 |
actor3D.setColor(Color.BLACK) |
502 |
|
503 |
# Default line width is 1. |
504 |
actor3D._setLineWidth(1) |
505 |
scene._addActor3D(self.__viewport, actor3D._getActor3D()) |
506 |
|
507 |
# ----- Map clipped using a scalar value ----- |
508 |
|
509 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
510 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
511 |
# will take place. |
512 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
513 |
lookup_table = LookupTable() |
514 |
lookup_table._setTableValue() |
515 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
516 |
lookup_table = LookupTable() |
517 |
lookup_table._setLookupTableToGreyScale() |
518 |
|
519 |
if(self.__cell_to_point == True): # Converts cell data to point data. |
520 |
c2p = CellDataToPointData( |
521 |
self.__data_collector._getDataCollectorOutput()) |
522 |
# None is used because a plane is not required when a scalar |
523 |
# value is used to perform the clipping. |
524 |
self._setupClipper(c2p._getCellToPointOutput(), None) |
525 |
elif(self.__cell_to_point == False): # No conversion happens. |
526 |
self._setupClipper( |
527 |
self.__data_collector._getDataCollectorOutput(),None) |
528 |
|
529 |
self._setupDataSetMapper(self._getClipperOutput(), |
530 |
lookup_table._getLookupTable()) |
531 |
|
532 |
self._setupActor3D(self._getDataSetMapper()) |
533 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
534 |
|
535 |
def _isModified(self): |
536 |
""" |
537 |
Return whether the MapOnScalarClip or DataCollector has been modified. |
538 |
|
539 |
@rtype: Boolean |
540 |
@return: True or False |
541 |
""" |
542 |
|
543 |
return self.__modified or self.__data_collector._isModified() |
544 |
|
545 |
def _render(self, scene): |
546 |
""" |
547 |
Render the surface map clip using scalar data. |
548 |
|
549 |
@type scene: L{Scene <scene.Scene>} object |
550 |
@param scene: Scene in which objects are to be rendered on |
551 |
""" |
552 |
|
553 |
if (self._isModified() == True): |
554 |
if(self.__data_collector._isScalarSet() == True): |
555 |
self.__data_collector._setActiveScalar() |
556 |
# self._isScalarRangeSet checks whether the scalar range has been |
557 |
# specified by the user. If it has, then the scalar range |
558 |
# read from the source will be ignored. |
559 |
if(not(self._isScalarRangeSet())): |
560 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
561 |
self.__modified = False |
562 |
|
563 |
|
564 |
############################################################################## |
565 |
|
566 |
|
567 |
from rotation import Rotation |
568 |
from geometry import Geometry |
569 |
|
570 |
# NOTE: DataSetMapper, Actor3D, Clipper and Rotation were inherited |
571 |
# to allow access to their public methods from the driver. |
572 |
class MapOnScalarClipWithRotation(DataSetMapper, Actor3D, Clipper, Rotation): |
573 |
""" |
574 |
This class works in a similar way to L{Map <map.Map>}, except that it |
575 |
shows a 2D scalar field clipped using a scalar value and subsequently |
576 |
rotated around the z-axis to create a 3D looking effect. This class should |
577 |
only be used with 2D data sets and NOT 3D. |
578 |
""" |
579 |
|
580 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
581 |
# This saves the user from specifying the viewport when there is only one. |
582 |
# If no lut is specified, the color scheme will be used. |
583 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST, |
584 |
lut = Lut.COLOR, cell_to_point = False): |
585 |
""" |
586 |
Initialise the MapOnScalarClipWithRotation. |
587 |
|
588 |
@attention: The source can either be point or cell data. If the |
589 |
source is cell data, a conversion to point data may or may not be |
590 |
required, in order for the object to be rendered correctly. |
591 |
If a conversion is needed, the 'cell_to_point' flag must be set to |
592 |
'True', otherwise 'False' (which is the default). On occasions, an |
593 |
inaccurate object may be rendered from cell data even after conversion. |
594 |
|
595 |
@type scene: L{Scene <scene.Scene>} object |
596 |
@param scene: Scene in which objects are to be rendered on |
597 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
598 |
object |
599 |
@param data_collector: Deal with source of data for visualisation |
600 |
@type viewport: L{Viewport <constant.Viewport>} constant |
601 |
@param viewport: Viewport in which objects are to be rendered on |
602 |
@type lut : L{Lut <constant.Lut>} constant |
603 |
@param lut: Lookup table color scheme |
604 |
@type cell_to_point: Boolean |
605 |
@param cell_to_point: Converts cell data to point data (by averaging) |
606 |
""" |
607 |
|
608 |
self.__data_collector = data_collector |
609 |
self.__viewport = viewport |
610 |
self.__lut = lut |
611 |
self.__cell_to_point = cell_to_point |
612 |
|
613 |
# Keeps track whether MapOnScalarClipWithRotation has been modified. |
614 |
self.__modified = True |
615 |
Clipper.__init__(self) |
616 |
Rotation.__init__(self) |
617 |
DataSetMapper.__init__(self) |
618 |
Actor3D.__init__(self) |
619 |
scene._addVisualizationModules(self) |
620 |
|
621 |
def _isModified(self): |
622 |
""" |
623 |
Return whether the MapOnScalarClipWithRotation or DataCollector has |
624 |
been modified. |
625 |
|
626 |
@rtype: Boolean |
627 |
@return: True or False |
628 |
""" |
629 |
|
630 |
return self.__modified or self.__data_collector._isModified() |
631 |
|
632 |
def _render(self, scene): |
633 |
""" |
634 |
Render the surface map clip using scalar data and subsequently rotated. |
635 |
|
636 |
@type scene: L{Scene <scene.Scene>} object |
637 |
@param scene: Scene in which objects are to be rendered on |
638 |
""" |
639 |
|
640 |
# This entire 'if' section had to be moved from the __init__ method |
641 |
# due to the use of 'GetPoints().GetNumberOfPoints()'. A source |
642 |
# (i.e. xml file) must be |
643 |
# supplied before 'GetPoints().GetNumberOfPoints()' is able to return |
644 |
# the correct value |
645 |
# when executed. This is to accommodate for lazy evaluation. |
646 |
if (self._isModified() == True): |
647 |
|
648 |
# Swaps the points from the y-axis to the z-axis and vice-versa. |
649 |
# This is needed as VTK is only able to perform rotation along |
650 |
# the z-axis. |
651 |
output = self.__data_collector._getDataCollectorOutput() |
652 |
num_points = output.GetPoints().GetNumberOfPoints() |
653 |
for i in range (num_points): |
654 |
point = output.GetPoints().GetPoint(i) |
655 |
output.GetPoints().SetPoint(i, point[0], point[2], point[1]) |
656 |
|
657 |
# --- Map clipped using a scalar value and subsequently rotated --- |
658 |
|
659 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
660 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
661 |
# will take place. |
662 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
663 |
lookup_table = LookupTable() |
664 |
lookup_table._setTableValue() |
665 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
666 |
lookup_table = LookupTable() |
667 |
lookup_table._setLookupTableToGreyScale() |
668 |
|
669 |
if(self.__cell_to_point == True): #Converts cell data to point data. |
670 |
c2p = CellDataToPointData(output) |
671 |
# None is used because a plane is not required when a scalar |
672 |
# value is used to perform the clipping. |
673 |
self._setupClipper(c2p._getCellToPointOutput(), None) |
674 |
elif(self.__cell_to_point == False): # No conversion happens. |
675 |
self._setupClipper(output, None) |
676 |
|
677 |
geometry = Geometry(self._getClipperOutput()) |
678 |
|
679 |
self._setupRotationExtrusionFilter(geometry._getGeometryOutput()) |
680 |
self._setupDataSetMapper(self._getRotationOutput(), |
681 |
lookup_table._getLookupTable()) |
682 |
|
683 |
self._setupActor3D(self._getDataSetMapper()) |
684 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
685 |
|
686 |
if(self.__data_collector._isScalarSet() == True): |
687 |
self.__data_collector._setActiveScalar() |
688 |
# self._isScalarRangeSet checks whether the scalar range has been |
689 |
# specified by the user. If it has, then the scalar range |
690 |
# read from the source will be ignored. |
691 |
if(not(self._isScalarRangeSet())): |
692 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
693 |
|
694 |
self.__modified = False |
695 |
|
696 |
|
697 |
|