isolines.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. """Draw the isolines and isobands of
  2. a scalar field H (height) on a surface"""
  3. from vedo import *
  4. mesh0 = ParametricShape('RandomHills')
  5. # ParametricShapes already have a scalar associated to points
  6. printc('Mesh point arrays:', mesh0.pointdata.keys())
  7. # so assign it a colormap:
  8. mesh0.cmap('terrain')
  9. isol = mesh0.isolines(n=10).color('w')
  10. isob = mesh0.isobands(n=5).add_scalarbar("H=Elevation")
  11. # make a copy and interpolate the Scalars from points to cells
  12. mesh1 = mesh0.clone().map_points_to_cells()
  13. printc('Mesh cell arrays :', mesh1.celldata.keys())
  14. gvecs = mesh1.gradient(on='cells')
  15. cc = mesh1.cell_centers().coordinates
  16. ars = Arrows(cc, cc + gvecs*0.01, c='bone_r').lighting('off')
  17. ars.add_scalarbar3d(title='|:nablaH|:dot0.01 [arb.units]')
  18. # colormap the gradient magnitude directly on the mesh
  19. mesh2 = mesh1.clone().cmap('jet', mag(gvecs), on='cells')
  20. mesh2.add_scalarbar3d(title='|:nablaH| [arb.units]')
  21. plt = Plotter(N=4, size=(1200,900), axes=11)
  22. plt.at(0).show(mesh0, isol, __doc__)
  23. plt.at(1).show(isob)
  24. plt.at(2).show(mesh1, isol, ars, "Arrows=:nablaH")
  25. plt.at(3).show(mesh2, "Color=|:nablaH|")
  26. plt.interactive().close()