fitspheres2.py 845 B

1234567891011121314151617181920212223242526272829
  1. """For each point finds the 12 closest ones and fit a sphere.
  2. Color points from the size of the sphere radius."""
  3. from vedo import *
  4. from vedo.pyplot import histogram
  5. plt = Plotter()
  6. msh = Mesh(dataurl+"cow.vtk").c("cyan7")
  7. pts1, pts2, vals = [], [], []
  8. msh_points = msh.points
  9. for i in range(0, msh.npoints, 10):
  10. p = msh_points[i]
  11. pts = msh.closest_point(p, n=12) # find the n-closest points to p
  12. sph = fit_sphere(pts) # find the fitting sphere
  13. if sph is None:
  14. continue
  15. value = sph.radius * 10
  16. n = versor(p - sph.center) # unit vector from sphere center to p
  17. vals.append(value)
  18. pts1.append(p)
  19. pts2.append(p + n / 8)
  20. plt += msh, Points(pts1), Lines(pts1, pts2).c("black")
  21. plt += histogram(vals, xtitle='radius', xlim=[0,2]).clone2d("bottom-left")
  22. plt += __doc__
  23. plt.show().close()