main.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <igl/active_set.h>
  2. #include <igl/boundary_facets.h>
  3. #include <igl/cotmatrix.h>
  4. #include <igl/invert_diag.h>
  5. #include <igl/jet.h>
  6. #include <igl/massmatrix.h>
  7. #include <igl/readOFF.h>
  8. #include <igl/opengl/glfw/Viewer.h>
  9. #include <Eigen/Sparse>
  10. #include <iostream>
  11. Eigen::VectorXi b;
  12. Eigen::VectorXd B,bc,lx,ux,Beq,Bieq,Z;
  13. Eigen::SparseMatrix<double> Q,Aeq,Aieq;
  14. void solve(igl::opengl::glfw::Viewer &viewer)
  15. {
  16. using namespace std;
  17. igl::active_set_params as;
  18. as.max_iter = 8;
  19. igl::active_set(Q,B,b,bc,Aeq,Beq,Aieq,Bieq,lx,ux,as,Z);
  20. viewer.data().set_data(Z);
  21. }
  22. bool key_down(igl::opengl::glfw::Viewer &viewer, unsigned char key, int mod)
  23. {
  24. switch(key)
  25. {
  26. case '.':
  27. Beq(0) *= 2.0;
  28. solve(viewer);
  29. return true;
  30. case ',':
  31. Beq(0) /= 2.0;
  32. solve(viewer);
  33. return true;
  34. case ' ':
  35. solve(viewer);
  36. return true;
  37. default:
  38. return false;
  39. }
  40. }
  41. int main(int argc, char *argv[])
  42. {
  43. using namespace Eigen;
  44. using namespace std;
  45. MatrixXd V;
  46. MatrixXi F;
  47. igl::readOFF(TUTORIAL_SHARED_PATH "/cheburashka.off",V,F);
  48. // Plot the mesh
  49. igl::opengl::glfw::Viewer viewer;
  50. viewer.data().set_mesh(V, F);
  51. viewer.data().show_lines = false;
  52. viewer.callback_key_down = &key_down;
  53. // One fixed point
  54. b.resize(1,1);
  55. // point on belly.
  56. b<<2556;
  57. bc.resize(1,1);
  58. bc<<1;
  59. // Construct Laplacian and mass matrix
  60. SparseMatrix<double> L,M,Minv;
  61. igl::cotmatrix(V,F,L);
  62. igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M);
  63. //M = (M/M.diagonal().maxCoeff()).eval();
  64. igl::invert_diag(M,Minv);
  65. // Bi-Laplacian
  66. Q = L.transpose() * (Minv * L);
  67. // Zero linear term
  68. B = VectorXd::Zero(V.rows(),1);
  69. // Lower and upper bound
  70. lx = VectorXd::Zero(V.rows(),1);
  71. ux = VectorXd::Ones(V.rows(),1);
  72. // Equality constraint constrain solution to sum to 1
  73. Beq.resize(1,1);
  74. Beq(0) = 0.08;
  75. Aeq = M.diagonal().sparseView().transpose();
  76. // (Empty inequality constraints)
  77. solve(viewer);
  78. cout<<
  79. "Press '.' to increase scale and resolve."<<endl<<
  80. "Press ',' to decrease scale and resolve."<<endl;
  81. viewer.launch();
  82. }