/[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 948 - (show annotations)
Thu Feb 1 07:23:34 2007 UTC (12 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 2744 byte(s)
fixed some bugs in pyvisi and added more epydocs.
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 value range (brighness) 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 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 saturation (vibrancy) range for the lookup table (between 0 and 1).
80
81 @type lower_range: Number
82 @param lower_range:Lower saturantion range
83 @type upper_range: Number
84 @param upper_range: Upper saturation range
85 """
86
87 self.__vtk_lookup_table.SetSaturationRange(lower_range, upper_range)
88
89 def __setRampToSQRT(self):
90 """
91 Set the table ramp to SQRT. The default ramp is S-curve.
92 """
93
94 self.__vtk_lookup_table.SetRampToSQRT()
95
96 def __setNumberOfTableValues(self, table_values):
97 """
98 Set the number of values (i.e. colors) in the lookup table.
99
100 @type table_values: Number
101 @param table_values: Number of values in the lookup table.
102 """
103
104 self.__vtk_lookup_table.SetNumberOfTableValues(table_values)
105
106 def _getLookupTable(self):
107 """
108 @rtype: vtkLookupTable
109 @return: Lookup table
110 """
111
112 return self.__vtk_lookup_table
113
114

  ViewVC Help
Powered by ViewVC 1.1.26