polyvector_field_singularities_from_matchings.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Olga Diamanti <olga.diam@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_POLYVECTOR_FIELD_SINGULARITIES_FROM_MATCHINGS
  9. #define IGL_POLYVECTOR_FIELD_SINGULARITIES_FROM_MATCHINGS
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl {
  14. // We are given a polyvector field on a mesh (with N vectors per face), and matchings between the vector sets
  15. // across all non-boundary edges. The function computes, for the one-ring
  16. // neighborhood of a given vertex, and for each of the vectors of the vector set,
  17. // the sequence of the vectors that match to it around the one-ring. If the vector that
  18. // we land on by following the matchings is not the original vector that we started from,
  19. // the vertex is a singularity.
  20. //
  21. // Inputs:
  22. // V #V by 3 list of the vertex positions
  23. // F #F by 3 list of the faces (must be triangles)
  24. // VF #V list of lists of incident faces (adjacency list), e.g.
  25. // as returned by igl::vertex_triangle_adjacency
  26. // E2F #E by 2 list of the edge-to-face relation (e.g. computed
  27. // via igl::edge_topology)
  28. // F2E #F by 3 list of the face-to-edge relation (e.g. computed
  29. // via igl::edge_topology)
  30. // TT #F by 3 triangle to triangle adjacent matrix (e.g. computed
  31. // via igl:triangle_triangle_adjacency)
  32. // match_ab #E by N matrix, describing for each edge the matching a->b, where a
  33. // and b are the faces adjacent to the edge (i.e. vector #i of
  34. // the vector set in a is matched to vector #mab[i] in b)
  35. // match_ba #E by N matrix, describing for each edge the matching b->a, where a
  36. // and b are the faces adjacent to the edge (i.e. vector #mba[i] of
  37. // the vector set in a is matched to vector #i in b)
  38. // vi the selected one ring
  39. //
  40. // Output:
  41. // mvi #numOneRingFaces by 1 list of the indices of the sequentially matching vectors
  42. // in the faces of the one ring (first enty is always vector_id, then the vector matching
  43. // vector_id in the next face, then the vector matching that in the third face etc.)
  44. // fi #numOneRingFaces by 1 list of the sequentially visited faces in the one ring neighborhood
  45. //
  46. template <typename DerivedV, typename DerivedF, typename DerivedM, typename VFType, typename DerivedTT>
  47. void polyvector_field_one_ring_matchings(const Eigen::PlainObjectBase<DerivedV> &V,
  48. const Eigen::PlainObjectBase<DerivedF> &F,
  49. const std::vector<std::vector<VFType> >& VF,
  50. const Eigen::MatrixXi& E2F,
  51. const Eigen::MatrixXi& F2E,
  52. const Eigen::PlainObjectBase<DerivedTT>& TT,
  53. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  54. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  55. const int vi,
  56. Eigen::MatrixXi &mvi,
  57. Eigen::VectorXi &fi);
  58. // Given a polyvector field on a mesh, and matchings between the vector sets
  59. // across all non-boundary edges, the function computes the singularities of the
  60. // polyvector field, by computing the one ring matchings.
  61. //
  62. // Inputs:
  63. // V #V by 3 list of the vertex positions
  64. // F #F by 3 list of the faces (must be triangles)
  65. // V_border #V by 1 list of booleans, indicating if the corresponging vertex is
  66. // at the mesh boundary, e.g. as returned by igl::is_border_vertex
  67. // VF #V list of lists of incident faces (adjacency list), e.g.
  68. // as returned by igl::vertex_triangle_adjacency
  69. // TT #F by 3 triangle to triangle adjacent matrix (e.g. computed
  70. // via igl:triangle_triangle_adjacency)
  71. // E2F #E by 2 list of the edge-to-face relation (e.g. computed
  72. // via igl::edge_topology)
  73. // F2E #F by 3 list of the face-to-edge relation (e.g. computed
  74. // via igl::edge_topology)
  75. // match_ab #E by N matrix, describing for each edge the matching a->b, where a
  76. // and b are the faces adjacent to the edge (i.e. vector #i of
  77. // the vector set in a is matched to vector #mab[i] in b)
  78. // match_ba #E by N matrix, describing for each edge the matching b->a, where a
  79. // and b are the faces adjacent to the edge (i.e. vector #mba[i] of
  80. // the vector set in a is matched to vector #i in b)
  81. //
  82. // Output:
  83. // singularities #S by 1 list of the indices of the singular vertices
  84. //
  85. template <typename DerivedV, typename DerivedF, typename DerivedM, typename VFType, typename DerivedS>
  86. IGL_INLINE void polyvector_field_singularities_from_matchings(
  87. const Eigen::PlainObjectBase<DerivedV> &V,
  88. const Eigen::PlainObjectBase<DerivedF> &F,
  89. const std::vector<bool> &V_border,
  90. const std::vector<std::vector<VFType> > &VF,
  91. const Eigen::MatrixXi &TT,
  92. const Eigen::MatrixXi &E2F,
  93. const Eigen::MatrixXi &F2E,
  94. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  95. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  96. Eigen::PlainObjectBase<DerivedS> &singularities);
  97. // Wrapper with only V,F and the matchings as input
  98. template <typename DerivedV, typename DerivedF, typename DerivedM, typename DerivedS>
  99. IGL_INLINE void polyvector_field_singularities_from_matchings(
  100. const Eigen::PlainObjectBase<DerivedV> &V,
  101. const Eigen::PlainObjectBase<DerivedF> &F,
  102. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  103. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  104. Eigen::PlainObjectBase<DerivedS> &singularities);
  105. // Same pair as above but also returns singularity indices
  106. template <typename DerivedV, typename DerivedF, typename DerivedM, typename DerivedS>
  107. IGL_INLINE void polyvector_field_singularities_from_matchings(
  108. const Eigen::PlainObjectBase<DerivedV> &V,
  109. const Eigen::PlainObjectBase<DerivedF> &F,
  110. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  111. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  112. Eigen::PlainObjectBase<DerivedS> &singularities,
  113. Eigen::PlainObjectBase<DerivedS> &singularity_indices);
  114. template <typename DerivedV, typename DerivedF, typename DerivedM, typename VFType, typename DerivedS>
  115. IGL_INLINE void polyvector_field_singularities_from_matchings(
  116. const Eigen::PlainObjectBase<DerivedV> &V,
  117. const Eigen::PlainObjectBase<DerivedF> &F,
  118. const std::vector<bool> &V_border,
  119. const std::vector<std::vector<VFType> > &VF,
  120. const Eigen::MatrixXi &TT,
  121. const Eigen::MatrixXi &E2F,
  122. const Eigen::MatrixXi &F2E,
  123. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  124. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  125. Eigen::PlainObjectBase<DerivedS> &singularities,
  126. Eigen::PlainObjectBase<DerivedS> &singularity_indices);
  127. };
  128. #ifndef IGL_STATIC_LIBRARY
  129. #include "polyvector_field_singularities_from_matchings.cpp"
  130. #endif
  131. #endif /* defined(IGL_POLYVECTOR_FIELD_SINGULARITIES_FROM_MATCHINGS) */