/[escript]/trunk/pyvisi/py_src/colormap.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/colormap.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 849 - (show annotations)
Fri Sep 15 07:11:55 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 3117 byte(s)
Optimized codes and modularized functions to make it more scalable. Partially 
integrated carpet into the existing modules.  

1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 class ColorMap:
7 """
8 Class that defines the mapping of colors.
9 """
10
11 def __init__(self, color_name):
12 """
13 @type color_name: String
14 @param color_name: Name of the color
15 """
16
17 self.color_name = color_name
18 self.color_map = {}
19 self.buildColorMap()
20
21 def buildColorMap(self):
22 """
23 Build a hash that defines mapping of colors.
24 """
25
26 self.color_map["Red"] = [1, 0, 0]
27 self.color_map["Green"]= [0, 1, 0]
28 self.color_map["Blue"] = [0, 0, 1]
29 self.color_map["Black"] = [0, 0, 0]
30 self.color_map["White"] = [1, 1, 1]
31 self.color_map["Yellow"] = [1,1,0]
32 self.color_map["Pink"] = [1, 0.0784, 0.4588]
33 self.color_map["Orange"] = [1, 0.2706, 0]
34 self.color_map["Purple"] = [0.5412, 0.1680, 0.8828]
35 self.color_map["Grey"] = [0.6602, 0.6602, 0.6602]
36 self.color_map["Brown"] = [0.5430, 0.2700, 0.0742]
37
38 def getR(self):
39 """
40 Return the red(R) value from the RGB.
41
42 @rtype: Number
43 @return: Red(R) value from the RGB
44 """
45
46 return self.color_map[self.color_name][0]
47
48 def getG(self):
49 """
50 Return the green(G) value from the RGB.
51
52 @rtype: Number
53 @return: Green(G) value from the RGB
54 """
55
56 return self.color_map[self.color_name][1]
57
58 def getB(self):
59 """
60 Return the blue(B) value from the RGB.
61
62 @rtype: Number
63 @return: Blue(B) value from the RGB
64 """
65
66 return self.color_map[self.color_name][2]
67
68 def getColor(self):
69 """
70 Return the name of the color.
71
72 @rtype: String
73 @return: Name of the color
74 """
75
76 return self.color_name
77
78 import vtk
79
80 class Lut:
81 """
82 Class that provides the functions to create a map spectrum.
83 """
84
85 def __init__(self):
86 self.vtk_lut = vtk.vtkLookupTable()
87
88 def setHue(self, lower_range, upper_range):
89 """
90 Set the upper and lower hue(color) range.
91
92 @type lower_range: Number
93 @param lower_range: Lower range of the hue
94 @type upper_range: Number
95 @param upper_range: Upper range of the hue
96 """
97
98 self.vtk_lut.SetHueRange(lower_range, upper_range)
99
100 def setSaturation(self, lower_range, upper_range):
101 """
102 Set the upper and lower saturation(vibrancy) range.
103
104 @type lower_range: Number
105 @param lower_range: Lower range of the saturation
106 @type upper_range: Number
107 @param upper_range: Higher range of the saturation
108 """
109
110 self.vtk_lut.SetSaturationRange(lower_range, upper_range)
111
112 def setValue(self, lower_range, upper_range):
113 """
114 Set the upper and lower value(brightness) range.
115
116 @type lower_range: Number
117 @param lower_range: Lower range of the value
118 @type upper_range: Number
119 @param upper_range: Upper range of the value
120 """
121
122 self.vtk_lut.SetValueRange(lower_range, upper_range)
123
124 def getLut(self):
125 """
126 Return the VTK lookup table.
127
128 @rtype: vtkLookupTable
129 @return: VTK Lookup table
130 """
131
132 return self.vtk_lut
133
134 class BlueToRed(Lut):
135 """
136 Class that creates a map with spectrum from blue to red.
137 """
138
139 def __init__(self):
140 Lut.__init__(self)
141 self.setHue(0.667, 0.0)
142
143 class RedToBlue(Lut):
144 """
145 Class that creates a map with spectrum from red to blue.
146 """
147
148 def __init__(self):
149 Lut.__init__(self)
150 self.setHue(0.0, 0.667)
151
152
153

  ViewVC Help
Powered by ViewVC 1.1.26