/[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 860 - (show annotations)
Thu Sep 28 08:17:29 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 3957 byte(s)
- added sample drivers on how to use all of the currently available modules.
- completed the epydocs for all the currently available modules.
- added the rotation feature for camera and plane cutting.


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 # Repositions the camera so that all actors can be seen.
35 self.scene.getRenderer().ResetCamera()
36
37 # Default camera focal point and position is the center.
38 center = self.data_collector.getReader().GetOutput().GetCenter()
39 self.setFocalPoint(Position(center[0], center[1], center[2]))
40 self.setPosition(Position(center[0], center[1], center[2]+10))
41
42 # Resets the camera clipping range to ensure no objects are cut off.
43 self.scene.getRenderer().ResetCameraClippingRange()
44 # Assigns camera to the scene.
45 self.scene.getRenderer().SetActiveCamera(self.vtk_camera)
46
47 def setClippingRange(self, near_clipping, far_clipping):
48 """
49 Set the near and far clipping plane of the camera.
50 @type near_clipping: Number
51 @param near_clipping: Distance to the near clipping plane
52 @type far_clipping: Number
53 @param far_clipping: Distance to the far clipping plane
54 """
55
56 self.vtk_camera.SetClippingRange(near_clipping, far_clipping)
57
58 def setFocalPoint(self, position):
59 """
60 Set the focal point of the camera.
61 @type position: L{Position <geo.Position>} object
62 @param position: Camera focal point
63 """
64
65 self.vtk_camera.SetFocalPoint(position.getXCoor(), position.getYCoor(),
66 position.getZCoor())
67
68 def setPosition(self, position):
69 """
70 Set the position of the camera.
71 @type position: L{Position <geo.Position>} object
72 @param position: Camera position
73 """
74
75 self.vtk_camera.SetPosition(position.getXCoor(), position.getYCoor(),
76 position.getZCoor())
77
78 def setViewUp(self, position):
79 """
80 Set the up direction of the camera.
81 @type position: L{Position <geo.Position>} object
82 @param position: Camera up direction
83 """
84
85 self.vtk_camera.SetViewUp(position.getXCoor(), position.getYCoor(),
86 position.getZCoor())
87
88 def zoom(self, factor):
89 """
90 Zoom in and out of the rendered object.
91 @type factor: Number
92 @param factor: Amount to zoom in and out
93 """
94
95 self.vtk_camera.Zoom(factor)
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
106 def elevation(self, angle):
107 """
108 Rotate the camera to the top and bottom.
109 @type angle: Number
110 @param angle: Degree to rotate the camera
111 """
112
113 self.vtk_camera.Elevation(angle)
114
115 def roll(self, angle):
116 """
117 Tilt the camera to the left and right.
118 @type angle: Number
119 @param angle: Degree to turn the camera
120 """
121
122 self.vtk_camera.Roll(angle)
123
124 def dolly(self, distance):
125 """
126 Move the camera towards and away from the focal point along the normal.
127 @type distance: Number
128 @param distance: Amount to move towards and away
129 """
130
131 self.vtk_camera(distance)
132
133 def backView(self):
134 """
135 View the back of the rendered object.
136 """
137
138 self.azimuth(180)
139
140 def topView(self):
141 """
142 View the top of the rendered object.
143 """
144
145 self.elevation(90)
146
147 def bottomView(self):
148 """
149 View the bottom of the rendered object.
150 """
151
152 self.elevation(-90)
153
154 def leftView(self):
155 """
156 View the left side of the rendered object.
157 """
158
159 self.azimuth(-90)
160
161 def rightView(self):
162 """
163 View the right side of the rendered object.
164 """
165
166 self.azimuth(90)
167
168 #def isometricView(self):
169 # self.elevation(-50)
170 #self.roll(30)
171 #self.azimuth(-90)

  ViewVC Help
Powered by ViewVC 1.1.26