502_LSCMParam.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 = ["viewer"]
  14. check_dependencies(dependencies)
  15. V = igl.eigen.MatrixXd()
  16. F = igl.eigen.MatrixXi()
  17. V_uv = igl.eigen.MatrixXd()
  18. def key_down(viewer, key, modifier):
  19. if key == ord('1'):
  20. # Plot the 3D mesh
  21. viewer.data.set_mesh(V, F)
  22. viewer.core.align_camera_center(V, F)
  23. elif key == ord('2'):
  24. # Plot the mesh in 2D using the UV coordinates as vertex coordinates
  25. viewer.data.set_mesh(V_uv, F)
  26. viewer.core.align_camera_center(V_uv, F)
  27. viewer.data.compute_normals()
  28. return False
  29. # Load a mesh in OFF format
  30. igl.readOFF(TUTORIAL_SHARED_PATH + "camelhead.off", V, F)
  31. # Fix two points on the boundary
  32. bnd = igl.eigen.MatrixXi()
  33. b = igl.eigen.MatrixXi(2, 1)
  34. igl.boundary_loop(F, bnd)
  35. b[0] = bnd[0]
  36. b[1] = bnd[int(bnd.size() / 2)]
  37. bc = igl.eigen.MatrixXd([[0, 0], [1, 0]])
  38. # LSCM parametrization
  39. igl.lscm(V, F, b, bc, V_uv)
  40. # Scale the uv
  41. V_uv *= 5
  42. # Plot the mesh
  43. viewer = igl.viewer.Viewer()
  44. viewer.data.set_mesh(V, F)
  45. viewer.data.set_uv(V_uv)
  46. viewer.callback_key_down = key_down
  47. # Disable wireframe
  48. viewer.core.show_lines = False
  49. # Draw checkerboard texture
  50. viewer.core.show_texture = True
  51. # Launch the viewer
  52. viewer.launch()