directed_edge_parents.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "directed_edge_parents.h"
  9. #include "slice_into.h"
  10. #include "slice.h"
  11. #include "colon.h"
  12. #include "setdiff.h"
  13. #include <algorithm>
  14. template <typename DerivedE, typename DerivedP>
  15. IGL_INLINE void igl::directed_edge_parents(
  16. const Eigen::PlainObjectBase<DerivedE> & E,
  17. Eigen::PlainObjectBase<DerivedP> & P)
  18. {
  19. using namespace Eigen;
  20. using namespace std;
  21. VectorXi I = VectorXi::Constant(E.maxCoeff()+1,1,-1);
  22. //I(E.col(1)) = 0:E.rows()-1
  23. slice_into(colon<int>(0,E.rows()-1),E.col(1).eval(),I);
  24. VectorXi roots,_;
  25. setdiff(E.col(0).eval(),E.col(1).eval(),roots,_);
  26. for_each(roots.data(),roots.data()+roots.size(),[&](int r){I(r)=-1;});
  27. slice(I,E.col(0).eval(),P);
  28. }
  29. #ifdef IGL_STATIC_LIBRARY
  30. // Explicit template specialization
  31. 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> >&);
  32. #endif