vector_area_matrix.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. MatrixXi E;
  25. boundary_facets(F,E);
  26. //Prepare a vector of triplets to set the matrix
  27. vector<Triplet<Scalar> > tripletList;
  28. tripletList.reserve(4*E.rows());
  29. for(int k = 0; k < E.rows(); k++)
  30. {
  31. int i = E(k,0);
  32. int j = E(k,1);
  33. tripletList.push_back(Triplet<Scalar>(i+n, j, -0.25));
  34. tripletList.push_back(Triplet<Scalar>(j, i+n, -0.25));
  35. tripletList.push_back(Triplet<Scalar>(i, j+n, 0.25));
  36. tripletList.push_back(Triplet<Scalar>(j+n, i, 0.25));
  37. }
  38. //Set A from triplets (Eigen will sum triplets with same coordinates)
  39. A.resize(n * 2, n * 2);
  40. A.setFromTriplets(tripletList.begin(), tripletList.end());
  41. }
  42. #ifdef IGL_STATIC_LIBRARY
  43. // Explicit template instantiation
  44. 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>&);
  45. #endif