502_LSCMParam.py 1.8 KB

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