/[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 1037 by jongui, Fri Mar 16 05:00:32 2007 UTC revision 1067 by jongui, Wed Mar 28 04:14:13 2007 UTC
# Line 33  class Scene: Line 33  class Scene:
33          self.__num_viewport = num_viewport          self.__num_viewport = num_viewport
34          self.__x_size = x_size          self.__x_size = x_size
35          self.__y_size = y_size          self.__y_size = y_size
36    
37            self.__OFFLINE = "offline"
38            self.__JPG = "jpg"
39            self.__BMP = "bmp"
40            self.__PNM = "pnm"
41            self.__PNG = "png"
42            self.__TIF = "tif"
43            self.__PS  = "ps"
44            
45          self.__vtk_render_window = vtk.vtkRenderWindow()          self.__vtk_render_window = vtk.vtkRenderWindow()
46          self.__setupScene()          self.__setupScene()
# Line 49  class Scene: Line 57  class Scene:
57          # Default title bar.          # Default title bar.
58          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")
59          self.__setSize(self.__x_size, self.__y_size)          self.__setSize(self.__x_size, self.__y_size)
60            
61          if(self.__renderer == Renderer.ONLINE): # True for online rendering.          # True for online rendering.
62            if(self.__renderer.startswith(Renderer.ONLINE)):
63              self.__setupOnlineRendering()              self.__setupOnlineRendering()
64          else: # True for offline rendering.              # True for all online renderers except Renderer.ONLINE.
65                if(self.__renderer != Renderer.ONLINE):
66                    self.__setupWindowToImage()
67            # True for offline rendering.
68            elif(self.__renderer.startswith(self.__OFFLINE)):
69              self.__setupOfflineRendering()              self.__setupOfflineRendering()
70                self.__setupWindowToImage()
71            # True for display rendering.
72            elif(self.__renderer.startswith(Renderer.DISPLAY)):
73                # True for all display renderers except Renderer.DISPLAY.
74                if(self.__renderer != Renderer.DISPLAY):
75                    self.__setupWindowToImage()
76                
77    
78      def __createViewport(self):      def __createViewport(self):
79          """          """
# Line 143  class Scene: Line 163  class Scene:
163    
164      def __setupOfflineRendering(self):      def __setupOfflineRendering(self):
165          """          """
166          Setup the window to image filter for offline rendering.          Enables the offline rendering. This prevents a window from coming
167            during the rendering process.
168          """          """
169    
170          # Enable offscreen rendering.          # Enable offscreen rendering.
171          self.__vtk_render_window.OffScreenRenderingOn()          self.__vtk_render_window.OffScreenRenderingOn()
172          # Convert the output of the render window into an image.  
173        def __setupWindowToImage(self):
174            """
175            Setup the window to image filter to convert the output of the render
176            window into an image.
177            """
178    
179          self.__vtk_window_to_image = vtk.vtkWindowToImageFilter()          self.__vtk_window_to_image = vtk.vtkWindowToImageFilter()
180          self.__vtk_window_to_image.SetInput(self.__vtk_render_window)          self.__vtk_window_to_image.SetInput(self.__vtk_render_window)
181          self.__vtk_image_writer = self.__getImageWriter()          self.__vtk_image_writer = self.__getImageWriter()
182            
183    
184      def __getImageWriter(self):      def __getImageWriter(self):
185          """          """
186          Return the appropriate image writer based on the specified offline          Return the appropriate image writer based on the specified
187          renderer.          renderer.
188    
189          @rtype: vtkImageWriter          @rtype: vtkImageWriter
190          @return: Image writer          @return: Image writer
191          """          """
192    
193          if(self.__renderer == Renderer.OFFLINE_JPG):          if(self.__renderer.endswith(self.__JPG)):
194              return vtk.vtkJPEGWriter()              return vtk.vtkJPEGWriter()
195          elif(self.__renderer == Renderer.OFFLINE_BMP):          elif(self.__renderer.endswith(self.__BMP)):
196              return vtk.vtkBMPWriter()              return vtk.vtkBMPWriter()
197          elif(self.__renderer == Renderer.OFFLINE_PNM):          elif(self.__renderer.endswith(self.__PNM)):
198              return vtk.vtkPNMWriter()              return vtk.vtkPNMWriter()
199          elif(self.__renderer == Renderer.OFFLINE_PNG):          elif(self.__renderer.endswith(self.__PNG)):
200              return vtk.vtkPNGWriter()              return vtk.vtkPNGWriter()
201          elif(self.__renderer == Renderer.OFFLINE_TIF):          elif(self.__renderer.endswith(self.__TIF)):
202              return vtk.vtkTIFFWriter()              return vtk.vtkTIFFWriter()
203          elif(self.__renderer == Renderer.OFFLINE_PS):          elif(self.__renderer.endswith(self.__PS)):
204              return vtk.vtkPostScriptWriter()              return vtk.vtkPostScriptWriter()
205            
206      def saveImage(self, image_name):      def __saveImage(self, image_name):
207          """          """
208          Save the rendered object as an image.          Save the rendered object as an image.
209    
210          @type image_name: String          @type image_name: String
211          @param image_name: Name of the saved image.          @param image_name: Name of the saved image.
212          """          """
       
         try:  
             # NOTE: Render and Modified must be called everytime before writing  
             # an image. Otherwise, only the first image will always be saved.  
             # This is due to the architecture of VTK.  
             self.__vtk_render_window.Render()  
             self.__vtk_window_to_image.Modified()  
               
             # Retrieve rendered object from the window and convert it into an  
             # image.  
             self.__vtk_image_writer.SetInput(  
                     self.__vtk_window_to_image.GetOutput())  
             self.__vtk_image_writer.SetFileName(image_name)  
             self.__vtk_image_writer.Write()      
         except AttributeError:  
             print "ERROR: Incorrect use of the '" + self.__renderer + \  
                     "' renderer. Kindly, use the 'offline' renderer instead."  
213    
214      def animate(self):          # NOTE: Render and Modified must be called everytime before writing
215            # an image. Otherwise, only the first image will always be saved.
216            # This is due to the architecture of VTK.
217            #self.__vtk_render_window.Render()
218            self.__vtk_window_to_image.Modified()
219            
220            # Retrieve rendered object from the window and convert it into an
221            # image.
222            self.__vtk_image_writer.SetInput(
223                    self.__vtk_window_to_image.GetOutput())
224            self.__vtk_image_writer.SetFileName(image_name)
225            self.__vtk_image_writer.Write()    
226    
227        def __animate(self):
228          """          """
229          Animate the object onto the scene on-the-fly. No interaction can occur.          Animate the object onto the scene on-the-fly. No interaction can occur.
230          """          """
231    
232          self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
233    
234      def render(self):      def render(self, image_name = None):
235          """          """
236          Render the object onto the scene.          Render the object either onto the scene or save it as an image or both.
237            (depending on the type of renderer).
238          """          """
239    
240          try:          # With Render() ONLY, the rendered object is animated onto the
241              self.__vtk_render_window.Render()          # scene on-the-fly and no interaction can occur.
242            self.__vtk_render_window.Render()
243    
244            if(self.__renderer.startswith(Renderer.ONLINE)):
245              # NOTE: Once Start is executed, the driver will not further execute              # NOTE: Once Start is executed, the driver will not further execute
246              # any subsequent codes thereafter.              # any subsequent codes thereafter unless the 'q' or 'e' keys are
247                # pressed.
248              self.__vtk_render_window_interactor.Start()              self.__vtk_render_window_interactor.Start()
249          except AttributeError:  
250              print "ERROR: Incorrect use of the '" + self.__renderer + \              # True for all online renderers except Renderer.ONLINE.
251                      "' renderer. Kindly, switch to the 'online'  renderer."              if(self.__renderer != Renderer.ONLINE):
252                    self.__saveImage(image_name)                    
253            # True for all display renderers except Renderer.DISPLAY.
254            elif(self.__renderer.startswith(self.__OFFLINE) or
255                    self.__renderer != Renderer.DISPLAY):
256                self.__saveImage(image_name)                    
257    
258            
259      def _addActor3D(self, viewport, actor):      def _addActor3D(self, viewport, actor):
260          """          """

Legend:
Removed from v.1037  
changed lines
  Added in v.1067

  ViewVC Help
Powered by ViewVC 1.1.26