105_Overlays.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import igl
  2. V = igl.eigen.MatrixXd()
  3. F = igl.eigen.MatrixXi()
  4. # Load a mesh in OFF format
  5. igl.readOFF("../tutorial/shared/bunny.off", V, F)
  6. # Find the bounding box
  7. m = V.colwiseMinCoeff()
  8. M = V.colwiseMaxCoeff()
  9. # Corners of the bounding box
  10. V_box = igl.eigen.MatrixXd(
  11. [
  12. [m[0,0], m[0,1], m[0,2]],
  13. [M[0,0], m[0,1], m[0,2]],
  14. [M[0,0], M[0,1], m[0,2]],
  15. [m[0,0], M[0,1], m[0,2]],
  16. [m[0,0], m[0,1], M[0,2]],
  17. [M[0,0], m[0,1], M[0,2]],
  18. [M[0,0], M[0,1], M[0,2]],
  19. [m[0,0], M[0,1], M[0,2]]
  20. ]
  21. )
  22. E_box = igl.eigen.MatrixXi(
  23. [
  24. [0, 1],
  25. [1, 2],
  26. [2, 3],
  27. [3, 0],
  28. [4, 5],
  29. [5, 6],
  30. [6, 7],
  31. [7, 4],
  32. [0, 4],
  33. [1, 5],
  34. [2, 6],
  35. [7 ,3]
  36. ]
  37. )
  38. # Plot the mesh
  39. viewer = igl.viewer.Viewer()
  40. viewer.data.set_mesh(V, F)
  41. # Plot the corners of the bounding box as points
  42. viewer.data.add_points(V_box,igl.eigen.MatrixXd([[1,0,0]]))
  43. # Plot the edges of the bounding box
  44. for i in range(0,E_box.rows()):
  45. viewer.data.add_edges(
  46. V_box.row(E_box[i,0]),
  47. V_box.row(E_box[i,1]),
  48. igl.eigen.MatrixXd([[1,0,0]]))
  49. # Plot labels with the coordinates of bounding box vertices
  50. l1 = 'x: ' + str(m[0,0]) + ' y: ' + str(m[0,1]) + ' z: ' + str(m[0,2])
  51. viewer.data.add_label(m.transpose(),l1)
  52. l2 = 'x: ' + str(M[0,0]) + ' y: ' + str(M[0,1]) + ' z: ' + str(M[0,2])
  53. viewer.data.add_label(M.transpose(),l2);
  54. # Launch the viewer
  55. viewer.launch();