lbs_matrix.h 3.7 KB

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