polyvector_field_matchings.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. // Outputs:
  26. // mab 1 by N row vector, describing the matching a->b (i.e. vector #i of the
  27. // vector set in a is matched to vector #mab[i] in b)
  28. // mba 1 by N row vector, describing the matching b->a (i.e. vector #mba[i]
  29. // of the vector set in a is matched to vector #i in b)
  30. //
  31. template <typename DerivedS, typename DerivedV, typename DerivedM>
  32. IGL_INLINE void polyvector_field_matching(
  33. const Eigen::PlainObjectBase<DerivedS>& _ua,
  34. const Eigen::PlainObjectBase<DerivedS>& _ub,
  35. const Eigen::PlainObjectBase<DerivedV>& na,
  36. const Eigen::PlainObjectBase<DerivedV>& nb,
  37. const Eigen::PlainObjectBase<DerivedV>& e,
  38. bool match_with_curl,
  39. Eigen::PlainObjectBase<DerivedM>& mab,
  40. Eigen::PlainObjectBase<DerivedM>& mba);
  41. // Given a mesh and a vector set field consisting of unordered N-vector sets defined
  42. // on the faces of the mesh, the function computes, for each (non-boundary) edge
  43. // the best order-preserving matching between the vector sets of the faces across
  44. // the edge, where "best" means to "with minimum curl", or "smoothest"
  45. // Inputs:
  46. // sol3D #F by 3n list of the 3D coordinates of the per-face vectors
  47. // (stacked horizontally for each triangle)
  48. // V #V by 3 list of mesh vertex coordinates
  49. // F #F by 3 list of mesh faces
  50. // E #E by 2 list of mesh edges (pairs of vertex indices)
  51. // FN #F by 3 list of face normals
  52. // E2F #E by 2 list of the edge-to-face relation (e.g. computed
  53. // via igl::edge_topology)
  54. // match_with_curl boolean flag, determines whether curl or smoothness matchings will
  55. // be computed
  56. // Outputs:
  57. // match_ab #E by N matrix, describing for each edge the matching a->b, where a
  58. // and b are the faces adjacent to the edge (i.e. vector #i of
  59. // the vector set in a is matched to vector #mab[i] in b)
  60. // match_ba #E by N matrix, describing for each edge the matching b->a, where a
  61. // and b are the faces adjacent to the edge (i.e. vector #mba[i] of
  62. // the vector set in a is matched to vector #i in b)
  63. // curl the per-edge curl of the matchings (zero for boundary edges)
  64. // Returns:
  65. // meanCurl the average of the per-edge curl values (only non-boundary edges are counted)
  66. //
  67. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedM, typename DerivedC>
  68. IGL_INLINE typename DerivedC::Scalar polyvector_field_matchings(
  69. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  70. const Eigen::PlainObjectBase<DerivedV>&V,
  71. const Eigen::PlainObjectBase<DerivedF>&F,
  72. const Eigen::PlainObjectBase<DerivedE>&E,
  73. const Eigen::PlainObjectBase<DerivedV>& FN,
  74. const Eigen::MatrixXi &E2F,
  75. bool match_with_curl,
  76. Eigen::PlainObjectBase<DerivedM>& match_ab,
  77. Eigen::PlainObjectBase<DerivedM>& match_ba,
  78. Eigen::PlainObjectBase<DerivedC>& curl);
  79. //Wrapper of the above with only vertices and faces as mesh input
  80. template <typename DerivedS, typename DerivedV, typename DerivedF, typename DerivedM, typename DerivedC>
  81. IGL_INLINE typename DerivedC::Scalar polyvector_field_matchings(
  82. const Eigen::PlainObjectBase<DerivedS>& sol3D,
  83. const Eigen::PlainObjectBase<DerivedV>&V,
  84. const Eigen::PlainObjectBase<DerivedF>&F,
  85. bool match_with_curl,
  86. Eigen::PlainObjectBase<DerivedM>& match_ab,
  87. Eigen::PlainObjectBase<DerivedM>& match_ba,
  88. Eigen::PlainObjectBase<DerivedC>& curl);
  89. };
  90. #ifndef IGL_STATIC_LIBRARY
  91. #include "polyvector_field_matchings.cpp"
  92. #endif
  93. #endif /* defined(IGL_POLYVECTOR_FIELD_MATCHINGS) */