areamatrix.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "areamatrix.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_vertices_sorted.h>
  14. template <typename DerivedV, typename DerivedF, typename Scalar>
  15. IGL_INLINE void igl::areamatrix(
  16. const Eigen::PlainObjectBase<DerivedV> & V,
  17. const Eigen::PlainObjectBase<DerivedF> & F,
  18. Eigen::SparseMatrix<Scalar>& A)
  19. {
  20. using namespace Eigen;
  21. using namespace std;
  22. SparseMatrix<Scalar> aux (V.rows() * 2, V.rows() * 2);
  23. SparseMatrix<Scalar> auxT(V.rows() * 2, V.rows() * 2);
  24. vector<Triplet<Scalar> > auxTripletList;
  25. vector<Triplet<Scalar> > auxTTripletList;
  26. Eigen::VectorXi bnd;
  27. igl::boundary_vertices_sorted(V,F,bnd);
  28. for(int k = 0; k < bnd.size(); k++)
  29. {
  30. int i = bnd[k];
  31. int j = k + 1 == bnd.size() ? bnd[0] : bnd[k+1];
  32. auxTripletList.push_back(Triplet<Scalar>(i+V.rows(), j, -0.5));
  33. auxTripletList.push_back(Triplet<Scalar>(i, j+V.rows(), 0.5));
  34. auxTTripletList.push_back(Triplet<Scalar>(j, i+V.rows(), -0.5));
  35. auxTTripletList.push_back(Triplet<Scalar>(j+V.rows(), i, 0.5));
  36. }
  37. aux.setFromTriplets(auxTripletList.begin(), auxTripletList.end());
  38. auxT.setFromTriplets(auxTTripletList.begin(), auxTTripletList.end());
  39. A = (aux + auxT)/2;
  40. }
  41. #ifndef IGL_HEADER_ONLY
  42. // Explicit template specialization
  43. // generated by autoexplicit.sh
  44. #endif