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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 943 - (show annotations)
Mon Jan 29 07:22:43 2007 UTC (14 years, 1 month ago) by jongui
File MIME type: text/x-python
File size: 2845 byte(s)
new pyvisi files
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class LookupTable:
8 """
9 Class that defines a lookup table for mapping scalar values into colors.
10 """
11
12 def __init__(self):
13 """
14 Initialise the lookup table.
15 """
16
17 self.__vtk_lookup_table = vtk.vtkLookupTable()
18 self.__vtk_inverse_lookup_table = vtk.vtkLookupTable()
19 self.__build()
20 #self._setTableValue()
21
22 def __build(self):
23 """
24 Generates the lookup table.
25 """
26
27 # NOTE: Build have to be executed prior to using SetTableValue.
28 self.__vtk_lookup_table.Build()
29 self.__vtk_inverse_lookup_table.Build()
30
31 def _setTableValue(self):
32 """
33 Setup the lookup table with colors.
34 """
35
36 # NOTE: The color values are inversed because VTK's default lookup
37 # table is inversed by itself. SetTableValue have to be executed after
38 # the Build.
39 for i in range(256):
40 self.__vtk_lookup_table.SetTableValue(
41 i, self.__vtk_inverse_lookup_table.GetTableValue(255 - i))
42
43 def _setLookupTableToGreyScale(self):
44 """
45 Setup the lookup table with grey scale.
46 """
47
48 #self.__vtk_lookup_table = vtk.vtkLookupTable()
49 self.__setHueRange(0,0)
50 self.__setSaturationRange(0,0)
51 self.__setValueRange(1,0)
52 self.__setNumberOfTableValues(256)
53 self.__setRampToSQRT()
54 #self.__vtk_lookup_table.Build()
55
56 def __setValueRange(self, lower_range, upper_range):
57 """
58 Set value range (brighness) for the lookup table (between 0 and 1).
59
60 @type lower_range: Number
61 @param lower_range:Lower value range
62 @type upper_range: Number
63 @param upper_range: Upper value range
64 """
65
66 self.__vtk_lookup_table.SetValueRange(lower_range, upper_range)
67
68 def __setHueRange(self, lower_range, upper_range):
69 """
70 Set hue (color) range for the lookup table (between 0 and 1).
71
72 @type lower_range: Number
73 @param lower_range:Lower hue range
74 @type upper_range: Number
75 @param upper_range: Upper hue range
76 """
77
78 self.__vtk_lookup_table.SetHueRange(lower_range, upper_range)
79
80 def __setSaturationRange(self, lower_range, upper_range):
81 """
82 Set saturation (vibrancy) range for the lookup table (between 0 and 1).
83
84 @type lower_range: Number
85 @param lower_range:Lower saturantion range
86 @type upper_range: Number
87 @param upper_range: Upper saturation range
88 """
89
90 self.__vtk_lookup_table.SetSaturationRange(lower_range, upper_range)
91
92 def __setRampToSQRT(self):
93 """
94 Set the table ramp to SQRT. The default ramp is S-curve.
95 """
96
97 self.__vtk_lookup_table.SetRampToSQRT()
98
99 def __setNumberOfTableValues(self, table_values):
100 """
101 Set the number of values (i.e. colors) in the lookup table.
102
103 @type table_values: Number
104 @param table_values: Number of values in the lookup table.
105 """
106
107 self.__vtk_lookup_table.SetNumberOfTableValues(table_values)
108
109 def _getLookupTable(self):
110 """
111 @rtype: vtkLookupTable
112 @return: Lookup table
113 """
114
115 return self.__vtk_lookup_table
116
117

  ViewVC Help
Powered by ViewVC 1.1.26