105_Overlays.py 1.4 KB

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