Datasets:

Modalities:
Image
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
File size: 1,681 Bytes
5b89cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <igl/boundary_loop.h>
#include <igl/harmonic.h>
#include <igl/map_vertices_to_circle.h>
#include <igl/read_triangle_mesh.h>
#include <igl/opengl/glfw/Viewer.h>



int main(int argc, char *argv[])

{
  Eigen::MatrixXd V, V_uv;
  Eigen::MatrixXi F;
  // Load a mesh in OFF format
  igl::read_triangle_mesh(TUTORIAL_SHARED_PATH "/camelhead.off", V, F);

  // Find the open boundary
  Eigen::VectorXi bnd;
  igl::boundary_loop(F,bnd);

  // Map the boundary to a circle, preserving edge proportions
  Eigen::MatrixXd bnd_uv;
  igl::map_vertices_to_circle(V,bnd,bnd_uv);

  // Harmonic parametrization for the internal vertices
  igl::harmonic(V,F,bnd,bnd_uv,1,V_uv);

  // Scale UV to make the texture more clear
  V_uv *= 5;

  // Plot the mesh
  igl::opengl::glfw::Viewer viewer;
  viewer.data().set_mesh(V, F);
  viewer.data().set_uv(V_uv);
  // Attach callback to allow toggling between 3D and 2D view
  viewer.callback_key_pressed = 
    [&V,&V_uv,&F](igl::opengl::glfw::Viewer& viewer, unsigned int key, int /*mod*/)
  {
    if(key == '3' || key == '2')
    {
      // Plot the 3D mesh or 2D UV coordinates
      viewer.data().set_vertices(key=='3'?V:V_uv);
      viewer.data().compute_normals();
      viewer.core().align_camera_center(key=='3'?V:V_uv,F);
      // key press was used
      return true;
    }
    // key press not used
    return false;
  };

  // Disable wireframe
  viewer.data().show_lines = false;

  // Draw default checkerboard texture
  viewer.data().show_texture = true;

  std::cout<<R"(

3  Show 3D model

2  Show 2D parametrization

)";

  // Launch the viewer
  viewer.launch();
}