/[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 946 - (show annotations)
Wed Jan 31 03:08:04 2007 UTC (12 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 2761 byte(s)
added colouring option to use either scalar data or vector data.
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

  ViewVC Help
Powered by ViewVC 1.1.26