triangle_triangle_adjacency.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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_TRIANGLE_TRIANGLE_ADJACENCY_H
  9. #define IGL_TRIANGLE_TRIANGLE_ADJACENCY_H
  10. #include "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. /// @param[in] F #F by simplex_size list of mesh faces (must be triangles)
  19. /// @param[out] TT #F by #3 adjacent matrix, the element i,j is the id of the triangle
  20. /// adjacent to the j edge of triangle i
  21. /// @param[out] TTi #F by #3 adjacent matrix, the element i,j is the id of edge of the
  22. /// triangle TT(i,j) that is adjacent with triangle i
  23. /// \note the first edge of a triangle is [0,1] the second [1,2] and the third
  24. /// [2,3]. This convention is DIFFERENT from
  25. /// cotmatrix_entries.h/edge_lengths.h/etc. To fix this you could use:
  26. ///
  27. /// \code{cpp}
  28. /// // Fix mis-match convention
  29. /// {
  30. /// Eigen::PermutationMatrix<3,3> perm(3);
  31. /// perm.indices() = Eigen::Vector3i(1,2,0);
  32. /// TT = (TT*perm).eval();
  33. /// TTi = (TTi*perm).eval();
  34. /// for(int i=0;i<TTi.rows();i++)
  35. /// for(int j=0;j<TTi.cols();j++)
  36. /// TTi(i,j)=TTi(i,j)==-1?-1:(TTi(i,j)+3-1)%3;
  37. /// }
  38. /// \endcode
  39. template <typename DerivedF, typename DerivedTT, typename DerivedTTi>
  40. IGL_INLINE void triangle_triangle_adjacency(
  41. const Eigen::MatrixBase<DerivedF>& F,
  42. Eigen::PlainObjectBase<DerivedTT>& TT,
  43. Eigen::PlainObjectBase<DerivedTTi>& TTi);
  44. /// \overload
  45. template <typename DerivedF, typename DerivedTT>
  46. IGL_INLINE void triangle_triangle_adjacency(
  47. const Eigen::MatrixBase<DerivedF>& F,
  48. Eigen::PlainObjectBase<DerivedTT>& TT);
  49. /// Preprocessing for triangle_triangle_adjacency
  50. /// @param[in] F #F by simplex_size list of mesh faces (must be triangles)
  51. /// @param[in] TT #F by #3 adjacent matrix, the element i,j is the id of the triangle
  52. /// adjacent to the j edge of triangle i
  53. ///
  54. /// \fileinfo
  55. template <typename DerivedF, typename TTT_type>
  56. IGL_INLINE void triangle_triangle_adjacency_preprocess(
  57. const Eigen::MatrixBase<DerivedF>& F,
  58. std::vector<std::vector<TTT_type> >& TTT);
  59. /// Extract the face adjacencies for triangle_triangle_adjacency
  60. ///
  61. /// @param[in] F #F by simplex_size list of mesh faces (must be triangles)
  62. /// @param[in] TTT #F list of lists adjacent triangles
  63. /// @param[in] TT #F by #3 adjacentmatrix, the element i,j is the id
  64. /// of edge of the triangle TT(i,j) that is adjacent with triangle i
  65. ///
  66. /// \fileinfo
  67. template <typename DerivedF, typename TTT_type, typename DerivedTT>
  68. IGL_INLINE void triangle_triangle_adjacency_extractTT(
  69. const Eigen::MatrixBase<DerivedF>& F,
  70. std::vector<std::vector<TTT_type> >& TTT,
  71. Eigen::PlainObjectBase<DerivedTT>& TT);
  72. /// Extract the face adjacencies indices for triangle_triangle_adjacency
  73. ///
  74. /// @param[in] F #F by simplex_size list of mesh faces (must be triangles)
  75. /// @param[in] TTT #F list of lists adjacent triangles
  76. /// @param[out] TTi #F by #3 adjacent matrix, the element i,j is the id of edge of the
  77. /// triangle TT(i,j) that is adjacent with triangle i
  78. ///
  79. /// \fileinfo
  80. template <typename DerivedF, typename TTT_type, typename DerivedTTi>
  81. IGL_INLINE void triangle_triangle_adjacency_extractTTi(
  82. const Eigen::MatrixBase<DerivedF>& F,
  83. std::vector<std::vector<TTT_type> >& TTT,
  84. Eigen::PlainObjectBase<DerivedTTi>& TTi);
  85. /// Adjacency list version, which works with non-manifold meshes
  86. ///
  87. /// @param[in] F #F by 3 list of triangle indices
  88. /// @param[out] TT #F by 3 list of lists so that TT[i][c] --> {j,k,...} means that
  89. /// faces j and k etc. are edge-neighbors of face i on face i's edge
  90. /// opposite corner c
  91. /// @param[out] TTj #F list of lists so that TTj[i][c] --> {j,k,...} means that face
  92. /// TT[i][c][0] is an edge-neighbor of face i incident on the edge of face
  93. /// TT[i][c][0] opposite corner j, and TT[i][c][1] " corner k, etc.
  94. template <
  95. typename DerivedF,
  96. typename TTIndex,
  97. typename TTiIndex>
  98. IGL_INLINE void triangle_triangle_adjacency(
  99. const Eigen::MatrixBase<DerivedF> & F,
  100. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  101. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  102. /// \overload
  103. template < typename DerivedF, typename TTIndex>
  104. IGL_INLINE void triangle_triangle_adjacency(
  105. const Eigen::MatrixBase<DerivedF> & F,
  106. std::vector<std::vector<std::vector<TTIndex> > > & TT);
  107. // @private
  108. // Wrapper with bool to choose whether to compute TTi (this prototype should
  109. // be "hidden").
  110. // @param[in] construct_TTi whether to compute TTi
  111. template <
  112. typename DerivedF,
  113. typename TTIndex,
  114. typename TTiIndex>
  115. IGL_INLINE void triangle_triangle_adjacency(
  116. const Eigen::MatrixBase<DerivedF> & F,
  117. const bool construct_TTi,
  118. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  119. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  120. /// \overload
  121. ///
  122. /// @param[in] E #F*3 by 2 list of all of directed edges in order (see
  123. /// `oriented_facets`)
  124. /// @param[in] EMAP #F*3 list of indices into uE, mapping each directed edge to unique
  125. /// undirected edge
  126. /// @param[in] uE2E #uE list of lists of indices into E of coexisting edges
  127. /// @param[in] construct_TTi whether to compute TTi
  128. ///
  129. /// \see unique_edge_map, oriented_facets
  130. template <
  131. typename DerivedE,
  132. typename DerivedEMAP,
  133. typename uE2EType,
  134. typename TTIndex,
  135. typename TTiIndex>
  136. IGL_INLINE void triangle_triangle_adjacency(
  137. const Eigen::MatrixBase<DerivedE> & E,
  138. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  139. const std::vector<std::vector<uE2EType > > & uE2E,
  140. const bool construct_TTi,
  141. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  142. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  143. /// \overload
  144. /// @param[in] uEC #uE+1 list of cumulative counts of directed edges sharing each
  145. /// unique edge so the uEC(i+1)-uEC(i) is the number of directed edges
  146. /// sharing the ith unique edge.
  147. /// @param[in] uEE #E list of indices into E, so that the consecutive segment of
  148. /// indices uEE.segment(uEC(i),uEC(i+1)-uEC(i)) lists all directed edges
  149. /// sharing the ith unique edge.
  150. template <
  151. typename DerivedEMAP,
  152. typename DeriveduEC,
  153. typename DeriveduEE,
  154. typename TTIndex,
  155. typename TTiIndex>
  156. IGL_INLINE void triangle_triangle_adjacency(
  157. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  158. const Eigen::MatrixBase<DeriveduEC> & uEC,
  159. const Eigen::MatrixBase<DeriveduEE> & uEE,
  160. const bool construct_TTi,
  161. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  162. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  163. }
  164. #ifndef IGL_STATIC_LIBRARY
  165. # include "triangle_triangle_adjacency.cpp"
  166. #endif
  167. #endif