tet_cut2.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Cut a TetMesh with a Mesh
  2. to generate an UnstructuredGrid"""
  3. from vedo import *
  4. settings.default_font = 'Calco'
  5. sphere = Sphere(r=500).x(400).c('green', 0.1)
  6. tetm1 = TetMesh(dataurl+'limb.vtu')
  7. tetm1.cmap('jet', tetm1.vertices[:, 2], name="ProximoDistal")
  8. # Clone and cut the TetMesh, this returns a UnstructuredGrid:
  9. ugrid1 = tetm1.clone().cut_with_mesh(sphere, invert=True)
  10. ugrid1.cmap("Purples_r", "SignedDistance")
  11. print(ugrid1)
  12. # Cut tetm, but the output will keep only the whole tets (NOT the polygonal boundary!):
  13. ugrid2 = tetm1.clone().cut_with_mesh(sphere, invert=True, whole_cells=True)
  14. tetm2 = TetMesh(ugrid2).cmap("Greens_r", "ProximoDistal")
  15. print(tetm2)
  16. # Cut tetm, but the output will keep only the tets on the boundary:
  17. ugrid3 = tetm1.clone().cut_with_mesh(sphere, on_boundary=True)
  18. tetm3 = TetMesh(ugrid3)
  19. tetm3.celldata.select("chem_0").cmap("Reds")
  20. print(tetm3)
  21. show([
  22. (ugrid1,sphere, __doc__),
  23. (tetm2, sphere, "Keep only tets that lie\ncompletely outside of the Sphere"),
  24. (tetm3, sphere, "Keep only tets that lie\nexactly on the Sphere"),
  25. ],
  26. N=3, axes=dict(xtitle='x in :mum'),
  27. ).close()