triangle_triangle_adjacency.h 4.9 KB

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