HalfEdgeIterator.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. namespace igl
  14. {
  15. // HalfEdgeIterator - 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. //
  29. // Templates:
  30. // DerivedF Matrix Type for F. Has to be explicitly declared.
  31. // Inputs:
  32. // F #F by 3 list of "faces"
  33. // FF #F by 3 list of triangle-triangle adjacency.
  34. // FFi #F by 3 list of FF inverse. For FF and FFi, refer to
  35. // "triangle_triangle_adjacency.h"
  36. // Usages:
  37. // FlipF/E/V changes solely one actual face/edge/vertex resp.
  38. // NextFE iterates through one-ring of a vertex robustly.
  39. //
  40. template <typename DerivedF>
  41. class HalfEdgeIterator
  42. {
  43. public:
  44. // Init the HalfEdgeIterator by specifying Face,Edge Index and Orientation
  45. IGL_INLINE HalfEdgeIterator(
  46. const Eigen::PlainObjectBase<DerivedF>& _F,
  47. const Eigen::PlainObjectBase<DerivedF>& _FF,
  48. const Eigen::PlainObjectBase<DerivedF>& _FFi,
  49. int _fi,
  50. int _ei,
  51. bool _reverse = false
  52. );
  53. // Change Face
  54. IGL_INLINE void flipF();
  55. // Change Edge
  56. IGL_INLINE void flipE();
  57. // Change Vertex
  58. IGL_INLINE void flipV();
  59. IGL_INLINE bool isBorder();
  60. /*!
  61. * Returns the 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 counterclockwise, this method iterate through the faces incident on vertex v,
  69. * producing the sequence a, b, c, d, a, b, c, ...
  70. */
  71. IGL_INLINE bool NextFE();
  72. // Get vertex index
  73. IGL_INLINE int Vi();
  74. // Get face index
  75. IGL_INLINE int Fi();
  76. // Get edge index
  77. IGL_INLINE int Ei();
  78. IGL_INLINE bool operator==(HalfEdgeIterator& p2);
  79. private:
  80. int fi;
  81. int ei;
  82. bool reverse;
  83. const Eigen::PlainObjectBase<DerivedF>& F;
  84. const Eigen::PlainObjectBase<DerivedF>& FF;
  85. const Eigen::PlainObjectBase<DerivedF>& FFi;
  86. };
  87. }
  88. #ifndef IGL_STATIC_LIBRARY
  89. # include "HalfEdgeIterator.cpp"
  90. #endif
  91. #endif