biharmonic_coordinates.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@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_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. // Templates:
  26. // HType should be a simple index type e.g. `int`,`size_t`
  27. // Inputs:
  28. // V #V by dim list of mesh vertex positions
  29. // T #T by dim+1 list of / triangle indices into V if dim=2
  30. // \ tetrahedron indices into V if dim=3
  31. // S #point-handles+#region-handles list of lists of selected vertices for
  32. // each handle. Point handles should have singleton lists and region
  33. // handles should have lists of size at least dim+1 (and these points
  34. // should be in general position).
  35. // Outputs:
  36. // W #V by #points-handles+(#region-handles * dim+1) matrix of weights so
  37. // that columns correspond to each handles generalized barycentric
  38. // coordinates (for point-handles) or animation space weights (for region
  39. // handles).
  40. // returns true only on success
  41. //
  42. // Example:
  43. //
  44. // MatrixXd W;
  45. // igl::biharmonic_coordinates(V,F,S,W);
  46. // const size_t dim = T.cols()-1;
  47. // MatrixXd H(W.cols(),dim);
  48. // {
  49. // int c = 0;
  50. // for(int h = 0;h<S.size();h++)
  51. // {
  52. // if(S[h].size()==1)
  53. // {
  54. // H.row(c++) = V.block(S[h][0],0,1,dim);
  55. // }else
  56. // {
  57. // H.block(c,0,dim+1,dim).setIdentity();
  58. // c+=dim+1;
  59. // }
  60. // }
  61. // }
  62. // assert( (V-(W*H)).array().maxCoeff() < 1e-7 );
  63. template <
  64. typename DerivedV,
  65. typename DerivedT,
  66. typename SType,
  67. typename DerivedW>
  68. IGL_INLINE bool biharmonic_coordinates(
  69. const Eigen::PlainObjectBase<DerivedV> & V,
  70. const Eigen::PlainObjectBase<DerivedT> & T,
  71. const std::vector<std::vector<SType> > & S,
  72. Eigen::PlainObjectBase<DerivedW> & W);
  73. // k 2-->biharmonic, 3-->triharmonic
  74. template <
  75. typename DerivedV,
  76. typename DerivedT,
  77. typename SType,
  78. typename DerivedW>
  79. IGL_INLINE bool biharmonic_coordinates(
  80. const Eigen::PlainObjectBase<DerivedV> & V,
  81. const Eigen::PlainObjectBase<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