Datasets:

Modalities:
Image
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
File size: 1,765 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
66
67
68
69
70
71

#include <igl/readOFF.h>
#include <igl/cotmatrix.h>
#include <igl/matlab/matlabinterface.h>
#include <igl/opengl/glfw/Viewer.h>
#include <iostream>

// On mac you may need to issue something like:
//
//     PATH=$PATH:/Applications/MATLAB_R2019a.app/bin/ ./tutorial/602_Matlab_bin

// Base mesh
Eigen::MatrixXd V;
Eigen::MatrixXi F;

// Matlab instance
Engine* engine;

// Eigenvectors of the laplacian
Eigen::MatrixXd EV;

// This function is called every time a keyboard button is pressed
bool key_down(igl::opengl::glfw::Viewer& viewer, unsigned char key, int modifier)

{
  if (key >= '1' && key <= '9')
  {
    viewer.data().set_data(EV.col((key - '1') + 1));
  }

  return false;
}

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

{
  // Load a mesh in OFF format
  igl::readOFF(TUTORIAL_SHARED_PATH "/3holes.off", V, F);

  // Launch MATLAB
  igl::matlab::mlinit(&engine);

  // Compute the discrete Laplacian operator
  Eigen::SparseMatrix<double> L;
  igl::cotmatrix(V,F,L);

  // Send Laplacian matrix to matlab
  igl::matlab::mlsetmatrix(&engine,"L",L);

  // Plot the laplacian matrix using matlab spy
  igl::matlab::mleval(&engine,"spy(L)");

  // Extract the first 10 eigenvectors
  igl::matlab::mleval(&engine,"[EV,~] = eigs(-L,10,'sm')");

  // Plot the size of EV (only for demonstration purposes)
  std::cerr << igl::matlab::mleval(&engine,"size(EV)") << std::endl;

  // Retrieve the result
  igl::matlab::mlgetmatrix(&engine,"EV",EV);

  // Plot the mesh
  igl::opengl::glfw::Viewer viewer;
  viewer.callback_key_down = &key_down;
  viewer.data().set_mesh(V, F);

  // Plot the first non-trivial eigenvector
  viewer.data().set_data(EV.col(1));

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