triangle_triangle_adjacency.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_TRIANGLE_TRIANGLE_ADJACENCY_H
  9. #define IGL_TRIANGLE_TRIANGLE_ADJACENCY_H
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. // Constructs the triangle-triangle adjacency matrix for a given
  16. // mesh (V,F).
  17. //
  18. // Templates:
  19. // Scalar derived type of eigen matrix for V (e.g. derived from
  20. // MatirxXd)
  21. // Index derived type of eigen matrix for F (e.g. derived from
  22. // MatrixXi)
  23. // Inputs:
  24. // V #V by dim list of mesh vertex positions
  25. // F #F by simplex_size list of mesh faces (must be triangles)
  26. // Outputs:
  27. // TT #F by #3 adjacent matrix, the element i,j is the id of the triangle adjacent to the j edge of triangle i
  28. // TTi #F by #3 adjacent matrix, the element i,j is the id of edge of the triangle TT(i,j) that is adjacent with triangle i
  29. // NOTE: the first edge of a triangle is [0,1] the second [1,2] and the third [2,3].
  30. // this convention is DIFFERENT from cotmatrix_entries.h
  31. // Known bug: this should not need to take V as input.
  32. template <typename Scalar, typename Index>
  33. IGL_INLINE void triangle_triangle_adjacency(const Eigen::PlainObjectBase<Scalar>& V,
  34. const Eigen::PlainObjectBase<Index>& F,
  35. Eigen::PlainObjectBase<Index>& TT);
  36. // Compute triangle-triangle adjacency with indices
  37. template <typename Scalar, typename Index>
  38. IGL_INLINE void triangle_triangle_adjacency(const Eigen::PlainObjectBase<Scalar>& V,
  39. const Eigen::PlainObjectBase<Index>& F,
  40. Eigen::PlainObjectBase<Index>& TT,
  41. Eigen::PlainObjectBase<Index>& TTi);
  42. // Preprocessing
  43. template <typename Scalar, typename Index>
  44. IGL_INLINE void triangle_triangle_adjacency_preprocess(const Eigen::PlainObjectBase<Scalar>& V,
  45. const Eigen::PlainObjectBase<Index>& F,
  46. std::vector<std::vector<int> >& TTT);
  47. // Extract the face adjacencies
  48. template <typename Index>
  49. IGL_INLINE void triangle_triangle_adjacency_extractTT(const Eigen::PlainObjectBase<Index>& F,
  50. std::vector<std::vector<int> >& TTT,
  51. Eigen::PlainObjectBase<Index>& TT);
  52. // Extract the face adjacencies indices (needed for fast traversal)
  53. template <typename Index>
  54. IGL_INLINE void triangle_triangle_adjacency_extractTTi(const Eigen::PlainObjectBase<Index>& F,
  55. std::vector<std::vector<int> >& TTT,
  56. Eigen::PlainObjectBase<Index>& TTi);
  57. // Adjacency list version, which works with non-manifold meshes
  58. //
  59. // Inputs:
  60. // F #F by 3 list of triangle indices
  61. // Outputs:
  62. // TT #F by 3 list of lists so that TT[i][c] --> {j,k,...} means that faces j and
  63. // k etc. are edge-neighbors of face i on face i's edge opposite corner c
  64. // TTj #F list of lists so that TTj[i][c] --> {j,k,...} means that face
  65. // TT[i][c][0] is an edge-neighbor of face i incident on the edge of face
  66. // TT[i][c][0] opposite corner j, and TT[i][c][1] " corner k, etc.
  67. template <
  68. typename DerivedF,
  69. typename TTIndex,
  70. typename TTiIndex>
  71. IGL_INLINE void triangle_triangle_adjacency(
  72. const Eigen::PlainObjectBase<DerivedF> & F,
  73. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  74. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  75. template < typename DerivedF, typename TTIndex>
  76. IGL_INLINE void triangle_triangle_adjacency(
  77. const Eigen::PlainObjectBase<DerivedF> & F,
  78. std::vector<std::vector<std::vector<TTIndex> > > & TT);
  79. // Wrapper with bool to choose whether to compute TTi (this prototype should
  80. // be "hidden").
  81. template <
  82. typename DerivedF,
  83. typename TTIndex,
  84. typename TTiIndex>
  85. IGL_INLINE void triangle_triangle_adjacency(
  86. const Eigen::PlainObjectBase<DerivedF> & F,
  87. const bool construct_TTi,
  88. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  89. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  90. // Inputs:
  91. // E #F*3 by 2 list of all of directed edges in order (see `all_edges`)
  92. // EMAP #F*3 list of indices into uE, mapping each directed edge to unique
  93. // undirected edge
  94. // uE2E #uE list of lists of indices into E of coexisting edges
  95. // See also: unique_edge_map, all_edges
  96. template <
  97. typename DerivedE,
  98. typename DerivedEMAP,
  99. typename uE2EType,
  100. typename TTIndex,
  101. typename TTiIndex>
  102. IGL_INLINE void triangle_triangle_adjacency(
  103. const Eigen::PlainObjectBase<DerivedE> & E,
  104. const Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
  105. const std::vector<std::vector<uE2EType > > & uE2E,
  106. const bool construct_TTi,
  107. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  108. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  109. }
  110. #ifndef IGL_STATIC_LIBRARY
  111. # include "triangle_triangle_adjacency.cpp"
  112. #endif
  113. #endif