/[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 859 by jongui, Wed Sep 20 03:23:16 2006 UTC revision 860 by jongui, Thu Sep 28 08:17:29 2006 UTC
# Line 4  Line 4 
4  """  """
5    
6  import vtk  import vtk
7    from geo import Position
8    
9  class Camera:  class Camera:
10      """      """
11      Class that controls the camera and its settings.      Class that controls the camera and its settings.
12      """      """
13    
14      def __init__(self, scene):      def __init__(self, scene, data_collector):
15          """          """
16          @type scene: L{Scene <scene.Scene>} object          @type scene: L{Scene <scene.Scene>} object
17          @param scene: Scene in which components are to be added to          @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          self.scene = scene
24            self.data_collector = data_collector
25          self.vtk_camera = vtk.vtkCamera()                self.vtk_camera = vtk.vtkCamera()      
26    
27          self.setCamera()          self.setCamera()
# Line 26  class Camera: Line 31  class Camera:
31          Set up the camera and associate it with the renderer.          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)          self.scene.getRenderer().SetActiveCamera(self.vtk_camera)
46    
47      def setClippingRange(self, near_clipping, far_clipping):      def setClippingRange(self, near_clipping, far_clipping):
48          """          """
49          Set the near and far clipping plane of the camera.          Set the near and far clipping plane of the camera.
   
50          @type near_clipping: Number          @type near_clipping: Number
51          @param near_clipping: Distance to the near clipping range          @param near_clipping: Distance to the near clipping plane
52          @type far_clipping: Number          @type far_clipping: Number
53          @param far_clipping: Distance to the far clipping plane          @param far_clipping: Distance to the far clipping plane
54          """          """
# Line 43  class Camera: Line 58  class Camera:
58      def setFocalPoint(self, position):      def setFocalPoint(self, position):
59          """          """
60          Set the focal point of the camera.          Set the focal point of the camera.
       
61          @type position: L{Position <geo.Position>} object          @type position: L{Position <geo.Position>} object
62          @param position: Camera focal point position          @param position: Camera focal point
63          """          """
64    
65          self.vtk_camera.SetFocalPoint(position.getXCoor(), position.getYCoor(),          self.vtk_camera.SetFocalPoint(position.getXCoor(), position.getYCoor(),
# Line 54  class Camera: Line 68  class Camera:
68      def setPosition(self, position):      def setPosition(self, position):
69          """          """
70          Set the position of the camera.          Set the position of the camera.
   
71          @type position: L{Position <geo.Position>} object          @type position: L{Position <geo.Position>} object
72          @param position: Camera position          @param position: Camera position
73          """          """
# Line 65  class Camera: Line 78  class Camera:
78      def setViewUp(self, position):      def setViewUp(self, position):
79          """          """
80          Set the up direction of the camera.          Set the up direction of the camera.
   
81          @type position: L{Position <geo.Position>} object          @type position: L{Position <geo.Position>} object
82          @param position: Camera view up position          @param position: Camera up direction
83          """          """
84    
85          self.vtk_camera.SetViewUp(position.getXCoor(), position.getYCoor(),          self.vtk_camera.SetViewUp(position.getXCoor(), position.getYCoor(),
86              position.getZCoor())              position.getZCoor())
87    
88      def setZoom(self, zoom):      def zoom(self, factor):
89          self.vtk_camera.Zoom(zoom)          """
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  class FrontView(Camera):      def bottomView(self):
148      pass          """
149            View the bottom of the rendered object.
150            """
151    
152  class BackView(Camera):          self.elevation(-90)
     pass  
153    
154  class TopView(Camera):      def leftView(self):
155      pass          """
156            View the left side of the rendered object.
157            """
158    
159  class BottomView(Camera):          self.azimuth(-90)
     pass  
160    
161  class LeftView(Camera):      def rightView(self):
162      pass          """
163            View the right side of the rendered object.
164            """
165    
166  class RightView(Camera):          self.azimuth(90)
     pass  
167    
168  class IsometricView(Camera):      #def isometricView(self):
169      pass      #   self.elevation(-50)
170            #self.roll(30)
171            #self.azimuth(-90)

Legend:
Removed from v.859  
changed lines
  Added in v.860

  ViewVC Help
Powered by ViewVC 1.1.26