/[escript]/trunk/pyvisi/py_src/renderers/plplot/surface_plot.py
ViewVC logotype

Annotation of /trunk/pyvisi/py_src/renderers/plplot/surface_plot.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 603 - (hide annotations)
Mon Mar 20 01:49:39 2006 UTC (15 years, 6 months ago) by gross
File MIME type: text/x-python
File size: 6596 byte(s)
pyvisi compiles now
1 cochrane 337 # Copyright (C) 2004-2005 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: surface_plot.py,v 1.1 2005/11/30 07:12:40 paultcochrane Exp $
18    
19     """
20     This file contains all of the classes for the various plotting objects.
21     """
22    
23     from pyvisi.renderers.plplot.common import debugMsg
24    
25     from pyvisi.renderers.plplot.plot import Plot
26    
27     __revision__ = '$Revision: 1.1 $'
28    
29 gross 603 class SurfacePlot(Plot):
30 cochrane 337 """
31     Surface plot
32     """
33    
34     def __init__(self, scene):
35     """
36     Initialisation of SurfacePlot class
37    
38     @param scene: the scene with which to associate the SurfacePlot
39     @type scene: Scene object
40     """
41     debugMsg("Called SurfacePlot.__init__()")
42     Plot.__init__(self, scene)
43    
44     # grab the renderer
45     self.renderer = scene.renderer
46    
47     # set up some of the attributes
48     self.title = None
49     self.xlabel = None
50     self.ylabel = None
51     self.zlabel = None
52    
53     # to show contours of the surface on the bottom of the axes, set
54     # this variable to True
55     self.contours = False
56    
57     # now add the object to the scene
58     scene.add(self)
59    
60     def setData(self, *dataList):
61     """
62     Sets the data to the given plot object.
63    
64     @param dataList: list of data objects to plot
65     @type dataList: tuple
66     """
67     debugMsg("Called setData() in SurfacePlot()")
68    
69     self.renderer.runString("# SurfacePlot.setData()")
70    
71     # for the moment, make sure that there are three arrays
72     if len(dataList) != 3:
73     raise ValueError, "Must have three arrays as input (at present)"
74    
75     # do some sanity checks on the data
76     xData = dataList[0]
77     yData = dataList[1]
78     zData = dataList[2]
79    
80     if len(xData.shape) != 1:
81     raise ValueError, "x data array is not of the correct shape: %s"\
82     % xData.shape
83    
84     if len(yData.shape) != 1:
85     raise ValueError, "y data array is not of the correct shape: %s"\
86     % yData.shape
87    
88     if len(zData.shape) != 2:
89     raise ValueError, "z data array is not of the correct shape: %s"\
90     % zData.shape
91    
92     # pass the data around
93     ## the x data
94     self.renderer.renderDict['_x'] = copy.deepcopy(xData)
95    
96     ## the y data
97     self.renderer.renderDict['_y'] = copy.deepcopy(yData)
98    
99     ## the z data
100     self.renderer.renderDict['_z'] = copy.deepcopy(zData)
101    
102     # determine the min and max of x, y and z in world coordinates
103     evalString = "_xMin = min(_x)\n"
104     evalString += "_xMax = max(_x)\n"
105     evalString += "_yMin = min(_y)\n"
106     evalString += "_yMax = max(_y)\n"
107     evalString += "_zMin = min(_z.flat)\n"
108     evalString += "_zMax = max(_z.flat)"
109     self.renderer.runString(evalString)
110    
111     # min and max of x and y variables in normalised coordinates
112     # values are those recommended in plplot documentation for surface
113     # plots, and are hardcoded here for the meantime.
114     evalString = "_xMin2D = -2.5\n"
115     evalString += "_xMax2D = 2.5\n"
116     evalString += "_yMin2D = -2.5\n"
117     evalString += "_yMax2D = 4.0"
118     self.renderer.runString(evalString)
119    
120     # sides of the box in normalised coordinates, again, these are those
121     # recommended by plplot
122     evalString = "_basex = 2.0\n"
123     evalString += "_basey = 4.0\n"
124     evalString += "_height = 3.0" # possible name clash???
125     self.renderer.runString(evalString)
126    
127     # the angle to view the box (this needs to be set up by a Camera()
128     # object in the future)
129     evalString = "_alt = 45.0\n"
130     evalString += "_az = 30.0"
131     self.renderer.runString(evalString)
132    
133     return
134    
135     def render(self):
136     """
137     Does SurfacePlot object specific rendering stuff
138     """
139     debugMsg("Called SurfacePlot.render()")
140    
141     self.renderer.runString("# SurfacePlot.render()")
142     # initialise plplot
143     self.renderer.runString("plplot.plinit()")
144    
145     # set up the viewport for plotting
146     evalString = "plplot.plenv(_xMin2D,_xMax2D,_yMin2D,_yMax2D, 0, -2)"
147     self.renderer.runString(evalString)
148    
149     # set up the window
150     evalString = "plplot.plw3d(_basex, _basey, _height, "
151     evalString += "_xMin, _xMax, _yMin, _yMax, _zMin, _zMax, "
152     evalString += "_alt, _az)"
153     self.renderer.runString(evalString)
154    
155     # if a title is not set, set it to a null string
156     # (this will help keep plplot happy)
157     if self.title is not None:
158     evalString = "plplot.plmtex(\"t\", 1.0, 0.5, 0.5, \"%s\")" % \
159     self.title
160     self.renderer.runString(evalString)
161    
162     # if an xlabel is not set, set it to a null string
163     if self.xlabel is None:
164     self.xlabel = ""
165    
166     # if a ylabel is not set, set it to a null string
167     if self.ylabel is None:
168     self.ylabel = ""
169    
170     # if a zlabel is not set, set it to a null string
171     if self.zlabel is None:
172     self.zlabel = ""
173    
174     # put the labels (if any) on the graph.
175     evalString = "plplot.plbox3(\"bnstu\", \"%s\", 0.0, 0, " % self.xlabel
176     evalString += "\"bnstu\", \"%s\", 0.0, 0, " % self.ylabel
177     evalString += "\"bcdmnstuv\", \"%s\", 0.0, 0)" % self.zlabel
178     self.renderer.runString(evalString)
179    
180     # plot it!
181     ### note: I can put other shading options into this call
182     evalString = "plplot.plsurf3d(_x, _y, _z, 0, ())"
183     self.renderer.runString(evalString)
184    
185     # finish stuff off
186     self.renderer.runString("plplot.plend()")
187    
188     # if contours is true, set the relevant option
189     if self.contours:
190     pass
191     # I need to implement this!!! And put it further up in render()
192    
193     return
194    
195     # vim: expandtab shiftwidth=4:

  ViewVC Help
Powered by ViewVC 1.1.26