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

Contents of /trunk/pyvisi/examples/imageOnPlane.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 337 - (show annotations)
Mon Dec 12 01:57:07 2005 UTC (13 years, 9 months ago) by cochrane
File MIME type: text/x-python
File size: 3602 byte(s)
Initial merge of pyvisi into esys repository.
1 # 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: imageOnPlane.py,v 1.2 2005/01/11 05:47:51 paultcochrane Exp $
18
19 ## @file imageLoadExample.py
20
21 """
22 Example of loading an image into pyvisi and mapping onto a plane
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 the vtk stuff
35 from pyvisi.renderers.vtk import *
36
37 # start a scene, using vtk as the renderer
38 scene = Scene()
39
40 # load a jpeg image into the scene
41 jpegImage = JpegImage(scene)
42 jpegImage.load(file="Flinders_eval.jpg")
43
44 # define a plane to map image to, and map it
45 plane = Plane(scene)
46 plane.mapImageToPlane(jpegImage)
47 plane.render()
48
49 # maybe instead of this render() mechanism, I should be explictly adding
50 # objects to be rendered at the end. Also, instead of trying to (say) render
51 # absolutely everything in that is intantiated, maybe have the add() mechanism
52 # that Alexei recommended. Say instead, jpegImage.addToScene(scene), which
53 # would have the ability to add the same object to different scenes.... And
54 # then all "added" objects would be rendered in the end. Need to think on
55 # this one...
56
57 # initialise a camera
58 camera = Camera(scene)
59
60 # I would far rather use this code, but atm, I can't work out how to do it
61 # scene.render()
62 # so I'm going to use this
63 #for i in range(360):
64 #scene.vtkCommand("_renderWindow.Render()")
65 #camera.setElevation(1)
66 #camera.setAzimuth(1)
67 #scene.vtkCommand("_renderer.ResetCamera()")
68 #evalStr = "print \"Angle is %d\"" % i
69 #scene.vtkCommand(evalStr)
70
71 scene.setBackgroundColor(0,0,0)
72
73 # render the scene
74 scene.render(pause=True,interactive=True)
75
76 # put an exit in here so that we don't run the vtk code
77 sys.exit()
78
79 # here is the original vtk code
80
81 import vtk
82
83 # set up the renderer and render window
84 _renderer = vtk.vtkRenderer()
85 _renderWindow = vtk.vtkRenderWindow()
86 _renderWindow.AddRenderer(_renderer)
87 _renderWindow.SetSize(1024,768)
88 _renderer.SetBackground(1,1,1)
89
90 # load the jpeg file
91 _jpegReader = vtk.vtkJPEGReader()
92 _jpegReader.SetFileName("Flinders_eval.jpg")
93
94 # set the jpeg file to the texture
95 _tex = vtk.vtkTexture()
96 _tex.SetInput(_jpegReader.GetOutput())
97
98 # get the plane and add it to the "scene"
99 _plane = vtk.vtkPlaneSource()
100 _planeMapper = vtk.vtkPolyDataMapper()
101 _planeMapper.SetInput(_plane.GetOutput())
102 _planeActor = vtk.vtkActor()
103 _planeActor.SetMapper(_planeMapper)
104 _planeActor.SetTexture(_tex)
105 _renderer.AddActor(_planeActor)
106
107 # set up a camera
108 _camera = vtk.vtkCamera()
109 _camera.SetFocalPoint(0,0,0)
110 _camera.SetPosition(1,1,1)
111 _camera.ComputeViewPlaneNormal()
112 _camera.SetViewUp(1,0,0)
113 _camera.OrthogonalizeViewUp()
114
115 _renderer.SetActiveCamera(_camera)
116 _renderer.ResetCamera()
117
118 # now see what was produced
119 _renderWindow.Render()
120
121 raw_input("Press enter to continue")
122
123

  ViewVC Help
Powered by ViewVC 1.1.26