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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1189 - (show annotations)
Thu Jun 7 05:31:25 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 4443 byte(s)
A Scalar Bar can now be displayed by creating an instance of a 'Legend'. The Scalar Bar can either show the scalar data range or vector data range. Corresponding examples and tests have also been added.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class DataSetMapper:
8 """
9 Class that defines a data set mapper.
10 """
11
12 def __init__(self):
13 """
14 Initialise the data set mapper.
15 """
16
17 self.__vtk_data_set_mapper = vtk.vtkDataSetMapper()
18 # Keeps track whether the scalar range has been specified
19 # by the user.
20 self.__scalar_range_set = False
21
22 # 'lookup_table = None' is used only by the Outline and ScalarBar.
23 def _setupDataSetMapper(self, object, lookup_table = None):
24 """
25 Setup the data set mapper.
26
27 @type object: vtkDataSet (i.e. vtkUnstructuredGrid, vtkPolyData, etc)
28 @param object: Data source map
29 @type lookup_table: vtkLookupTable
30 @param lookup_table: Maps scalar values to colors
31 """
32
33 self.__object = object
34 self.__setInput()
35
36 if(lookup_table != None): # False for the outline.
37 self.__setLookupTable(lookup_table)
38
39 def __setInput(self):
40 """
41 Set the input for the data set mapper.
42 """
43
44 self.__vtk_data_set_mapper.SetInput(self.__object)
45
46 def __setLookupTable(self, lookup_table):
47 """
48 Set the lookup table for the data set mapper.
49
50 @type lookup_table: vtkLookupTable
51 @param lookup_table: Map scalar values to colors
52 """
53
54 self.__vtk_data_set_mapper.SetLookupTable(lookup_table)
55
56 def setScalarRange(self, lower_range, upper_range):
57 """
58 Set the minimum and maximium scalar range for the data set mapper. This
59 method is called when the range has been specified by the user.
60 Therefore, the scalar range read from the source will be ignored.
61
62 @type lower_range: Lower range of scalar value
63 @param lower_range: Number
64 @type upper_range: Upper range of scalar value
65 @param upper_range: Number
66 """
67
68 self.__scalar_range_set = True
69 self.__vtk_data_set_mapper.SetScalarRange(lower_range, upper_range)
70
71 def _setScalarRange(self, range):
72 """
73 Set the minimum and maximum scalar range for the data set mapper. This
74 method is called when the range has NOT been specified by the user.
75 Therefore, the scalar range read from the source will be used instead.
76
77 @type range: Two column tuple containing numbers
78 @param range: Minimum and maximum data set mapper scalar range
79 """
80
81 self.__vtk_data_set_mapper.SetScalarRange(range)
82
83 def _setScalarVisibilityOn(self):
84 """
85 Scalar data is used to color the rendered object.
86 """
87
88 self.__vtk_data_set_mapper.ScalarVisibilityOn()
89
90 def _getDataSetMapper(self):
91 """
92 Return the data set mapper.
93
94 @rtype: vtkDataSetMapper
95 @return: Data set mapper
96 """
97
98 return self.__vtk_data_set_mapper
99
100 def _getDataSetMapperLookupTable(self):
101 """
102 Return the data set mapper's lookup table.
103
104 @rtype: vtkScalarsToColors
105 @return: Converts scalar data to colors
106 """
107
108 return self.__vtk_data_set_mapper.GetLookupTable()
109
110 def _isScalarRangeSet(self):
111 """
112 Return whether the data set mapper's scalar range has been specified \
113 by the user.
114
115 @rtype: Boolean
116 @return: True or False
117 """
118
119 return self.__scalar_range_set
120
121 def _getDataSetMapperRange(self):
122 """
123 Return the mapper's scalar range.
124
125 @rtype: Two column tuple containing numbers
126 @return: Minimum and maximum data set mapper scalar range
127 """
128
129 return self.__vtk_data_set_mapper.GetScalarRange()
130
131
132 ###############################################################################
133
134
135 class ImageMapper:
136 """
137 Class that defines a image mapper.
138 """
139
140 def __init__(self):
141 """
142 Initialise the image mapper.
143 """
144
145 self.__vtk_image_mapper = vtk.vtkImageMapper()
146
147 def _setupImageMapper(self, object):
148 """
149 Setup the image mapper.
150
151 @type object: vtkImageData
152 @param object: Image data
153 """
154
155 self.__object = object
156 self.__setInput()
157 # Both color window and color level needs to be set, otherwise only
158 # a black image will be produced. Both values were obtained from
159 # an example found on the VTK site.
160 self.__setColorWindow(255)
161 self.__setColorLevel(127.5)
162
163 def __setInput(self):
164 """
165 Set the input for the image mapper.
166 """
167
168 self.__vtk_image_mapper.SetInput(self.__object)
169
170 def __setColorWindow(self, color):
171 """
172 Set the color of the window.
173 """
174
175 self.__vtk_image_mapper.SetColorWindow(color)
176
177 def __setColorLevel(self, color):
178 """
179 Set the color level of the window.
180 """
181
182 self.__vtk_image_mapper.SetColorLevel(color)
183
184 def _getImageMapper(self):
185 """
186 Return the image mapper.
187
188 @rtype: vtkImageMapper
189 @return: Image mapper
190 """
191
192 return self.__vtk_image_mapper
193

  ViewVC Help
Powered by ViewVC 1.1.26