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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 943 - (show annotations)
Mon Jan 29 07:22:43 2007 UTC (13 years, 7 months ago) by jongui
File MIME type: text/x-python
File size: 4698 byte(s)
new pyvisi files
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class Actor3D:
8 """
9 Class that defines a 3D actor.
10 """
11
12 def __init__(self, mapper):
13 """
14 Initialise the 3D actor.
15
16 @type mapper: vtkDataSetMapper
17 @param mapper: Mapped data
18 """
19
20 self.__mapper = mapper
21 self.__vtk_actor3D = vtk.vtkActor()
22 self.__setMapper()
23
24 def __setMapper(self):
25 """
26 Set the mapper for the 3D actor.
27 """
28
29 self.__vtk_actor3D.SetMapper(self.__mapper)
30
31 def _setTexture(self, texture):
32 """
33 Set the texture for the 3D actor.
34 """
35
36 self.__vtk_actor3D.SetTexture(texture)
37
38 def setOpacity(self, opacity):
39 """
40 Set the opacity (transparency) of the 3D actor.
41
42 @type opacity: Number (between 0 and 1)
43 @param opacity: Opacity (transparency) of the 3D actor
44 """
45
46 self.__vtk_actor3D.GetProperty().SetOpacity(opacity)
47
48 def setColor(self, color):
49 """
50 Set the color of the 3D actor.
51
52 @type color: L{Color <constant.Color>} constant
53 @param color: 3D actor color
54 """
55
56 # NOTE: Must be used before actor.GetProperty().SetColor()
57 # in order for the change of color to rendered objects to take effect.
58 self.__mapper.ScalarVisibilityOff()
59
60 # NOTE: Must be used after mapper.ScalarVisibilityOff()
61 # in order for the change of color rendered objects to take effect.
62 self.__vtk_actor3D.GetProperty().SetColor(color)
63
64 def setRepresentationToWireframe(self):
65 """
66 Set the representation of the 3D actor to Wireframe.
67 """
68
69 self.__vtk_actor3D.GetProperty().SetRepresentationToWireframe()
70
71 def _setLineWidth(self, line_width):
72 """
73 Set the line width of the 3D actor.
74
75 @type line_width: Number
76 @param line_width: 3D actor line width
77 """
78
79 self.__vtk_actor3D.GetProperty().SetLineWidth(line_width)
80
81
82 def _getActor3D(self):
83 """
84 Return the 3D actor.
85
86 @rtype: vtkActor
87 @return: 3D actor
88 """
89
90 return self.__vtk_actor3D
91
92
93 ############################################################################
94
95
96
97 class Actor2D:
98 """
99 Class that defines a 2D actor.
100 """
101
102 def __init__(self, mapper):
103 """
104 Initialise the 2D actor.
105
106 @type mapper: vtkImageMapper, etc
107 @param mapper: Mapped data
108 """
109
110 self.__mapper = mapper
111 self._vtk_actor2D = vtk.vtkActor2D()
112 self.__setMapper()
113
114 def __setMapper(self):
115 """
116 Set the mapper for the 2D actor.
117 """
118
119 self._vtk_actor2D.SetMapper(self.__mapper)
120
121 def setPosition(self, position):
122 """
123 Set the position of the 2D actor. Default position is the lower left
124 hand corner.
125
126 @type position: L{LocalPosition <position.LocalPosition>} object
127 @param position: 2D actor position
128 """
129
130 self._vtk_actor2D.SetPosition(position._getLocalPosition())
131
132 def _getActor2D(self):
133 """
134 Return the 2D actor.
135
136 @rtype: vtkActor2D
137 @return 2D actor
138 """
139
140 return self._vtk_actor2D
141
142
143 class TextActor(Actor2D):
144 """
145 Class that defines a 2D text actor.
146 """
147
148 def __init__(self, text):
149 """
150 Initialise the 2D text actor.
151
152 @type text: String
153 @param text: 2D text to be displayed
154 """
155
156 self.__text = text
157 self._vtk_actor2D = vtk.vtkTextActor()
158
159 self.__setInput()
160
161 def __setInput(self):
162 """
163 Set the 2D text to be displayed.
164 """
165
166 self._vtk_actor2D.SetInput(self.__text)
167
168 def setFontSize(self, size):
169 """
170 Set the 2D text size.
171
172 @type size: Number
173 @param size: Size of the 2D text
174 """
175
176 self._vtk_actor2D.GetTextProperty().SetFontSize(size)
177
178 def setFontToTimes(self):
179 """
180 Set the 2D text font type to times new roman.
181 """
182
183 self._vtk_actor2D.GetTextProperty().SetFontFamilyToTimes()
184
185 def setFontToArial(self):
186 """
187 Set the 2D text font type to arial.
188 """
189
190 self._vtk_actor2D.GetTextProperty().SetFontFamilyToArial()
191
192 def setFontToCourier(self):
193 """
194 Set the 2D text front type to courier.
195 """
196
197 self._vtk_actor2D.GetTextProperty().SetFontFamilyToCourier()
198
199 def setJustificationToCenter(self):
200 """
201 Set the 2D text to center justification.
202 """
203
204 self._vtk_actor2D.GetTextProperty().SetJustificationToCentered()
205
206 def setJustificationToLeft(self):
207 """
208 Set the 2D text to left justification.
209 """
210
211 self._vtk_actor2D.GetTextProperty().SetJustificationToLeft()
212
213 def setJustificationToRight(self):
214 """
215 Set the 2D text to right justification.
216 """
217
218 self._vtk_actor2D.GetTextProperty().SetJustificationToRight()
219
220 def boldOn(self):
221 """
222 Bold the 2D text.
223 """
224
225 self._vtk_actor2D.GetTextProperty().BoldOn()
226
227 def shadowOn(self):
228 """
229 Apply shadow onto the 2D text to ease visibility.
230 """
231
232 self._vtk_actor2D.GetTextProperty().ShadowOn()
233
234 def setColor(self, color):
235 """
236 Set the color of the text.
237
238 @type color: L{Color <constant.Color>} constant
239 @param color: 2D text color
240 """
241
242 self._vtk_actor2D.GetTextProperty().SetColor(color)
243

  ViewVC Help
Powered by ViewVC 1.1.26