triangle_triangle_adjacency.h 4.7 KB

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