HalfEdgeIterator.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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 "HalfEdgeIterator.h"
  9. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  10. IGL_INLINE igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::HalfEdgeIterator(
  11. const Eigen::PlainObjectBase<DerivedF>& _F,
  12. const Eigen::PlainObjectBase<DerivedFF>& _FF,
  13. const Eigen::PlainObjectBase<DerivedFFi>& _FFi,
  14. int _fi,
  15. int _ei,
  16. bool _reverse
  17. )
  18. : fi(_fi), ei(_ei), reverse(_reverse), F(_F), FF(_FF), FFi(_FFi)
  19. {}
  20. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  21. IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipF()
  22. {
  23. if (isBorder())
  24. return;
  25. int fin = (FF)(fi,ei);
  26. int ein = (FFi)(fi,ei);
  27. fi = fin;
  28. ei = ein;
  29. reverse = !reverse;
  30. }
  31. // Change Edge
  32. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  33. IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipE()
  34. {
  35. if (!reverse)
  36. ei = (ei+2)%3; // ei-1
  37. else
  38. ei = (ei+1)%3;
  39. reverse = !reverse;
  40. }
  41. // Change Vertex
  42. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  43. IGL_INLINE void igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::flipV()
  44. {
  45. reverse = !reverse;
  46. }
  47. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  48. IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::isBorder()
  49. {
  50. return (FF)(fi,ei) == -1;
  51. }
  52. /*!
  53. * Returns the next edge skipping the border
  54. * _________
  55. * /\ c | b /\
  56. * / \ | / \
  57. * / d \ | / a \
  58. * /______\|/______\
  59. * v
  60. * In this example, if a and d are of-border and the pos is iterating counterclockwise, this method iterate through the faces incident on vertex v,
  61. * producing the sequence a, b, c, d, a, b, c, ...
  62. */
  63. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  64. IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::NextFE()
  65. {
  66. if ( isBorder() ) // we are on a border
  67. {
  68. do
  69. {
  70. flipF();
  71. flipE();
  72. } while (!isBorder());
  73. flipE();
  74. return false;
  75. }
  76. else
  77. {
  78. flipF();
  79. flipE();
  80. return true;
  81. }
  82. }
  83. // Get vertex index
  84. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  85. IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Vi()
  86. {
  87. assert(fi >= 0);
  88. assert(fi < F.rows());
  89. assert(ei >= 0);
  90. assert(ei <= 2);
  91. if (!reverse)
  92. return (F)(fi,ei);
  93. else
  94. return (F)(fi,(ei+1)%3);
  95. }
  96. // Get face index
  97. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  98. IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Fi()
  99. {
  100. return fi;
  101. }
  102. // Get edge index
  103. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  104. IGL_INLINE int igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::Ei()
  105. {
  106. return ei;
  107. }
  108. template <typename DerivedF, typename DerivedFF, typename DerivedFFi>
  109. IGL_INLINE bool igl::HalfEdgeIterator<DerivedF,DerivedFF,DerivedFFi>::operator==(HalfEdgeIterator& p2)
  110. {
  111. return
  112. (
  113. (fi == p2.fi) &&
  114. (ei == p2.ei) &&
  115. (reverse == p2.reverse) &&
  116. (F == p2.F) &&
  117. (FF == p2.FF) &&
  118. (FFi == p2.FFi)
  119. );
  120. }
  121. #ifdef IGL_STATIC_LIBRARY
  122. // Explicit template instantiation
  123. template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::HalfEdgeIterator(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, int, int, bool);
  124. template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::HalfEdgeIterator(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, int, bool);
  125. template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::NextFE();
  126. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Ei();
  127. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Ei();
  128. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::Ei();
  129. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::Fi();
  130. template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> ,Eigen::Matrix<int, -1, 3, 0, -1, 3> >::NextFE();
  131. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Vi();
  132. template igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::HalfEdgeIterator(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, int, bool);
  133. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Fi();
  134. template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipE();
  135. template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipF();
  136. template void igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::flipV();
  137. template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >::operator==(igl::HalfEdgeIterator<Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1>,Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  138. template int igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::Fi();
  139. template bool igl::HalfEdgeIterator<Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >::NextFE();
  140. #endif