/[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

trunk/pyvisi/py_src/camera.py revision 1147 by ksteube, Wed May 16 06:39:11 2007 UTC temp_trunk_copy/pyvisi/py_src/camera.py revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC
# Line 1  Line 1 
1  """  """
2  @author: John NGUI  @var __author__: name of author
3    @var __copyright__: copyrights
4    @var __license__: licence agreement
5    @var __url__: url entry point on documentation
6    @var __version__: version
7    @var __date__: date of the version
8  """  """
9    
10    __author__="John Ngui, john.ngui@uq.edu.au"
11    __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
12                        http://www.access.edu.au
13                    Primary Business: Queensland, Australia"""
14    __license__="""Licensed under the Open Software License version 3.0
15                 http://www.opensource.org/licenses/osl-3.0.php"""
16    __url__="http://www.iservo.edu.au/esys"
17    __version__="$Revision$"
18    __date__="$Date$"
19    
20    
21  import vtk  import vtk
22  from position import GlobalPosition  from position import GlobalPosition
23  from constant import Viewport  from constant import Viewport
# Line 16  class Camera: Line 32  class Camera:
32    
33      # 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.
34      # 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.
35      def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST):      def __init__(self, scene, viewport = Viewport.SOUTH_WEST):
36          """          """
37          Initialise the camera.          Initialise the camera.
38    
39          @type scene: L{Scene <scene.Scene>} object          @type scene: L{Scene <scene.Scene>} object
40          @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  
41          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
42          @param viewport: Viewport in which objects are to be rendered on          @param viewport: Viewport in which objects are to be rendered on
43          """          """
44    
         self.__scene = scene  
         self.__data_collector = data_collector  
45          self.__viewport = viewport          self.__viewport = viewport
   
