502_LSCMParam.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Add the igl library to the modules search path
  2. import sys, os
  3. sys.path.insert(0, os.getcwd() + "/../")
  4. import igl
  5. V = igl.eigen.MatrixXd()
  6. F = igl.eigen.MatrixXi()
  7. V_uv = igl.eigen.MatrixXd()
  8. def key_down(viewer, key, modifier):
  9. if key == ord('1'):
  10. # Plot the 3D mesh
  11. viewer.data.set_mesh(V,F)
  12. viewer.core.align_camera_center(V,F)
  13. elif key == ord('2'):
  14. # Plot the mesh in 2D using the UV coordinates as vertex coordinates
  15. viewer.data.set_mesh(V_uv,F)
  16. viewer.core.align_camera_center(V_uv,F)
  17. viewer.data.compute_normals()
  18. return False
  19. # Load a mesh in OFF format
  20. igl.readOFF("../../tutorial/shared/camelhead.off", V, F);
  21. # Fix two points on the boundary
  22. bnd = igl.eigen.MatrixXi()
  23. b = igl.eigen.MatrixXi(2,1)
  24. igl.boundary_loop(F,bnd)
  25. b[0] = bnd[0]
  26. b[1] = bnd[int(bnd.size()/2)]
  27. bc = igl.eigen.MatrixXd([[0,0],[1,0]])
  28. # LSCM parametrization
  29. igl.lscm(V,F,b,bc,V_uv)
  30. # Scale the uv
  31. V_uv *= 5
  32. # Plot the mesh
  33. viewer = igl.viewer.Viewer()
  34. viewer.data.set_mesh(V, F)
  35. viewer.data.set_uv(V_uv)
  36. viewer.callback_key_down = key_down
  37. # Disable wireframe
  38. viewer.core.show_lines = False
  39. # Draw checkerboard texture
  40. viewer.core.show_texture = True
  41. # Launch the viewer
  42. viewer.launch()