tet_build.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """Build a TetMesh (tetrahedral mesh)
  2. by manually defining vertices and cells"""
  3. from vedo import *
  4. points = [
  5. (0, 0, 0), # first tet
  6. (1, 0, 0),
  7. (1, 1, 0),
  8. (0, 1, 2),
  9. (3, 3, 3), # second tet
  10. (4, 3, 3),
  11. (4, 4, 3),
  12. (3, 4, 4),
  13. (2, 5, 3), # third tet
  14. (3, 5, 3),
  15. (3, 6, 3),
  16. (2, 5, 5),
  17. ]
  18. # Cells are defined by a list of 4 vertex indices
  19. # note that "cells" and "tetrahedrons" are the same thing
  20. tets = [[0,1,2,3], [4,5,6,7], [8,9,10,11]]
  21. # Define a scalar value for each cell we have created
  22. values = np.array([10.0, 20.0, 30.0])
  23. # Create the TeTMesh object and assign any number of data arrays to it
  24. tm = TetMesh([points, tets])
  25. tm.celldata["myscalar1"] = values
  26. tm.celldata["myscalar2"] = -values / 10
  27. tm.pointdata["myvector"] = np.random.rand(tm.npoints)
  28. # ...
  29. print(tm)
  30. tm.celldata.select("myscalar2").cmap('jet').add_scalarbar()
  31. # tm.color('green') # or set a single color
  32. # Create labels for the vertices
  33. labels = tm.labels2d('id', scale=2)
  34. show(tm, labels, __doc__, axes=1).close()