edge_flaps.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "edge_flaps.h"
  9. #include "unique_edge_map.h"
  10. #include <vector>
  11. #include <cassert>
  12. IGL_INLINE void igl::edge_flaps(
  13. const Eigen::MatrixXi & F,
  14. const Eigen::MatrixXi & E,
  15. const Eigen::VectorXi & EMAP,
  16. Eigen::MatrixXi & EF,
  17. Eigen::MatrixXi & EI)
  18. {
  19. EF.resize(E.rows(),2);
  20. EI.resize(E.rows(),2);
  21. // loop over all faces
  22. for(int f = 0;f<F.rows();f++)
  23. {
  24. // loop over edges across from corners
  25. for(int v = 0;v<3;v++)
  26. {
  27. // get edge id
  28. const int e = EMAP(v*F.rows()+f);
  29. // See if this is left or right flap w.r.t. edge orientation
  30. if( F(f,(v+1)%3) == E(e,0) && F(f,(v+2)%3) == E(e,1))
  31. {
  32. EF(e,0) = f;
  33. EI(e,0) = v;
  34. }else
  35. {
  36. assert(F(f,(v+1)%3) == E(e,1) && F(f,(v+2)%3) == E(e,0));
  37. EF(e,1) = f;
  38. EI(e,1) = v;
  39. }
  40. }
  41. }
  42. }
  43. IGL_INLINE void igl::edge_flaps(
  44. const Eigen::MatrixXi & F,
  45. Eigen::MatrixXi & E,
  46. Eigen::VectorXi & EMAP,
  47. Eigen::MatrixXi & EF,
  48. Eigen::MatrixXi & EI)
  49. {
  50. Eigen::MatrixXi allE;
  51. std::vector<std::vector<int> > uE2E;
  52. igl::unique_edge_map(F,allE,E,EMAP,uE2E);
  53. // Const-ify to call overload
  54. const auto & cE = E;
  55. const auto & cEMAP = EMAP;
  56. return edge_flaps(F,cE,cEMAP,EF,EI);
  57. }