vector_area_matrix.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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 "vector_area_matrix.h"
  9. #include <vector>
  10. // Bug in unsupported/Eigen/SparseExtra needs iostream first
  11. #include <iostream>
  12. #include <unsupported/Eigen/SparseExtra>
  13. //#include <igl/boundary_loop.h>
  14. #include <igl/boundary_facets.h>
  15. template <typename DerivedF, typename Scalar>
  16. IGL_INLINE void igl::vector_area_matrix(
  17. const Eigen::PlainObjectBase<DerivedF> & F,
  18. Eigen::SparseMatrix<Scalar>& A)
  19. {
  20. using namespace Eigen;
  21. using namespace std;
  22. // number of vertices
  23. const int n = F.maxCoeff()+1;
  24. SparseMatrix<Scalar> aux (n * 2, n * 2);
  25. SparseMatrix<Scalar> auxT(n * 2, n * 2);
  26. vector<Triplet<Scalar> > auxTripletList;
  27. vector<Triplet<Scalar> > auxTTripletList;
  28. MatrixXi E;
  29. boundary_facets(F,E);
  30. for(int k = 0; k < E.rows(); k++)
  31. {
  32. int i = E(k,0);
  33. int j = E(k,1);
  34. auxTripletList.push_back(Triplet<Scalar>(i+n, j, -0.5));
  35. auxTripletList.push_back(Triplet<Scalar>(i, j+n, 0.5));
  36. auxTTripletList.push_back(Triplet<Scalar>(j, i+n, -0.5));
  37. auxTTripletList.push_back(Triplet<Scalar>(j+n, i, 0.5));
  38. }
  39. aux.setFromTriplets(auxTripletList.begin(), auxTripletList.end());
  40. auxT.setFromTriplets(auxTTripletList.begin(), auxTTripletList.end());
  41. A = (aux + auxT)/2;
  42. }
  43. #ifdef IGL_STATIC_LIBRARY
  44. // Explicit template specialization
  45. template void igl::vector_area_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int>&);
  46. #endif