pos.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_POS_H
  9. #define IGL_POS_H
  10. #include <Eigen/Core>
  11. #include <vector>
  12. namespace igl
  13. {
  14. // Pos - Fake halfedge for fast and easy navigation on triangle meshes with VT and TT adj
  15. //template <typename S>
  16. template <typename DerivedF>
  17. class Pos
  18. {
  19. public:
  20. // Init the pos by specifying Face,Edge Index and Orientation
  21. Pos(
  22. // const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* F,
  23. // Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FF,
  24. // Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FFi,
  25. const Eigen::PlainObjectBase<DerivedF>* F,
  26. const Eigen::PlainObjectBase<DerivedF>* FF,
  27. const Eigen::PlainObjectBase<DerivedF>* FFi,
  28. int fi,
  29. int ei,
  30. bool reverse = false
  31. )
  32. : F(F), FF(FF), FFi(FFi), fi(fi), ei(ei), reverse(reverse)
  33. {}
  34. // Change Face
  35. void flipF()
  36. {
  37. if (isBorder())
  38. return;
  39. int fin = (*FF)(fi,ei);
  40. int ein = (*FFi)(fi,ei);
  41. int reversen = !reverse;
  42. fi = fin;
  43. ei = ein;
  44. reverse = reversen;
  45. }
  46. // Change Edge
  47. void flipE()
  48. {
  49. if (!reverse)
  50. ei = (ei+2)%3; // ei-1
  51. else
  52. ei = (ei+1)%3;
  53. reverse = !reverse;
  54. }
  55. // Change Vertex
  56. void flipV()
  57. {
  58. reverse = !reverse;
  59. }
  60. bool isBorder()
  61. {
  62. return (*FF)(fi,ei) == -1;
  63. }
  64. /*!
  65. * Returns the next edge skipping the border
  66. * _________
  67. * /\ c | b /\
  68. * / \ | / \
  69. * / d \ | / a \
  70. * /______\|/______\
  71. * v
  72. * 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,
  73. * producing the sequence a, b, c, d, a, b, c, ...
  74. */
  75. bool NextFE()
  76. {
  77. if ( isBorder() ) // we are on a border
  78. {
  79. do
  80. {
  81. flipF();
  82. flipE();
  83. } while (!isBorder());
  84. flipE();
  85. return false;
  86. }
  87. else
  88. {
  89. flipF();
  90. flipE();
  91. return true;
  92. }
  93. }
  94. // Get vertex index
  95. int Vi()
  96. {
  97. assert(fi >= 0);
  98. assert(fi < F->rows());
  99. assert(ei >= 0);
  100. assert(ei <= 2);
  101. if (!reverse)
  102. return (*F)(fi,ei);
  103. else
  104. return (*F)(fi,(ei+1)%3);
  105. }
  106. // Get face index
  107. int Fi()
  108. {
  109. return fi;
  110. }
  111. // Get edge index
  112. int Ei()
  113. {
  114. return ei;
  115. }
  116. bool operator==(Pos& p2)
  117. {
  118. return
  119. (
  120. (fi == p2.fi) &&
  121. (ei == p2.ei) &&
  122. (reverse == p2.reverse) &&
  123. (F == p2.F) &&
  124. (FF == p2.FF) &&
  125. (FFi == p2.FFi)
  126. );
  127. }
  128. private:
  129. int fi;
  130. int ei;
  131. bool reverse;
  132. const Eigen::PlainObjectBase<DerivedF>* F;
  133. const Eigen::PlainObjectBase<DerivedF>* FF;
  134. const Eigen::PlainObjectBase<DerivedF>* FFi;
  135. // const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* F;
  136. // const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FF;
  137. // const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FFi;
  138. };
  139. }
  140. #endif