/[escript]/tags/trunk_2172_checkpoint/pyvisi/py_src/lookuptable.py
ViewVC logotype

Annotation of /tags/trunk_2172_checkpoint/pyvisi/py_src/lookuptable.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2174 - (hide annotations)
Wed Dec 17 09:21:26 2008 UTC (12 years, 4 months ago) by phornby
Original Path: tags/trunk_at_2172_checkpoint/pyvisi/py_src/lookuptable.py
File MIME type: text/x-python
File size: 3789 byte(s)
Conform to previous naming convention.
1 ksteube 1809
2     ########################################################
3     #
4     # Copyright (c) 2003-2008 by University of Queensland
5     # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14     __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15     Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20     __url__="http://www.uq.edu.au/esscc/escript-finley"
21    
22 ksteube 1147 """
23 jongui 1197 @var __author__: name of author
24     @var __copyright__: copyrights
25     @var __license__: licence agreement
26     @var __url__: url entry point on documentation
27     @var __version__: version
28     @var __date__: date of the version
29 ksteube 1147 """
30    
31 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
32    
33 ksteube 1147 import vtk
34    
35     class LookupTable:
36     """
37     Class that defines a lookup table for mapping scalar values into colors.
38     """
39    
40     def __init__(self):
41     """
42     Initialise the lookup table.
43     """
44    
45     self.__vtk_lookup_table = vtk.vtkLookupTable()
46     self.__vtk_inverse_lookup_table = vtk.vtkLookupTable()
47     self.__build()
48    
49     def __build(self):
50     """
51     Generates the lookup table.
52     """
53    
54     # NOTE: Build have to be executed prior to using SetTableValue (if any).
55     self.__vtk_lookup_table.Build()
56     self.__vtk_inverse_lookup_table.Build()
57    
58     def _setTableValue(self):
59     """
60     Setup the lookup table with colors.
61     """
62    
63     # NOTE: The color values are inversed because VTK's default lookup
64     # table is inversed by itself. SetTableValue have to be executed after
65     # the Build.
66     for i in range(256):
67     self.__vtk_lookup_table.SetTableValue(
68     i, self.__vtk_inverse_lookup_table.GetTableValue(255 - i))
69    
70     def _setLookupTableToGreyScale(self):
71     """
72     Setup the lookup table with grey scale.
73     """
74    
75     self.__setHueRange(0,0)
76     self.__setSaturationRange(0,0)
77     self.__setValueRange(1,0)
78     self.__setNumberOfTableValues(256)
79     self.__setRampToSQRT()
80    
81     def __setValueRange(self, lower_range, upper_range):
82     """
83     Set the value range (brightness) for the lookup table (between 0 and 1).
84    
85     @type lower_range: Number
86     @param lower_range:Lower value range
87     @type upper_range: Number
88     @param upper_range: Upper value range
89     """
90    
91     self.__vtk_lookup_table.SetValueRange(lower_range, upper_range)
92    
93     def __setHueRange(self, lower_range, upper_range):
94     """
95     Set the hue (color) range for the lookup table (between 0 and 1).
96    
97     @type lower_range: Number
98     @param lower_range:Lower hue range
99     @type upper_range: Number
100     @param upper_range: Upper hue range
101     """
102    
103     self.__vtk_lookup_table.SetHueRange(lower_range, upper_range)
104    
105     def __setSaturationRange(self, lower_range, upper_range):
106     """
107     Set the saturation (vibrancy) range for the lookup table \
108     (between 0 and 1).
109    
110     @type lower_range: Number
111     @param lower_range:Lower saturantion range
112     @type upper_range: Number
113     @param upper_range: Upper saturation range
114     """
115    
116     self.__vtk_lookup_table.SetSaturationRange(lower_range, upper_range)
117    
118     def __setRampToSQRT(self):
119     """
120     Set the table ramp to SQRT. The default ramp is S-curve.
121     """
122    
123     self.__vtk_lookup_table.SetRampToSQRT()
124    
125     def __setNumberOfTableValues(self, table_values):
126     """
127     Set the number of values (i.e. colors) in the lookup table.
128    
129     @type table_values: Number
130     @param table_values: Number of colors in the lookup table.
131     """
132    
133     self.__vtk_lookup_table.SetNumberOfTableValues(table_values)
134    
135     def _getLookupTable(self):
136     """
137 jongui 1148 Return the lookup table.
138    
139 ksteube 1147 @rtype: vtkLookupTable
140     @return: Lookup table
141     """
142    
143     return self.__vtk_lookup_table
144 jongui 1189
145 ksteube 1147
146    

  ViewVC Help
Powered by ViewVC 1.1.26