105_Overlays.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # This file is part of libigl, a simple c++ geometry processing library.
  2. #
  3. # Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com>
  4. #
  5. # This Source Code Form is subject to the terms of the Mozilla Public License
  6. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. # obtain one at http://mozilla.org/MPL/2.0/.
  8. import sys, os
  9. # Add the igl library to the modules search path
  10. sys.path.insert(0, os.getcwd() + "/../")
  11. import pyigl as igl
  12. from shared import TUTORIAL_SHARED_PATH, check_dependencies
  13. dependencies = ["glfw"]
  14. check_dependencies(dependencies)
  15. V = igl.eigen.MatrixXd()
  16. F = igl.eigen.MatrixXi()
  17. # Load a mesh in OFF format
  18. igl.readOFF(TUTORIAL_SHARED_PATH + "bunny.off", V, F)
  19. # Find the bounding box
  20. m = V.colwiseMinCoeff()
  21. M = V.colwiseMaxCoeff()
  22. # Corners of the bounding box
  23. V_box = igl.eigen.MatrixXd(
  24. [
  25. [m[0, 0], m[0, 1], m[0, 2]],
  26. [M[0, 0], m[0, 1], m[0, 2]],
  27. [M[0, 0], M[0, 1], m[0, 2]],
  28. [m[0, 0], M[0, 1], m[0, 2]],
  29. [m[0, 0], m[0, 1], M[0, 2]],
  30. [M[0, 0], m[0, 1], M[0, 2]],
  31. [M[0, 0], M[0, 1], M[0, 2]],
  32. [m[0, 0], M[0, 1], M[0, 2]]
  33. ]
  34. )
  35. E_box = igl.eigen.MatrixXd(
  36. [
  37. [0, 1],
  38. [1, 2],
  39. [2, 3],
  40. [3, 0],
  41. [4, 5],
  42. [5, 6],
  43. [6, 7],
  44. [7, 4],
  45. [0, 4],
  46. [1, 5],
  47. [2, 6],
  48. [7, 3]
  49. ]
  50. ).castint()
  51. # Plot the mesh
  52. viewer = igl.glfw.Viewer()
  53. viewer.data().set_mesh(V, F)
  54. # Plot the corners of the bounding box as points
  55. viewer.data().add_points(V_box, igl.eigen.MatrixXd([[1, 0, 0]]))
  56. # Plot the edges of the bounding box
  57. for i in range(0, E_box.rows()):
  58. viewer.data().add_edges(
  59. V_box.row(E_box[i, 0]),
  60. V_box.row(E_box[i, 1]),
  61. igl.eigen.MatrixXd([[1, 0, 0]]))
  62. # Plot labels with the coordinates of bounding box vertices
  63. l1 = 'x: ' + str(m[0, 0]) + ' y: ' + str(m[0, 1]) + ' z: ' + str(m[0, 2])
  64. viewer.data().add_label(m.transpose(), l1)
  65. l2 = 'x: ' + str(M[0, 0]) + ' y: ' + str(M[0, 1]) + ' z: ' + str(M[0, 2])
  66. viewer.data().add_label(M.transpose(), l2)
  67. # Launch the viewer
  68. viewer.launch()