polyvector_field_matchings.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_MATCHINGS
  9. #define IGL_POLYVECTOR_FIELD_MATCHINGS
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl {
  14. // Given a pair of adjacent faces a and b, and a set of N unordered vectors
  15. // of a vector set defined on each face, the function computes the best order-preserving
  16. // matching between them, where "best" means "minimum curl", or "smoothest".
  17. // Inputs:
  18. // _ua 1 by 3N row vector of the vectors on face a, stacked horizontally
  19. // _ub 1 by 3N row vector of the vectors on face b, stacked horizontally
  20. // na 1 by 3, normal of face a
  21. // nb 1 by 3, normal of face b
  22. // e 1 by 3, the vector corresponding to the shared edge between a and b
  23. // match_with_curl boolean flag, determines whether a curl or a smoothness matching will
  24. // be computed
  25. // is_symmetric boolean flag, determines whether the input vector set field is symmetric(
  26. // =consists of pairwise collinear vectors in each set, in which case only one
  27. // of the vectors in the pair is stored) or not, i.e. the set contains all the vectors
  28. // )
  29. // Outputs:
  30. // mab 1 by N row vector, describing the matching a->b (i.e. vector #i of the
  31. // vector set in a is matched to vector #mab[i] in b)
  32. // mba 1 by N row vector, describing the matching b->a (i.e. vector #mba[i]
  33. // of the vector set in a is matched to vector #i in b)
  34. //
  35. template <typename DerivedS, typename DerivedV, typename DerivedM>
  36. IGL_INLINE void polyvector_field_matching(
  37. const Eigen::PlainObjectBase<DerivedS>& _ua,
  38. const Eigen::PlainObjectBase<DerivedS>& _ub,
  39. const Eigen::PlainObjectBase<DerivedV>& na,
  40. const Eigen::PlainObjectBase<DerivedV>& nb,
  41. const Eigen::PlainObjectBase<DerivedV>& e,
  42. bool match_with_curl,
  43. Eigen::PlainObjectBase<DerivedM>& mab,
  44. Eigen::PlainObjectBase<DerivedM>& mba,
  45. bool is_symmetric);
  46. // Given a mesh and a vector set field consisting of unordered N-vector sets defined
  47. // on the faces of the mesh, the function computes, for each (non-boundary) edge
  48. // the best order-preserving matching between the vector sets of the faces across
  49. // the edge, where "best" means to "with minimum curl", or "smoothest"
  50. // Inputs:
  51. // sol3D #F by 3n list of the 3D coordinates of the per-face vectors
  52. // (stacked horizontally for each triangle)
  53. // V #V by 3 list of mesh vertex coordinates
  54. // F #F by 3 list of mesh faces
  55. // E #E by 2 list of mesh edges (pairs of vertex indices)
  56. // FN #F by 3 list of face normals
  57. // E2F #E by 2 list of the edge-to-face relation (e.g. computed
  58. // via igl::edge_topology)
  59. // match_with_curl boolean flag, determines whether curl or smoothness matchings will
  60. // be computed
  61. // is_symmetric boolean flag, determines whether the input vector set field is symmetric(
  62. // =consists of pairwise collinear vectors in each set, in which case only one
  63. // of the vectors in the pair is stored) or not, i.e. the set contains all the vectors
  64. // Outputs:
  65. // match_ab #E by N matrix, describing for each edge the matching a->b, where a
  66. // and b are the faces adjacent to the edge (i.e. vector #i of
  67. // the vector set in a is matched to vector #mab[i] in b)
  68. // match_ba #E by N matrix, describing for each edge the matching b->a, where a
  69. // and b are the faces adjacent to the edge (i.e. vector #mba[i] of
  70. // the vector set in a is matched to vector #i in b)
  71. // curl the per-edge curl of the matchings (zero for boundary edges)
  72. // Returns:
  73. // meanCurl the average of the per-edge curl values (only non-boundary edges are counted)
  74. //
  75. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedM, typename DerivedC>
  76. IGL_INLINE typename DerivedC::Scalar polyvector_field_matchings(
  77. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  78. const Eigen::PlainObjectBase<DerivedV>&V,
  79. const Eigen::PlainObjectBase<DerivedF>&F,
  80. const Eigen::PlainObjectBase<DerivedE>&E,
  81. const Eigen::PlainObjectBase<DerivedV>& FN,
  82. const Eigen::MatrixXi &E2F,
  83. bool match_with_curl,
  84. bool is_symmetric,
  85. Eigen::PlainObjectBase<DerivedM>& match_ab,
  86. Eigen::PlainObjectBase<DerivedM>& match_ba,
  87. Eigen::PlainObjectBase<DerivedC>& curl);
  88. //Wrapper of the above with only vertices and faces as mesh input
  89. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedM, typename DerivedC>
  90. IGL_INLINE typename DerivedC::Scalar polyvector_field_matchings(
  91. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  92. const Eigen::PlainObjectBase<DerivedV>&V,
  93. const Eigen::PlainObjectBase<DerivedF>&F,
  94. bool match_with_curl,
  95. bool is_symmetric,
  96. Eigen::PlainObjectBase<DerivedM>& match_ab,
  97. Eigen::PlainObjectBase<DerivedM>& match_ba,
  98. Eigen::PlainObjectBase<DerivedC>& curl);
  99. //Wrappers with no curl output
  100. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedM>
  101. IGL_INLINE void polyvector_field_matchings(
  102. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  103. const Eigen::PlainObjectBase<DerivedV>&V,
  104. const Eigen::PlainObjectBase<DerivedF>&F,
  105. bool match_with_curl,
  106. bool is_symmetric,
  107. Eigen::PlainObjectBase<DerivedM>& match_ab,
  108. Eigen::PlainObjectBase<DerivedM>& match_ba);
  109. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedM>
  110. IGL_INLINE void polyvector_field_matchings(
  111. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  112. const Eigen::PlainObjectBase<DerivedV>&V,
  113. const Eigen::PlainObjectBase<DerivedF>&F,
  114. const Eigen::PlainObjectBase<DerivedE>&E,
  115. const Eigen::PlainObjectBase<DerivedV>& FN,
  116. const Eigen::MatrixXi &E2F,
  117. bool match_with_curl,
  118. bool is_symmetric,
  119. Eigen::PlainObjectBase<DerivedM>& match_ab,
  120. Eigen::PlainObjectBase<DerivedM>& match_ba);
  121. };
  122. #ifndef IGL_STATIC_LIBRARY
  123. #include "polyvector_field_matchings.cpp"
  124. #endif
  125. #endif /* defined(IGL_POLYVECTOR_FIELD_MATCHINGS) */