edges.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "edges.h"
  9. #include "adjacency_matrix.h"
  10. IGL_INLINE void igl::edges( const Eigen::MatrixXi& F, Eigen::MatrixXi& E)
  11. {
  12. // build adjacency matrix
  13. Eigen::SparseMatrix<int> A;
  14. igl::adjacency_matrix(F,A);
  15. // Number of non zeros should be twice number of edges
  16. assert(A.nonZeros()%2 == 0);
  17. // Resize to fit edges
  18. E.resize(A.nonZeros()/2,2);
  19. int i = 0;
  20. // Iterate over outside
  21. for(int k=0; k<A.outerSize(); ++k)
  22. {
  23. // Iterate over inside
  24. for(Eigen::SparseMatrix<int>::InnerIterator it (A,k); it; ++it)
  25. {
  26. // only add edge in one direction
  27. if(it.row()<it.col())
  28. {
  29. E(i,0) = it.row();
  30. E(i,1) = it.col();
  31. i++;
  32. }
  33. }
  34. }
  35. }