/[escript]/trunk/pyvisi/pyvisi/renderers/vtk/arrow_plot.py
ViewVC logotype

Diff of /trunk/pyvisi/pyvisi/renderers/vtk/arrow_plot.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 421 by cochrane, Mon Dec 12 01:57:07 2005 UTC revision 422 by cochrane, Fri Jan 6 03:10:54 2006 UTC
# Line 14  Line 14 
14  # along with this program; if not, write to the Free Software  # along with this program; if not, write to the Free Software
15  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16    
17  # $Id: arrow_plot.py,v 1.1 2005/11/30 03:07:18 paultcochrane Exp $  # $Id: arrow_plot.py,v 1.2 2006/01/05 01:51:53 paultcochrane Exp $
18    
19  """  """
20  Class and functions associated with a pyvisi ArrowPlot objects  Class and functions associated with a pyvisi ArrowPlot objects
# Line 29  import copy Line 29  import copy
29  # module specific imports  # module specific imports
30  from pyvisi.renderers.vtk.plot import Plot  from pyvisi.renderers.vtk.plot import Plot
31    
32  __revision__ = '$Revision: 1.1 $'  __revision__ = '$Revision: 1.2 $'
33    
34  class ArrowPlot(Plot):  class ArrowPlot(Plot):
35      """      """
# Line 154  class ArrowPlot(Plot): Line 154  class ArrowPlot(Plot):
154              % len(dataList)              % len(dataList)
155          raise ValueError, errorString          raise ValueError, errorString
156    
157          #####!!!! now process the data properly so that I can plot it.          domainData = escriptX.convertToNumArray()
158          print "escriptZ.shape() = %s" % escriptZ.shape()          fieldData = escriptZ.convertToNumArray()
         print "escriptX.shape() = %s" % escriptX.shape()  
   
         # need to check the length of the vector data...  If it has  
         # z-elements, print a warning and say they are being set to  
         # zero.  Also need to check the grid; it should be just a plane  
         # not a block of data.  
159    
160          raise ImplementationError, "Can't process escript Data yet"          # now check the shapes
161            if len(domainData.shape) != 2:
162            raise ValueError, \
163                "domainData shape is not 2D.  I got %d dims" % \
164                len(domainData.shape)
165    
166            if len(fieldData.shape) != 2:
167            raise ValueError, \
168                "fieldData shape is not 2D.  I got %d dims" % \
169                len(fieldData.shape)
170    
171            # we expect only 2D vectors, so make sure that the second
172            # dimension of the array is equal to 2
173            if fieldData.shape[1] != 2:
174            raise ValueError, \
175                "fieldData vectors not 2D.  I got %d dims" % \
176                fieldData.shape[1]
177    
178            # make sure the lengths agree
179            if domainData.shape[0] != fieldData.shape[0]:
180            raise ValueError, \
181                "domainData and fieldData lengths don't agree"
182    
183            # split the domainData and fieldData up into x and y parts
184            xData = domainData[:,0]
185            yData = domainData[:,1]
186    
187            dxData = fieldData[:,0]
188            dyData = fieldData[:,1]
189    
190            # now pass the data to the render dictionary so that the render code
191            # knows what it's supposed to plot
192            # x data
193            self.renderer.renderDict['_x'] = copy.deepcopy(xData)
194        
195            # y data
196            self.renderer.renderDict['_y'] = copy.deepcopy(yData)
197        
198            # dx data
199            self.renderer.renderDict['_dx'] = copy.deepcopy(dxData)
200        
201            # dy data
202            self.renderer.renderDict['_dy'] = copy.deepcopy(dyData)
203        
204            # keep the number of points for future reference
205            numPoints = len(xData)
206    
207            # construct the points data
208            evalString = "_points = vtk.vtkPoints()\n"
209            evalString += "_points.SetNumberOfPoints(%d)\n" % numPoints
210            evalString += "for _j in range(%d):\n" % numPoints
211            evalString += "    _points.InsertPoint(_j, _x[_j], _y[_j], 0.0)\n"
212            self.renderer.runString(evalString)
213    
214            # construct the vectors
215            evalString = "_vectors = vtk.vtkFloatArray()\n"
216            evalString += "_vectors.SetNumberOfComponents(3)\n"
217            evalString += "_vectors.SetNumberOfTuples(%d)\n" % numPoints
218            evalString += "_vectors.SetName(\"vectors\")\n"
219            evalString += "for _j in range(%d):\n" % numPoints
220            evalString += \
221                "    _vectors.InsertTuple3(_j, _dx[_j], _dy[_j], 0.0)\n"
222            self.renderer.runString(evalString)
223    
224            # construct the grid
225            evalString = "_grid = vtk.vtkUnstructuredGrid()\n"
226            evalString += "_grid.SetPoints(_points)\n"
227            evalString += "_grid.GetPointData().AddArray(_vectors)\n"
228            evalString += "_grid.GetPointData().SetActiveVectors(\"vectors\")"
229            self.renderer.runString(evalString)
230    
231      elif self.otherData:      elif self.otherData:
232    
# Line 334  class ArrowPlot(Plot): Line 397  class ArrowPlot(Plot):
397          evalString += "_textProp.ItalicOff()\n"          evalString += "_textProp.ItalicOff()\n"
398          evalString += "_textProp.ShadowOff()\n"          evalString += "_textProp.ShadowOff()\n"
399          evalString += "_textProp.SetColor(0,0,0)\n"          evalString += "_textProp.SetColor(0,0,0)\n"
400        self.renderer.runString(evalString)
401    
402          # set the title if set          # set the title if set
403          if self.title is not None:          if self.title is not None:
404              # add a title              # add a title
405              evalString += "_titleMapper = vtk.vtkTextMapper()\n"              evalString = "_titleMapper = vtk.vtkTextMapper()\n"
406              evalString += "_titleMapper.SetInput(\"%s\")\n" % self.title              evalString += "_titleMapper.SetInput(\"%s\")\n" % self.title
407                            
408              evalString += "_titleProp = _titleMapper.GetTextProperty()\n"              evalString += "_titleProp = _titleMapper.GetTextProperty()\n"

Legend:
Removed from v.421  
changed lines
  Added in v.422

  ViewVC Help
Powered by ViewVC 1.1.26