Package pyllar :: Module Mesh
[hide private]
[frames] | no frames]

Source Code for Module pyllar.Mesh

 1  """ The 3d surface mesh class for Pyllar.""" 
 2   
 3   
 4  from Plottable import Plottable 
 5  import vtk 
 6  from numpy import * 
 7   
 8   
9 -class Mesh(Plottable):
10 """ The Mesh class represents a 3D surface of rectilinear (in x and y) data. 11 """ 12
13 - def __init__(self, x, y, z, colored=0):
14 """ Create an instance of the Mesh class. 15 16 x and y are vectors defining the independent grid. 17 colored can be 0 for a sild color and 1 for a colorscale. 18 """ 19 20 # create plottable defaults 21 self.pos = array([0,0,0]) 22 self.direction = array([1.0,0.0,0.0]) 23 24 # create the points that define the mesh 25 points = vtk.vtkPoints() 26 xlen = len(x) 27 ylen = len(y) 28 points.SetNumberOfPoints(size(z)) 29 i = 0 30 zlo = z[0,0] 31 zmax = z[0,0] 32 for iy in range(ylen): 33 for ix in range(xlen): 34 points.SetPoint(i, x[ix], y[iy], z[ix,iy]) 35 i += 1 36 if z[ix,iy] < zlo: 37 zlo = z[ix,iy] 38 if z[ix,iy] > zmax: 39 zmax = z[ix,iy] 40 41 meshSG = vtk.vtkStructuredGrid() 42 meshSG.SetDimensions(xlen,ylen,1) 43 meshSG.SetPoints(points) 44 meshGeom = vtk.vtkStructuredGridGeometryFilter() 45 meshGeom.SetInput(meshSG) 46 47 # set the colorscale 48 if colored > 0: 49 elev = vtk.vtkElevationFilter() 50 elev.SetInput(meshGeom.GetOutput()) 51 pdnormals = vtk.vtkPolyDataNormals() 52 pdnormals.SetInput(elev.GetPolyDataOutput()) 53 54 meshMapper = vtk.vtkPolyDataMapper() 55 56 if colored > 0: 57 meshMapper.SetInput(pdnormals.GetOutput()) 58 meshMapper.ScalarVisibilityOn() 59 meshMapper.SetScalarRange(zlo,zmax) 60 meshMapper.SetLookupTable(lutRedBlue) 61 lutRedBlue.SetTableRange(zlo,zmax) 62 else: 63 meshMapper.SetInput(meshGeom.GetOutput()) 64 65 # create actor 66 self.actor = vtk.vtkActor() 67 self.actor.SetMapper(meshMapper) 68 69 # add to the axes 70 self.AddToAxes()
71 72 73 # define the lookup table that maps heights to colors 74 lutRedBlue = vtk.vtkLookupTable() 75 lutRedBlue.Build() 76