interpolate_scalar2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. """Use scipy to interpolate the value of a scalar known on a set
  2. of points on a new set of points where the scalar is not defined.
  3. Two interpolation methods are possible:
  4. Radial Basis Function (used here), and Nearest Point."""
  5. import numpy as np
  6. from vedo import *
  7. from scipy.interpolate import Rbf, NearestNDInterpolator as Near
  8. mesh = Mesh(dataurl+"bunny.obj").normalize()
  9. pts = mesh.vertices
  10. # pick a subset of 100 points where a scalar descriptor is known
  11. ptsubset = pts[:100]
  12. # assume the descriptor value is some function of the point coord y
  13. x, y, z = np.split(ptsubset, 3, axis=1)
  14. desc = 3*sin(4*y)
  15. # build the interpolator to determine the scalar value
  16. # for the rest of mesh vertices:
  17. itr = Rbf(x, y, z, desc) # Radial Basis Function interpolator
  18. #itr = Near(ptsubset, desc) # Nearest-neighbour interpolator
  19. # interpolate descriptor on the full set of mesh vertices
  20. xi, yi, zi = np.split(pts, 3, axis=1)
  21. interpolated_desc = itr(xi, yi, zi)
  22. mesh.cmap('rainbow', interpolated_desc).add_scalarbar(title='3sin(4y)')
  23. rpts = Points(ptsubset).point_size(8).c('white')
  24. show(mesh, rpts, __doc__, axes=1).close()