remesh_ACVD.py 1004 B

12345678910111213141516171819202122232425
  1. """Remesh a surface mesh using the ACVD algorithm."""
  2. # Needs PyACVD: pip install pyacvd
  3. # See: https://github.com/akaszynski/pyacvd
  4. from vedo import Sphere, Mesh, show
  5. from vedo.pyplot import histogram
  6. from pyvista import wrap
  7. from pyacvd import Clustering
  8. msh1 = Sphere(res=50).cut_with_plane()
  9. msh1.compute_quality().cmap('RdYlGn', on='cells', vmin=0, vmax=70).linewidth(1)
  10. clus = Clustering(wrap(msh1.dataset))
  11. clus.cluster(1000, maxiter=100, iso_try=10, debug=False)
  12. pvremsh1 = clus.create_mesh()
  13. msh2 = Mesh(pvremsh1).shift([2,0,0])
  14. msh2.compute_quality().cmap('RdYlGn', on='cells', vmin=0, vmax=70).linewidth(1)
  15. his1 = histogram(msh1.celldata["Quality"], xlim=(0,70), aspect=2, c='RdYlGn', title='Original Quality')
  16. his2 = histogram(msh2.celldata["Quality"], xlim=(0,70), aspect=2, c='RdYlGn', title='Remeshed Quality')
  17. his1 = his1.clone2d('bottom-left', 0.75)
  18. his2 = his2.clone2d('bottom-right', 0.75)
  19. show(msh1, msh2, his1, his2, __doc__, bg='k5', bg2='wheat')
  20. #remsh1.write('sphere.vtk')