File: mousehover2.py

package info (click to toggle)
vedo 2025.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,404 kB
  • sloc: python: 64,792; javascript: 1,932; xml: 437; sh: 139; makefile: 6
file content (24 lines) | stat: -rw-r--r-- 821 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Hover mouse to interactively fit a sphere to a region of the mesh"""
from vedo import *

def func(event):  # callback function
    p = event.picked3d
    if p is None:
        return
    pts = Points(msh.closest_point(p, n=50), r=6)
    sph = fit_sphere(pts).alpha(0.1).pickable(False)
    pts.name = "mypoints"   # we give it a name to make it easy to
    sph.name = "mysphere"   # remove the old and add the new ones
    txt.text(f'Radius : {sph.radius}\nResidue: {sph.residue}')
    plt.remove("mypoints", "mysphere").add(pts, sph).render()

txt = Text2D(__doc__, bg='yellow', font='Calco')

msh = Mesh(dataurl+'290.vtk').subdivide()
msh.compute_curvature(method=2)
msh.cmap('PRGn', vmin=-0.02).add_scalarbar()

plt = Plotter(axes=1)
plt.add_callback('mouse hover', func)
plt.show(msh, txt, viewup='z')
plt.close()