interpolate_scalar4.py 983 B

1234567891011121314151617181920212223242526272829303132
  1. """Interpolate cell values from a quad-mesh to a tri-mesh"""
  2. from vedo import Grid, show
  3. # Make up some quad mesh with associated scalars
  4. g1 = Grid(res=(25,25)).wireframe(0).lw(1)
  5. scalars = g1.coordinates[:,1]
  6. g1.cmap("viridis", scalars, vmin=-1, vmax=1, name='gene')
  7. g1.map_points_to_cells() # move the array to cells (faces)
  8. g1.add_scalarbar(horizontal=1)
  9. g1.rotate_z(20) # let's rotate it a bit so it's visible
  10. # Interpolate first mesh onto a new triangular mesh
  11. eps = 0.01
  12. g2 = Grid(res=(50,50)).pos(0.2, 0.2, 0.1).wireframe(0).lw(0)
  13. g2.triangulate()
  14. # Interpolate by averaging the closest 3 points:
  15. #g2.interpolate_data_from(g1, on='cells', n=3)
  16. # Interpolate by picking points in a specified radius,
  17. # if there are no points in that radius set null value -1
  18. g2.interpolate_data_from(
  19. g1,
  20. on='cells',
  21. radius=0.1+eps,
  22. null_strategy=1,
  23. null_value=-1,
  24. )
  25. g2.cmap('hot', 'gene', on='cells', vmin=-1, vmax=1).add_scalarbar()
  26. show(g1, g2, __doc__, axes=1)