/[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 1147 - (show annotations)
Wed May 16 06:39:11 2007 UTC (12 years, 1 month ago) by ksteube
File MIME type: text/x-python
File size: 2841 byte(s)
Added back in some files that were accidentally deleted.

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 of the 3D actor.
27 """
28
29 self.__vtk_actor3D.SetMapper(self.__mapper)
30
31 def _setTexture(self, texture):
32 """
33 Set the texture of the 3D actor.
34
35 @type texture: vtkTexture
36 @param texture: Texture of the rendered object
37 """
38
39 self.__vtk_actor3D.SetTexture(texture)
40
41 def setOpacity(self, opacity):
42 """
43 Set the opacity (transparency) of the 3D actor.
44
45 @type opacity: Number (between 0 and 1)
46 @param opacity: Opacity (transparency) of the 3D actor
47 """
48
49 self.__vtk_actor3D.GetProperty().SetOpacity(opacity)
50
51 def setColor(self, color):
52 """
53 Set the color of the 3D actor.
54
55 @type color: L{Color <constant.Color>} constant
56 @param color: Color of the 3D actor
57 """
58
59 # NOTE: Must be used before actor.GetProperty().SetColor()
60 # in order for the change of color to take effect.
61 self.__mapper.ScalarVisibilityOff()
62
63 # NOTE: Must be used after mapper.ScalarVisibilityOff()
64 # in order for the change of color to take effect.
65 self.__vtk_actor3D.GetProperty().SetColor(color)
66
67 def setRepresentationToWireframe(self):
68 """
69 Set the representation of the 3D actor to Wireframe.
70 """
71
72 self.__vtk_actor3D.GetProperty().SetRepresentationToWireframe()
73
74 def _setLineWidth(self, line_width):
75 """
76 Set the line width of the 3D actor.
77
78 @type line_width: Number
79 @param line_width: 3D actor line width
80 """
81
82 self.__vtk_actor3D.GetProperty().SetLineWidth(line_width)
83
84 def _getActor3D(self):
85 """
86 Return the 3D actor.
87
88 @rtype: vtkActor
89 @return: 3D actor
90 """
91
92 return self.__vtk_actor3D
93
94
95 ###############################################################################
96
97
98 class Actor2D:
99 """
100 Class that defines a 2D actor.
101 """
102
103 def __init__(self, mapper):
104 """
105 Initialise the 2D actor.
106
107 @type mapper: vtkMapper2D
108 @param mapper: Mapped data
109 """
110
111 self.__mapper = mapper
112 self._vtk_actor2D = vtk.vtkActor2D()
113 self.__setMapper()
114
115 def __setMapper(self):
116 """
117 Set the mapper for the 2D actor.
118 """
119
120 self._vtk_actor2D.SetMapper(self.__mapper)
121
122 def setPosition(self, position):
123 """
124 Set the position (XY) of the 2D actor. Default position is the lower
125 left hand corner of the window / viewport.
126
127 @type position: L{LocalPosition <position.LocalPosition>} object
128 @param position: Position of the 2D actor
129 """
130
131 self._vtk_actor2D.SetPosition(position._getLocalPosition())
132
133 def _getActor2D(self):
134 """
135 Return the 2D actor.
136
137 @rtype: vtkActor2D
138 @return 2D actor
139 """
140
141 return self._vtk_actor2D
142

  ViewVC Help
Powered by ViewVC 1.1.26