triangle_triangle_adjacency.h 4.7 KB

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