// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "forward_kinematics.h" #include #include IGL_INLINE void igl::forward_kinematics( const Eigen::MatrixXd & C, const Eigen::MatrixXi & BE, const Eigen::VectorXi & P, const std::vector< Eigen::Quaterniond,Eigen::aligned_allocator > & dQ, const std::vector & dT, std::vector< Eigen::Quaterniond,Eigen::aligned_allocator > & vQ, std::vector & vT) { using namespace std; using namespace Eigen; const int m = BE.rows(); assert(m == P.rows()); assert(m == (int)dQ.size()); assert(m == (int)dT.size()); vector computed(m,false); vQ.resize(m); vT.resize(m); // Dynamic programming function fk_helper = [&] (int b) { if(!computed[b]) { if(P(b) < 0) { // base case for roots vQ[b] = dQ[b]; const Vector3d r = C.row(BE(b,0)).transpose(); vT[b] = r-dQ[b]*r + dT[b]; }else { // Otherwise first compute parent's const int p = P(b); fk_helper(p); vQ[b] = vQ[p] * dQ[b]; const Vector3d r = C.row(BE(b,0)).transpose(); vT[b] = vT[p] - vQ[b]*r + vQ[p]*(r + dT[b]); } computed[b] = true; } }; for(int b = 0;b > & dQ, std::vector< Eigen::Quaterniond,Eigen::aligned_allocator > & vQ, std::vector & vT) { std::vector dT(BE.rows(),Eigen::Vector3d(0,0,0)); return forward_kinematics(C,BE,P,dQ,dT,vQ,vT); } IGL_INLINE void igl::forward_kinematics( const Eigen::MatrixXd & C, const Eigen::MatrixXi & BE, const Eigen::VectorXi & P, const std::vector< Eigen::Quaterniond,Eigen::aligned_allocator > & dQ, const std::vector & dT, Eigen::MatrixXd & T) { using namespace Eigen; using namespace std; vector< Quaterniond,aligned_allocator > vQ; vector< Vector3d> vT; forward_kinematics(C,BE,P,dQ,dT,vQ,vT); const int dim = C.cols(); T.resize(BE.rows()*(dim+1),dim); for(int e = 0;e > & dQ, Eigen::MatrixXd & T) { std::vector dT(BE.rows(),Eigen::Vector3d(0,0,0)); return forward_kinematics(C,BE,P,dQ,dT,T); } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation #endif