vector_area_matrix.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <[email protected]>
  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::MatrixBase<DerivedF> & F,
  17. Eigen::SparseMatrix<Scalar>& A)
  18. {
  19. // number of vertices
  20. const int n = F.maxCoeff()+1;
  21. assert(F.cols() == 3);
  22. Eigen::MatrixXi E;
  23. boundary_facets(F,E);
  24. //Prepare a vector of triplets to set the matrix
  25. std::vector<Eigen::Triplet<Scalar> > tripletList;
  26. tripletList.reserve(4*E.rows());
  27. for(int k = 0; k < E.rows(); k++)
  28. {
  29. int i = E(k,0);
  30. int j = E(k,1);
  31. tripletList.push_back(Eigen::Triplet<Scalar>(i+n, j, -0.25));
  32. tripletList.push_back(Eigen::Triplet<Scalar>(j, i+n, -0.25));
  33. tripletList.push_back(Eigen::Triplet<Scalar>(i, j+n, 0.25));
  34. tripletList.push_back(Eigen::Triplet<Scalar>(j+n, i, 0.25));
  35. }
  36. //Set A from triplets (Eigen will sum triplets with same coordinates)
  37. A.resize(n * 2, n * 2);
  38. A.setFromTriplets(tripletList.begin(), tripletList.end());
  39. }
  40. #ifdef IGL_STATIC_LIBRARY
  41. // Explicit template instantiation
  42. template void igl::vector_area_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int>&);
  43. #endif