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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 943 by jongui, Mon Jan 29 07:22:43 2007 UTC revision 947 by jongui, Wed Jan 31 07:17:43 2007 UTC
# Line 8  from constant import Viewport Line 8  from constant import Viewport
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.
# Line 23  class Camera: Line 23  class Camera:
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
# Line 38  class Camera: Line 38  class Camera:
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          """          """
# Line 63  class Camera: Line 64  class Camera:
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          """          """
# Line 73  class Camera: Line 75  class Camera:
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
# Line 85  class Camera: Line 88  class Camera:
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          """          """
# Line 95  class Camera: Line 99  class Camera:
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          """          """
# Line 105  class Camera: Line 110  class Camera:
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)
# Line 137  class Camera: Line 144  class Camera:
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)
# Line 145  class Camera: Line 152  class Camera:
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)
# Line 153  class Camera: Line 160  class Camera:
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)
# Line 161  class Camera: Line 168  class Camera:
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)
# Line 169  class Camera: Line 176  class Camera:
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)
# Line 178  class Camera: Line 185  class Camera:
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()

Legend:
Removed from v.943  
changed lines
  Added in v.947

  ViewVC Help
Powered by ViewVC 1.1.26