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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1153 - (hide annotations)
Thu May 17 06:33:54 2007 UTC (13 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 2856 byte(s)
Made some minor modifications and fixed minor bugs. Most tests appear to pass on the Altix although there are two tests which occasionally throw an error related to memory corruption.
1 ksteube 1147 """
2     @author: John NGUI
3     """
4    
5     import vtk
6    
7     class Actor3D:
8     """
9     Class that defines a 3D actor.
10     """
11    
12 jongui 1148 def __init__(self):
13 ksteube 1147 """
14     Initialise the 3D actor.
15 jongui 1148 """
16 ksteube 1147
17 jongui 1148 self.__vtk_actor3D = vtk.vtkActor()
18    
19     def _setupActor3D(self, mapper):
20     """
21     Setup the 3D actor.
22    
23 ksteube 1147 @type mapper: vtkDataSetMapper
24     @param mapper: Mapped data
25     """
26    
27     self.__mapper = mapper
28     self.__setMapper()
29 jongui 1148
30 ksteube 1147 def __setMapper(self):
31     """
32     Set the mapper of the 3D actor.
33     """
34    
35     self.__vtk_actor3D.SetMapper(self.__mapper)
36    
37     def _setTexture(self, texture):
38     """
39     Set the texture of the 3D actor.
40    
41     @type texture: vtkTexture
42     @param texture: Texture of the rendered object
43     """
44    
45     self.__vtk_actor3D.SetTexture(texture)
46    
47     def setOpacity(self, opacity):
48     """
49     Set the opacity (transparency) of the 3D actor.
50    
51     @type opacity: Number (between 0 and 1)
52     @param opacity: Opacity (transparency) of the 3D actor
53     """
54    
55     self.__vtk_actor3D.GetProperty().SetOpacity(opacity)
56    
57     def setColor(self, color):
58     """
59     Set the color of the 3D actor.
60    
61     @type color: L{Color <constant.Color>} constant
62     @param color: Color of the 3D actor
63     """
64    
65     # NOTE: Must be used before actor.GetProperty().SetColor()
66     # in order for the change of color to take effect.
67     self.__mapper.ScalarVisibilityOff()
68    
69     self.__vtk_actor3D.GetProperty().SetColor(color)
70    
71     def setRepresentationToWireframe(self):
72     """
73     Set the representation of the 3D actor to Wireframe.
74     """
75    
76     self.__vtk_actor3D.GetProperty().SetRepresentationToWireframe()
77    
78     def _setLineWidth(self, line_width):
79     """
80     Set the line width of the 3D actor.
81    
82     @type line_width: Number
83     @param line_width: 3D actor line width
84     """
85    
86     self.__vtk_actor3D.GetProperty().SetLineWidth(line_width)
87    
88     def _getActor3D(self):
89     """
90     Return the 3D actor.
91    
92     @rtype: vtkActor
93     @return: 3D actor
94     """
95    
96     return self.__vtk_actor3D
97    
98    
99     ###############################################################################
100    
101    
102     class Actor2D:
103     """
104     Class that defines a 2D actor.
105     """
106    
107 jongui 1148 def __init__(self):
108 ksteube 1147 """
109     Initialise the 2D actor.
110 jongui 1148 """
111 ksteube 1147
112 jongui 1148 self._vtk_actor2D = vtk.vtkActor2D()
113    
114     def _setupActor2D(self, mapper):
115     """
116     Setup the 2D actor.
117    
118 ksteube 1147 @type mapper: vtkMapper2D
119     @param mapper: Mapped data
120     """
121    
122     self.__mapper = mapper
123     self.__setMapper()
124    
125     def __setMapper(self):
126     """
127     Set the mapper for the 2D actor.
128     """
129    
130     self._vtk_actor2D.SetMapper(self.__mapper)
131    
132     def setPosition(self, position):
133     """
134     Set the position (XY) of the 2D actor. Default position is the lower
135     left hand corner of the window / viewport.
136    
137     @type position: L{LocalPosition <position.LocalPosition>} object
138     @param position: Position of the 2D actor
139     """
140    
141     self._vtk_actor2D.SetPosition(position._getLocalPosition())
142    
143     def _getActor2D(self):
144     """
145     Return the 2D actor.
146    
147     @rtype: vtkActor2D
148     @return 2D actor
149     """
150    
151     return self._vtk_actor2D
152    

  ViewVC Help
Powered by ViewVC 1.1.26