remesh_meshfix.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #Credits:
  2. #M. Attene. A lightweight approach to repairing digitized polygon meshes.
  3. #The Visual Computer, 2010. (c) Springer. DOI: 10.1007/s00371-010-0416-3
  4. #http://pymeshfix.pyvista.org
  5. #TetGen, a Delaunay-Based Quality Tetrahedral Mesh Generator
  6. #https://github.com/pyvista/tetgen
  7. #
  8. # pip install pymeshfix
  9. # pip install tetgen
  10. #
  11. import pymeshfix
  12. import tetgen
  13. import vedo
  14. amesh = vedo.Mesh(vedo.dataurl+'290.vtk')
  15. # repairing also closes the mesh in a nice way
  16. meshfix = pymeshfix.MeshFix(amesh.points, amesh.cells)
  17. meshfix.repair()
  18. repaired = vedo.Mesh(meshfix.mesh).linewidth(1).alpha(0.5)
  19. # tetralize the closed surface
  20. tet = tetgen.TetGen(repaired.points, repaired.cells)
  21. tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
  22. tmesh = vedo.TetMesh(tet.grid)
  23. # save it to disk
  24. # tmesh.write("my_tetmesh.vtu")
  25. plt = vedo.Plotter(N=3, axes=1)
  26. plt.at(0).show("Original mesh", amesh)
  27. plt.at(1).show("Repaired mesh", repaired)
  28. plt.at(2).show("Tetrahedral mesh\n(click & press shift-X)", tmesh.tomesh().shrink())
  29. plt.interactive().close()