/[escript]/trunk/pyvisi/examples/view2DMeshExample.py
ViewVC logotype

Annotation of /trunk/pyvisi/examples/view2DMeshExample.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (hide annotations)
Mon Dec 12 01:57:07 2005 UTC (13 years, 10 months ago) by cochrane
File MIME type: text/x-python
File size: 2499 byte(s)
Initial merge of pyvisi into esys repository.
1 cochrane 337 # Copyright (C) 2004 Paul Cochrane
2     #
3     # This program is free software; you can redistribute it and/or
4     # modify it under the terms of the GNU General Public License
5     # as published by the Free Software Foundation; either version 2
6     # of the License, or (at your option) any later version.
7     #
8     # This program is distributed in the hope that it will be useful,
9     # but WITHOUT ANY WARRANTY; without even the implied warranty of
10     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11     # GNU General Public License for more details.
12     #
13     # You should have received a copy of the GNU General Public License
14     # along with this program; if not, write to the Free Software
15     # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16    
17     # $Id: view2DMeshExample.py,v 1.3 2005/02/08 08:27:26 paultcochrane Exp $
18    
19     ## @file view2DMeshExample.py
20    
21     """
22     Example of loading a two-dimensional mesh into pyvisi and viewing it
23    
24     Will hopefully help me write a decent interface.
25     """
26    
27     import sys,os
28    
29     # this means that one can run the script from the examples directory
30     sys.path.append('../')
31    
32     # import the python visualisation interface
33     from pyvisi import *
34     # import vtk stuff
35     from pyvisi.renderers.vtk import *
36    
37     # start a scene, using vtk as the renderer
38     scene = Scene()
39     scene.setSize()
40     scene.setBackgroundColor(0,0,0)
41    
42     # render the scene
43     scene.render(pause=True)
44    
45     # put an exit in here so that we don't run the vtk code
46     sys.exit()
47    
48     # here is the original vtk code
49    
50     import vtk
51    
52     # set up the renderer and render window
53     _renderer = vtk.vtkRenderer()
54     _renderWindow = vtk.vtkRenderWindow()
55     _renderWindow.AddRenderer(_renderer)
56     _renderWindow.SetSize(1024,768)
57     _renderer.SetBackground(0,0,0)
58    
59     # load the jpeg file
60     _jpegReader = vtk.vtkJPEGReader()
61     _jpegReader.SetFileName("Flinders_eval.jpg")
62    
63     # set the jpeg file to the texture
64     _tex = vtk.vtkTexture()
65     _tex.SetInput(_jpegReader.GetOutput())
66    
67     # get the plane and add it to the "scene"
68     _plane = vtk.vtkPlaneSource()
69     _planeMapper = vtk.vtkPolyDataMapper()
70     _planeMapper.SetInput(_plane.GetOutput())
71     _planeActor = vtk.vtkActor()
72     _planeActor.SetMapper(_planeMapper)
73     _planeActor.SetTexture(_tex)
74     _renderer.AddActor(_planeActor)
75    
76     # set up a camera
77     _camera = vtk.vtkCamera()
78     _camera.SetFocalPoint(0,0,0)
79     _camera.SetPosition(1,1,1)
80     _camera.ComputeViewPlaneNormal()
81     _camera.SetViewUp(1,0,0)
82     _camera.OrthogonalizeViewUp()
83    
84     _renderer.SetActiveCamera(_camera)
85     _renderer.ResetCamera()
86    
87     # now see what was produced
88     _renderWindow.Render()
89    
90     raw_input("Press enter to continue")
91    
92    

  ViewVC Help
Powered by ViewVC 1.1.26