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

Diff of /temp_trunk_copy/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 1158 by jongui, Tue May 22 04:24:01 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    
         self.__scene = scene  
         self.__data_collector = data_collector  
29          self.__viewport = viewport          self.__viewport = viewport
   
30          self.__vtk_camera = vtk.vtkCamera()          self.__vtk_camera = vtk.vtkCamera()
31          self.__setupCamera()  
32                    # Keeps track whether camera has been modified.
33      def __setupCamera(self):          self.__modified = True
34            # Keeps track whether the modification to the camera was due to the
35            # instantiation. If it is, then __setupCamera() method is called.
36            self.__initialization = True
37            scene._addVisualizationModules(self)
38    
39        def __setupCamera(self, scene):
40          """          """
41          Setup the camera.          Setup the camera.
42    
43            @type scene: L{Scene <scene.Scene>} object
44            @param scene: Scene in which objects are to be rendered on
45          """          """
46    
47          # Assign the camera to the appropriate renderer          # Assign the camera to the appropriate renderer
48          self.__scene._setActiveCamera(self.__viewport, self.__vtk_camera)          scene._setActiveCamera(self.__viewport, self.__vtk_camera)
49          self.__resetCamera()              self.__resetCamera(scene)  
50    
51      def setFocalPoint(self, position):      def setFocalPoint(self, position):
52          """          """
# Line 54  class Camera: Line 57  class Camera:
57          """          """
58    
59          self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())                self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())      
60          self.__resetCameraClippingRange()          self.__modified = True
61    
62      def setPosition(self, position):      def setPosition(self, position):
63          """          """
# Line 65  class Camera: Line 68  class Camera:
68          """          """
69    
70          self.__vtk_camera.SetPosition(position._getGlobalPosition())          self.__vtk_camera.SetPosition(position._getGlobalPosition())
71          self.__resetCameraClippingRange()          self.__modified = True
72    
73      def setClippingRange(self, near_clipping, far_clipping):      def setClippingRange(self, near_clipping, far_clipping):
74          """          """
# Line 98  class Camera: Line 101  class Camera:
101          """          """
102    
103          self.__vtk_camera.Azimuth(angle)          self.__vtk_camera.Azimuth(angle)
104          self.__resetCameraClippingRange()          self.__modified = True
105    
106      def elevation(self, angle):      def elevation(self, angle):
107          """          """
# Line 115  class Camera: Line 118  class Camera:
118          # With the view up recomputed, the elevation angle can reach between          # With the view up recomputed, the elevation angle can reach between
119          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.
120          self.__vtk_camera.OrthogonalizeViewUp()          self.__vtk_camera.OrthogonalizeViewUp()
121          self.__resetCameraClippingRange()          self.__modified = True
122    
123      def roll(self, angle):      def roll(self, angle):
124          """          """
# Line 126  class Camera: Line 129  class Camera:
129          """          """
130    
131          self.__vtk_camera.Roll(-angle)          self.__vtk_camera.Roll(-angle)
132          self.__resetCameraClippingRange()          self.__modified = True
133    
134      def backView(self):      def backView(self):
135          """          """
# Line 181  class Camera: Line 184  class Camera:
184          """          """
185    
186          self.__vtk_camera.Dolly(distance)          self.__vtk_camera.Dolly(distance)
187          self.__resetCameraClippingRange()          self.__modified = True
188    
189      def __resetCameraClippingRange(self):      def __resetCameraClippingRange(self, scene):
190          """          """
191          Reset the camera clipping range based on the bounds of the visible          Reset the camera clipping range based on the bounds of the visible
192          actors. This ensures the rendered object is not cut-off.          actors. This ensures the rendered object is not cut-off.
193          Needs to be called whenever the camera's settings are modified.          Needs to be called whenever the camera's settings are modified.
194    
195            @type scene: L{Scene <scene.Scene>} object
196            @param scene: Scene in which objects are to be rendered on
197          """          """
198    
199          self.__scene._getRenderer()[self.__viewport].ResetCameraClippingRange()          scene._getRenderer()[self.__viewport].ResetCameraClippingRange()
200    
201      def __resetCamera(self):      def __resetCamera(self, scene):
202          """          """
203          Repositions the camera to view the center point of the actors.          Repositions the camera to view the center point of the actors.
204    
205            @type scene: L{Scene <scene.Scene>} object
206            @param scene: Scene in which objects are to be rendered on
207          """          """
208    
209          self.__scene._getRenderer()[self.__viewport].ResetCamera()          scene._getRenderer()[self.__viewport].ResetCamera()
210            
211        def _isModified(self):
212            """
213            Return whether the Camera has been modified.
214    
215            @rtype: Boolean
216            @return: True or False
217            """
218    
219            if (self.__modified == True):
220                return True
221            else:
222                return False
223    
224        def _render(self, scene):
225            """
226            Render the camera.
227    
228            @type scene: L{Scene <scene.Scene>} object
229            @param scene: Scene in which objects are to be rendered on
230            """
231    
232            if(self._isModified() == True):
233                # Will only be true once only when the camera is instantiated.
234                if(self.__initialization == True):
235                    self.__setupCamera(scene)
236                    self.__initialization == False
237    
238                self.__resetCameraClippingRange(scene)
239                self.__isModified = False
240                
241    

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

  ViewVC Help
Powered by ViewVC 1.1.26