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

  ViewVC Help
Powered by ViewVC 1.1.26