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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 839 - (hide annotations)
Wed Sep 6 04:53:50 2006 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 4068 byte(s)
- Added lookup table spectrum from blue to red and red to blue.
- Updated open scene to scene

1 gross 792 """
2 jongui 839 @var RED: Constant representing red
3     @type RED: RGB color
4     @var GREEN: Constant representing green
5     @type GREEN: RGB color
6     @var BLUE: Constant representing blue
7     @type BLUE: RGB color
8     @var BLACK: Constant representing black
9     @type BLACK: RBG color
10     @var WHITE: Constant representing white
11     @type WHITE: RGB color
12     @var YELLOW: Constant representing yellow
13     @type YELLOW: RGB color
14     @var PINK: Constant represnting pink
15     @type PINK: RGB color
16     @var ORANGE: Constant representing orange
17     @type ORANGE: RGB color
18     @var PURPLE: Constant representing purple
19     @type PURPLE: RGB color
20     @var GREY: Constant representing grey
21     @type GREY: RGB color
22     @var BROWN: Constant representing brown
23     @type BROWN: RGB color
24    
25     @author: John Ngui
26     @author: Lutz Gross
27 gross 792 """
28    
29 jongui 833 class ColorMap:
30 jongui 837 """
31 jongui 839 Class that defines the mapping of colors.
32 jongui 837 """
33 gross 792
34 jongui 837 def __init__(self, color_name):
35     """
36     @type color_name: String
37     @param color_name: Name of the color
38     """
39    
40     self.color_name = color_name
41     self.colorMap = {}
42     self.buildColorMap()
43    
44     def buildColorMap(self):
45     """
46     Build a hash that defines mapping of colors.
47     """
48    
49     self.colorMap["Red"] = [255, 0, 0]
50     self.colorMap["Green"]= [0, 255, 0]
51     self.colorMap["Blue"] = [0, 0, 255]
52     self.colorMap["Black"] = [0, 0, 0]
53     self.colorMap["White"] = [255, 255, 255]
54     self.colorMap["Yelow"] = [255, 255, 0]
55     self.colorMap["Pink"] = [255, 20, 147]
56     self.colorMap["Orange"] = [255, 69, 0]
57     self.colorMap["Purple"] = [138, 43, 226]
58     self.colorMap["Grey"] = [169, 169, 169]
59     self.colorMap["Brown"] = [139, 69, 19]
60    
61     def getR(self):
62     """
63     Return the red(R) value from the RGB.
64    
65     @rtype: Number
66     @return: Red(R) value from the RGB
67     """
68    
69     return self.colorMap[self.color_name][0]
70    
71     def getG(self):
72     """
73     Return the green(G) value from the RGB.
74    
75     @rtype: Number
76     @return: Green(R) value from the RGB
77     """
78    
79     return self.colorMap[self.color_name][1]
80    
81     def getB(self):
82     """
83     Return the blue(B) value from the RGB.
84    
85     @rtype: Number
86 jongui 839 @return: Blue(B) value from the RGB
87 jongui 837 """
88    
89     return self.colorMap[self.color_name][2]
90    
91     def getColor(self):
92     """
93     Return the name of the color.
94    
95     @rtype: String
96     @return: Name of the color
97     """
98    
99     return self.color_name
100    
101     # Constants
102     RED = ColorMap("Red")
103     GREEN = ColorMap("Green")
104     BLUE = ColorMap("Blue")
105     BLACK = ColorMap("Black")
106     WHITE = ColorMap("White")
107     YELLOW = ColorMap("Yellow")
108     PINK = ColorMap("Pink")
109     ORANGE = ColorMap("Orange")
110     PURPLE = ColorMap("Purple")
111     GREY = ColorMap("Grey")
112     BROWN = ColorMap("Brown")
113 jongui 839
114     import vtk
115    
116     class Lut:
117     """
118     Class that provides the functions to create a map spectrum.
119     """
120    
121     def __init__(self):
122     self.vtk_lut = vtk.vtkLookupTable()
123 jongui 837
124 jongui 839 def setHue(self, lower_range, upper_range):
125     """
126     Set the upper and lower hue(color) range.
127 jongui 837
128 jongui 839 @type lower_range: Number
129     @param lower_range: Lower range of the hue
130     @type upper_range: Number
131     @param upper_range: Upper range of the hue
132     """
133 gross 792
134 jongui 839 self.vtk_lut.SetHueRange(lower_range, upper_range)
135    
136     def setSaturation(self, lower_range, upper_range):
137     """
138     Set the upper and lower saturation(vibrancy) range.
139    
140     @type lower_range: Number
141     @param lower_range: Lower range of the saturation
142     @type upper_range: Number
143     @param upper_range: Higher range of the saturation
144     """
145    
146     self.vtk_lut.SetSaturationRange(lower_range, upper_range)
147    
148     def setValue(self, lower_range, upper_range):
149     """
150     Set the upper and lower value(brightness) range.
151    
152     @type lower_range: Number
153     @param lower_range: Lower range of the value
154     @type upper_range: Number
155     @param upper_range: Upper range of the value
156     """
157    
158     self.vtk_lut.SetValueRange(lower_range, upper_range)
159    
160     def getLut(self):
161     """
162     Return the VTK lookup table.
163    
164     @rtype: vtkLookupTable
165     @return: VTK Lookup table
166     """
167    
168     return self.vtk_lut
169    
170     class BlueToRed(Lut):
171     """
172     Class that creates a map with spectrum from blue to red.
173     """
174    
175     def __init__(self):
176     Lut.__init__(self)
177     self.setHue(0.667, 0.0)
178    
179     class RedToBlue(Lut):
180     """
181     Class that creates a map with spectrum from red to blue.
182     """
183    
184     def __init__(self):
185     Lut.__init__(self)
186     self.setHue(0.0, 0.667)
187    
188    
189    

  ViewVC Help
Powered by ViewVC 1.1.26