HalfEdgeIterator.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // Inputs:
  31. // F #F by 3 list of "faces"
  32. // FF #F by 3 list of triangle-triangle adjacency.
  33. // FFi #F by 3 list of FF inverse. For FF and FFi, refer to
  34. // "triangle_triangle_adjacency.h"
  35. // Usages:
  36. // FlipF/E/V changes solely one actual face/edge/vertex resp.
  37. // NextFE iterates through one-ring of a vertex robustly.
  38. //
  39. template <
  40. typename DerivedF,
  41. typename DerivedFF,
  42. typename DerivedFFi>
  43. class HalfEdgeIterator
  44. {
  45. public:
  46. // Init the HalfEdgeIterator by specifying Face,Edge Index and Orientation
  47. IGL_INLINE HalfEdgeIterator(
  48. const Eigen::PlainObjectBase<DerivedF>& _F,
  49. const Eigen::PlainObjectBase<DerivedFF>& _FF,
  50. const Eigen::PlainObjectBase<DerivedFFi>& _FFi,
  51. int _fi,
  52. int _ei,
  53. bool _reverse = false
  54. );
  55. // Change Face
  56. IGL_INLINE void flipF();
  57. // Change Edge
  58. IGL_INLINE void flipE();
  59. // Change Vertex
  60. IGL_INLINE void flipV();
  61. IGL_INLINE bool isBorder();
  62. /*!
  63. * Returns the next edge skipping the border
  64. * _________
  65. * /\ c | b /\
  66. * / \ | / \
  67. * / d \ | / a \
  68. * /______\|/______\
  69. * v
  70. * In this example, if a and d are of-border and the pos is iterating
  71. counterclockwise, this method iterate through the faces incident on vertex
  72. v,
  73. * producing the sequence a, b, c, d, a, b, c, ...
  74. */
  75. IGL_INLINE bool NextFE();
  76. // Get vertex index
  77. IGL_INLINE int Vi();
  78. // Get face index
  79. IGL_INLINE int Fi();
  80. // Get edge index
  81. IGL_INLINE int Ei();
  82. IGL_INLINE bool operator==(HalfEdgeIterator& p2);
  83. private:
  84. int fi;
  85. int ei;
  86. bool reverse;
  87. // All the same type? This is likely to break.
  88. const Eigen::PlainObjectBase<DerivedF> & F;
  89. const Eigen::PlainObjectBase<DerivedFF> & FF;
  90. const Eigen::PlainObjectBase<DerivedFFi> & FFi;
  91. };
  92. }
  93. #ifndef IGL_STATIC_LIBRARY
  94. # include "HalfEdgeIterator.cpp"
  95. #endif
  96. #endif