adjacency_matrix.cpp 707 B

123456789101112131415161718192021222324252627282930313233
  1. #include "adjacency_matrix.h"
  2. #include "verbose.h"
  3. template <typename T>
  4. IGL_INLINE void igl::adjacency_matrix(
  5. const Eigen::MatrixXi & F,
  6. Eigen::SparseMatrix<T>& A)
  7. {
  8. Eigen::DynamicSparseMatrix<T, Eigen::RowMajor>
  9. dyn_A(F.maxCoeff()+1, F.maxCoeff()+1);
  10. dyn_A.reserve(6*(F.maxCoeff()+1));
  11. // Loop over faces
  12. for(int i = 0;i<F.rows();i++)
  13. {
  14. // Loop over this face
  15. for(int j = 0;j<F.cols();j++)
  16. {
  17. // Get indices of edge: s --> d
  18. int s = F(i,j);
  19. int d = F(i,(j+1)%F.cols());
  20. dyn_A.coeffRef(s, d) = 1;
  21. dyn_A.coeffRef(d, s) = 1;
  22. }
  23. }
  24. A = Eigen::SparseMatrix<T>(dyn_A);
  25. }
  26. #ifndef IGL_HEADER_ONLY
  27. // Explicit template specialization
  28. #endif