/[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 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 3967 byte(s)
Change __url__ to launchpad site

1
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__="https://launchpad.net/escript-finley"
21
22 """
23 @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 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33 import vtk
34 from esys.escript import getMPISizeWorld
35
36 class LookupTable:
37 """
38 Class that defines a lookup table for mapping scalar values into colors.
39 """
40
41 def __init__(self):
42 """
43 Initialise the lookup table.
44 """
45 if getMPISizeWorld()>1:
46 raise ValueError,"pyvisi.LookupTable is not running on more than one processor."
47
48 self.__vtk_lookup_table = vtk.vtkLookupTable()
49 self.__vtk_inverse_lookup_table = vtk.vtkLookupTable()
50 self.__build()
51
52 def __build(self):
53 """
54 Generates the lookup table.
55 """
56
57 # NOTE: Build have to be executed prior to using SetTableValue (if any).
58 self.__vtk_lookup_table.Build()
59 self.__vtk_inverse_lookup_table.Build()
60
61 def _setTableValue(self):
62 """
63 Setup the lookup table with colors.
64 """
65
66 # NOTE: The color values are inversed because VTK's default lookup
67 # table is inversed by itself. SetTableValue have to be executed after
68 # the Build.
69 for i in range(256):
70 self.__vtk_lookup_table.SetTableValue(
71 i, self.__vtk_inverse_lookup_table.GetTableValue(255 - i))
72
73 def _setLookupTableToGreyScale(self):
74 """
75 Setup the lookup table with grey scale.
76 """
77
78 self.__setHueRange(0,0)
79 self.__setSaturationRange(0,0)
80 self.__setValueRange(1,0)
81 self.__setNumberOfTableValues(256)
82 self.__setRampToSQRT()
83
84 def __setValueRange(self, lower_range, upper_range):
85 """
86 Set the value range (brightness) for the lookup table (between 0 and 1).
87
88 @type lower_range: Number
89 @param lower_range:Lower value range
90 @type upper_range: Number
91 @param upper_range: Upper value range
92 """
93
94 self.__vtk_lookup_table.SetValueRange(lower_range, upper_range)
95
96 def __setHueRange(self, lower_range, upper_range):
97 """
98 Set the hue (color) range for the lookup table (between 0 and 1).
99
100 @type lower_range: Number
101 @param lower_range:Lower hue range
102 @type upper_range: Number
103 @param upper_range: Upper hue range
104 """
105
106 self.__vtk_lookup_table.SetHueRange(lower_range, upper_range)
107
108 def __setSaturationRange(self, lower_range, upper_range):
109 """
110 Set the saturation (vibrancy) range for the lookup table \
111 (between 0 and 1).
112
113 @type lower_range: Number
114 @param lower_range:Lower saturantion range
115 @type upper_range: Number
116 @param upper_range: Upper saturation range
117 """
118
119 self.__vtk_lookup_table.SetSaturationRange(lower_range, upper_range)
120
121 def __setRampToSQRT(self):
122 """
123 Set the table ramp to SQRT. The default ramp is S-curve.
124 """
125
126 self.__vtk_lookup_table.SetRampToSQRT()
127
128 def __setNumberOfTableValues(self, table_values):
129 """
130 Set the number of values (i.e. colors) in the lookup table.
131
132 @type table_values: Number
133 @param table_values: Number of colors in the lookup table.
134 """
135
136 self.__vtk_lookup_table.SetNumberOfTableValues(table_values)
137
138 def _getLookupTable(self):
139 """
140 Return the lookup table.
141
142 @rtype: vtkLookupTable
143 @return: Lookup table
144 """
145
146 return self.__vtk_lookup_table
147
148
149

  ViewVC Help
Powered by ViewVC 1.1.26