/[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 996 - (show annotations)
Mon Feb 26 03:43:13 2007 UTC (12 years, 11 months ago) by jongui
File MIME type: text/x-python
File size: 2887 byte(s)
Updated the drivers. Setting the active scalar/vector/tensor is now done in the DataCollector. i.e. 
dc = DataCollector(...)
dc.setFileName(...)
dc.setActiveScalar(...)

The use of setActiveScalar / setActiveVector / setActiveTensor have to be done after the setFileName.
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 of the rendered objects to take
61 # effect.
62 self.__mapper.ScalarVisibilityOff()
63
64 # NOTE: Must be used after mapper.ScalarVisibilityOff()
65 # in order for the change of color of the rendered objects to take
66 # effect.
67 self.__vtk_actor3D.GetProperty().SetColor(color)
68
69 def setRepresentationToWireframe(self):
70 """
71 Set the representation of the 3D actor to Wireframe.
72 """
73
74 self.__vtk_actor3D.GetProperty().SetRepresentationToWireframe()
75
76 def _setLineWidth(self, line_width):
77 """
78 Set the line width of the 3D actor.
79
80 @type line_width: Number
81 @param line_width: 3D actor line width
82 """
83
84 self.__vtk_actor3D.GetProperty().SetLineWidth(line_width)
85
86 def _getActor3D(self):
87 """
88 Return the 3D actor.
89
90 @rtype: vtkActor
91 @return: 3D actor
92 """
93
94 return self.__vtk_actor3D
95
96
97 ###############################################################################
98
99
100 class Actor2D:
101 """
102 Class that defines a 2D actor.
103 """
104
105 def __init__(self, mapper):
106 """
107 Initialise the 2D actor.
108
109 @type mapper: vtkMapper2D, etc
110 @param mapper: Mapped data
111 """
112
113 self.__mapper = mapper
114 self._vtk_actor2D = vtk.vtkActor2D()
115 self.__setMapper()
116
117 def __setMapper(self):
118 """
119 Set the mapper for the 2D actor.
120 """
121
122 self._vtk_actor2D.SetMapper(self.__mapper)
123
124 def setPosition(self, position):
125 """
126 Set the position of the 2D actor. Default position is the lower left
127 hand corner of the window.
128
129 @type position: L{LocalPosition <position.LocalPosition>} object
130 @param position: Position of the 2D actor
131 """
132
133 self._vtk_actor2D.SetPosition(position._getLocalPosition())
134
135 def _getActor2D(self):
136 """
137 Return the 2D actor.
138
139 @rtype: vtkActor2D
140 @return 2D actor
141 """
142
143 return self._vtk_actor2D
144

  ViewVC Help
Powered by ViewVC 1.1.26