501_HarmonicParam.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Add the igl library to the modules search path
  2. import sys, os
  3. sys.path.insert(0, os.getcwd() + "/../")
  4. import pyigl as 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. # Find the open boundary
  22. bnd = igl.eigen.MatrixXi()
  23. igl.boundary_loop(F,bnd)
  24. # Map the boundary to a circle, preserving edge proportions
  25. bnd_uv = igl.eigen.MatrixXd()
  26. igl.map_vertices_to_circle(V,bnd,bnd_uv)
  27. # Harmonic parametrization for the internal vertices
  28. igl.harmonic(V,F,bnd,bnd_uv,1,V_uv)
  29. # Scale UV to make the texture more clear
  30. V_uv *= 5;
  31. # Plot the mesh
  32. viewer = igl.viewer.Viewer()
  33. viewer.data.set_mesh(V, F)
  34. viewer.data.set_uv(V_uv)
  35. viewer.callback_key_down = key_down
  36. # Disable wireframe
  37. viewer.core.show_lines = False
  38. # Draw checkerboard texture
  39. viewer.core.show_texture = True
  40. # Launch the viewer
  41. viewer.launch()