/[escript]/branches/windows_from_1456_trunk_merge_to_1459_trunk/pyvisi/py_src/mapper.py
ViewVC logotype

Contents of /branches/windows_from_1456_trunk_merge_to_1459_trunk/pyvisi/py_src/mapper.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1461 - (show annotations)
Fri Mar 28 07:51:34 2008 UTC (12 years, 11 months ago) by trankine
File MIME type: text/x-python
File size: 5050 byte(s)
get the name right
1 """
2 @var __author__: name of author
3 @var __copyright__: copyrights
4 @var __license__: licence agreement
5 @var __url__: url entry point on documentation
6 @var __version__: version
7 @var __date__: date of the version
8 """
9
10 __author__="John Ngui, john.ngui@uq.edu.au"
11 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12 http://www.access.edu.au
13 Primary Business: Queensland, Australia"""
14 __license__="""Licensed under the Open Software License version 3.0
15 http://www.opensource.org/licenses/osl-3.0.php"""
16 __url__="http://www.iservo.edu.au/esys"
17 __version__="$Revision$"
18 __date__="$Date$"
19
20
21 import vtk
22
23 class DataSetMapper:
24 """
25 Class that defines a data set mapper.
26 """
27
28 def __init__(self):
29 """
30 Initialise the data set mapper.
31 """
32
33 self.__vtk_data_set_mapper = vtk.vtkDataSetMapper()
34 # Keeps track whether the scalar range has been specified
35 # by the user.
36 self.__scalar_range_set = False
37
38 # 'lookup_table = None' is used only by the Outline.
39 def _setupDataSetMapper(self, object, lookup_table = None):
40 """
41 Setup the data set mapper.
42
43 @type object: vtkDataSet (i.e. vtkUnstructuredGrid, vtkPolyData, etc)
44 @param object: Data source map
45 @type lookup_table: vtkLookupTable
46 @param lookup_table: Maps scalar values to colors
47 """
48
49 self.__object = object
50 self.__setInput()
51
52 if(lookup_table != None): # False for the outline.
53 self.__setLookupTable(lookup_table)
54
55 def __setInput(self):
56 """
57 Set the input for the data set mapper.
58 """
59
60 self.__vtk_data_set_mapper.SetInput(self.__object)
61
62 def __setLookupTable(self, lookup_table):
63 """
64 Set the lookup table for the data set mapper.
65
66 @type lookup_table: vtkLookupTable
67 @param lookup_table: Map scalar values to colors
68 """
69
70 self.__vtk_data_set_mapper.SetLookupTable(lookup_table)
71
72 def setScalarRange(self, lower_range, upper_range):
73 """
74 Set the minimum and maximium scalar range for the data set mapper. This
75 method is called when the range has been specified by the user.
76 Therefore, the scalar range read from the source will be ignored.
77
78 @type lower_range: Lower range of scalar value
79 @param lower_range: Number
80 @type upper_range: Upper range of scalar value
81 @param upper_range: Number
82 """
83
84 self.__scalar_range_set = True
85 self.__vtk_data_set_mapper.SetScalarRange(lower_range, upper_range)
86
87 def _setScalarRange(self, range):
88 """
89 Set the minimum and maximum scalar range for the data set mapper. This
90 method is called when the range has NOT been specified by the user.
91 Therefore, the scalar range read from the source will be used instead.
92
93 @type range: Two column tuple containing numbers
94 @param range: Minimum and maximum data set mapper scalar range
95 """
96
97 self.__vtk_data_set_mapper.SetScalarRange(range)
98
99 def _setScalarVisibilityOn(self):
100 """
101 Scalar data is used to color the rendered object.
102 """
103
104 self.__vtk_data_set_mapper.ScalarVisibilityOn()
105
106 def _getDataSetMapper(self):
107 """
108 Return the data set mapper.
109
110 @rtype: vtkDataSetMapper
111 @return: Data set mapper
112 """
113
114 return self.__vtk_data_set_mapper
115
116 def _getDataSetMapperLookupTable(self):
117 """
118 Return the data set mapper's lookup table.
119
120 @rtype: vtkScalarsToColors
121 @return: Converts scalar data to colors
122 """
123
124 return self.__vtk_data_set_mapper.GetLookupTable()
125
126 def _isScalarRangeSet(self):
127 """
128 Return whether the data set mapper's scalar range has been specified \
129 by the user.
130
131 @rtype: Boolean
132 @return: True or False
133 """
134
135 return self.__scalar_range_set
136
137 def _getDataSetMapperRange(self):
138 """
139 Return the mapper's scalar range.
140
141 @rtype: Two column tuple containing numbers
142 @return: Minimum and maximum range of the data set mapper's scalar range
143 """
144
145 return self.__vtk_data_set_mapper.GetScalarRange()
146
147
148 ###############################################################################
149
150
151 class ImageMapper:
152 """
153 Class that defines an image mapper.
154 """
155
156 def __init__(self):
157 """
158 Initialise the image mapper.
159 """
160
161 self.__vtk_image_mapper = vtk.vtkImageMapper()
162
163 def _setupImageMapper(self, object):
164 """
165 Setup the image mapper.
166
167 @type object: vtkImageData
168 @param object: Image data
169 """
170
171 self.__object = object
172 self.__setInput()
173 # Both color window and color level needs to be set, otherwise only
174 # a black image will be produced. Both values were obtained from
175 # an example found on the VTK site.
176 self.__setColorWindow(255)
177 self.__setColorLevel(127.5)
178
179 def __setInput(self):
180 """
181 Set the input for the image mapper.
182 """
183
184 self.__vtk_image_mapper.SetInput(self.__object)
185
186 def __setColorWindow(self, color):
187 """
188 Set the color of the window.
189 """
190
191 self.__vtk_image_mapper.SetColorWindow(color)
192
193 def __setColorLevel(self, color):
194 """
195 Set the color level of the window.
196 """
197
198 self.__vtk_image_mapper.SetColorLevel(color)
199
200 def _getImageMapper(self):
201 """
202 Return the image mapper.
203
204 @rtype: vtkImageMapper
205 @return: Image mapper
206 """
207
208 return self.__vtk_image_mapper
209

  ViewVC Help
Powered by ViewVC 1.1.26