edges.cpp 702 B

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