directed_edge_parents.cpp 1.3 KB

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