harmonic.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. switch(F.cols())
  27. {
  28. case 3:
  29. massmatrix(V,F,MASSMATRIX_VORONOI,M);
  30. break;
  31. case 4:
  32. default:
  33. massmatrix(V,F,MASSMATRIX_BARYCENTRIC,M);
  34. break;
  35. }
  36. invert_diag(M,Mi);
  37. SparseMatrix<double> Q = -L;
  38. for(int p = 1;p<k;p++)
  39. {
  40. Q = (Q*Mi*-L).eval();
  41. }
  42. const VectorXd B = VectorXd::Zero(V.rows(),1);
  43. min_quad_with_fixed_data<double> data;
  44. min_quad_with_fixed_precompute(Q,b,SparseMatrix<double>(),true,data);
  45. W.resize(V.rows(),bc.cols());
  46. for(int w = 0;w<bc.cols();w++)
  47. {
  48. const VectorXd bcw = bc.col(w);
  49. VectorXd Ww;
  50. if(!min_quad_with_fixed_solve(data,B,bcw,VectorXd(),Ww))
  51. {
  52. return false;
  53. }
  54. W.col(w) = Ww;
  55. }
  56. return true;
  57. }