mousehover2.py 870 B

123456789101112131415161718192021222324
  1. """Hover mouse to interactively fit a sphere to a region of the mesh"""
  2. from vedo import Points, fit_sphere, Text2D, Mesh, dataurl, Plotter
  3. def func(event): # callback function
  4. p = event.picked3d
  5. if p is None:
  6. return
  7. pts = Points(msh.closest_point(p, n=50), r=6)
  8. sph = fit_sphere(pts).alpha(0.1).pickable(False)
  9. pts.name = "mypoints" # we give it a name to make it easy to
  10. sph.name = "mysphere" # remove the old and add the new ones
  11. txt.text(f'Radius : {sph.radius}\nResidue: {sph.residue}')
  12. plt.remove("mypoints", "mysphere").add(pts, sph).render()
  13. txt = Text2D(__doc__, bg='yellow', font='Calco')
  14. msh = Mesh(dataurl+'290.vtk').subdivide()
  15. msh.compute_curvature(method=2)
  16. msh.cmap('PRGn', vmin=-0.02).add_scalarbar()
  17. plt = Plotter(axes=1)
  18. plt.add_callback('mouse hover', func)
  19. plt.show(msh, txt, viewup='z')
  20. plt.close()