adjacency_matrix.cpp 830 B

12345678910111213141516171819202122232425262728293031323334353637
  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. dyn_A.reserve(6*(F.maxCoeff()+1));
  14. // Loop over faces
  15. for(int i = 0;i<F.rows();i++)
  16. {
  17. // Loop over this face
  18. for(int j = 0;j<F.cols();j++)
  19. {
  20. // Get indices of edge: s --> d
  21. int s = F(i,j);
  22. int d = F(i,(j+1)%F.cols());
  23. dyn_A.coeffRef(s, d) = 1;
  24. dyn_A.coeffRef(d, s) = 1;
  25. }
  26. }
  27. A = Eigen::SparseMatrix<T>(dyn_A);
  28. }
  29. #ifndef IGL_HEADER_ONLY
  30. // Explicit template specialization
  31. #endif