polyvector_field_singularities_from_matchings.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include <igl/polyvector_field_singularities_from_matchings.h>
  2. #include <igl/is_border_vertex.h>
  3. #include <igl/vertex_triangle_adjacency.h>
  4. #include <igl/list_to_matrix.h>
  5. #include <igl/triangle_triangle_adjacency.h>
  6. #include <igl/edge_topology.h>
  7. template <typename DerivedV, typename DerivedF, typename DerivedM, typename VFType, typename DerivedTT>
  8. void igl::polyvector_field_one_ring_matchings(const Eigen::PlainObjectBase<DerivedV> &V,
  9. const Eigen::PlainObjectBase<DerivedF> &F,
  10. const std::vector<std::vector<VFType> >& VF,
  11. const Eigen::MatrixXi& E2F,
  12. const Eigen::MatrixXi& F2E,
  13. const Eigen::PlainObjectBase<DerivedTT>& TT,
  14. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  15. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  16. const int vi,
  17. const int vector_to_match,
  18. Eigen::VectorXi &mvi,
  19. Eigen::VectorXi &fi)
  20. {
  21. int half_degree = match_ab.cols();
  22. mvi.resize(VF[vi].size()+1,1);
  23. fi.resize(VF[vi].size()+1,1);
  24. //start from one face
  25. const int &fstart = VF[vi][0];
  26. int current_face = fstart;
  27. int i =0;
  28. mvi[i] = vector_to_match;
  29. fi[i] = current_face;
  30. int next_face = -1;
  31. while (next_face != fstart)
  32. {
  33. // look for the vertex
  34. int j=-1;
  35. for (unsigned z=0; z<3; ++z)
  36. if (F(current_face,z) == vi)
  37. j=z;
  38. assert(j!=-1);
  39. next_face = TT(current_face, j);
  40. ++i;
  41. // look at the edge between the two faces
  42. const int &current_edge = F2E(current_face,j);
  43. // check its orientation to determine whether match_ab or match_ba should be used
  44. if ((E2F(current_edge,0) == current_face) &&
  45. (E2F(current_edge,1) == next_face) )
  46. {
  47. //look at match_ab
  48. mvi[i] = match_ab(current_edge,(mvi[i-1])%half_degree);
  49. }
  50. else
  51. {
  52. assert((E2F(current_edge,1) == current_face) &&
  53. (E2F(current_edge,0) == next_face));
  54. //look at match_ba
  55. mvi[i] = match_ba(current_edge,(mvi[i-1])%half_degree);
  56. }
  57. if (mvi[i-1]>=half_degree)
  58. mvi[i] = (mvi[i]+half_degree)%(2*half_degree);
  59. current_face = next_face;
  60. fi[i] = current_face;
  61. }
  62. }
  63. template <typename DerivedV, typename DerivedF, typename DerivedM, typename DerivedS>
  64. IGL_INLINE void igl::polyvector_field_singularities_from_matchings(
  65. const Eigen::PlainObjectBase<DerivedV> &V,
  66. const Eigen::PlainObjectBase<DerivedF> &F,
  67. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  68. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  69. Eigen::PlainObjectBase<DerivedS> &singularities)
  70. {
  71. std::vector<bool> V_border = igl::is_border_vertex(V,F);
  72. std::vector<std::vector<int> > VF, VFi;
  73. igl::vertex_triangle_adjacency(V,F,VF,VFi);
  74. Eigen::MatrixXi TT, TTi;
  75. igl::triangle_triangle_adjacency(F,TT,TTi);
  76. Eigen::MatrixXi E, E2F, F2E;
  77. igl::edge_topology(V,F,E,F2E,E2F);
  78. igl::polyvector_field_singularities_from_matchings(V, F, V_border, VF, TT, E2F, F2E, match_ab, match_ba, singularities);
  79. }
  80. template <typename DerivedV, typename DerivedF, typename DerivedM, typename VFType, typename DerivedS>
  81. IGL_INLINE void igl::polyvector_field_singularities_from_matchings(
  82. const Eigen::PlainObjectBase<DerivedV> &V,
  83. const Eigen::PlainObjectBase<DerivedF> &F,
  84. const std::vector<bool> &V_border,
  85. const std::vector<std::vector<VFType> > &VF,
  86. const Eigen::MatrixXi &TT,
  87. const Eigen::MatrixXi &E2F,
  88. const Eigen::MatrixXi &F2E,
  89. const Eigen::PlainObjectBase<DerivedM> &match_ab,
  90. const Eigen::PlainObjectBase<DerivedM> &match_ba,
  91. Eigen::PlainObjectBase<DerivedS> &singularities)
  92. {
  93. int numV = V.rows();
  94. std::vector<int> singularities_v;
  95. int half_degree = match_ab.cols();
  96. //pick one of the vectors to check for singularities
  97. for (int vector_to_match = 0; vector_to_match < half_degree; ++vector_to_match)
  98. {
  99. for (int vi =0; vi<numV; ++vi)
  100. {
  101. ///check that is on border..
  102. if (V_border[vi])
  103. continue;
  104. Eigen::VectorXi mvi,fi;
  105. igl::polyvector_field_one_ring_matchings(V, F, VF, E2F, F2E, TT, match_ab, match_ba, vi, vector_to_match, mvi, fi);
  106. if(mvi.tail(1) != mvi.head(1))
  107. singularities_v.push_back(vi);
  108. }
  109. }
  110. std::sort(singularities_v.begin(), singularities_v.end());
  111. auto last = std::unique(singularities_v.begin(), singularities_v.end());
  112. singularities_v.erase(last, singularities_v.end());
  113. igl::list_to_matrix(singularities_v, singularities);
  114. }
  115. #ifdef IGL_STATIC_LIBRARY
  116. // Explicit template specialization
  117. template void igl::polyvector_field_singularities_from_matchings<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, int, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, std::vector<bool, std::allocator<bool> > const&, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  118. template void igl::polyvector_field_singularities_from_matchings<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  119. #endif