/[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 1148 by jongui, Wed May 16 22:45:33 2007 UTC revision 1197 by jongui, Mon Jun 18 02:08:34 2007 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 26  class Camera: Line 42  class Camera:
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  
45          self.__viewport = viewport          self.__viewport = viewport
46          self.__vtk_camera = vtk.vtkCamera()          self.__vtk_camera = vtk.vtkCamera()
47    
# Line 35  class Camera: Line 50  class Camera:
50          # Keeps track whether the modification to the camera was due to the          # Keeps track whether the modification to the camera was due to the
51          # instantiation. If it is, then __setupCamera() method is called.          # instantiation. If it is, then __setupCamera() method is called.
52          self.__initialization = True          self.__initialization = True
53          self.__scene._addVisualizationModules(self)          scene._addVisualizationModules(self)
54    
55      def __setupCamera(self):      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 174  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.__modified = True          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):      def _isModified(self):
244          """          """
# Line 213  class Camera: Line 253  class Camera:
253          else:          else:
254              return False              return False
255    
256      def _render(self):      def _render(self, scene):
257          """          """
258          Render the camera.          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):          if(self._isModified() == True):
265              # Will only be true once only when the camera is instantiated.              # Will only be true once only when the camera is instantiated.
266              if(self.__initialization == True):              if(self.__initialization == True):
267                  self.__setupCamera()                  self.__setupCamera(scene)
268                  self.__initialization == False                  self.__initialization == False
269    
270              self.__resetCameraClippingRange()              self.__resetCameraClippingRange(scene)
271              self.__isModified = False              self.__modified = False
272                            
273    

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

  ViewVC Help
Powered by ViewVC 1.1.26