deform_skeleton.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #include "deform_skeleton.h"
  9. void igl::deform_skeleton(
  10. const Eigen::MatrixXd & C,
  11. const Eigen::MatrixXi & BE,
  12. const std::vector<
  13. Eigen::Affine3d,Eigen::aligned_allocator<Eigen::Affine3d> > & vA,
  14. Eigen::MatrixXd & CT,
  15. Eigen::MatrixXi & BET)
  16. {
  17. assert(BE.rows() == (int)vA.size());
  18. CT.resize(2*BE.rows(),C.cols());
  19. BET.resize(BE.rows(),2);
  20. for(int e = 0;e<BE.rows();e++)
  21. {
  22. BET(e,0) = 2*e;
  23. BET(e,1) = 2*e+1;
  24. Eigen::Affine3d a = vA[e];
  25. Eigen::Vector3d c0 = C.row(BE(e,0));
  26. Eigen::Vector3d c1 = C.row(BE(e,1));
  27. CT.row(2*e) = a * c0;
  28. CT.row(2*e+1) = a * c1;
  29. }
  30. }
  31. IGL_INLINE void igl::deform_skeleton(
  32. const Eigen::MatrixXd & C,
  33. const Eigen::MatrixXi & BE,
  34. const Eigen::MatrixXd & T,
  35. Eigen::MatrixXd & CT,
  36. Eigen::MatrixXi & BET)
  37. {
  38. //assert(BE.rows() == (int)vA.size());
  39. CT.resize(2*BE.rows(),C.cols());
  40. BET.resize(BE.rows(),2);
  41. for(int e = 0;e<BE.rows();e++)
  42. {
  43. BET(e,0) = 2*e;
  44. BET(e,1) = 2*e+1;
  45. Eigen::Matrix4d t;
  46. t << T.block(e*4,0,4,3).transpose(), 0,0,0,0;
  47. Eigen::Affine3d a;
  48. a.matrix() = t;
  49. Eigen::Vector3d c0 = C.row(BE(e,0));
  50. Eigen::Vector3d c1 = C.row(BE(e,1));
  51. CT.row(2*e) = a * c0;
  52. CT.row(2*e+1) = a * c1;
  53. }
  54. }