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

Contents of /trunk/pyvisi_old/examples/basicContourExample.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: 3496 byte(s)
switched off pyvisi
1 # $Id: basicContourExample.py,v 1.7 2005/04/29 00:32:20 paultcochrane Exp $
2
3 """
4 Example of a basic contour plot
5
6 Will hopefully help me write a decent interface.
7
8 @var __author__: name of author
9 @var __license__: licence agreement
10 @var __copyright__: copyrights
11 @var __url__: url entry point on documentation
12 @var __version__: version
13 @var __date__: date of the version
14 """
15
16 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
17 http://www.access.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __author__="Paul Cochrane"
22 __url__="http://www.iservo.edu.au/esys"
23 __version__="$Revision$"
24 __date__="$Date$"
25
26
27 import sys,os
28
29 # import the python visualisation interface
30 from esys.pyvisi import *
31
32 # original vtk code
33 import vtk
34
35 import numarray
36
37 # generate the x and y grid data
38 x = numarray.arrayrange(-1, 1, stride=0.5, type='Float')
39 y = numarray.arrayrange(-1, 1, stride=0.5, type='Float')
40
41 # generate a matrix of repeated x values (c.f. repmat() in matlab)
42 xm = numarray.zeros([len(x), len(y)], type='Float')
43 for i in range(len(y)):
44 xm[:,i] = x
45
46 # generate a matrix of repeated y values (c.f. repmat() in matlab)
47 ym = numarray.zeros([len(x), len(y)], type='Float')
48 for i in range(len(x)):
49 ym[i,:] = y
50
51 sigma = 0.2 # the spread of the distribution
52
53 # generate the distribution
54 distn = numarray.exp(-(xm*xm + ym*ym)/sigma)
55
56 # convert the x data into vtkFloatArray objects
57 xvtk = vtk.vtkFloatArray()
58 for i in range(len(x)):
59 xvtk.InsertNextValue(x[i])
60
61 # convert the y data into vtkFloatArray objects
62 yvtk = vtk.vtkFloatArray()
63 for i in range(len(y)):
64 yvtk.InsertNextValue(y[i])
65
66 # convert the distribution data into vtkFloatArray objects
67 distnvtk = vtk.vtkFloatArray()
68 for i in range(len(x)):
69 for j in range(len(y)):
70 distnvtk.InsertNextValue(distn[i,j])
71
72 # make the points to put into the grid
73 points = vtk.vtkPoints()
74 values = vtk.vtkFloatArray()
75 count = 0
76 for i in xrange(len(x)):
77 for j in xrange(len(y)):
78 points.InsertPoint(count, x[i], y[j], 0)
79 values.InsertValue(count, distn[i,j])
80 count += 1
81
82 # now make the strips (whatever they are...)
83 #strips = vtk.vtkCellArray()
84 #strips.InsertNextCell(len(x)*len(y)) # number of points
85 #for i in xrange(len(x)*len(y)):
86 #strips.InsertCellPoint(i)
87
88 #strips.InsertCellPoint(0)
89 #strips.InsertCellPoint(1)
90 #strips.InsertCellPoint(7)
91 #strips.InsertCellPoint(6)
92 #strips.InsertCellPoint(2)
93 #strips.InsertCellPoint(3)
94 #strips.InsertCellPoint(5)
95 #strips.InsertCellPoint(4)
96
97 strips = vtk.vtkCellArray()
98 p2c = vtk.vtkPointDataToCellData()
99 p2c.SetInput(points)
100
101 # set up the polygonal data object
102 polyData = vtk.vtkPolyData()
103 polyData.SetPoints(points)
104 polyData.SetStrips(strips)
105 polyData.GetPointData().SetScalars(values)
106
107 warp = vtk.vtkWarpScalar()
108 warp.SetInput(polyData)
109 warp.SetScaleFactor(0.5)
110
111 contMapper = vtk.vtkPolyDataMapper()
112 contMapper.SetInput(warp.GetPolyDataOutput())
113 contMapper.SetScalarRange(polyData.GetScalarRange())
114
115 contActor = vtk.vtkActor()
116 contActor.SetMapper(contMapper)
117
118 ren = vtk.vtkRenderer()
119 renWin = vtk.vtkRenderWindow()
120 renWin.AddRenderer(ren)
121 iren = vtk.vtkRenderWindowInteractor()
122 iren.SetRenderWindow(renWin)
123
124 ren.AddActor(contActor)
125 renWin.SetSize(400,400)
126 ren.SetBackground(1,1,1)
127 iren.Initialize()
128 renWin.Render()
129 iren.Start()
130 #raw_input("Press enter to continue")
131
132
133 # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26