HalfEdgeIterator.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef IGL_HALFEDGEITERATOR_H
  9. #define IGL_HALFEDGEITERATOR_H
  10. #include <Eigen/Core>
  11. #include <vector>
  12. #include <igl/igl_inline.h>
  13. // This file violates many of the libigl style guidelines.
  14. namespace igl
  15. {
  16. // HalfEdgeIterator - Fake halfedge for fast and easy navigation
  17. // on triangle meshes with vertex_triangle_adjacency and
  18. // triangle_triangle adjacency
  19. //
  20. // Note: this is different to classical Half Edge data structure.
  21. // Instead, it follows cell-tuple in [Brisson, 1989]
  22. // "Representing geometric structures in d dimensions: topology and order."
  23. // This class can achieve local navigation similar to half edge in OpenMesh
  24. // But the logic behind each atom operation is different.
  25. // So this should be more properly called TriangleTupleIterator.
  26. //
  27. // Each tuple contains information on (face, edge, vertex)
  28. // and encoded by (face, edge \in {0,1,2}, bool reverse)
  29. //
  30. // Templates:
  31. // DerivedF Matrix Type for F. Has to be explicitly declared.
  32. // Inputs:
  33. // F #F by 3 list of "faces"
  34. // FF #F by 3 list of triangle-triangle adjacency.
  35. // FFi #F by 3 list of FF inverse. For FF and FFi, refer to
  36. // "triangle_triangle_adjacency.h"
  37. // Usages:
  38. // FlipF/E/V changes solely one actual face/edge/vertex resp.
  39. // NextFE iterates through one-ring of a vertex robustly.
  40. //
  41. template <
  42. typename DerivedF,
  43. typename DerivedFF,
  44. typename DerivedFFi>
  45. class HalfEdgeIterator
  46. {
  47. public:
  48. // Init the HalfEdgeIterator by specifying Face,Edge Index and Orientation
  49. IGL_INLINE HalfEdgeIterator(
  50. const Eigen::PlainObjectBase<DerivedF>& _F,
  51. const Eigen::PlainObjectBase<DerivedFF>& _FF,
  52. const Eigen::PlainObjectBase<DerivedFFi>& _FFi,
  53. int _fi,
  54. int _ei,
  55. bool _reverse = false
  56. );
  57. // Change Face
  58. IGL_INLINE void flipF();
  59. // Change Edge
  60. IGL_INLINE void flipE();
  61. // Change Vertex
  62. IGL_INLINE void flipV();
  63. IGL_INLINE bool isBorder();
  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
  73. counterclockwise, this method iterate through the faces incident on vertex
  74. v,
  75. * producing the sequence a, b, c, d, a, b, c, ...
  76. */
  77. IGL_INLINE bool NextFE();
  78. // Get vertex index
  79. IGL_INLINE int Vi();
  80. // Get face index
  81. IGL_INLINE int Fi();
  82. // Get edge index
  83. IGL_INLINE int Ei();
  84. IGL_INLINE bool operator==(HalfEdgeIterator& p2);
  85. private:
  86. int fi;
  87. int ei;
  88. bool reverse;
  89. // All the same type? This is likely to break.
  90. const DerivedF & F;
  91. const DerivedFF & FF;
  92. const DerivedFFi & FFi;
  93. };
  94. }
  95. #ifndef IGL_STATIC_LIBRARY
  96. # include "HalfEdgeIterator.cpp"
  97. #endif
  98. #endif