/[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 882 - (hide annotations)
Fri Oct 27 08:15:33 2006 UTC (15 years, 9 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 gross 792 """
2 jongui 839 @author: John Ngui
3     @author: Lutz Gross
4 gross 792 """
5    
6 jongui 830 import vtk
7 jongui 860 from geo import Position
8 gross 792
9 jongui 830 class Camera:
10 jongui 837 """
11 jongui 839 Class that controls the camera and its settings.
12 jongui 837 """
13    
14 jongui 860 def __init__(self, scene, data_collector):
15 jongui 837 """
16 jongui 846 @type scene: L{Scene <scene.Scene>} object
17 jongui 839 @param scene: Scene in which components are to be added to
18 jongui 860 @type data_collector: L{DataCollector <datacollector.DataCollector>}
19     object
20     @param data_collector: Source of data for visualization
21 jongui 837 """
22    
23 jongui 839 self.scene = scene
24 jongui 860 self.data_collector = data_collector
25 jongui 852 self.vtk_camera = vtk.vtkCamera()
26 gross 792
27 jongui 830 self.setCamera()
28    
29     def setCamera(self):
30 jongui 837 """
31     Set up the camera and associate it with the renderer.
32     """
33    
34 jongui 879 self.resetCamera()
35     # Resets the camera clipping range to ensure no objects are cut off.
36     self.scene.getRenderer().ResetCameraClippingRange()
37    
38 jongui 860 # 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 jongui 879 #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 jongui 860
48     # Resets the camera clipping range to ensure no objects are cut off.
49     self.scene.getRenderer().ResetCameraClippingRange()
50 jongui 879 self.resetCamera()
51 jongui 830
52     def setClippingRange(self, near_clipping, far_clipping):
53 jongui 837 """
54     Set the near and far clipping plane of the camera.
55     @type near_clipping: Number
56 jongui 860 @param near_clipping: Distance to the near clipping plane
57 jongui 837 @type far_clipping: Number
58     @param far_clipping: Distance to the far clipping plane
59     """
60    
61 jongui 830 self.vtk_camera.SetClippingRange(near_clipping, far_clipping)
62 jongui 879 self.resetCamera()
63 jongui 830
64 jongui 835 def setFocalPoint(self, position):
65 jongui 837 """
66     Set the focal point of the camera.
67     @type position: L{Position <geo.Position>} object
68 jongui 860 @param position: Camera focal point
69 jongui 837 """
70    
71 jongui 835 self.vtk_camera.SetFocalPoint(position.getXCoor(), position.getYCoor(),
72     position.getZCoor())
73 jongui 879 self.resetCamera()
74 jongui 830
75 jongui 835 def setPosition(self, position):
76 jongui 837 """
77     Set the position of the camera.
78     @type position: L{Position <geo.Position>} object
79     @param position: Camera position
80     """
81    
82 jongui 835 self.vtk_camera.SetPosition(position.getXCoor(), position.getYCoor(),
83     position.getZCoor())
84 jongui 879 self.resetCamera()
85 jongui 830
86 jongui 835 def setViewUp(self, position):
87 jongui 837 """
88     Set the up direction of the camera.
89     @type position: L{Position <geo.Position>} object
90 jongui 860 @param position: Camera up direction
91 jongui 837 """
92    
93 jongui 835 self.vtk_camera.SetViewUp(position.getXCoor(), position.getYCoor(),
94     position.getZCoor())
95 jongui 879 self.resetCamera()
96 jongui 830
97 jongui 860 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 jongui 830
104 jongui 860 self.vtk_camera.Azimuth(angle)
105 jongui 879 self.resetCamera()
106 gross 792
107 jongui 860 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 gross 792
114 jongui 860 self.vtk_camera.Elevation(angle)
115 jongui 882 # 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 jongui 879 self.resetCamera()
122 gross 792
123 jongui 860 def roll(self, angle):
124     """
125 jongui 879 Roll the camera to the left and right.
126 jongui 860 @type angle: Number
127     @param angle: Degree to turn the camera
128     """
129 gross 792
130 jongui 882 self.vtk_camera.Roll(-angle)
131 jongui 879 self.resetCamera()
132 gross 792
133 jongui 860 def backView(self):
134     """
135     View the back of the rendered object.
136     """
137    
138     self.azimuth(180)
139 jongui 879 self.resetCamera()
140 jongui 860
141     def topView(self):
142     """
143     View the top of the rendered object.
144     """
145    
146 jongui 882 self.elevation(90)
147 jongui 879 self.resetCamera()
148 jongui 860
149     def bottomView(self):
150     """
151     View the bottom of the rendered object.
152     """
153    
154 jongui 882 self.elevation(-90)
155 jongui 879 self.resetCamera()
156 jongui 860
157     def leftView(self):
158     """
159     View the left side of the rendered object.
160     """
161    
162     self.azimuth(-90)
163 jongui 879 self.resetCamera()
164 jongui 860
165     def rightView(self):
166     """
167     View the right side of the rendered object.
168     """
169    
170     self.azimuth(90)
171 jongui 879 self.resetCamera()
172 jongui 860
173 jongui 882 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 jongui 879 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