triangle_triangle_adjacency.h 5.5 KB

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