46          self.__vtk_camera = vtk.vtkCamera()          self.__vtk_camera = vtk.vtkCamera()
47          self.__setupCamera()  
48                    # Keeps track whether camera has been modified.
49      def __setupCamera(self):          self.__modified = True
50            # Keeps track whether the modification to the camera was due to the
51            # instantiation. If it is, then __setupCamera() method is called.
52            self.__initialization = True
53            scene._addVisualizationModules(self)
54    
55        def __setupCamera(self, scene):
56          """          """
57          Setup the camera.          Setup the camera.
58    
59            @type scene: L{Scene <scene.Scene>} object
60            @param scene: Scene in which objects are to be rendered on
61          """          """
62    
63          # Assign the camera to the appropriate renderer          # Assign the camera to the appropriate renderer
64          self.__scene._setActiveCamera(self.__viewport, self.__vtk_camera)          scene._setActiveCamera(self.__viewport, self.__vtk_camera)
65          self.__resetCamera()              self.__resetCamera(scene)  
66    
67      def setFocalPoint(self, position):      def setFocalPoint(self, position):
68          """          """
# Line 54  class Camera: Line 73  class Camera:
73          """          """
74    
75          self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())                self.__vtk_camera.SetFocalPoint(position._getGlobalPosition())      
76          self.__resetCameraClippingRange()          self.__modified = True
77    
78      def setPosition(self, position):      def setPosition(self, position):
79          """          """
# Line 65  class Camera: Line 84  class Camera:
84          """          """
85    
86          self.__vtk_camera.SetPosition(position._getGlobalPosition())          self.__vtk_camera.SetPosition(position._getGlobalPosition())
87          self.__resetCameraClippingRange()          self.__modified = True
88    
89      def setClippingRange(self, near_clipping, far_clipping):      def setClippingRange(self, near_clipping, far_clipping):
90          """          """
# Line 98  class Camera: Line 117  class Camera:
117          """          """
118    
119          self.__vtk_camera.Azimuth(angle)          self.__vtk_camera.Azimuth(angle)
120          self.__resetCameraClippingRange()          self.__modified = True
121    
122      def elevation(self, angle):      def elevation(self, angle):
123          """          """
# Line 115  class Camera: Line 134  class Camera:
134          # With the view up recomputed, the elevation angle can reach between          # With the view up recomputed, the elevation angle can reach between
135          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.          # 90/-90 degrees. Exceeding that, the rendered object may be incorrect.
136          self.__vtk_camera.OrthogonalizeViewUp()          self.__vtk_camera.OrthogonalizeViewUp()
137          self.__resetCameraClippingRange()          self.__modified = True
138    
139      def roll(self, angle):      def roll(self, angle):
140          """          """
# Line 126  class Camera: Line 145  class Camera:
145          """          """
146    
147          self.__vtk_camera.Roll(-angle)          self.__vtk_camera.Roll(-angle)
148          self.__resetCameraClippingRange()          self.__modified = True
149    
150      def backView(self):      def backView(self):
151          """          """
# Line 173  class Camera: Line 192  class Camera:
192                    
193      def dolly(self, distance):      def dolly(self, distance):
194          """          """
195          Move the camera towards (greater than 1) and away (less than 1) from          Move the camera towards (greater than 1) the rendered object. However,
196          the rendered object.          the camera is unable to be moved away from the rendered object.
197    
198          @type distance: Number          @type distance: Number
199          @param distance: Amount to move towards or away the rendered object          @param distance: Amount to move towards the rendered object
200          """          """
201    
202          self.__vtk_camera.Dolly(distance)          self.__vtk_camera.Dolly(distance)
203          self.__resetCameraClippingRange()          self.__modified = True
204    
205      def __resetCameraClippingRange(self):      def parallelProjectionOn(self):
206            """
207            Enable camera parallel projection.
208            """
209    
210            self.__vtk_camera.ParallelProjectionOn()
211            self.__modified = True
212    
213        def parallelProjectionOff(self):
214            """
215            Disable camera parallel projection.
216            """
217    
218            self.__vtk_camera.ParallelProjectionOff()
219            self.__modified = True
220    
221        def __resetCameraClippingRange(self, scene):
222          """          """
223          Reset the camera clipping range based on the bounds of the visible          Reset the camera clipping range based on the bounds of the visible
224          actors. This ensures the rendered object is not cut-off.          actors. This ensures the rendered object is not cut-off.
225          Needs to be called whenever the camera's settings are modified.          Needs to be called whenever the camera's settings are modified.
226    
227            @type scene: L{Scene <scene.Scene>} object
228            @param scene: Scene in which objects are to be rendered on
229          """          """
230    
231          self.__scene._getRenderer()[self.__viewport].ResetCameraClippingRange()          scene._getRenderer()[self.__viewport].ResetCameraClippingRange()
232    
233      def __resetCamera(self):      def __resetCamera(self, scene):
234          """          """
235          Repositions the camera to view the center point of the actors.          Repositions the camera to view the center point of the actors.
236    
237            @type scene: L{Scene <scene.Scene>} object
238            @param scene: Scene in which objects are to be rendered on
239          """          """
240    
241          self.__scene._getRenderer()[self.__viewport].ResetCamera()          scene._getRenderer()[self.__viewport].ResetCamera()
242            
243        def _isModified(self):
244            """
245            Return whether the Camera has been modified.
246    
247            @rtype: Boolean
248            @return: True or False
249            """
250    
251            if (self.__modified == True):
252                return True
253            else:
254                return False
255    
256        def _render(self, scene):
257            """
258            Render the camera.
259    
260            @type scene: L{Scene <scene.Scene>} object
261            @param scene: Scene in which objects are to be rendered on
262            """
263    
264            if(self._isModified() == True):
265                # Will only be true once only when the camera is instantiated.
266                if(self.__initialization == True):
267                    self.__setupCamera(scene)
268                    self.__initialization == False
269    
270                self.__resetCameraClippingRange(scene)
271                self.__modified = False
272                
273    

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

  ViewVC Help
Powered by ViewVC 1.1.26