1 |
jongui |
1189 |
""" |
2 |
|
|
@author: John NGUI |
3 |
|
|
""" |
4 |
|
|
|
5 |
|
|
import vtk |
6 |
|
|
from mapper import DataSetMapper |
7 |
|
|
from actor import Actor2D, Actor3D |
8 |
|
|
from lookuptable import LookupTable |
9 |
|
|
from constant import Viewport, Color, Lut, LegendType |
10 |
|
|
from scalarbar import ScalarBar |
11 |
|
|
|
12 |
|
|
# NOTE: ScalarBarModule, DataSetMapper and Actor3D were inherited to allow |
13 |
|
|
# access to their public methods from the driver. |
14 |
|
|
class Legend(ScalarBar, DataSetMapper, Actor3D): |
15 |
|
|
""" |
16 |
|
|
Class that shows a scalar field on a domain surface. The domain surface |
17 |
|
|
can either be colored or grey-scaled, depending on the lookup table used. |
18 |
|
|
""" |
19 |
|
|
|
20 |
|
|
# The SOUTH_WEST default viewport is used when there is only one viewport. |
21 |
|
|
# This saves the user from specifying the viewport when there is only one. |
22 |
|
|
def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,\ |
23 |
|
|
lut = Lut.COLOR, legend = LegendType.SCALAR): |
24 |
|
|
""" |
25 |
|
|
Initialise the Legend. |
26 |
|
|
|
27 |
|
|
@type scene: L{Scene <scene.Scene>} object |
28 |
|
|
@param scene: Scene in which objects are to be rendered on |
29 |
|
|
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
30 |
|
|
object |
31 |
|
|
@param data_collector: Deal with source of data for vizualisation |
32 |
|
|
@type viewport: L{Viewport <constant.Viewport>} constant |
33 |
|
|
@param viewport: Viewport in which objects are to be rendered on |
34 |
|
|
@type lut : L{Lut <constant.Lut>} constant |
35 |
|
|
@param lut: Lookup table color scheme |
36 |
|
|
@type legend: L{Lut <constant.LegendType>} constant |
37 |
|
|
@param legend: Type of legend |
38 |
|
|
""" |
39 |
|
|
|
40 |
|
|
self.__data_collector = data_collector |
41 |
|
|
self.__viewport = viewport |
42 |
|
|
self.__lut = lut |
43 |
|
|
self.__legend = legend |
44 |
|
|
|
45 |
|
|
self.__modified = True # Keeps track whether Legend has been modified. |
46 |
|
|
ScalarBar.__init__(self) |
47 |
|
|
|
48 |
|
|
# NOTE: DataSetMapper and Actor3D were required in order for the |
49 |
|
|
# scalar bar to be colored. If the mapper and actor were not used, |
50 |
|
|
# the scalar bar will be black in color. |
51 |
|
|
DataSetMapper.__init__(self) |
52 |
|
|
Actor3D.__init__(self) |
53 |
|
|
scene._addVisualizationModules(self) |
54 |
|
|
|
55 |
|
|
# ----- Scalar Bar ----- |
56 |
|
|
|
57 |
|
|
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
58 |
|
|
# before DataSetMapper. If it is done after DataSetMapper, no effect |
59 |
|
|
# will take place. |
60 |
|
|
if(self.__lut == Lut.COLOR): # Colored lookup table. |
61 |
|
|
lookup_table = LookupTable() |
62 |
|
|
lookup_table._setTableValue() |
63 |
|
|
elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
64 |
|
|
lookup_table = LookupTable() |
65 |
|
|
lookup_table._setLookupTableToGreyScale() |
66 |
|
|
|
67 |
|
|
self._setupDataSetMapper(\ |
68 |
|
|
self.__data_collector._getDataCollectorOutput(), \ |
69 |
|
|
lookup_table._getLookupTable()) |
70 |
|
|
self._setScalarBarLookupTable(self._getDataSetMapperLookupTable()) |
71 |
|
|
self.setOrientationToHorizontal() |
72 |
|
|
self._setupActor3D(self._getDataSetMapper()) |
73 |
|
|
self.setOpacity(0) |
74 |
|
|
scene._addActor3D(self.__viewport, self._getActor3D()) |
75 |
|
|
scene._addActor3D(self.__viewport, self._getScalarBar()) |
76 |
|
|
|
77 |
|
|
def _isModified(self): |
78 |
|
|
""" |
79 |
|
|
Return whether the Legend or DataCollector has been modified. |
80 |
|
|
|
81 |
|
|
@rtype: Boolean |
82 |
|
|
@return: True or False |
83 |
|
|
""" |
84 |
|
|
|
85 |
|
|
return self.__modified or self.__data_collector._isModified() |
86 |
|
|
|
87 |
|
|
def _render(self, scene): |
88 |
|
|
""" |
89 |
|
|
Render the legend. |
90 |
|
|
|
91 |
|
|
@type scene: L{Scene <scene.Scene>} object |
92 |
|
|
@param scene: Scene in which objects are to be rendered on |
93 |
|
|
""" |
94 |
|
|
|
95 |
|
|
if (self._isModified() == True): |
96 |
|
|
if(self.__data_collector._isScalarSet() == True): |
97 |
|
|
self.__data_collector._setActiveScalar() |
98 |
|
|
|
99 |
|
|
# self._isScalarRangeSet checks whether the scalar range has been |
100 |
|
|
# specified by the user. If it has, then the scalar range |
101 |
|
|
# read from the source will be ignored. |
102 |
|
|
if(self.__legend == LegendType.SCALAR and \ |
103 |
|
|
(not(self._isScalarRangeSet()))): |
104 |
|
|
self._setScalarRange(self.__data_collector._getScalarRange()) |
105 |
|
|
elif(self.__legend == LegendType.VECTOR and \ |
106 |
|
|
(not(self._isScalarRangeSet()))): |
107 |
|
|
self._setScalarRange(self.__data_collector._getVectorRange()) |
108 |
|
|
self.__modified = False |
109 |
|
|
|
110 |
|
|
|