/[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 1147 by ksteube, Wed May 16 06:39:11 2007 UTC revision 1148 by jongui, Wed May 16 22:45:33 2007 UTC
# Line 16  class Camera: Line 16  class Camera:
16    
17      # 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.
18      # This saves the user from specifying the viewport when there is only one.      # This saves the user from specifying the viewport when there is only one.
19      def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST):      def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
20          """          """
21          Initialise the camera.          Initialise the camera.
22    
23          @type scene: L{Scene <scene.Scene>} object          @type scene: L{Scene <scene.Scene>} object
24          @param scene: Scene in which objects are to be rendered on          @param scene: Scene in which objects are to be rendered on
         @type data_collector: L{DataCollector <datacollector.DataCollector>}  
                 object  
         @param data_collector: Deal with the source data for vizualisation  
25          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
26          @param viewport: Viewport in which objects are to be rendered on          @param viewport: Viewport in which objects are to be rendered on
27          """          """
28    
29          self.__scene = scene          self.__scene = scene
         self.__data_collector = data_collector  
30          self.__viewport = viewport          self.__viewport = viewport
   
31          self.__vtk_camera = vtk.vtkCamera()          self.__vtk_camera = vtk.vtkCamera()
32          self.__setupCamera()  
33                    # Keeps track whether camera has been modified.
34            self.__modified = True
35            # Keeps track whether the modification to the camera was due to the
36            # instantiation. If it is, then __setupCamera() method is called.
37            self.__initialization = True
38            self.__scene._addVisualizationModules(self)
39    
40      def __setupCamera(self):      def __setupCamera(self):
41          """          """
42          Setup the camera.          Setup the camera.
# Line 54  class Camera: Line 55  class Camera:
55          """          """
56    
57          self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())                self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())      
58          self.__resetCameraClippingRange()          self.__modified = True
59    
60      def setPosition(self, position):      def setPosition(self, position):
61          """          """
# Line 65  class Camera: Line 66  class Camera:
66          """          """
67    
68          self.__vtk_camera.SetPosition(position._getGlobalPosition())          self.__vtk_camera.SetPosition(position._getGlobalPosition())
69          self.__resetCameraClippingRange()          self.__modified = True
70    
71      def setClippingRange(self, near_clipping, far_clipping):      def setClippingRange(self, near_clipping, far_clipping):
72          """          """
# Line 98  class Camera: Line 99  class Camera:
99          """          """
100    
101          self.__vtk_camera.Azimuth(angle)          self.__vtk_camera.Azimuth(angle)
102          self.__resetCameraClippingRange()          self.__modified = True
103    
104      def elevation(self, angle):      def elevation(self, angle):
105          """          """
# Line 115  class Camera: Line 116  class Camera:
116          # With the view up recomputed, the elevation angle can reach between          # With the view up recomputed, the elevation angle can reach between
117          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.
118          self.__vtk_camera.OrthogonalizeViewUp()          self.__vtk_camera.OrthogonalizeViewUp()
119          self.__resetCameraClippingRange()          self.__modified = True
120    
121      def roll(self, angle):      def roll(self, angle):
122          """          """
# Line 126  class Camera: Line 127  class Camera:
127          """          """
128    
129          self.__vtk_camera.Roll(-angle)          self.__vtk_camera.Roll(-angle)
130          self.__resetCameraClippingRange()          self.__modified = True
131    
132      def backView(self):      def backView(self):
133          """          """
# Line 181  class Camera: Line 182  class Camera:
182          """          """
183    
184          self.__vtk_camera.Dolly(distance)          self.__vtk_camera.Dolly(distance)
185          self.__resetCameraClippingRange()          self.__modified = True
186    
187      def __resetCameraClippingRange(self):      def __resetCameraClippingRange(self):
188          """          """
# Line 198  class Camera: Line 199  class Camera:
199          """          """
200    
201          self.__scene._getRenderer()[self.__viewport].ResetCamera()          self.__scene._getRenderer()[self.__viewport].ResetCamera()
202            
203        def _isModified(self):
204            """
205            Return whether the Camera has been modified.
206    
207            @rtype: Boolean
208            @return: True or False
209            """
210    
211            if (self.__modified == True):
212                return True
213            else:
214                return False
215    
216        def _render(self):
217            """
218            Render the camera.
219            """
220    
221            if(self._isModified() == True):
222                # Will only be true once only when the camera is instantiated.
223                if(self.__initialization == True):
224                    self.__setupCamera()
225                    self.__initialization == False
226    
227                self.__resetCameraClippingRange()
228                self.__isModified = False
229                
230    

Legend:
Removed from v.1147  
changed lines
  Added in v.1148

  ViewVC Help
Powered by ViewVC 1.1.26