adjacency_matrix.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "adjacency_matrix.h"
  2. #include "verbose.h"
  3. // Bug in unsupported/Eigen/SparseExtra needs iostream first
  4. #include <iostream>
  5. #include <unsupported/Eigen/SparseExtra>
  6. template <typename T>
  7. IGL_INLINE void igl::adjacency_matrix(
  8. const Eigen::MatrixXi & F,
  9. Eigen::SparseMatrix<T>& A)
  10. {
  11. Eigen::DynamicSparseMatrix<T, Eigen::RowMajor>
  12. dyn_A(F.maxCoeff()+1, F.maxCoeff()+1);
  13. switch(F.cols())
  14. {
  15. case 3:
  16. dyn_A.reserve(6*(F.maxCoeff()+1));
  17. break;
  18. case 4:
  19. dyn_A.reserve(26*(F.maxCoeff()+1));
  20. break;
  21. }
  22. // Loop over faces
  23. for(int i = 0;i<F.rows();i++)
  24. {
  25. // Loop over this face
  26. for(int j = 0;j<F.cols();j++)
  27. {
  28. // Get indices of edge: s --> d
  29. int s = F(i,j);
  30. int d = F(i,(j+1)%F.cols());
  31. dyn_A.coeffRef(s, d) = 1;
  32. dyn_A.coeffRef(d, s) = 1;
  33. }
  34. }
  35. A = Eigen::SparseMatrix<T>(dyn_A);
  36. }
  37. #ifndef IGL_HEADER_ONLY
  38. // Explicit template specialization
  39. template void igl::adjacency_matrix<int>(Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::SparseMatrix<int, 0, int>&);
  40. #endif