vector_area_matrix.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "boundary_facets.h"
  10. #include <vector>
  11. // Bug in unsupported/Eigen/SparseExtra needs iostream first
  12. #include <iostream>
  13. #include <unsupported/Eigen/SparseExtra>
  14. template <typename DerivedF, typename Scalar>
  15. IGL_INLINE void igl::vector_area_matrix(
  16. const Eigen::PlainObjectBase<DerivedF> & F,
  17. Eigen::SparseMatrix<Scalar>& A)
  18. {
  19. using namespace Eigen;
  20. using namespace std;
  21. // number of vertices
  22. const int n = F.maxCoeff()+1;
  23. MatrixXi E;
  24. boundary_facets(F,E);
  25. //Prepare a vector of triplets to set the matrix
  26. vector<Triplet<Scalar> > tripletList;
  27. tripletList.reserve(4*E.rows());
  28. for(int k = 0; k < E.rows(); k++)
  29. {
  30. int i = E(k,0);
  31. int j = E(k,1);
  32. tripletList.push_back(Triplet<Scalar>(i+n, j, -0.25));
  33. tripletList.push_back(Triplet<Scalar>(j, i+n, -0.25));
  34. tripletList.push_back(Triplet<Scalar>(i, j+n, 0.25));
  35. tripletList.push_back(Triplet<Scalar>(j+n, i, 0.25));
  36. }
  37. //Set A from triplets (Eigen will sum triplets with same coordinates)
  38. A.resize(n * 2, n * 2);
  39. A.setFromTriplets(tripletList.begin(), tripletList.end());
  40. }
  41. #ifdef IGL_STATIC_LIBRARY
  42. // Explicit template instantiation
  43. 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>&);
  44. #endif