1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from position import LocalPosition |
7 |
from constant import Color |
8 |
|
9 |
class ScalarBar: |
10 |
""" |
11 |
Class that defines a scalar bar. |
12 |
""" |
13 |
|
14 |
def __init__(self): |
15 |
""" |
16 |
Initialise the scalar bar. |
17 |
""" |
18 |
|
19 |
self.__vtk_scalar_bar = vtk.vtkScalarBarActor() |
20 |
self.__setupScalarBar() |
21 |
|
22 |
def __setupScalarBar(self): |
23 |
""" |
24 |
Setup the scalar bar. |
25 |
""" |
26 |
|
27 |
self.__vtk_scalar_bar.GetPositionCoordinate().SetCoordinateSystemToViewport() |
28 |
self.setNumberOfLabels(8) |
29 |
# Set the default color of the scalar bar's title and label to black. |
30 |
self.setTitleColor(Color.BLACK) |
31 |
self.setLabelColor(Color.BLACK) |
32 |
self.titleBoldOff() |
33 |
self.labelBoldOff() |
34 |
|
35 |
def _setScalarBarLookupTable(self, lookup_table): |
36 |
""" |
37 |
Set the scalar bar's lookup table. |
38 |
|
39 |
@type lookup_table: vtkScalarsToColors |
40 |
@param lookup_table: Converts scalar data to colors |
41 |
""" |
42 |
|
43 |
self.__vtk_scalar_bar.SetLookupTable(lookup_table) |
44 |
|
45 |
def setNumberOfLabels(self, labels): |
46 |
""" |
47 |
Set the number of lables on the scalar bar. |
48 |
|
49 |
@type labels: Number |
50 |
@param labels: Number of labels on the scalar bar |
51 |
""" |
52 |
|
53 |
self.__vtk_scalar_bar.SetNumberOfLabels(labels) |
54 |
|
55 |
def setTitle(self, title): |
56 |
""" |
57 |
Set the title on the scalar bar. |
58 |
|
59 |
@type title: String |
60 |
@param title: Title on the scalar bar |
61 |
""" |
62 |
|
63 |
self.__vtk_scalar_bar.SetTitle(title) |
64 |
|
65 |
def setPosition(self, position): |
66 |
""" |
67 |
Set the local position of the scalar bar. |
68 |
|
69 |
@type position: L{LocalPosition <position.LocalPosition>} object |
70 |
@param position: Position of the scalar bar |
71 |
""" |
72 |
|
73 |
self.__vtk_scalar_bar.SetPosition(position._getXCoor(), \ |
74 |
position._getYCoor()) |
75 |
|
76 |
def setOrientationToHorizontal(self): |
77 |
""" |
78 |
Set the orientation of the scalar bar to horizontal. |
79 |
""" |
80 |
|
81 |
self.__vtk_scalar_bar.SetOrientationToHorizontal() |
82 |
self.setWidth(0.8) |
83 |
self.setHeight(0.10) |
84 |
self.setPosition(LocalPosition(130,5)) |
85 |
|
86 |
def setOrientationToVertical(self): |
87 |
""" |
88 |
Set the orientation of the scalar bar to vertical. |
89 |
""" |
90 |
|
91 |
self.__vtk_scalar_bar.SetOrientationToVertical() |
92 |
self.setWidth(0.14) |
93 |
self.setHeight(0.85) |
94 |
self.setPosition(LocalPosition(5,150)) |
95 |
|
96 |
def setHeight(self, height): |
97 |
""" |
98 |
Set the height of the scalar bar. |
99 |
|
100 |
@type height: Number |
101 |
@param height: Height of the scalar bar |
102 |
""" |
103 |
|
104 |
self.__vtk_scalar_bar.SetHeight(height) |
105 |
|
106 |
def setWidth(self, width): |
107 |
""" |
108 |
Set the width of the scalar bar. |
109 |
|
110 |
@type width: Number |
111 |
@param width: Width of the scalar bar. |
112 |
""" |
113 |
|
114 |
self.__vtk_scalar_bar.SetWidth(width) |
115 |
|
116 |
def setLabelColor(self, color): |
117 |
""" |
118 |
Set the color of the scalar bar's label. |
119 |
|
120 |
@type color: L{Color <constant.Color>} constant |
121 |
@param color: Color of the scalar bar label |
122 |
""" |
123 |
|
124 |
self.__getLabelProperty().SetColor(color) |
125 |
|
126 |
def labelBoldOn(self): |
127 |
""" |
128 |
Enable the bold on the scalar bar's label. |
129 |
""" |
130 |
|
131 |
self.__getLabelProperty().BoldOn() |
132 |
|
133 |
def labelBoldOff(self): |
134 |
""" |
135 |
Disable the bold on the scalar bar's label. |
136 |
""" |
137 |
|
138 |
self.__getLabelProperty().BoldOff() |
139 |
|
140 |
def setTitleColor(self, color): |
141 |
""" |
142 |
Set the color of the scalar bar's title. |
143 |
|
144 |
@type color: L{Color <constant.Color>} constant |
145 |
@param color: Color of the scalar bar title |
146 |
""" |
147 |
|
148 |
self.__getTitleProperty().SetColor(color) |
149 |
|
150 |
def titleBoldOn(self): |
151 |
""" |
152 |
Enable the bold on the scalar bar's title. |
153 |
""" |
154 |
|
155 |
self.__getTitleProperty().BoldOn() |
156 |
|
157 |
def titleBoldOff(self): |
158 |
""" |
159 |
Disable the bold on the scalar bar's title. |
160 |
""" |
161 |
|
162 |
self.__getTitleProperty().BoldOff() |
163 |
|
164 |
def __getLabelProperty(self): |
165 |
""" |
166 |
Return the scalar bar's label property. |
167 |
|
168 |
@rtype: vtkTextPorperty |
169 |
@return: Scalar bar's label property |
170 |
""" |
171 |
|
172 |
return self.__vtk_scalar_bar.GetLabelTextProperty() |
173 |
|
174 |
def __getTitleProperty(self): |
175 |
""" |
176 |
Return the scalar bar's title property. |
177 |
|
178 |
@rtype: vtkTextPorperty |
179 |
@return: Scalar bar's title property |
180 |
""" |
181 |
|
182 |
return self.__vtk_scalar_bar.GetTitleTextProperty() |
183 |
|
184 |
def _getScalarBar(self): |
185 |
""" |
186 |
Return the scalar bar. |
187 |
|
188 |
@rtype: vtkScalarBarActor |
189 |
@return: Scalar bar actor |
190 |
""" |
191 |
|
192 |
return self.__vtk_scalar_bar |
193 |
|