edges.cpp 717 B

12345678910111213141516171819202122232425262728293031
  1. #include "edges.h"
  2. #include <map>
  3. #include "adjacency_matrix.h"
  4. IGL_INLINE void igl::edges( const Eigen::MatrixXi& F, Eigen::MatrixXi& E)
  5. {
  6. // build adjacency matrix
  7. Eigen::SparseMatrix<int> A;
  8. igl::adjacency_matrix(F,A);
  9. // Number of non zeros should be twice number of edges
  10. assert(A.nonZeros()%2 == 0);
  11. // Resize to fit edges
  12. E.resize(A.nonZeros()/2,2);
  13. int i = 0;
  14. // Iterate over outside
  15. for(int k=0; k<A.outerSize(); ++k)
  16. {
  17. // Iterate over inside
  18. for(Eigen::SparseMatrix<int>::InnerIterator it (A,k); it; ++it)
  19. {
  20. // only add edge in one direction
  21. if(it.row()<it.col())
  22. {
  23. E(i,0) = it.row();
  24. E(i,1) = it.col();
  25. i++;
  26. }
  27. }
  28. }
  29. }