/[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 1148 - (hide annotations)
Wed May 16 22:45:33 2007 UTC (13 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 2941 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
1 ksteube 1147 """
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 jongui 1148 # 'lookup_table = None' is used only by the Outline.
13     def __init__(self):
14 ksteube 1147 """
15     Initialise the data set mapper.
16 jongui 1148 """
17 ksteube 1147
18 jongui 1148 self.__vtk_data_set_mapper = vtk.vtkDataSetMapper()
19    
20     def _setupDataSetMapper(self, object, lookup_table = None):
21     """
22     Setup the data set mapper.
23    
24 ksteube 1147 @type object: vtkDataSet (i.e. vtkUnstructuredGrid, vtkPolyData, etc)
25     @param object: Data source map
26     @type lookup_table: vtkLookupTable
27     @param lookup_table: Maps scalar values to colors
28     """
29    
30     self.__object = object
31     self.__setInput()
32    
33     if(lookup_table != None): # False for the outline.
34     self.__setLookupTable(lookup_table)
35    
36     def __setInput(self):
37     """
38     Set the input for the data set mapper.
39     """
40    
41     self.__vtk_data_set_mapper.SetInput(self.__object)
42    
43     def __setLookupTable(self, lookup_table):
44     """
45     Set the lookup table for the data set mapper.
46    
47     @type lookup_table: vtkLookupTable
48     @param lookup_table: Map scalar values to colors
49     """
50    
51     self.__vtk_data_set_mapper.SetLookupTable(lookup_table)
52    
53     def _setScalarRange(self, range):
54     """
55     Set the minimum and maximum scalar range for the data set mapper.
56    
57     @type range: Two column tuple containing numbers
58     @param range: Minimum and maximum data set mapper scalar range
59     """
60    
61     self.__vtk_data_set_mapper.SetScalarRange(range)
62    
63     def _setScalarVisibilityOn(self):
64     """
65     Scalar data is used to color the rendered object.
66     """
67    
68     self.__vtk_data_set_mapper.ScalarVisibilityOn()
69    
70     def _getDataSetMapper(self):
71     """
72     Return the data set mapper.
73    
74     @rtype: vtkDataSetMapper
75     @return: Data set mapper
76     """
77    
78     return self.__vtk_data_set_mapper
79    
80    
81     ###############################################################################
82    
83    
84     class ImageMapper:
85     """
86     Class that defines a image mapper.
87     """
88    
89 jongui 1148 def __init__(self):
90 ksteube 1147 """
91     Initialise the image mapper.
92     """
93    
94     self.__vtk_image_mapper = vtk.vtkImageMapper()
95    
96 jongui 1148 def _setupImageMapper(self, object):
97 ksteube 1147 """
98     Setup the image mapper.
99 jongui 1148
100     @type object: vtkImageData
101     @param object: Image data
102 ksteube 1147 """
103    
104 jongui 1148 self.__object = object
105 ksteube 1147 self.__setInput()
106     # Both color window and color level needs to be set, otherwise only
107     # a black image will be produced. Both values were obtained from
108     # an example found on the VTK site.
109     self.__setColorWindow(255)
110     self.__setColorLevel(127.5)
111    
112     def __setInput(self):
113     """
114     Set the input for the image mapper.
115     """
116    
117     self.__vtk_image_mapper.SetInput(self.__object)
118    
119     def __setColorWindow(self, color):
120     """
121     Set the color of the window.
122     """
123    
124     self.__vtk_image_mapper.SetColorWindow(color)
125    
126     def __setColorLevel(self, color):
127     """
128     Set the color level of the window.
129     """
130    
131     self.__vtk_image_mapper.SetColorLevel(color)
132    
133     def _getImageMapper(self):
134     """
135     Return the image mapper.
136    
137     @rtype: vtkImageMapper
138     @return: Image mapper
139     """
140    
141     return self.__vtk_image_mapper

  ViewVC Help
Powered by ViewVC 1.1.26