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
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
21 self.pos = array([0,0,0])
22 self.direction = array([1.0,0.0,0.0])
23
24
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
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
66 self.actor = vtk.vtkActor()
67 self.actor.SetMapper(meshMapper)
68
69
70 self.AddToAxes()
71
72
73
74 lutRedBlue = vtk.vtkLookupTable()
75 lutRedBlue.Build()
76