adjacency_list.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef IGL_ADJACENCY_MATRIX_H
  2. #define IGL_ADJACENCY_MATRIX_H
  3. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  4. #include <Eigen/Dense>
  5. #include <Eigen/Sparse>
  6. namespace igl
  7. {
  8. // Constructs the graph adjacency list of a given mesh (V,F)
  9. // Templates:
  10. // T should be a eigen sparse matrix primitive type like int or double
  11. // Inputs:
  12. // F #F by dim list of mesh faces (must be triangles)
  13. // Outputs:
  14. // A vector<vector<T> > containing at row i the adjacent vertices of vertex i
  15. //
  16. // Example:
  17. // // Mesh in (V,F)
  18. // vector<vector<double> > A;
  19. // adjacency_list(F,A);
  20. //
  21. // See also: edges, cotmatrix, diag
  22. template <typename T>
  23. inline void adjacency_list(
  24. const Eigen::MatrixXi & F,
  25. vector<vector<T> >& A
  26. );
  27. }
  28. // Implementation
  29. #include "verbose.h"
  30. template <typename T>
  31. inline void igl::adjacency_list(
  32. const Eigen::MatrixXi & F,
  33. vector<vector<T> >& A)
  34. {
  35. A.clear();
  36. A.resize(F.maxCoeff()+1);
  37. // Loop over faces
  38. for(int i = 0;i<F.rows();i++)
  39. {
  40. // Loop over this face
  41. for(int j = 0;j<F.cols();j++)
  42. {
  43. // Get indices of edge: s --> d
  44. int s = F(i,j);
  45. int d = F(i,(j+1)%F.cols());
  46. if (s>d)
  47. {
  48. A[s].push_back(d);
  49. A[d].push_back(s);
  50. }
  51. }
  52. }
  53. }
  54. #endif