edge_flaps.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "edge_flaps.h"
  9. #include "unique_edge_map.h"
  10. #include <vector>
  11. #include <cassert>
  12. template <
  13. typename DerivedF,
  14. typename DeriveduE,
  15. typename DerivedEMAP,
  16. typename DerivedEF,
  17. typename DerivedEI>
  18. IGL_INLINE void igl::edge_flaps(
  19. const Eigen::MatrixBase<DerivedF> & F,
  20. const Eigen::MatrixBase<DeriveduE> & uE,
  21. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  22. Eigen::PlainObjectBase<DerivedEF> & EF,
  23. Eigen::PlainObjectBase<DerivedEI> & EI)
  24. {
  25. // Initialize to boundary value
  26. EF.setConstant(uE.rows(),2,-1);
  27. EI.setConstant(uE.rows(),2,-1);
  28. // loop over all faces
  29. for(int f = 0;f<F.rows();f++)
  30. {
  31. // loop over edges across from corners
  32. for(int v = 0;v<3;v++)
  33. {
  34. // get edge id
  35. const int e = EMAP(v*F.rows()+f);
  36. // See if this is left or right flap w.r.t. edge orientation
  37. if( F(f,(v+1)%3) == uE(e,0) && F(f,(v+2)%3) == uE(e,1))
  38. {
  39. EF(e,0) = f;
  40. EI(e,0) = v;
  41. }else
  42. {
  43. assert(F(f,(v+1)%3) == uE(e,1) && F(f,(v+2)%3) == uE(e,0));
  44. EF(e,1) = f;
  45. EI(e,1) = v;
  46. }
  47. }
  48. }
  49. }
  50. template <
  51. typename DerivedF,
  52. typename DeriveduE,
  53. typename DerivedEMAP,
  54. typename DerivedEF,
  55. typename DerivedEI>
  56. IGL_INLINE void igl::edge_flaps(
  57. const Eigen::MatrixBase<DerivedF> & F,
  58. Eigen::PlainObjectBase<DeriveduE> & uE,
  59. Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
  60. Eigen::PlainObjectBase<DerivedEF> & EF,
  61. Eigen::PlainObjectBase<DerivedEI> & EI)
  62. {
  63. Eigen::MatrixXi allE;
  64. igl::unique_edge_map(F,allE,uE,EMAP);
  65. // Const-ify to call overload
  66. const auto & cuE = uE;
  67. const auto & cEMAP = EMAP;
  68. return edge_flaps(F,cuE,cEMAP,EF,EI);
  69. }
  70. #ifdef IGL_STATIC_LIBRARY
  71. // Explicit template specialization
  72. template void igl::edge_flaps<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::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::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>> const&, 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>>&);
  73. template void igl::edge_flaps<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::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>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&);
  74. #endif