/[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 948 by jongui, Mon Jan 29 07:22:43 2007 UTC revision 949 by jongui, Fri Feb 2 05:33:05 2007 UTC
# Line 16  class Scene: Line 16  class Scene:
16          Initialise the scene.          Initialise the scene.
17    
18          @type renderer: String          @type renderer: String
19          @param renderer: Type of rendering (i.e. online, offline_jpeg, etc)          @param renderer: Type of rendering (i.e.Renderer.ONLINE, etc)
20          @type num_viewport: Number          @type num_viewport: Number
21          @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
22          @type x_size: Number          @type x_size: Number
23          @param x_size: Size of the render window on the x-axis          @param x_size: Size of the render window along the x-axis
24          @type y_size: Number          @type y_size: Number
25          @param y_size: Size of the render window on the y-axis          @param y_size: Size of the render window along the y-axis
26          """          """
27    
28          self.__renderer = renderer          self.__renderer = renderer
29          self.__num_viewport = num_viewport          self.__num_viewport = num_viewport
30            self.__x_size = x_size
31            self.__y_size = y_size
32            
         self.__createViewport()          
33          self.__vtk_render_window = vtk.vtkRenderWindow()          self.__vtk_render_window = vtk.vtkRenderWindow()
34            self.__setupScene()
35            
36        def __setupScene(self):
37            """
38            Setup the scene.
39            """
40    
41            self.__createViewport()        
42          self.__addRenderer()          self.__addRenderer()
43          self.setBackground(Color.WHITE) # Default background color is white.          self.setBackground(Color.WHITE) # Default background color is white.
44    
45          # Default title bar.          # Default title bar.
46          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")          self.setTitleBar("Earth Systems Science Computational Centre (ESSCC)")
47          self.__setSize(x_size, y_size)          self.__setSize(self.__x_size, self.__y_size)
48                    
49          if(renderer == Renderer.ONLINE): # True for online rendering.          if(self.__renderer == Renderer.ONLINE): # True for online rendering.
50              self.__setupOnlineRendering()              self.__setupOnlineRendering()
51          else: # True for offline rendering.          else: # True for offline rendering.
52              self.__setupOfflineRendering()              self.__setupOfflineRendering()
53    
54    
55      def __createViewport(self):      def __createViewport(self):
56          """          """
57          Create the viewport(s) in the scene.          Create the viewport(s) in the scene.
58          """          """
59    
60          # Create the the renderer(s) for the viewport(s).          # Create the renderer(s) for the viewport(s).
61          self.__vtk_renderer = []          self.__vtk_renderer = []
62          for viewport in range(0, self.__num_viewport):          for viewport in range(0, self.__num_viewport):
63              self.__vtk_renderer.append(vtk.vtkRenderer())              self.__vtk_renderer.append(vtk.vtkRenderer())
# Line 74  class Scene: Line 86  class Scene:
86                    
87          # Color the entire scene (background) black initially.          # Color the entire scene (background) black initially.
88          # This is carried out mainly to have the borders between          # This is carried out mainly to have the borders between
89          # the viewports black.          # the viewports visibly black.
90          if(self.__num_viewport == 4):          if(self.__num_viewport == 4):
91              self.__vtk_renderer_background.SetBackground(Color.BLACK)              self.__vtk_renderer_background.SetBackground(Color.BLACK)
92    
# Line 108  class Scene: Line 120  class Scene:
120          Set the size of the render window.          Set the size of the render window.
121    
122          @type x_size: Number          @type x_size: Number
123          @param x_size: Size of the render window on the x-axis          @param x_size: Size of the render window along the x-axis
124          @type y_size: Number          @type y_size: Number
125          @param y_size: Size of the render window on the y-axis          @param y_size: Size of the render window along the y-axis
126          """          """
127    
128          self.__vtk_render_window.SetSize(x_size, y_size)              self.__vtk_render_window.SetSize(x_size, y_size)    
# Line 142  class Scene: Line 154  class Scene:
154          """          """
155          Return the appropriate image writer based on the specified offline          Return the appropriate image writer based on the specified offline
156          renderer.          renderer.
157    
158            @rtype: vtkImageWriter
159            @return: Image writer
160          """          """
161    
162          if(self.__renderer == Renderer.OFFLINE_JPG):          if(self.__renderer == Renderer.OFFLINE_JPG):
163              return vtk.vtkJPEGWriter() # Generate a .jpg image              return vtk.vtkJPEGWriter()
164          elif(self.__renderer == Renderer.OFFLINE_BMP):          elif(self.__renderer == Renderer.OFFLINE_BMP):
165              return vtk.vtkBMPWriter()              return vtk.vtkBMPWriter()
166          elif(self.__renderer == Renderer.OFFLINE_PNM):          elif(self.__renderer == Renderer.OFFLINE_PNM):
# Line 159  class Scene: Line 174  class Scene:
174            
175      def saveImage(self, image_name):      def saveImage(self, image_name):
176          """          """
177          Save the rendered objects as an image.          Save the rendered object as an image.
178    
179          @type image_name: String          @type image_name: String
180          @param image_name: Name of the saved image.          @param image_name: Name of the saved image.
# Line 171  class Scene: Line 186  class Scene:
186          self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
187          self.__vtk_window_to_image.Modified()          self.__vtk_window_to_image.Modified()
188                    
189          # Retrieve the the converted imaged from the window.          # Retrieve rendered object from the window and convert it into an
190            # image.
191          self.__vtk_image_writer.SetInput(          self.__vtk_image_writer.SetInput(
192                  self.__vtk_window_to_image.GetOutput())                  self.__vtk_window_to_image.GetOutput())
193          self.__vtk_image_writer.SetFileName(image_name)          self.__vtk_image_writer.SetFileName(image_name)
# Line 179  class Scene: Line 195  class Scene:
195    
196      def render(self):      def render(self):
197          """          """
198          Render the objects onto the scene.          Render the object onto the scene.
199          """          """
200    
201          self.__vtk_render_window.Render()          self.__vtk_render_window.Render()
202    
203          # NOTE: Once Start is executed, the driver will not further execute          # NOTE: Once Start is executed, the driver will not further execute
204          # any subsequent codes thereafter.          # any subsequent codes thereafter.
205          self.__vtk_render_window_interactor.Start()          self.__vtk_render_window_interactor.Start()
# Line 217  class Scene: Line 235  class Scene:
235          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
236          @param viewport: Viewport which the camera is to be added to          @param viewport: Viewport which the camera is to be added to
237          @type camera: L{Camera <camera.Camera>} object          @type camera: L{Camera <camera.Camera>} object
238          @param camera: Camera to be assigned to the viewport          @param camera: Camera which is to be assigned to the viewport
239          """          """
240    
241          self.__vtk_renderer[viewport].SetActiveCamera(camera)          self.__vtk_renderer[viewport].SetActiveCamera(camera)
# Line 225  class Scene: Line 243  class Scene:
243      def _addLight(self, viewport, light):      def _addLight(self, viewport, light):
244          """          """
245          Add the light to the appropriate viewport.          Add the light to the appropriate viewport.
246    
247          @type viewport: L{Viewport <constant.Viewport>} constant          @type viewport: L{Viewport <constant.Viewport>} constant
248          @param viewport: Viewport which the camera is to be added to          @param viewport: Viewport which the camera is to be added to
249          @type light: L{Light <light.Light>} object          @type light: L{Light <light.Light>} object
250          @param light: Light to be assigned to the viewport          @param light: Light which is to be assigned to the viewport
251          """          """
252    
253          self.__vtk_renderer[viewport].AddLight(light)          self.__vtk_renderer[viewport].AddLight(light)
# Line 237  class Scene: Line 256  class Scene:
256          """          """
257          Return the renderer(s)          Return the renderer(s)
258    
259          @rtype: One column list of vtkRenderer          @rtype: One or more column tuple of vtkRenderer
260          @return: Renderer(s)          @return: Renderer(s)
261          """          """
262            

Legend:
Removed from v.948  
changed lines
  Added in v.949

  ViewVC Help
Powered by ViewVC 1.1.26