deform_skeleton.cpp 1.5 KB

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