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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 822 - (show annotations)
Tue Aug 29 01:39:27 2006 UTC (13 years, 1 month ago) by jongui
File MIME type: text/x-python
File size: 3377 byte(s)
Added:
trunk/pyvisi/py_src/driver.py

Modified:
trunk/pyvisi/py_src/datacollector.py
trunk/pyvisi/py_src/map.py
trunk/pyvisi/py_src/scene.py


1 """
2 Example of loading an image into pyvisi and mapping onto a plane
3
4 Will hopefully help me write a decent interface.
5
6 @var __author__: name of author
7 @var __license__: licence agreement
8 @var __copyright__: copyrights
9 @var __url__: url entry point on documentation
10 @var __version__: version
11 @var __date__: date of the version
12 """
13
14 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
15 http://www.access.edu.au
16 Primary Business: Queensland, Australia"""
17 __license__="""Licensed under the Open Software License version 3.0
18 http://www.opensource.org/licenses/osl-3.0.php"""
19 __author__="Paul Cochrane"
20 __url__="http://www.iservo.edu.au/esys"
21 __version__="$Revision$"
22 __date__="$Date$"
23
24
25 import sys,os
26
27 # this means that one can run the script from the examples directory
28 sys.path.append('../')
29
30 # import the python visualisation interface
31 from pyvisi_old import *
32 # import the vtk stuff
33 from pyvisi_old.renderers.vtk import *
34
35 # start a scene, using vtk as the renderer
36 scene = Scene()
37
38 # load a jpeg image into the scene
39 jpegImage = JpegImage(scene)
40 jpegImage.load(file="Flinders_eval.jpg")
41
42 # define a plane to map image to, and map it
43 plane = Plane(scene)
44 plane.mapImageToPlane(jpegImage)
45 plane.render()
46
47 # maybe instead of this render() mechanism, I should be explictly adding
48 # objects to be rendered at the end. Also, instead of trying to (say) render
49 # absolutely everything in that is intantiated, maybe have the add() mechanism
50 # that Alexei recommended. Say instead, jpegImage.addToScene(scene), which
51 # would have the ability to add the same object to different scenes.... And
52 # then all "added" objects would be rendered in the end. Need to think on
53 # this one...
54
55 # initialise a camera
56 camera = Camera(scene)
57
58 # I would far rather use this code, but atm, I can't work out how to do it
59 # scene.render()
60 # so I'm going to use this
61 #for i in range(360):
62 #scene.vtkCommand("_renderWindow.Render()")
63 #camera.setElevation(1)
64 #camera.setAzimuth(1)
65 #scene.vtkCommand("_renderer.ResetCamera()")
66 #evalStr = "print \"Angle is %d\"" % i
67 #scene.vtkCommand(evalStr)
68
69 scene.setBackgroundColor(0,0,0)
70
71 # render the scene
72 scene.render(pause=True,interactive=True)
73
74 # put an exit in here so that we don't run the vtk code
75 sys.exit()
76
77 # here is the original vtk code
78
79 import vtk
80
81 # set up the renderer and render window
82 _renderer = vtk.vtkRenderer()
83 _renderWindow = vtk.vtkRenderWindow()
84 _renderWindow.AddRenderer(_renderer)
85 _renderWindow.SetSize(1024,768)
86 _renderer.SetBackground(1,1,1)
87
88 # load the jpeg file
89 _jpegReader = vtk.vtkJPEGReader()
90 _jpegReader.SetFileName("Flinders_eval.jpg")
91
92 # set the jpeg file to the texture
93 _tex = vtk.vtkTexture()
94 _tex.SetInput(_jpegReader.GetOutput())
95
96 # get the plane and add it to the "scene"
97 _plane = vtk.vtkPlaneSource()
98 _planeMapper = vtk.vtkPolyDataMapper()
99 _planeMapper.SetInput(_plane.GetOutput())
100 _planeActor = vtk.vtkActor()
101 _planeActor.SetMapper(_planeMapper)
102 _planeActor.SetTexture(_tex)
103 _renderer.AddActor(_planeActor)
104
105 # set up a camera
106 _camera = vtk.vtkCamera()
107 _camera.SetFocalPoint(0,0,0)
108 _camera.SetPosition(1,1,1)
109 _camera.ComputeViewPlaneNormal()
110 _camera.SetViewUp(1,0,0)
111 _camera.OrthogonalizeViewUp()
112
113 _renderer.SetActiveCamera(_camera)
114 _renderer.ResetCamera()
115
116 # now see what was produced
117 _renderWindow.Render()
118
119 raw_input("Press enter to continue")
120
121

  ViewVC Help
Powered by ViewVC 1.1.26