501_HarmonicParam.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import igl
  2. V = igl.eigen.MatrixXd()
  3. F = igl.eigen.MatrixXi()
  4. V_uv = igl.eigen.MatrixXd()
  5. def key_down(viewer, key, modifier):
  6. if key == ord('1'):
  7. # Plot the 3D mesh
  8. viewer.data.set_mesh(V,F)
  9. viewer.core.align_camera_center(V,F)
  10. elif key == ord('2'):
  11. # Plot the mesh in 2D using the UV coordinates as vertex coordinates
  12. viewer.data.set_mesh(V_uv,F)
  13. viewer.core.align_camera_center(V_uv,F)
  14. viewer.data.compute_normals()
  15. return False
  16. # Load a mesh in OFF format
  17. igl.readOFF("../tutorial/shared/camelhead.off", V, F)
  18. # Find the open boundary
  19. bnd = igl.eigen.MatrixXi()
  20. igl.boundary_loop(F,bnd)
  21. # Map the boundary to a circle, preserving edge proportions
  22. bnd_uv = igl.eigen.MatrixXd()
  23. igl.map_vertices_to_circle(V,bnd,bnd_uv)
  24. # Harmonic parametrization for the internal vertices
  25. igl.harmonic(V,F,bnd,bnd_uv,1,V_uv)
  26. # Scale UV to make the texture more clear
  27. V_uv *= 5;
  28. # Plot the mesh
  29. viewer = igl.viewer.Viewer()
  30. viewer.data.set_mesh(V, F)
  31. viewer.data.set_uv(V_uv)
  32. viewer.callback_key_down = key_down
  33. # Disable wireframe
  34. viewer.core.show_lines = False
  35. # Draw checkerboard texture
  36. viewer.core.show_texture = True
  37. # Launch the viewer
  38. viewer.launch()