delete_mesh_pts.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. """Remove points and cells from a mesh
  2. which are closest to a specified point."""
  3. from vedo import settings, Mesh, dataurl, printc, Point, Sphere, show
  4. # Enable depth peeling for the scene
  5. settings.use_depth_peeling = True
  6. # Load the apple mesh from a url, set the colors and line width
  7. msh = Mesh(dataurl+'apple.ply')
  8. msh.c('lightgreen').bc('tomato').lw(1)
  9. # Set a point and a radius to find the closest points in the mesh to it
  10. pt = [1, 0.5, 1]
  11. R = 1.2
  12. ids = msh.closest_point(pt, radius=R, return_point_id=True)
  13. # Remove the cells from the mesh by their ids
  14. # and clean the mesh by removing orphaned vertices not associated to any cell
  15. printc('#points before:', msh.npoints, c='g')
  16. msh.delete_cells_by_point_index(ids)
  17. msh.clean()
  18. printc('#points after :', msh.npoints, c='g')
  19. # Create a sphere object with the given point and radius, and set transparency
  20. sph = Sphere(pt, r=R, alpha=0.1)
  21. # Show the point, the sphere, the modified mesh, the script docstring and axes
  22. # then close the window
  23. show(Point(pt), sph, msh, __doc__, axes=1).close()