triangle_triangle_adjacency.h 7.3 KB

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