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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 786 - (show annotations)
Tue Jul 25 04:58:05 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/x-python
File size: 3256 byte(s)
switched off pyvisi
1 # $Id: ballPlot.py,v 1.6 2005/11/08 08:23:45 paultcochrane Exp $
2
3 """
4 Example of plotting spheres with pyvisi
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
26 numArgs = len(sys.argv)
27 if numArgs == 1:
28 ren_mod = "vtk"
29 else:
30 ren_mod = sys.argv[1]
31
32 import random
33
34 # set up some data to plot
35 from Numeric import *
36
37 # the three axes in space
38 # this will give us 10 particles (_not_ 1000)
39 x = arange(10, typecode=Float)
40 y = arange(10, typecode=Float)
41 z = arange(10, typecode=Float)
42
43 # 3D position information
44 posArray = []
45 for i in range(len(x)):
46 for j in range(len(y)):
47 for k in range(len(z)):
48 posArray.append( (x[i], y[j], z[k]) )
49
50 # radius information
51 random.seed()
52 radiiArray = zeros(len(x)*len(y)*len(z), typecode=Float)
53 for i in range(len(x)*len(y)*len(z)):
54 radiiArray[i] = random.random()*0.8
55
56 # tag information
57 random.seed()
58 tagsArray = zeros(len(x)*len(y)*len(z), typecode=Int)
59 for i in range(len(x)*len(y)*len(z)):
60 tagsArray[i] = int(random.random()*10)
61
62 # example code for how a user would write a script in pyvisi
63 from esys.pyvisi import * # base level visualisation stuff
64 # import the objects to render the scene using the specific renderer
65 if ren_mod == "vtk":
66 from esys.pyvisi.renderers.vtk import * # vtk
67 elif ren_mod == "povray":
68 from esys.pyvisi.renderers.povray import * # povray
69 else:
70 raise ValueError, "Unknown renderer module"
71
72 # define the scene object
73 # a Scene is a container for all of the kinds of things you want to put
74 # into your plot for instance, images, meshes, arrow/vector/quiver plots,
75 # contour plots, spheres etc.
76 scene = Scene()
77
78 # create a BallPlot object
79 plot = BallPlot(scene)
80
81 # add some helpful info to the plot
82 plot.title = 'Example ball plot'
83
84 # assign some data to the plot
85 # one way of doing it
86 # (tags indirectly determine colour of the spheres in the plot)
87 plot.setData(points=posArray, radii=radiiArray, tags=tagsArray)
88
89 # render the scene
90 scene.render(pause=True, interactive=True)
91
92 # without specifying a tags array input
93 plot.setData(points=posArray, radii=radiiArray)
94 # render the scene
95 scene.render(pause=True, interactive=True)
96
97 # another way loading an old style-vtk file
98 plot.setData(fname="cp_test_0.vtk",
99 format="vtk",
100 radii="radius",
101 tags="particleTag")
102
103 # render the scene to screen
104 scene.render(pause=True, interactive=True)
105
106 # another way loading a vtk xml file
107 plot.setData(fname="cp_test_0.xml",
108 format="vtk-xml",
109 radii="radius",
110 tags="particleTag")
111
112 # render the scene to screen
113 scene.render(pause=True, interactive=True)
114
115 # save the scene out to file
116 scene.save(fname="ballPlot.png", format="png")
117
118 # vim: expandtab shiftwidth=4:
119

  ViewVC Help
Powered by ViewVC 1.1.26