orient_halfedges.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Oded Stein <[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 "orient_halfedges.h"
  9. #include "oriented_facets.h"
  10. #include "unique_simplices.h"
  11. template <typename DerivedF, typename DerivedE, typename DerivedOE>
  12. IGL_INLINE void
  13. igl::orient_halfedges(
  14. const Eigen::MatrixBase<DerivedF>& F,
  15. Eigen::PlainObjectBase<DerivedE>& E,
  16. Eigen::PlainObjectBase<DerivedOE>& oE)
  17. {
  18. assert(F.cols()==3 && "This only works for triangle meshes.");
  19. using Int = typename DerivedF::Scalar;
  20. const Eigen::Index m = F.rows();
  21. DerivedE allE, EE;
  22. oriented_facets(F, allE);
  23. Eigen::Matrix<Int, Eigen::Dynamic, 1> IA, IC;
  24. unique_simplices(allE, EE, IA, IC);
  25. E.resize(m, 3);
  26. oE.resize(m, 3);
  27. for(Eigen::Index f=0; f<m; ++f) {
  28. for(int e=0; e<3; ++e) {
  29. const Int ind = f + m*e;
  30. E(f,e) = IC(ind);
  31. assert((EE(E(f,e),0)==allE(ind,0) || EE(E(f,e),0)==allE(ind,1)) &&
  32. "Something is wrong in the edge matrix.");
  33. oE(f,e) = EE(E(f,e),0)==allE(ind,0) ? 1 : -1;
  34. }
  35. }
  36. }
  37. #ifdef IGL_STATIC_LIBRARY
  38. // Explicit template instantiation
  39. template void igl::orient_halfedges<Eigen::Matrix<int, -1, -1, 0, -1, -1>, 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> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  40. #endif