warp2.py 887 B

12345678910111213141516171819202122232425262728
  1. """Warp a region of a mesh using Thin Plate Splines.
  2. Red points stay fixed while a single point in space
  3. moves as the arrow indicates."""
  4. from vedo import *
  5. settings.use_depth_peeling = True
  6. mesh = Mesh(dataurl+"man.vtk").color('w')
  7. # a heavily decimated copy with about 200 points
  8. meshdec = mesh.clone().triangulate().decimate(n=200)
  9. sources = [[0.9, 0.0, 0.2]] # this point moves
  10. targets = [[1.2, 0.0, 0.4]] # ...to this.
  11. for pt in meshdec.vertices:
  12. if pt[0] < 0.3: # these pts don't move
  13. sources.append(pt) # (e.i. source = target)
  14. targets.append(pt)
  15. arrow = Arrows(sources, targets)
  16. apts = Points(sources).c("red")
  17. warp = mesh.clone().warp(sources, targets)
  18. warp.c("blue", 0.3).wireframe()
  19. sphere = Sphere(r=0.3).pos(1,0,-.50)
  20. sphere.apply_transform(warp.transform)
  21. # print(warp.transform)
  22. show(mesh, arrow, warp, apts, sphere, axes=1).close()