recosurface.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Reconstruct a polygonal surface
  2. from a point cloud:
  3. 1. An object is loaded and
  4. noise is added to its vertices.
  5. 2. The point cloud is smoothened
  6. with MLS (Moving Least Squares)
  7. 3. Impose a minimum distance among points
  8. 4. A triangular mesh is extracted from
  9. this set of sparse Points.
  10. """
  11. from vedo import dataurl, printc, Plotter, Points, Mesh, Text2D
  12. plt = Plotter(shape=(1,5))
  13. plt.at(0).show(Text2D(__doc__, s=0.75, font='Theemim', bg='green5'))
  14. # 1. load a mesh
  15. mesh = Mesh(dataurl+"apple.ply").subdivide()
  16. plt.at(1).show(mesh)
  17. # Add noise
  18. pts0 = Points(mesh, r=3).add_gaussian_noise(1)
  19. plt.at(2).show(pts0)
  20. # 2. Smooth the point cloud with MLS
  21. pts1 = pts0.clone().smooth_mls_2d(f=0.8)
  22. printc("Nr of points before cleaning nr. points:", pts1.npoints)
  23. # 3. Impose a min distance among mesh points
  24. pts1.subsample(0.005)
  25. printc(" after cleaning nr. points:", pts1.npoints)
  26. plt.at(3).show(pts1)
  27. # 4. Reconstruct a polygonal surface from the point cloud
  28. reco = pts1.reconstruct_surface(dims=100, radius=0.2).c("gold")
  29. plt.at(4).show(reco, axes=7, zoom=1.2)
  30. plt.interactive().close()