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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 882 - (show annotations)
Fri Oct 27 08:15:33 2006 UTC (12 years, 8 months ago) by jongui
File MIME type: text/x-python
File size: 4645 byte(s)
Fixed some bugs in the camera module but yet to fix bugs in the plane module.

1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from geo import Position
8
9 class Camera:
10 """
11 Class that controls the camera and its settings.
12 """
13
14 def __init__(self, scene, data_collector):
15 """
16 @type scene: L{Scene <scene.Scene>} object
17 @param scene: Scene in which components are to be added to
18 @type data_collector: L{DataCollector <datacollector.DataCollector>}
19 object
20 @param data_collector: Source of data for visualization
21 """
22
23 self.scene = scene
24 self.data_collector = data_collector
25 self.vtk_camera = vtk.vtkCamera()
26
27 self.setCamera()
28
29 def setCamera(self):
30 """
31 Set up the camera and associate it with the renderer.
32 """
33
34 self.resetCamera()
35 # Resets the camera clipping range to ensure no objects are cut off.
36 self.scene.getRenderer().ResetCameraClippingRange()
37
38 # Default camera focal point and position is the center.
39 center = self.data_collector.getReader().GetOutput().GetCenter()
40 self.setFocalPoint(Position(center[0], center[1], center[2]))
41 #print center[0], center[1], center[2]
42 # Camera distance from the rendered object = z + (x*4)
43 self.setPosition(
44 Position(center[0], center[1], center[2] + (center[0] * 4)))
45 # Assigns camera to the scene.
46 self.scene.getRenderer().SetActiveCamera(self.vtk_camera)
47
48 # Resets the camera clipping range to ensure no objects are cut off.
49 self.scene.getRenderer().ResetCameraClippingRange()
50 self.resetCamera()
51
52 def setClippingRange(self, near_clipping, far_clipping):
53 """
54 Set the near and far clipping plane of the camera.
55 @type near_clipping: Number
56 @param near_clipping: Distance to the near clipping plane
57 @type far_clipping: Number
58 @param far_clipping: Distance to the far clipping plane
59 """
60
61 self.vtk_camera.SetClippingRange(near_clipping, far_clipping)
62 self.resetCamera()
63
64 def setFocalPoint(self, position):
65 """
66 Set the focal point of the camera.
67 @type position: L{Position <geo.Position>} object
68 @param position: Camera focal point
69 """
70
71 self.vtk_camera.SetFocalPoint(position.getXCoor(), position.getYCoor(),
72 position.getZCoor())
73 self.resetCamera()
74
75 def setPosition(self, position):
76 """
77 Set the position of the camera.
78 @type position: L{Position <geo.Position>} object
79 @param position: Camera position
80 """
81
82 self.vtk_camera.SetPosition(position.getXCoor(), position.getYCoor(),
83 position.getZCoor())
84 self.resetCamera()
85
86 def setViewUp(self, position):
87 """
88 Set the up direction of the camera.
89 @type position: L{Position <geo.Position>} object
90 @param position: Camera up direction
91 """
92
93 self.vtk_camera.SetViewUp(position.getXCoor(), position.getYCoor(),
94 position.getZCoor())
95 self.resetCamera()
96
97 def azimuth(self, angle):
98 """
99 Rotate the camera to the left and right.
100 @type angle: Number
101 @param angle: Degree to rotate the camera
102 """
103
104 self.vtk_camera.Azimuth(angle)
105 self.resetCamera()
106
107 def elevation(self, angle):
108 """
109 Rotate the camera to the top and bottom.
110 @type angle: Number
111 @param angle: Degree to rotate the camera
112 """
113
114 self.vtk_camera.Elevation(angle)
115 # Recompute the view up vector. If not used the elevation angle cannot
116 # cannot exceed 87/-87 degrees. Otherwise a warning resetting the
117 # view up will be thrown and the rendered object may be incorrect.
118 # With the view up recomputed, the elevation angle can reach between
119 # 90/-90 degress. More than that, the rendered object may be incorrect.
120 self.vtk_camera.OrthogonalizeViewUp()
121 self.resetCamera()
122
123 def roll(self, angle):
124 """
125 Roll the camera to the left and right.
126 @type angle: Number
127 @param angle: Degree to turn the camera
128 """
129
130 self.vtk_camera.Roll(-angle)
131 self.resetCamera()
132
133 def backView(self):
134 """
135 View the back of the rendered object.
136 """
137
138 self.azimuth(180)
139 self.resetCamera()
140
141 def topView(self):
142 """
143 View the top of the rendered object.
144 """
145
146 self.elevation(90)
147 self.resetCamera()
148
149 def bottomView(self):
150 """
151 View the bottom of the rendered object.
152 """
153
154 self.elevation(-90)
155 self.resetCamera()
156
157 def leftView(self):
158 """
159 View the left side of the rendered object.
160 """
161
162 self.azimuth(-90)
163 self.resetCamera()
164
165 def rightView(self):
166 """
167 View the right side of the rendered object.
168 """
169
170 self.azimuth(90)
171 self.resetCamera()
172
173 def isometricView(self):
174 """
175 View the isometric side of the rendered object.
176 """
177
178 self.roll(-45)
179 self.elevation(-45)
180
181 def resetCamera(self):
182 """
183 Repositions the camera so that all actors can be seen. Needs to
184 be called whenever the camera's settings are modified.
185 """
186
187 self.scene.getRenderer().ResetCamera()
188
189

  ViewVC Help
Powered by ViewVC 1.1.26