HalfEdgeIterator.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <[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. #ifndef IGL_HALFEDGEITERATOR_H
  9. #define IGL_HALFEDGEITERATOR_H
  10. #include <Eigen/Core>
  11. #include <vector>
  12. #include "igl_inline.h"
  13. namespace igl
  14. {
  15. /// Fake halfedge for fast and easy navigation
  16. /// on triangle meshes with vertex_triangle_adjacency and
  17. /// triangle_triangle adjacency
  18. ///
  19. /// Note: this is different to classical Half Edge data structure.
  20. /// Instead, it follows cell-tuple in [Brisson, 1989]
  21. /// "Representing geometric structures in d dimensions: topology and order."
  22. /// This class can achieve local navigation similar to half edge in OpenMesh
  23. /// But the logic behind each atom operation is different.
  24. /// So this should be more properly called TriangleTupleIterator.
  25. ///
  26. /// Each tuple contains information on (face, edge, vertex)
  27. /// and encoded by (face, edge \in {0,1,2}, bool reverse)
  28. template <
  29. typename DerivedF,
  30. typename DerivedFF,
  31. typename DerivedFFi>
  32. class HalfEdgeIterator
  33. {
  34. public:
  35. /// Init the HalfEdgeIterator by specifying Face,Edge Index and Orientation
  36. ///
  37. /// @param[in] F #F by 3 list of "faces"
  38. /// @param[in] FF #F by 3 list of triangle-triangle adjacency.
  39. /// @param[in] FFi #F by 3 list of FF inverse. For FF and FFi, refer to
  40. /// "triangle_triangle_adjacency.h"
  41. /// @param[in] _fi index of the selected face
  42. /// @param[in] _ii index of the selected face
  43. /// @param[in] _reverse orientation of the selected face
  44. IGL_INLINE HalfEdgeIterator(
  45. const Eigen::MatrixBase<DerivedF>& _F,
  46. const Eigen::MatrixBase<DerivedFF>& _FF,
  47. const Eigen::MatrixBase<DerivedFFi>& _FFi,
  48. int _fi,
  49. int _ei,
  50. bool _reverse = false
  51. );
  52. /// Change Face
  53. IGL_INLINE void flipF();
  54. /// Change Edge
  55. IGL_INLINE void flipE();
  56. /// Change Vertex
  57. IGL_INLINE void flipV();
  58. /// Determine if on border.
  59. /// @returns true if the current edge is on the border
  60. IGL_INLINE bool isBorder();
  61. /// Change to next edge skipping the border
  62. /// _________
  63. /// /\ c | b /\
  64. /// / \ | / \
  65. /// / d \ | / a \
  66. /// /______\|/______\
  67. /// v
  68. /// In this example, if a and d are of-border and the pos is iterating
  69. /// counterclockwise, this method iterate through the faces incident on vertex
  70. /// v,
  71. /// producing the sequence a, b, c, d, a, b, c, ...
  72. ///
  73. /// @returns true if the next edge is not on the border
  74. IGL_INLINE bool NextFE();
  75. /// Get vertex index
  76. /// @return vertex index
  77. IGL_INLINE int Vi();
  78. /// Get face index
  79. /// @return face index
  80. IGL_INLINE int Fi();
  81. /// Get edge index
  82. /// @return edge index
  83. IGL_INLINE int Ei();
  84. /// Check if two HalfEdgeIterator are the same
  85. /// @return true if two HalfEdgeIterator are the same
  86. IGL_INLINE bool operator==(HalfEdgeIterator& p2);
  87. private:
  88. int fi;
  89. int ei;
  90. bool reverse;
  91. // All the same type? This is likely to break.
  92. const Eigen::MatrixBase<DerivedF> & F;
  93. const Eigen::MatrixBase<DerivedFF> & FF;
  94. const Eigen::MatrixBase<DerivedFFi> & FFi;
  95. };
  96. }
  97. #ifndef IGL_STATIC_LIBRARY
  98. # include "HalfEdgeIterator.cpp"
  99. #endif
  100. #endif