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): |
13 |
""" |
14 |
Initialise the 3D actor. |
15 |
""" |
16 |
|
17 |
self.__vtk_actor3D = vtk.vtkActor() |
18 |
|
19 |
def _setupActor3D(self, mapper): |
20 |
""" |
21 |
Setup the 3D actor. |
22 |
|
23 |
@type mapper: vtkDataSetMapper |
24 |
@param mapper: Mapped data |
25 |
""" |
26 |
|
27 |
self.__mapper = mapper |
28 |
self.__setMapper() |
29 |
|
30 |
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 |
def __init__(self): |
108 |
""" |
109 |
Initialise the 2D actor. |
110 |
""" |
111 |
|
112 |
self._vtk_actor2D = vtk.vtkActor2D() |
113 |
|
114 |
def _setupActor2D(self, mapper): |
115 |
""" |
116 |
Setup the 2D actor. |
117 |
|
118 |
@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 |
|