directed_edge_parents.cpp 1012 B

123456789101112131415161718192021222324252627
  1. #include "directed_edge_parents.h"
  2. #include "slice_into.h"
  3. #include "slice.h"
  4. #include "colon.h"
  5. #include "setdiff.h"
  6. #include <algorithm>
  7. template <typename DerivedE, typename DerivedP>
  8. IGL_INLINE void igl::directed_edge_parents(
  9. const Eigen::PlainObjectBase<DerivedE> & E,
  10. Eigen::PlainObjectBase<DerivedP> & P)
  11. {
  12. using namespace Eigen;
  13. using namespace std;
  14. VectorXi I = VectorXi::Constant(E.maxCoeff()+1,1,-1);
  15. //I(E.col(1)) = 0:E.rows()-1
  16. slice_into(colon<int>(0,E.rows()-1),E.col(1).eval(),I);
  17. VectorXi roots,_;
  18. setdiff(E.col(0).eval(),E.col(1).eval(),roots,_);
  19. for_each(roots.data(),roots.data()+roots.size(),[&](int r){I(r)=-1;});
  20. slice(I,E.col(0).eval(),P);
  21. }
  22. #ifdef IGL_STATIC_LIBRARY
  23. // Explicit template instanciation
  24. template void igl::directed_edge_parents<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  25. #endif