harmonic.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "harmonic.h"
  9. #include "cotmatrix.h"
  10. #include "massmatrix.h"
  11. #include "invert_diag.h"
  12. #include "min_quad_with_fixed.h"
  13. #include <Eigen/Sparse>
  14. IGL_INLINE bool igl::harmonic(
  15. const Eigen::MatrixXd & V,
  16. const Eigen::MatrixXi & F,
  17. const Eigen::VectorXi & b,
  18. const Eigen::MatrixXd & bc,
  19. const int k,
  20. Eigen::MatrixXd & W)
  21. {
  22. using namespace igl;
  23. using namespace Eigen;
  24. SparseMatrix<double> L,M,Mi;
  25. cotmatrix(V,F,L);
  26. massmatrix(V,F,MASSMATRIX_VORONOI,M);
  27. invert_diag(M,Mi);
  28. SparseMatrix<double> Q = -L;
  29. for(int p = 1;p<k;p++)
  30. {
  31. Q = (Q*Mi*-L).eval();
  32. }
  33. const VectorXd B = VectorXd::Zero(V.rows(),1);
  34. min_quad_with_fixed_data<double> data;
  35. min_quad_with_fixed_precompute(Q,b,SparseMatrix<double>(),true,data);
  36. W.resize(V.rows(),bc.cols());
  37. for(int w = 0;w<bc.cols();w++)
  38. {
  39. const VectorXd bcw = bc.col(w);
  40. VectorXd Ww;
  41. if(!min_quad_with_fixed_solve(data,B,bcw,VectorXd(),Ww))
  42. {
  43. return false;
  44. }
  45. W.col(w) = Ww;
  46. }
  47. return true;
  48. }