biharmonic_coordinates.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <[email protected]>
  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_BIHARMONIC_COORDINATES_H
  9. #define IGL_BIHARMONIC_COORDINATES_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <vector>
  13. namespace igl
  14. {
  15. /// Compute "discrete biharmonic generalized barycentric coordinates" as
  16. /// described in "Linear Subspace Design for Real-Time Shape Deformation"
  17. /// [Wang et al. 2015]. Not to be confused with "Bounded Biharmonic Weights
  18. /// for Real-Time Deformation" [Jacobson et al. 2011] or "Biharmonic
  19. /// Coordinates" (2D complex barycentric coordinates) [Weber et al. 2012].
  20. /// These weights minimize a discrete version of the squared Laplacian energy
  21. /// subject to positional interpolation constraints at selected vertices
  22. /// (point handles) and transformation interpolation constraints at regions
  23. /// (region handles).
  24. ///
  25. /// @tparam SType should be a simple index type e.g. `int`,`size_t`
  26. /// @param[in] V #V by dim list of mesh vertex positions
  27. /// @param[in] T #T by dim+1 list of / triangle indices into V if dim=2
  28. /// \ tetrahedron indices into V if dim=3
  29. /// @param[in] S #point-handles+#region-handles list of lists of selected vertices for
  30. /// each handle. Point handles should have singleton lists and region
  31. /// handles should have lists of size at least dim+1 (and these points
  32. /// should be in general position).
  33. /// @param[out] W #V by #points-handles+(#region-handles * dim+1) matrix of weights so
  34. /// that columns correspond to each handles generalized barycentric
  35. /// coordinates (for point-handles) or animation space weights (for region
  36. /// handles).
  37. /// @return true only on success
  38. ///
  39. /// #### Example:
  40. ///
  41. /// \code{cpp}
  42. /// Eigen::MatrixXd W;
  43. /// igl::biharmonic_coordinates(V,F,S,W);
  44. /// const size_t dim = T.cols()-1;
  45. /// Eigen::MatrixXd H(W.cols(),dim);
  46. /// {
  47. /// int c = 0;
  48. /// for(int h = 0;h<S.size();h++)
  49. /// {
  50. /// if(S[h].size()==1)
  51. /// {
  52. /// H.row(c++) = V.block(S[h][0],0,1,dim);
  53. /// }else
  54. /// {
  55. /// H.block(c,0,dim+1,dim).setIdentity();
  56. /// c+=dim+1;
  57. /// }
  58. /// }
  59. /// }
  60. /// assert( (V-(W*H)).array().maxCoeff() < 1e-7 );
  61. /// \endcode
  62. template <
  63. typename DerivedV,
  64. typename DerivedT,
  65. typename SType,
  66. typename DerivedW>
  67. IGL_INLINE bool biharmonic_coordinates(
  68. const Eigen::MatrixBase<DerivedV> & V,
  69. const Eigen::MatrixBase<DerivedT> & T,
  70. const std::vector<std::vector<SType> > & S,
  71. Eigen::PlainObjectBase<DerivedW> & W);
  72. /// \overload
  73. /// @param[in] k power of Laplacian (experimental)
  74. template <
  75. typename DerivedV,
  76. typename DerivedT,
  77. typename SType,
  78. typename DerivedW>
  79. IGL_INLINE bool biharmonic_coordinates(
  80. const Eigen::MatrixBase<DerivedV> & V,
  81. const Eigen::MatrixBase<DerivedT> & T,
  82. const std::vector<std::vector<SType> > & S,
  83. const int k,
  84. Eigen::PlainObjectBase<DerivedW> & W);
  85. };
  86. # ifndef IGL_STATIC_LIBRARY
  87. # include "biharmonic_coordinates.cpp"
  88. # endif
  89. #endif