105_Overlays.py 2.2 KB

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