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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 860 - (show annotations)
Thu Sep 28 08:17:29 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 3558 byte(s)
- added sample drivers on how to use all of the currently available modules.
- completed the epydocs for all the currently available modules.
- added the rotation feature for camera and plane cutting.


1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from constants import *
8
9 class Scene:
10 """
11 Class that defines a scene in which components are displayed.
12 """
13
14 def __init__(self, renderer, x_size = 800, y_size = 600):
15 """
16 @type renderer: String
17 @param renderer: Type of rendering
18 @type x_size: Number
19 @param x_size: Size of the rendering window on the x-axis
20 @type y_size: Number
21 @param y_size: Size of the rendering window on the y-axis
22 """
23
24 self.renderer = renderer
25 self.x_size = x_size
26 self.y_size = y_size
27 self.vtk_renderer = vtk.vtkRenderer()
28 self.vtk_render_window = vtk.vtkRenderWindow()
29
30 self.setRenderWindow()
31 #self.setRenderWindowInteractor()
32
33 def saveImage(self, image_name):
34 """
35 Save the rendered object as an image.
36 @type image_name: String
37 @param image_name: Name of the image file
38 """
39
40 self.vtk_render_window.Render()
41 #self.vtk_render_window.OffScreenRenderingOn()
42 #self.vtk_render_window.OffScreenRenderingOff()
43
44 # Converts the output of the render window into vtkImageData.
45 vtk_window_to_image = vtk.vtkWindowToImageFilter()
46 vtk_window_to_image.Modified() # Update precaution
47 vtk_window_to_image.Update() # Update precaution
48 vtk_window_to_image.SetInput(self.vtk_render_window)
49 # Force an update to the of the output image as vtk window's
50 # modification time does not get updated automatically.
51 vtk_window_to_image.Modified() # Update precaution
52 vtk_window_to_image.Update() # Update precaution
53
54 # Write the image to file.
55 vtk_image_writer = self.getImageWriter(self.renderer)
56 vtk_image_writer.SetInput(vtk_window_to_image.GetOutput())
57 vtk_image_writer.SetFileName(image_name)
58 vtk_image_writer.Write()
59
60
61 def setRenderWindow(self):
62 """
63 Set up the renderer and rendering window.
64 """
65
66 self.vtk_render_window.AddRenderer(self.vtk_renderer)
67 # Title of the render window.
68 self.vtk_render_window.SetWindowName(
69 "Earth Systems Science Computational Centre Rendering Tool")
70 self.vtk_render_window.SetSize(self.x_size, self.y_size)
71 # Default background color is white.
72 self.vtk_renderer.SetBackground(
73 WHITE[0], WHITE[1], WHITE[2])
74
75 def setRenderWindowInteractor(self):
76 """
77 Set up the render window interactor.
78 """
79
80 vtk_render_window_interactor = vtk.vtkRenderWindowInteractor()
81 vtk_render_window_interactor.SetRenderWindow(self.vtk_render_window)
82 vtk_render_window_interactor.Initialize()
83 self.vtk_render_window.Render()
84 vtk_render_window_interactor.Start()
85
86
87 def render(self):
88 """
89 Render the image.
90 """
91
92 vtk_render_window_interactor = vtk.vtkRenderWindowInteractor()
93 vtk_render_window_interactor.SetRenderWindow(self.vtk_render_window)
94 vtk_render_window_interactor.Initialize()
95 self.vtk_render_window.Render()
96 vtk_render_window_interactor.Start()
97
98
99 def getImageWriter(self, renderer):
100 """
101 Determine the type of renderer and return the correponding image writer.
102 @type renderer: String
103 @param renderer: Type of renderer
104 """
105
106 if(renderer == "vtk_jpeg"):
107 return vtk.vtkJPEGWriter()
108 elif(renderer == "vtk_bmp"):
109 return vtk.vtkBMPWriter()
110 elif(renderer == "vtk_pnm"):
111 return vtk.vtkPNMWriter()
112 elif(renderer == "vtk_png"):
113 return vtk.vtkPNGWriter()
114 elif(renderer == "vtk_tiff"):
115 return vtk.vtkTIFFWriter()
116 elif(renderer == "vtk_ps"):
117 return vtk.vtkPostScriptWriter()
118
119 def getRenderer(self):
120 """
121 Return the renderer.
122
123 @rtype: vtkRenderer
124 @return: VTK renderer that is used to render objects on the window
125 """
126
127 return self.vtk_renderer

  ViewVC Help
Powered by ViewVC 1.1.26