harmonic.cpp 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "harmonic.h"
  2. #include "cotmatrix.h"
  3. #include "massmatrix.h"
  4. #include "invert_diag.h"
  5. #include "min_quad_with_fixed.h"
  6. #include <Eigen/Sparse>
  7. IGL_INLINE bool igl::harmonic(
  8. const Eigen::MatrixXd & V,
  9. const Eigen::MatrixXi & F,
  10. const Eigen::VectorXi & b,
  11. const Eigen::MatrixXd & bc,
  12. const int k,
  13. Eigen::MatrixXd & W)
  14. {
  15. using namespace igl;
  16. using namespace Eigen;
  17. SparseMatrix<double> L,M,Mi;
  18. cotmatrix(V,F,L);
  19. massmatrix(V,F,MASSMATRIX_VORONOI,M);
  20. invert_diag(M,Mi);
  21. SparseMatrix<double> Q = -L;
  22. for(int p = 1;p<k;p++)
  23. {
  24. Q = (Q*Mi*-L).eval();
  25. }
  26. const VectorXd B = VectorXd::Zero(V.rows(),1);
  27. min_quad_with_fixed_data<double> data;
  28. min_quad_with_fixed_precompute(Q,b,SparseMatrix<double>(),true,data);
  29. W.resize(V.rows(),bc.cols());
  30. for(int w = 0;w<bc.cols();w++)
  31. {
  32. const VectorXd bcw = bc.col(w);
  33. VectorXd Ww;
  34. if(!min_quad_with_fixed_solve(data,B,bcw,VectorXd(),Ww))
  35. {
  36. return false;
  37. }
  38. W.col(w) = Ww;
  39. }
  40. return true;
  41. }