main.cpp 2.2 KB

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