facet_adjacency_matrix.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Alec Jacobson <[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 "facet_adjacency_matrix.h"
  9. #include "unique_edge_map.h"
  10. template <typename DerivedF, typename Atype>
  11. IGL_INLINE void igl::facet_adjacency_matrix(
  12. const Eigen::MatrixBase<DerivedF> & F,
  13. Eigen::SparseMatrix<Atype> & A)
  14. {
  15. using namespace Eigen;
  16. typedef typename DerivedF::Scalar Index;
  17. const int m = F.rows();
  18. Eigen::Matrix<Index,Dynamic,1> EMAP,uEE,uEC;
  19. Eigen::Matrix<Index,Dynamic,2> E,uE;
  20. igl::unique_edge_map(F,E,uE,EMAP,uEC,uEE);
  21. std::vector<Eigen::Triplet<Index> > AIJV;
  22. AIJV.reserve(2*uE.rows());
  23. const int nu = uE.rows();
  24. for(int ue = 0;ue<nu;ue++)
  25. {
  26. // number of faces incident on this unique edge
  27. const int mue = uEC(ue+1)-uEC(ue);
  28. // base offset in uEE
  29. const int uECue = uEC(ue);
  30. assert(uECue < uEE.rows());
  31. for(int i = 0;i<mue;i++)
  32. {
  33. const auto ii = uEE(uECue+i)%m;
  34. for(int j = 0;j<mue;j++)
  35. {
  36. const auto jj = uEE(uECue+j)%m;
  37. if(ii != jj){ AIJV.emplace_back(ii,jj,1);}
  38. }
  39. }
  40. }
  41. // Facet Adjacency matrix (with (arbitrary) >0
  42. A.resize(m,m);
  43. A.setFromTriplets(AIJV.begin(),AIJV.end());
  44. // Set all non-zerro values to 1
  45. for(int g = 0;g<A.outerSize();g++)
  46. {
  47. for(typename Eigen::SparseMatrix<Atype>::InnerIterator it (A,g); it; ++it)
  48. {
  49. if(it.value()) it.valueRef() = 1;
  50. }
  51. }
  52. }
  53. #ifdef IGL_STATIC_LIBRARY
  54. // Explicit template instantiation
  55. // generated by autoexplicit.sh
  56. template void igl::facet_adjacency_matrix<Eigen::Matrix<int, -1, -1, 0, -1, -1>, int>(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<int, 0, int>&);
  57. #endif