struc_grid1.py 994 B

123456789101112131415161718192021222324252627
  1. # A StructuredGrid is a dataset where edges of the hexahedrons are
  2. # not necessarily parallel to the coordinate axes.
  3. # It can be thought of as a tessellation of a block of 3D space,
  4. # similar to a `RectilinearGrid`
  5. # except that the cells are not necessarily cubes, they can have different
  6. # orientations but are connected in the same way as a `RectilinearGrid`.
  7. from vedo import *
  8. # a noisy geometry
  9. cx = np.sqrt(np.linspace(100, 400, 10))
  10. cy = np.linspace(30, 40, 20)
  11. cz = np.linspace(40, 50, 30)
  12. x, y, z = np.meshgrid(cx, cy, cz) + np.random.normal(0, 0.01, (20, 10, 30))
  13. # sgrid1 = StructuredGrid(dataurl + "structgrid.vts")
  14. sgrid1 = StructuredGrid([x, y, z])
  15. sgrid1.cmap("viridis", sgrid1.vertices[:, 0]+np.sin(sgrid1.vertices[:, 1]))
  16. print(sgrid1)
  17. sgrid2 = sgrid1.clone().cut_with_plane(normal=(-1,1,1), origin=[14,34,44])
  18. msh2 = sgrid2.tomesh(shrink=0.9).linewidth(1).cmap("viridis")
  19. show(
  20. [["StructuredGrid", sgrid1], ["Shrinked Mesh", msh2]],
  21. N=2, axes=1, viewup="z",
  22. )