interpolate_scalar1.py 670 B

12345678910111213141516171819
  1. """Interpolate the scalar values from
  2. one Mesh or Points object onto another one"""
  3. from vedo import *
  4. import numpy as np
  5. mesh = Mesh(dataurl+"bunny.obj")
  6. # pick 100 points where we assume that some scalar value is known
  7. # (can be ANY points, not necessarily taken from the mesh)
  8. pts2 = mesh.points[:100]
  9. # assume the value is random
  10. scalars = np.random.randint(45,123, 100)
  11. # create a set of points with this scalar values
  12. points = Points(pts2, r=10).cmap('rainbow', scalars)
  13. # interpolate from points onto the mesh, by averaging the 5 closest ones
  14. mesh.interpolate_data_from(points, n=5).cmap('rainbow').add_scalarbar()
  15. show(mesh, points, __doc__, axes=9).close()