line2mesh_tri.py 713 B

12345678910111213141516171819202122232425
  1. """Generate a polygonal Mesh from a contour line"""
  2. from vedo import dataurl, Assembly, Line, show
  3. from vedo.pyplot import histogram
  4. shapes = Assembly(dataurl + "timecourse1d.npy") # group of lines
  5. shape = shapes[56] # pick one
  6. cmap = "RdYlBu"
  7. # Generate the Mesh from the line
  8. msh = shape.generate_mesh(invert=True)
  9. msh.smooth() # make the triangles more uniform
  10. msh.compute_quality() # add a measure of triangle quality
  11. msh.cmap(cmap)
  12. contour = Line(shape).c("red4").lw(5)
  13. labels = contour.labels("id")
  14. histo = histogram(
  15. msh.celldata["Quality"],
  16. xtitle="triangle mesh quality",
  17. aspect=25/9,
  18. c=cmap,
  19. ).clone2d("bottom-right")
  20. show(contour, labels, msh, histo, __doc__).close()