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

Annotation of /trunk/pyvisi/py_src/camera.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 947 - (hide annotations)
Wed Jan 31 07:17:43 2007 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 4941 byte(s)
added some epydocs.
1 jongui 943 """
2     @author: John NGUI
3     """
4    
5     import vtk
6     from position import GlobalPosition
7     from constant import Viewport
8    
9     class Camera:
10     """
11 jongui 947 Class that defines a camera.
12 jongui 943 """
13    
14     # The SOUTH_WEST default viewport is used when there is only one viewport.
15     # This saves the user from specifying the viewport when there is only one.
16     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST):
17     """
18     Initialise the camera.
19    
20     @type scene: L{Scene <scene.Scene>} object
21     @param scene: Scene in which objects are to be rendered on
22     @type data_collector: L{DataCollector <datacollector.DataCollector>}
23     object
24     @param data_collector: Deal with source of data for visualisation
25     @type viewport: L{Viewport <constant.Viewport>} constant
26 jongui 947 @param viewport: Viewport in which object are to be rendered on
27 jongui 943 """
28    
29     self.__scene = scene
30     self.__data_collector = data_collector
31     self.__viewport = viewport
32    
33     self.__vtk_camera = vtk.vtkCamera()
34     self.__setupCamera()
35    
36     def __setupCamera(self):
37     """
38     Setup the camera.
39     """
40    
41 jongui 947 # Default camera focal point is the center of the object.
42 jongui 943 center = self.__data_collector._getOutput().GetCenter()
43     self.setFocalPoint(GlobalPosition(center[0], center[1], center[2]))
44 jongui 947
45 jongui 943 # Default camera position is the center of the object but with a slight
46     # distance on the z-axis.
47     self.setPosition(GlobalPosition(center[0], center[1], center[2] * 3))
48 jongui 947
49 jongui 943 # Assign the camera to the appropriate renderer
50     self.__scene._setActiveCamera(self.__viewport, self.__vtk_camera)
51     self.__resetCamera()
52    
53     def setFocalPoint(self, position):
54     """
55     Set the focal point of the camera.
56 jongui 947
57 jongui 943 @type position: L{GlobalPosition <position.GlobalPosition>} object
58     @param position: Camera focal point
59     """
60    
61     self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())
62     self.__resetCamera()
63    
64     def setPosition(self, position):
65     """
66     Set the position of the camera.
67 jongui 947
68 jongui 943 @type position: L{GlobalPosition <position.GlobalPosition>} object
69     @param position: Camera position
70     """
71    
72     self.__vtk_camera.SetPosition(position._getGlobalPosition())
73     self.__resetCamera()
74    
75     def setClippingRange(self, near_clipping, far_clipping):
76     """
77     Set the near and far clipping plane of the camera.
78 jongui 947
79 jongui 943 @type near_clipping: Number
80     @param near_clipping: Distance to the near clipping plane
81     @type far_clipping: Number
82     @param far_clipping: Distance to the far clipping plane
83     """
84    
85     self.vtk__camera.SetClippingRange(near_clipping, far_clipping)
86     self.__resetCamera()
87    
88     def setViewUp(self, position):
89     """
90     Set the view up direction of the camera.
91 jongui 947
92 jongui 943 @type position: L{GlobalPosition <position.GlobalPosition>} object
93     @param position: Camera view up direction
94     """
95    
96     self.__vtk_camera.SetViewUp(position._getGlobalPosition())
97     self.__resetCamera()
98    
99     def azimuth(self, angle):
100     """
101     Rotate the camera to the left and right.
102 jongui 947
103 jongui 943 @type angle: Number
104     @param angle: Degree to rotate the camera
105     """
106    
107     self.__vtk_camera.Azimuth(angle)
108     self.__resetCamera()
109    
110     def elevation(self, angle):
111     """
112     Rotate the camera to the top and bottom.
113 jongui 947
114 jongui 943 @type angle: Number
115     @param angle: Degree to rotate the camera (only between -90 and 90)
116     """
117    
118     self.__vtk_camera.Elevation(angle)
119     # Recompute the view up vector. If not used the elevation angle is
120 jongui 947 # unable to exceed 87/-87 degrees. Also, a warning resetting the
121 jongui 943 # view up will also be thrown and the rendered object may be incorrect.
122     # With the view up recomputed, the elevation angle can reach between
123 jongui 947 # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.
124 jongui 943 self.__vtk_camera.OrthogonalizeViewUp()
125     self.__resetCamera()
126    
127     def roll(self, angle):
128     """
129     Roll the camera to the left and right.
130 jongui 947
131 jongui 943 @type angle: Number
132 jongui 947 @param angle: Degree to roll the camera
133 jongui 943 """
134    
135     self.__vtk_camera.Roll(-angle)
136    
137     def backView(self):
138     """
139 jongui 947 Rotate the camera to view the back of the rendered object.
140 jongui 943 """
141    
142     self.azimuth(180)
143     self.__resetCamera()
144    
145     def topView(self):
146     """
147 jongui 947 Rotate the camera to view the top of the rendered object.
148 jongui 943 """
149    
150     self.elevation(90)
151     self.__resetCamera()
152    
153     def bottomView(self):
154     """
155 jongui 947 Rotate the camera to view the bottom of the rendered object.
156 jongui 943 """
157    
158     self.elevation(-90)
159     self.__resetCamera()
160    
161     def leftView(self):
162     """
163 jongui 947 Rotate the camera to view the left side of the rendered object.
164 jongui 943 """
165    
166     self.azimuth(-90)
167     self.__resetCamera()
168    
169     def rightView(self):
170     """
171 jongui 947 Rotate the camera to view the right side of the rendered object.
172 jongui 943 """
173    
174     self.azimuth(90)
175     self.__resetCamera()
176    
177     def isometricView(self):
178     """
179 jongui 947 Rotate the camera to view the isometric side of the rendered object.
180 jongui 943 """
181    
182     self.roll(-45)
183     self.elevation(-45)
184    
185     def __resetCamera(self):
186     """
187     Reposition the camera so that all actors can be seen. Needs to
188 jongui 947 be called whenever the camera's settings are modified in order for the
189     changes to take effect correctly.
190 jongui 943 """
191    
192     self.__scene._getRenderer()[self.__viewport].ResetCamera()
193    

  ViewVC Help
Powered by ViewVC 1.1.26