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 Actor2D, Actor3D |
37 |
from lookuptable import LookupTable |
38 |
from constant import Viewport, Color, Lut, LegendType |
39 |
from scalarbar import ScalarBar |
40 |
|
41 |
# NOTE: ScalarBarModule, DataSetMapper and Actor3D were inherited to allow |
42 |
# access to their public methods from the driver. |
43 |
class Legend(ScalarBar, DataSetMapper, Actor3D): |
44 |
""" |
45 |
Class that shows a scalar field on a domain surface. The domain surface |
46 |
can either be colored or grey-scaled, depending on the lookup table used. |
47 |
""" |
48 |
|
49 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
50 |
# This saves the user from specifying the viewport when there is only one. |
51 |
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,\ |
52 |
lut = Lut.COLOR, legend = LegendType.SCALAR): |
53 |
""" |
54 |
Initialise the Legend. |
55 |
|
56 |
@type scene: L{Scene <scene.Scene>} object |
57 |
@param scene: Scene in which objects are to be rendered on |
58 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
59 |
object |
60 |
@param data_collector: Deal with source of data for vizualisation |
61 |
@type viewport: L{Viewport <constant.Viewport>} constant |
62 |
@param viewport: Viewport in which objects are to be rendered on |
63 |
@type lut : L{Lut <constant.Lut>} constant |
64 |
@param lut: Lookup table color scheme |
65 |
@type legend: L{Lut <constant.LegendType>} constant |
66 |
@param legend: Type of legend |
67 |
""" |
68 |
|
69 |
self.__data_collector = data_collector |
70 |
self.__viewport = viewport |
71 |
self.__lut = lut |
72 |
self.__legend = legend |
73 |
|
74 |
self.__modified = True # Keeps track whether Legend has been modified. |
75 |
ScalarBar.__init__(self) |
76 |
|
77 |
# NOTE: DataSetMapper and Actor3D were required in order for the |
78 |
# scalar bar to be colored. If the mapper and actor were not used, |
79 |
# the scalar bar will be black in color. |
80 |
DataSetMapper.__init__(self) |
81 |
Actor3D.__init__(self) |
82 |
scene._addVisualizationModules(self) |
83 |
|
84 |
# ----- Scalar Bar ----- |
85 |
|
86 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
87 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
88 |
# will take place. |
89 |
if(self.__lut == Lut.COLOR): # Colored lookup table. |
90 |
lookup_table = LookupTable() |
91 |
lookup_table._setTableValue() |
92 |
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
93 |
lookup_table = LookupTable() |
94 |
lookup_table._setLookupTableToGreyScale() |
95 |
|
96 |
self._setupDataSetMapper(\ |
97 |
self.__data_collector._getDataCollectorOutput(), \ |
98 |
lookup_table._getLookupTable()) |
99 |
self._setScalarBarLookupTable(self._getDataSetMapperLookupTable()) |
100 |
self.setOrientationToHorizontal() |
101 |
self._setupActor3D(self._getDataSetMapper()) |
102 |
self.setOpacity(0) |
103 |
scene._addActor3D(self.__viewport, self._getActor3D()) |
104 |
scene._addActor3D(self.__viewport, self._getScalarBar()) |
105 |
|
106 |
def _isModified(self): |
107 |
""" |
108 |
Return whether the Legend or DataCollector has been modified. |
109 |
|
110 |
@rtype: Boolean |
111 |
@return: True or False |
112 |
""" |
113 |
|
114 |
return self.__modified or self.__data_collector._isModified() |
115 |
|
116 |
def _render(self, scene): |
117 |
""" |
118 |
Render the legend. |
119 |
|
120 |
@type scene: L{Scene <scene.Scene>} object |
121 |
@param scene: Scene in which objects are to be rendered on |
122 |
""" |
123 |
|
124 |
if (self._isModified() == True): |
125 |
if(self.__data_collector._isScalarSet() == True): |
126 |
self.__data_collector._setActiveScalar() |
127 |
|
128 |
# self._isScalarRangeSet checks whether the scalar range has been |
129 |
# specified by the user. If it has, then the scalar range |
130 |
# read from the source will be ignored. |
131 |
if(self.__legend == LegendType.SCALAR and \ |
132 |
(not(self._isScalarRangeSet()))): |
133 |
self._setScalarRange(self.__data_collector._getScalarRange()) |
134 |
elif(self.__legend == LegendType.VECTOR and \ |
135 |
(not(self._isScalarRangeSet()))): |
136 |
self._setScalarRange(self.__data_collector._getVectorRange()) |
137 |
self.__modified = False |
138 |
|
139 |
|