/[escript]/trunk/pyvisi/py_src/scene.py
ViewVC logotype

Diff of /trunk/pyvisi/py_src/scene.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1077 by jongui, Wed Mar 28 04:14:13 2007 UTC revision 1078 by jongui, Thu Apr 5 06:18:47 2007 UTC
# Line 7  from constant import Renderer, Color, Vi Line 7  from constant import Renderer, Color, Vi
7    
8  class Scene:  class Scene:
9      """      """
10      Class that defines a scene. A scene is a window in which objects are      Class that defines a scene. A scene is a window in which objects are to
11      to be rendered on. Only one scene needs to be created and can display      be rendered on. Only one scene needs to be created. However, a scene may
12      data from one source. However, a scene may be divided into four      be divided into four smaller windows called viewports (if needed).
13      smaller windows called viewports (if needed). The four viewports in      Each viewport can render a different object.  
     turn can display data from four different sources.  
14      """      """
15    
16      def __init__(self, renderer = Renderer.ONLINE, num_viewport = 1,      def __init__(self, renderer = Renderer.ONLINE, num_viewport = 1,
# Line 19  class Scene: Line 18  class Scene:
18          """          """
19          Initialise the scene.          Initialise the scene.
20    
21          @type renderer: String          @type renderer: L{Renderer <constant.Renderer>} constant
22          @param renderer: Type of renderer (i.e.Renderer.ONLINE, etc)          @param renderer: Type of renderer
23          @type num_viewport: Number          @type num_viewport: Number
24          @param num_viewport: Number of viewport(s) in the scene. Either 1 or 4          @param num_viewport: Number of viewport(s) in the scene. Either 1 or 4
25          @type x_size: Number          @type x_size: Number
# Line 58  class Scene: Line 57  class Scene:
57          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")
58          self.__setSize(self.__x_size, self.__y_size)          self.__setSize(self.__x_size, self.__y_size)
59    
60          # True for online rendering.          # True for Online rendering.
61          if(self.__renderer.startswith(Renderer.ONLINE)):          if(self.__renderer.startswith(Renderer.ONLINE)):
62              self.__setupOnlineRendering()              self.__setupOnlineRendering()
63              # True for all online renderers except Renderer.ONLINE.              # True for all Online renderers except Renderer.ONLINE.
64              if(self.__renderer != Renderer.ONLINE):              if(self.__renderer != Renderer.ONLINE):
65                  self.__setupWindowToImage()                  self.__setupWindowToImage()
66          # True for offline rendering.          # True for Offline rendering.
67          elif(self.__renderer.startswith(self.__OFFLINE)):          elif(self.__renderer.startswith(self.__OFFLINE)):
68              self.__setupOfflineRendering()              self.__setupOfflineRendering()
69              self.__setupWindowToImage()              self.__setupWindowToImage()
70          # True for display rendering.          # True for Display rendering.
71          elif(self.__renderer.startswith(Renderer.DISPLAY)):          elif(self.__renderer.startswith(Renderer.DISPLAY)):
72              # True for all display renderers except Renderer.DISPLAY.              # True for all Display renderers except Renderer.DISPLAY.
73              if(self.__renderer != Renderer.DISPLAY):              if(self.__renderer != Renderer.DISPLAY):
74                  self.__setupWindowToImage()                  self.__setupWindowToImage()
               
75    
76      def __createViewport(self):      def __createViewport(self):
77          """          """
# Line 86  class Scene: Line 84  class Scene:
84              self.__vtk_renderer.append(vtk.vtkRenderer())              self.__vtk_renderer.append(vtk.vtkRenderer())
85                            
86          if(self.__num_viewport == 4):          if(self.__num_viewport == 4):
87              # Renderer for the entire scene (background to the viewports).                # Renderer for the entire scene (background).  
88              self.__vtk_renderer_background = vtk.vtkRenderer()              self.__vtk_renderer_background = vtk.vtkRenderer()
89    
90              # Specify the positioning of the four viewports (between 0 and 1).              # Specify the positioning of the four viewports (between 0 and 1).
# Line 120  class Scene: Line 118  class Scene:
118          """          """
119          Add the renderer(s) to the render window.          Add the renderer(s) to the render window.
120          """          """
121          # Renderer for the black scene (background).  
122            # Add the renderer for the black scene (background).
123          if(self.__num_viewport == 4):          if(self.__num_viewport == 4):
124              self.__vtk_render_window.AddRenderer(              self.__vtk_render_window.AddRenderer(
125                      self.__vtk_renderer_background)                      self.__vtk_renderer_background)
# Line 163  class Scene: Line 162  class Scene:
162    
163      def __setupOfflineRendering(self):      def __setupOfflineRendering(self):
164          """          """
165          Enables the offline rendering. This prevents a window from coming          Enables the offline rendering (no window comes up).
         during the rendering process.  
166          """          """
167    
168          # Enable offscreen rendering.          # Enables the offscreen rendering.
169          self.__vtk_render_window.OffScreenRenderingOn()          self.__vtk_render_window.OffScreenRenderingOn()
170    
171      def __setupWindowToImage(self):      def __setupWindowToImage(self):
172          """          """
173          Setup the window to image filter to convert the output of the render          Setup the window to image filter to convert the output from the render
174          window into an image.          window into an image.
175          """          """
176    
# Line 180  class Scene: Line 178  class Scene:
178          self.__vtk_window_to_image.SetInput(self.__vtk_render_window)          self.__vtk_window_to_image.SetInput(self.__vtk_render_window)
179          self.__vtk_image_writer = self.__getImageWriter()          self.__vtk_image_writer = self.__getImageWriter()
180                    
   
181      def __getImageWriter(self):      def __getImageWriter(self):
182          """          """
183          Return the appropriate image writer based on the specified          Return the appropriate image writer based on the specified renderer.
         renderer.  
184    
185          @rtype: vtkImageWriter          @rtype: vtkImageWriter
186          @return: Image writer          @return: Image writer
# Line 214  class Scene: Line 210  class Scene:
210          # NOTE: Render and Modified must be called everytime before writing          # NOTE: Render and Modified must be called everytime before writing
211          # an image. Otherwise, only the first image will always be saved.          # an image. Otherwise, only the first image will always be saved.
212          # This is due to the architecture of VTK.          # This is due to the architecture of VTK.
213          #self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
214          self.__vtk_window_to_image.Modified()          self.__vtk_window_to_image.Modified()
215                    
216          # Retrieve rendered object from the window and convert it into an          # Retrieve the rendered object from the window and convert it into an
217          # image.          # image.
218          self.__vtk_image_writer.SetInput(          self.__vtk_image_writer.SetInput(
219                  self.__vtk_window_to_image.GetOutput())                  self.__vtk_window_to_image.GetOutput())
# Line 226  class Scene: Line 222  class Scene:
222    
223      def __animate(self):      def __animate(self):
224          """          """
225          Animate the object onto the scene on-the-fly. No interaction can occur.          Animate the rendered object on-the-fly.
226          """          """
227    
228            # With Render() ONLY, the rendered object is animated onto the
229            # scene on-the-fly and no interaction can occur.
230          self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
231    
232      def render(self, image_name = None):      def render(self, image_name = None):
233          """          """
234          Render the object either onto the scene or save it as an image or both.          Render the object using either the online, offline or display mode.
         (depending on the type of renderer).  
235          """          """
236    
         # With Render() ONLY, the rendered object is animated onto the  
         # scene on-the-fly and no interaction can occur.  
237          self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
238    
239          if(self.__renderer.startswith(Renderer.ONLINE)):          if(self.__renderer.startswith(Renderer.ONLINE)):
240              # NOTE: Once Start is executed, the driver will not further execute              # NOTE: Once Start() is executed, the driver will not further
241              # any subsequent codes thereafter unless the 'q' or 'e' keys are              # execute any subsequent codes thereafter unless the 'q' or
242              # pressed.              # 'e' keys are pressed.
243              self.__vtk_render_window_interactor.Start()              self.__vtk_render_window_interactor.Start()
244    
245              # True for all online renderers except Renderer.ONLINE.              # True for all online renderers except Renderer.ONLINE.
# Line 254  class Scene: Line 249  class Scene:
249          elif(self.__renderer.startswith(self.__OFFLINE) or          elif(self.__renderer.startswith(self.__OFFLINE) or
250                  self.__renderer != Renderer.DISPLAY):                  self.__renderer != Renderer.DISPLAY):
251              self.__saveImage(image_name)                                  self.__saveImage(image_name)                    
   
252            
253      def _addActor3D(self, viewport, actor):      def _addActor3D(self, viewport, actor):
254          """          """
255          Add the actor3D to the appropriate viewport.          Add the actor3D to the appropriate viewport.
256    
257          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
258          @param viewport: Viewport which the actor3D is to be added to          @param viewport: Viewport in which the actor3D is to be added to
259          @type actor: L{Actor3D <actor.Actor3D>} object          @type actor: vtkActor
260          @param actor: Actor3D which is to be added to the viewport          @param actor: Actor3D which is to be added to the viewport
261          """          """
262    
# Line 273  class Scene: Line 267  class Scene:
267          Add the actor2D to the appropriate viewport.          Add the actor2D to the appropriate viewport.
268    
269          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
270          @param viewport: Viewport which the actor2D is to be added to          @param viewport: Viewport in which the actor2D is to be added to
271          @type actor: L{Actor2D <actor.Actor2D>} object          @type actor: vtkActor2D
272          @param actor: Actor2D which is to be added to the viewport          @param actor: Actor2D which is to be added to the viewport
273          """          """
274    
# Line 285  class Scene: Line 279  class Scene:
279          Set the camera to the appropriate viewport.          Set the camera to the appropriate viewport.
280    
281          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
282          @param viewport: Viewport which the camera is to be added to          @param viewport: Viewport in which the camera is to be added to
283          @type camera: L{Camera <camera.Camera>} object          @type camera: vtkCamera
284          @param camera: Camera which is to be assigned to the viewport          @param camera: Camera which is to be assigned to the viewport
285          """          """
286    
# Line 297  class Scene: Line 291  class Scene:
291          Add the light to the appropriate viewport.          Add the light to the appropriate viewport.
292    
293          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
294          @param viewport: Viewport which the camera is to be added to          @param viewport: Viewport in which the camera is to be added to
295          @type light: L{Light <light.Light>} object          @type light: vtkLight
296          @param light: Light which is to be assigned to the viewport          @param light: Light which is to be assigned to the viewport
297          """          """
298    
# Line 308  class Scene: Line 302  class Scene:
302          """          """
303          Return the renderer(s)          Return the renderer(s)
304    
305          @rtype: One or more column tuple of vtkRenderer          @rtype: List
306          @return: Renderer(s)          @return: A list of renderer(s)
307          """          """
308            
309          return self.__vtk_renderer          return self.__vtk_renderer

Legend:
Removed from v.1077  
changed lines
  Added in v.1078

  ViewVC Help
Powered by ViewVC 1.1.26