/[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 803 by gross, Wed Aug 9 23:18:05 2006 UTC revision 822 by jongui, Tue Aug 29 01:39:27 2006 UTC
# Line 19  __url__="http://www.iservo.edu.au/esys" Line 19  __url__="http://www.iservo.edu.au/esys"
19  __version__="$Revision:$"  __version__="$Revision:$"
20  __date__="$Date:$"  __date__="$Date:$"
21    
22  from camera import IsometricCamera  import vtk
23  from colors import White  
24    class OpenScene:
25        def __init__(self, renderer = "vtk-online", x_size = 800, y_size = 600):
26            self.renderer = renderer
27            self.x_size = x_size
28            self.y_size = y_size
29            self.vtk_renderer = None
30            self.vtk_render_window = None
31    
32            self.setupRenderingWindow()
33    
34        def setupRenderingWindow(self):
35            self.vtk_renderer = vtk.vtkRenderer()
36            self.vtk_render_window = vtk.vtkRenderWindow()
37            self.vtk_render_window.AddRenderer(self.vtk_renderer)
38            self.vtk_render_window.SetSize(self.x_size, self.y_size)
39            self.vtk_renderer.SetBackground(1, 1, 1)    
40    
41        def render(self):
42            vtk_render_window_interactor = vtk.vtkRenderWindowInteractor()
43            vtk_render_window_interactor.SetRenderWindow(self.vtk_render_window)
44            vtk_render_window_interactor.Initialize()
45            self.vtk_render_window.Render()
46            vtk_render_window_interactor.Start()
47    
48        def getRenderer(self):
49            return self.vtk_renderer
50            
51            
52    
53    
54        
55    
56    
57    
 def Scene(Component):  
    """  
    a scene for visualization  
    """  
    def __init__(self,x_size,y_size):  
       super(Scene, self).__init__()  
       self.x_size=x_size  
       self.y_size=y_size  
       self.setBackgroundColor()  
       self.setCamera()  
   
    def render(self,filename=None,wait=False):  
       """  
       renders the scene. If filename is present the file is rendered in the file filename  
       """  
       pass  
   
    def _addComponent(self,comp):  
        pass  
   
    def setBackgroundColor(self,color=White()):  
       """  
       Sets the background color of the Scene  
   
       @param color: The color to set the background to.  Can be RGB or CMYK  
       @type color: L{Color}  
       """  
       pass  
   
 def openScene(renderer="pyvisi",x_size=640,y_size=480):  
      """  
      opens a scene  
   
      @param renderer: renderer to be used  
      @param x_size: window width (in pixel)  
      @param y_size: window height (in pixel)  
      @param camera: camera  
      @param background: background color  
      @returns: L{Scene}  
      """  
      if renderer == "vtk_online":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"online", offscreen=False)  
      elif renderer == "vtk_ps":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"ps", offscreen=True)  
      elif renderer == "vtk_png":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"png", offscreen=True)  
      elif renderer == "vtk_jpeg":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"jpeg", offscreen=True)  
      elif renderer == "vtk_tiff":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"tiff", offscreen=True)  
      elif renderer == "vtk_bmp":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"bmp", offscreen=True)  
      elif renderer == "vtk_pnm":  
          import renderers.vtk.VTKScene as VTKScene  
          return VTKScene(x_size,y_size,"pnm", offscreen=True)  
      elif renderer == "pyvisi" or renderer==None:  
          import Scene  
          return Scene(x_size,y_size)  
      else:  
          raise ValueError, "Unknown renderer %s."%renderer  
 ##########################################################################################  
 ## vtk specific stuff (should be in renderers.vtk)  
 ##########################################################################################  
 def renderArrow(comp):  
       pass #  
 class VTKScene(Scene):  
     def __init__(x_size,y_size,format,offscreen):  
          super(VTKScene, self).__init__()  
          self.__comps=[]  
          pass  
     def _addComponent(self,comp):  
         if isinstance(Arrow,comp):  
            # ... some vtk set up here"  
            comp._render=renderArrow  
         self.__comps.append(comp)  
   
     def render(self,filename=None,wait=False):  
       """  
       renders the scene. If filename is present the file is rendered in the file filename  
       """  
       for i in self.__comps: i.render()  
       pass # more rendering work  
       for i in self.__comps: i.markFeaturesAsUsed()  
     

Legend:
Removed from v.803  
changed lines
  Added in v.822

  ViewVC Help
Powered by ViewVC 1.1.26