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

Contents of /tags/trunk_2172_checkpoint/pyvisi/py_src/mapper.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2175 - (show annotations)
Wed Dec 17 09:22:40 2008 UTC (12 years, 2 months ago) by phornby
File MIME type: text/x-python
File size: 5475 byte(s)
Try again at conforming to naming convention.
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__="http://www.uq.edu.au/esscc/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
35 class DataSetMapper:
36 """
37 Class that defines a data set mapper.
38 """
39
40 def __init__(self):
41 """
42 Initialise the data set mapper.
43 """
44
45 self.__vtk_data_set_mapper = vtk.vtkDataSetMapper()
46 # Keeps track whether the scalar range has been specified
47 # by the user.
48 self.__scalar_range_set = False
49
50 # 'lookup_table = None' is used only by the Outline.
51 def _setupDataSetMapper(self, object, lookup_table = None):
52 """
53 Setup the data set mapper.
54
55 @type object: vtkDataSet (i.e. vtkUnstructuredGrid, vtkPolyData, etc)
56 @param object: Data source map
57 @type lookup_table: vtkLookupTable
58 @param lookup_table: Maps scalar values to colors
59 """
60
61 self.__object = object
62 self.__setInput()
63
64 if(lookup_table != None): # False for the outline.
65 self.__setLookupTable(lookup_table)
66
67 def __setInput(self):
68 """
69 Set the input for the data set mapper.
70 """
71
72 self.__vtk_data_set_mapper.SetInput(self.__object)
73
74 def __setLookupTable(self, lookup_table):
75 """
76 Set the lookup table for the data set mapper.
77
78 @type lookup_table: vtkLookupTable
79 @param lookup_table: Map scalar values to colors
80 """
81
82 self.__vtk_data_set_mapper.SetLookupTable(lookup_table)
83
84 def setScalarRange(self, lower_range, upper_range):
85 """
86 Set the minimum and maximium scalar range for the data set mapper. This
87 method is called when the range has been specified by the user.
88 Therefore, the scalar range read from the source will be ignored.
89
90 @type lower_range: Lower range of scalar value
91 @param lower_range: Number
92 @type upper_range: Upper range of scalar value
93 @param upper_range: Number
94 """
95
96 self.__scalar_range_set = True
97 self.__vtk_data_set_mapper.SetScalarRange(lower_range, upper_range)
98
99 def _setScalarRange(self, range):
100 """
101 Set the minimum and maximum scalar range for the data set mapper. This
102 method is called when the range has NOT been specified by the user.
103 Therefore, the scalar range read from the source will be used instead.
104
105 @type range: Two column tuple containing numbers
106 @param range: Minimum and maximum data set mapper scalar range
107 """
108 self.__scalar_range_set = True
109 self.__vtk_data_set_mapper.SetScalarRange(range)
110
111 def _setScalarVisibilityOn(self):
112 """
113 Scalar data is used to color the rendered object.
114 """
115
116 self.__vtk_data_set_mapper.ScalarVisibilityOn()
117
118 def _getDataSetMapper(self):
119 """
120 Return the data set mapper.
121
122 @rtype: vtkDataSetMapper
123 @return: Data set mapper
124 """
125
126 return self.__vtk_data_set_mapper
127
128 def _getDataSetMapperLookupTable(self):
129 """
130 Return the data set mapper's lookup table.
131
132 @rtype: vtkScalarsToColors
133 @return: Converts scalar data to colors
134 """
135
136 return self.__vtk_data_set_mapper.GetLookupTable()
137
138 def _isScalarRangeSet(self):
139 """
140 Return whether the data set mapper's scalar range has been specified \
141 by the user.
142
143 @rtype: Boolean
144 @return: True or False
145 """
146
147 return self.__scalar_range_set
148
149 def _getDataSetMapperRange(self):
150 """
151 Return the mapper's scalar range.
152
153 @rtype: Two column tuple containing numbers
154 @return: Minimum and maximum range of the data set mapper's scalar range
155 """
156
157 return self.__vtk_data_set_mapper.GetScalarRange()
158
159
160 ###############################################################################
161
162
163 class ImageMapper:
164 """
165 Class that defines an image mapper.
166 """
167
168 def __init__(self):
169 """
170 Initialise the image mapper.
171 """
172
173 self.__vtk_image_mapper = vtk.vtkImageMapper()
174
175 def _setupImageMapper(self, object):
176 """
177 Setup the image mapper.
178
179 @type object: vtkImageData
180 @param object: Image data
181 """
182
183 self.__object = object
184 self.__setInput()
185 # Both color window and color level needs to be set, otherwise only
186 # a black image will be produced. Both values were obtained from
187 # an example found on the VTK site.
188 self.__setColorWindow(255)
189 self.__setColorLevel(127.5)
190
191 def __setInput(self):
192 """
193 Set the input for the image mapper.
194 """
195
196 self.__vtk_image_mapper.SetInput(self.__object)
197
198 def __setColorWindow(self, color):
199 """
200 Set the color of the window.
201 """
202
203 self.__vtk_image_mapper.SetColorWindow(color)
204
205 def __setColorLevel(self, color):
206 """
207 Set the color level of the window.
208 """
209
210 self.__vtk_image_mapper.SetColorLevel(color)
211
212 def _getImageMapper(self):
213 """
214 Return the image mapper.
215
216 @rtype: vtkImageMapper
217 @return: Image mapper
218 """
219
220 return self.__vtk_image_mapper
221

  ViewVC Help
Powered by ViewVC 1.1.26