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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1197 - (hide annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 5048 byte(s)
Update the way movies are generated. Please refer to the examples. 

The user can now either specify the image range(first and last images inclusive):
mov.imageRange(input_directory = PYVISI_EXAMPLE_IMAGES_PATH,
        first_image = IMAGE_NAME + "000938.jpg",
		last_image = IMAGE_NAME + "000948.jpg")
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))

or the user can specify a list of images:

lst = ['image1.jpg', 'image5.jpg', 'image7.jpg]
mov.imageList(input_directory = PYVISI_EXAMPLE_IMAGES_PATH, image_list = lst)
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))


1 ksteube 1147 """
2 jongui 1197 @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 ksteube 1147 """
9    
10 jongui 1197 __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 ksteube 1147 import vtk
22    
23     class DataSetMapper:
24     """
25     Class that defines a data set mapper.
26     """
27    
28 jongui 1148 def __init__(self):
29 ksteube 1147 """
30     Initialise the data set mapper.
31 jongui 1148 """
32 ksteube 1147
33 jongui 1148 self.__vtk_data_set_mapper = vtk.vtkDataSetMapper()
34 jongui 1189 # Keeps track whether the scalar range has been specified
35     # by the user.
36     self.__scalar_range_set = False
37 jongui 1148
38 jongui 1189 # 'lookup_table = None' is used only by the Outline and ScalarBar.
39 jongui 1148 def _setupDataSetMapper(self, object, lookup_table = None):
40     """
41     Setup the data set mapper.
42    
43 ksteube 1147 @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 jongui 1189 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 ksteube 1147 def _setScalarRange(self, range):
88     """
89 jongui 1189 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 ksteube 1147
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 jongui 1189
116     def _getDataSetMapperLookupTable(self):
117     """
118     Return the data set mapper's lookup table.
119 ksteube 1147
120 jongui 1189 @rtype: vtkScalarsToColors
121     @return: Converts scalar data to colors
122     """
123 ksteube 1147
124 jongui 1189 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 data set mapper scalar range
143     """
144    
145     return self.__vtk_data_set_mapper.GetScalarRange()
146    
147    
148 ksteube 1147 ###############################################################################
149    
150    
151     class ImageMapper:
152     """
153     Class that defines a image mapper.
154     """
155    
156 jongui 1148 def __init__(self):
157 ksteube 1147 """
158     Initialise the image mapper.
159     """
160    
161     self.__vtk_image_mapper = vtk.vtkImageMapper()
162    
163 jongui 1148 def _setupImageMapper(self, object):
164 ksteube 1147 """
165     Setup the image mapper.
166 jongui 1148
167     @type object: vtkImageData
168     @param object: Image data
169 ksteube 1147 """
170    
171 jongui 1148 self.__object = object
172 ksteube 1147 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 jongui 1189

  ViewVC Help
Powered by ViewVC 1.1.26