triangle_triangle_adjacency.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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(
  34. const Eigen::PlainObjectBase<Scalar>& V,
  35. const Eigen::PlainObjectBase<Index>& F,
  36. Eigen::PlainObjectBase<Index>& TT);
  37. // Compute triangle-triangle adjacency with indices
  38. template <typename Scalar, typename Index>
  39. IGL_INLINE void triangle_triangle_adjacency(
  40. const Eigen::PlainObjectBase<Scalar>& V,
  41. const Eigen::PlainObjectBase<Index>& F,
  42. Eigen::PlainObjectBase<Index>& TT,
  43. Eigen::PlainObjectBase<Index>& TTi);
  44. template <typename DerivedF, typename DerivedTT, typename DerivedTTi>
  45. IGL_INLINE void triangle_triangle_adjacency(
  46. const Eigen::PlainObjectBase<DerivedF>& F,
  47. Eigen::PlainObjectBase<DerivedTT>& TT,
  48. Eigen::PlainObjectBase<DerivedTTi>& TTi);
  49. // Preprocessing
  50. template <typename Scalar, typename Index>
  51. IGL_INLINE void triangle_triangle_adjacency_preprocess(
  52. const Eigen::PlainObjectBase<Scalar>& V,
  53. const Eigen::PlainObjectBase<Index>& F,
  54. std::vector<std::vector<int> >& TTT);
  55. template <typename DerivedF>
  56. IGL_INLINE void triangle_triangle_adjacency_preprocess(
  57. const Eigen::PlainObjectBase<DerivedF>& F,
  58. std::vector<std::vector<int> >& TTT);
  59. // Extract the face adjacencies
  60. template <typename DerivedF, typename DerivedTT>
  61. IGL_INLINE void triangle_triangle_adjacency_extractTT(
  62. const Eigen::PlainObjectBase<DerivedF>& F,
  63. std::vector<std::vector<int> >& TTT,
  64. Eigen::PlainObjectBase<DerivedTT>& TT);
  65. // Extract the face adjacencies indices (needed for fast traversal)
  66. template <typename DerivedF, typename DerivedTTi>
  67. IGL_INLINE void triangle_triangle_adjacency_extractTTi(
  68. const Eigen::PlainObjectBase<DerivedF>& F,
  69. std::vector<std::vector<int> >& TTT,
  70. Eigen::PlainObjectBase<DerivedTTi>& TTi);
  71. // Adjacency list version, which works with non-manifold meshes
  72. //
  73. // Inputs:
  74. // F #F by 3 list of triangle indices
  75. // Outputs:
  76. // TT #F by 3 list of lists so that TT[i][c] --> {j,k,...} means that faces j and
  77. // k etc. are edge-neighbors of face i on face i's edge opposite corner c
  78. // TTj #F list of lists so that TTj[i][c] --> {j,k,...} means that face
  79. // TT[i][c][0] is an edge-neighbor of face i incident on the edge of face
  80. // TT[i][c][0] opposite corner j, and TT[i][c][1] " corner k, etc.
  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. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  88. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  89. template < typename DerivedF, typename TTIndex>
  90. IGL_INLINE void triangle_triangle_adjacency(
  91. const Eigen::PlainObjectBase<DerivedF> & F,
  92. std::vector<std::vector<std::vector<TTIndex> > > & TT);
  93. // Wrapper with bool to choose whether to compute TTi (this prototype should
  94. // be "hidden").
  95. template <
  96. typename DerivedF,
  97. typename TTIndex,
  98. typename TTiIndex>
  99. IGL_INLINE void triangle_triangle_adjacency(
  100. const Eigen::PlainObjectBase<DerivedF> & F,
  101. const bool construct_TTi,
  102. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  103. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  104. // Inputs:
  105. // E #F*3 by 2 list of all of directed edges in order (see `all_edges`)
  106. // EMAP #F*3 list of indices into uE, mapping each directed edge to unique
  107. // undirected edge
  108. // uE2E #uE list of lists of indices into E of coexisting edges
  109. // See also: unique_edge_map, all_edges
  110. template <
  111. typename DerivedE,
  112. typename DerivedEMAP,
  113. typename uE2EType,
  114. typename TTIndex,
  115. typename TTiIndex>
  116. IGL_INLINE void triangle_triangle_adjacency(
  117. const Eigen::PlainObjectBase<DerivedE> & E,
  118. const Eigen::PlainObjectBase<DerivedEMAP> & EMAP,
  119. const std::vector<std::vector<uE2EType > > & uE2E,
  120. const bool construct_TTi,
  121. std::vector<std::vector<std::vector<TTIndex> > > & TT,
  122. std::vector<std::vector<std::vector<TTiIndex> > > & TTi);
  123. }
  124. #ifndef IGL_STATIC_LIBRARY
  125. # include "triangle_triangle_adjacency.cpp"
  126. #endif
  127. #endif