lbs_matrix.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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_LBS_MATRIX_H
  9. #define IGL_LBS_MATRIX_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. /// Linear blend skinning can be expressed by V' = M * T where V' is
  16. /// a #V by dim matrix of deformed vertex positions (one vertex per row), M is a
  17. /// #V by (dim+1)*#T (composed of weights and rest positions) and T is a
  18. /// #T*(dim+1) by dim matrix of #T stacked transposed transformation matrices.
  19. /// See equations (1) and (2) in "Fast Automatic Skinning Transformations"
  20. /// [Jacobson et al 2012]
  21. ///
  22. /// @param[in] V #V by dim list of rest positions
  23. /// @param[in] W #V+ by #T list of weights
  24. /// @param[out] M #V by #T*(dim+1)
  25. ///
  26. /// In MATLAB:
  27. ///
  28. /// kron(ones(1,size(W,2)),[V ones(size(V,1),1)]).*kron(W,ones(1,size(V,2)+1))
  29. IGL_INLINE void lbs_matrix(
  30. const Eigen::MatrixXd & V,
  31. const Eigen::MatrixXd & W,
  32. Eigen::MatrixXd & M);
  33. /// Construct a matrix that when multiplied against a column of
  34. /// affine transformation entries computes new coordinates of the vertices
  35. ///
  36. /// \note I'm not sure it makes since that the result is stored as a sparse matrix.
  37. /// The number of non-zeros per row *is* dependent on the number of mesh
  38. /// vertices and handles.
  39. ///
  40. /// @param[in] V #V by dim list of vertex rest positions
  41. /// @param[in] W #V by #handles list of correspondence weights
  42. /// @param[out] M #V * dim by #handles * dim * (dim+1) matrix such that
  43. /// new_V(:) = LBS(V,W,A) = reshape(M * A,size(V)), where A is a column
  44. /// vectors formed by the entries in each handle's dim by dim+1
  45. /// transformation matrix. Specifcally, A =
  46. /// reshape(permute(Astack,[3 1 2]),n*dim*(dim+1),1)
  47. /// or A = [Lxx;Lyx;Lxy;Lyy;tx;ty], and likewise for other dim
  48. /// if Astack(:,:,i) is the dim by (dim+1) transformation at handle i
  49. ///
  50. /// \fileinfo
  51. IGL_INLINE void lbs_matrix_column(
  52. const Eigen::MatrixXd & V,
  53. const Eigen::MatrixXd & W,
  54. Eigen::SparseMatrix<double>& M);
  55. /// \overload
  56. IGL_INLINE void lbs_matrix_column(
  57. const Eigen::MatrixXd & V,
  58. const Eigen::MatrixXd & W,
  59. Eigen::MatrixXd & M);
  60. /// \overload
  61. /// \brief W as a full matrix of weights
  62. /// (each vertex has #handles weights), a constant number of weights are given
  63. /// for each vertex.
  64. ///
  65. /// @param[in] W #V by k list of k correspondence weights per vertex
  66. /// @param[in] WI #V by k list of k correspondence weight indices per vertex. Such that
  67. /// W(j,WI(i)) gives the ith most significant correspondence weight on vertex j
  68. IGL_INLINE void lbs_matrix_column(
  69. const Eigen::MatrixXd & V,
  70. const Eigen::MatrixXd & W,
  71. const Eigen::MatrixXi & WI,
  72. Eigen::SparseMatrix<double>& M);
  73. /// \overload
  74. IGL_INLINE void lbs_matrix_column(
  75. const Eigen::MatrixXd & V,
  76. const Eigen::MatrixXd & W,
  77. const Eigen::MatrixXi & WI,
  78. Eigen::MatrixXd & M);
  79. }
  80. #ifndef IGL_STATIC_LIBRARY
  81. #include "lbs_matrix.cpp"
  82. #endif
  83. #endif