/[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 879 - (show annotations)
Wed Oct 25 03:56:34 2006 UTC (14 years, 4 months ago) by jongui
File MIME type: text/x-python
File size: 3669 byte(s)
First prototype of pyvisi is almost done (testing to be done). 
Added all the epydocs and latex files.

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 to be 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 self.vtk_render_window_interactor = vtk.vtkRenderWindowInteractor()
30
31 self.setRenderWindow()
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.OffScreenRenderingOn()
41 self.vtk_render_window.Render()
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.Update() # Update precaution
47 vtk_window_to_image.SetInput(self.vtk_render_window)
48 vtk_window_to_image.Modified() # Update precaution
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 render(self):
76 """
77 Render the image.
78 """
79
80 # True if not initialized yet.
81 if(self.vtk_render_window_interactor.GetInitialized() == 0):
82 self.vtk_render_window_interactor.SetRenderWindow(
83 self.vtk_render_window)
84 self.vtk_render_window_interactor.Initialize()
85 self.vtk_render_window.Render()
86 #self.vtk_render_window_interactor.GetInitialized()
87 self.vtk_render_window_interactor.Start()
88 else: # True if already initialized.
89 #self.vtk_render_window.Modified()
90 self.vtk_render_window.Render()
91 #self.vtk_render_window.Modified()
92
93 def animate(self):
94 """
95 Perform animation on the fly by rendering many files. No interaction
96 can occur.
97 """
98
99 self.vtk_render_window.Render()
100
101 def getImageWriter(self, renderer):
102 """
103 Determine the type of renderer and return the correponding image writer.
104 @type renderer: String
105 @param renderer: Type of renderer
106 """
107
108 if(renderer == "vtk_jpeg"):
109 return vtk.vtkJPEGWriter()
110 elif(renderer == "vtk_bmp"):
111 return vtk.vtkBMPWriter()
112 elif(renderer == "vtk_pnm"):
113 return vtk.vtkPNMWriter()
114 elif(renderer == "vtk_png"):
115 return vtk.vtkPNGWriter()
116 elif(renderer == "vtk_tiff"):
117 return vtk.vtkTIFFWriter()
118 elif(renderer == "vtk_ps"):
119 return vtk.vtkPostScriptWriter()
120
121 def getRenderer(self):
122 """
123 Return the renderer.
124
125 @rtype: vtkRenderer
126 @return: VTK renderer that is used to render objects on the window
127 """
128
129 return self.vtk_renderer

  ViewVC Help
Powered by ViewVC 1.1.26