8 |
|
|
9 |
class Camera: |
class Camera: |
10 |
""" |
""" |
11 |
Class that defines a camera and its settings. |
Class that defines a camera. |
12 |
""" |
""" |
13 |
|
|
14 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
23 |
object |
object |
24 |
@param data_collector: Deal with source of data for visualisation |
@param data_collector: Deal with source of data for visualisation |
25 |
@type viewport: L{Viewport <constant.Viewport>} constant |
@type viewport: L{Viewport <constant.Viewport>} constant |
26 |
@param viewport: Viewport in which the object is to be rendered on |
@param viewport: Viewport in which object are to be rendered on |
27 |
""" |
""" |
28 |
|
|
29 |
self.__scene = scene |
self.__scene = scene |
38 |
Setup the camera. |
Setup the camera. |
39 |
""" |
""" |
40 |
|
|
|
center = self.__data_collector._getOutput().GetCenter() |
|
41 |
# Default camera focal point is the center of the object. |
# Default camera focal point is the center of the object. |
42 |
|
center = self.__data_collector._getOutput().GetCenter() |
43 |
self.setFocalPoint(GlobalPosition(center[0], center[1], center[2])) |
self.setFocalPoint(GlobalPosition(center[0], center[1], center[2])) |
44 |
|
|
45 |
# Default camera position is the center of the object but with a slight |
# Default camera position is the center of the object but with a slight |
46 |
# distance on the z-axis. |
# distance on the z-axis. |
47 |
self.setPosition(GlobalPosition(center[0], center[1], center[2] * 3)) |
self.setPosition(GlobalPosition(center[0], center[1], center[2] * 3)) |
48 |
|
|
49 |
# Assign the camera to the appropriate renderer |
# Assign the camera to the appropriate renderer |
|
#self.__scene._getRenderer()[self.__viewport].SetActiveCamera( |
|
|
# self.__vtk_camera) |
|
50 |
self.__scene._setActiveCamera(self.__viewport, self.__vtk_camera) |
self.__scene._setActiveCamera(self.__viewport, self.__vtk_camera) |
51 |
self.__resetCamera() |
self.__resetCamera() |
52 |
|
|
53 |
def setFocalPoint(self, position): |
def setFocalPoint(self, position): |
54 |
""" |
""" |
55 |
Set the focal point of the camera. |
Set the focal point of the camera. |
56 |
|
|
57 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
58 |
@param position: Camera focal point |
@param position: Camera focal point |
59 |
""" |
""" |
64 |
def setPosition(self, position): |
def setPosition(self, position): |
65 |
""" |
""" |
66 |
Set the position of the camera. |
Set the position of the camera. |
67 |
|
|
68 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
69 |
@param position: Camera position |
@param position: Camera position |
70 |
""" |
""" |
75 |
def setClippingRange(self, near_clipping, far_clipping): |
def setClippingRange(self, near_clipping, far_clipping): |
76 |
""" |
""" |
77 |
Set the near and far clipping plane of the camera. |
Set the near and far clipping plane of the camera. |
78 |
|
|
79 |
@type near_clipping: Number |
@type near_clipping: Number |
80 |
@param near_clipping: Distance to the near clipping plane |
@param near_clipping: Distance to the near clipping plane |
81 |
@type far_clipping: Number |
@type far_clipping: Number |
88 |
def setViewUp(self, position): |
def setViewUp(self, position): |
89 |
""" |
""" |
90 |
Set the view up direction of the camera. |
Set the view up direction of the camera. |
91 |
|
|
92 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
93 |
@param position: Camera view up direction |
@param position: Camera view up direction |
94 |
""" |
""" |
99 |
def azimuth(self, angle): |
def azimuth(self, angle): |
100 |
""" |
""" |
101 |
Rotate the camera to the left and right. |
Rotate the camera to the left and right. |
102 |
|
|
103 |
@type angle: Number |
@type angle: Number |
104 |
@param angle: Degree to rotate the camera |
@param angle: Degree to rotate the camera |
105 |
""" |
""" |
110 |
def elevation(self, angle): |
def elevation(self, angle): |
111 |
""" |
""" |
112 |
Rotate the camera to the top and bottom. |
Rotate the camera to the top and bottom. |
113 |
|
|
114 |
@type angle: Number |
@type angle: Number |
115 |
@param angle: Degree to rotate the camera (only between -90 and 90) |
@param angle: Degree to rotate the camera (only between -90 and 90) |
116 |
""" |
""" |
117 |
|
|
118 |
self.__vtk_camera.Elevation(angle) |
self.__vtk_camera.Elevation(angle) |
119 |
# Recompute the view up vector. If not used the elevation angle is |
# Recompute the view up vector. If not used the elevation angle is |
120 |
# unable to exceed 87/-87 degrees. Secondly, a warning resetting the |
# unable to exceed 87/-87 degrees. Also, a warning resetting the |
121 |
# view up will also be thrown and the rendered object may be incorrect. |
# 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 |
# With the view up recomputed, the elevation angle can reach between |
123 |
# 90/-90 degress. Exceeding that, the rendered object may be incorrect. |
# 90/-90 degrees. Exceeding that, the rendered object may be incorrect. |
124 |
self.__vtk_camera.OrthogonalizeViewUp() |
self.__vtk_camera.OrthogonalizeViewUp() |
125 |
self.__resetCamera() |
self.__resetCamera() |
126 |
|
|
127 |
def roll(self, angle): |
def roll(self, angle): |
128 |
""" |
""" |
129 |
Roll the camera to the left and right. |
Roll the camera to the left and right. |
130 |
|
|
131 |
@type angle: Number |
@type angle: Number |
132 |
@param angle: Degree to turn the camera |
@param angle: Degree to roll the camera |
133 |
""" |
""" |
134 |
|
|
135 |
self.__vtk_camera.Roll(-angle) |
self.__vtk_camera.Roll(-angle) |
136 |
|
|
137 |
def backView(self): |
def backView(self): |
138 |
""" |
""" |
139 |
View the back of the rendered object. |
Rotate the camera to view the back of the rendered object. |
140 |
""" |
""" |
141 |
|
|
142 |
self.azimuth(180) |
self.azimuth(180) |
144 |
|
|
145 |
def topView(self): |
def topView(self): |
146 |
""" |
""" |
147 |
View the top of the rendered object. |
Rotate the camera to view the top of the rendered object. |
148 |
""" |
""" |
149 |
|
|
150 |
self.elevation(90) |
self.elevation(90) |
152 |
|
|
153 |
def bottomView(self): |
def bottomView(self): |
154 |
""" |
""" |
155 |
View the bottom of the rendered object. |
Rotate the camera to view the bottom of the rendered object. |
156 |
""" |
""" |
157 |
|
|
158 |
self.elevation(-90) |
self.elevation(-90) |
160 |
|
|
161 |
def leftView(self): |
def leftView(self): |
162 |
""" |
""" |
163 |
View the left side of the rendered object. |
Rotate the camera to view the left side of the rendered object. |
164 |
""" |
""" |
165 |
|
|
166 |
self.azimuth(-90) |
self.azimuth(-90) |
168 |
|
|
169 |
def rightView(self): |
def rightView(self): |
170 |
""" |
""" |
171 |
View the right side of the rendered object. |
Rotate the camera to view the right side of the rendered object. |
172 |
""" |
""" |
173 |
|
|
174 |
self.azimuth(90) |
self.azimuth(90) |
176 |
|
|
177 |
def isometricView(self): |
def isometricView(self): |
178 |
""" |
""" |
179 |
View the isometric side of the rendered object. |
Rotate the camera to view the isometric side of the rendered object. |
180 |
""" |
""" |
181 |
|
|
182 |
self.roll(-45) |
self.roll(-45) |
185 |
def __resetCamera(self): |
def __resetCamera(self): |
186 |
""" |
""" |
187 |
Reposition the camera so that all actors can be seen. Needs to |
Reposition the camera so that all actors can be seen. Needs to |
188 |
be called whenever the camera's settings are modified. |
be called whenever the camera's settings are modified in order for the |
189 |
|
changes to take effect correctly. |
190 |
""" |
""" |
191 |
|
|
192 |
self.__scene._getRenderer()[self.__viewport].ResetCamera() |
self.__scene._getRenderer()[self.__viewport].ResetCamera() |