/[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 1147 - (show annotations)
Wed May 16 06:39:11 2007 UTC (12 years, 2 months ago) by ksteube
File MIME type: text/x-python
File size: 2761 byte(s)
Added back in some files that were accidentally deleted.

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
21 def __build(self):
22 """
23 Generates the lookup table.
24 """
25
26 # NOTE: Build have to be executed prior to using SetTableValue (if any).
27 self.__vtk_lookup_table.Build()
28 self.__vtk_inverse_lookup_table.Build()
29
30 def _setTableValue(self):
31 """
32 Setup the lookup table with colors.
33 """
34
35 # NOTE: The color values are inversed because VTK's default lookup
36 # table is inversed by itself. SetTableValue have to be executed after
37 # the Build.
38 for i in range(256):
39 self.__vtk_lookup_table.SetTableValue(
40 i, self.__vtk_inverse_lookup_table.GetTableValue(255 - i))
41
42 def _setLookupTableToGreyScale(self):
43 """
44 Setup the lookup table with grey scale.
45 """
46
47 self.__setHueRange(0,0)
48 self.__setSaturationRange(0,0)
49 self.__setValueRange(1,0)
50 self.__setNumberOfTableValues(256)
51 self.__setRampToSQRT()
52
53 def __setValueRange(self, lower_range, upper_range):
54 """
55 Set the value range (brightness) for the lookup table (between 0 and 1).
56
57 @type lower_range: Number
58 @param lower_range:Lower value range
59 @type upper_range: Number
60 @param upper_range: Upper value range
61 """
62
63 self.__vtk_lookup_table.SetValueRange(lower_range, upper_range)
64
65 def __setHueRange(self, lower_range, upper_range):
66 """
67 Set the hue (color) range for the lookup table (between 0 and 1).
68
69 @type lower_range: Number
70 @param lower_range:Lower hue range
71 @type upper_range: Number
72 @param upper_range: Upper hue range
73 """
74
75 self.__vtk_lookup_table.SetHueRange(lower_range, upper_range)
76
77 def __setSaturationRange(self, lower_range, upper_range):
78 """
79 Set the saturation (vibrancy) range for the lookup table \
80 (between 0 and 1).
81
82 @type lower_range: Number
83 @param lower_range:Lower saturantion range
84 @type upper_range: Number
85 @param upper_range: Upper saturation range
86 """
87
88 self.__vtk_lookup_table.SetSaturationRange(lower_range, upper_range)
89
90 def __setRampToSQRT(self):
91 """
92 Set the table ramp to SQRT. The default ramp is S-curve.
93 """
94
95 self.__vtk_lookup_table.SetRampToSQRT()
96
97 def __setNumberOfTableValues(self, table_values):
98 """
99 Set the number of values (i.e. colors) in the lookup table.
100
101 @type table_values: Number
102 @param table_values: Number of colors in the lookup table.
103 """
104
105 self.__vtk_lookup_table.SetNumberOfTableValues(table_values)
106
107 def _getLookupTable(self):
108 """
109 @rtype: vtkLookupTable
110 @return: Lookup table
111 """
112
113 return self.__vtk_lookup_table
114
115

  ViewVC Help
Powered by ViewVC 1.1.26