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