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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26