// // Copyright (c) 2015-2018 CNRS // Copyright (c) 2015 Wandercraft, 86 rue de Paris 91400 Orsay, France. // #ifndef __pinocchio_model_hxx__ #define __pinocchio_model_hxx__ #include "pinocchio/spatial/fwd.hpp" #include "pinocchio/utils/string-generator.hpp" #include "pinocchio/multibody/liegroup/liegroup-algo.hpp" #include #include /// @cond DEV namespace pinocchio { namespace details { struct FilterFrame { const std::string & name; const FrameType & typeMask; FilterFrame(const std::string& name, const FrameType & typeMask) : name(name), typeMask(typeMask) {} template bool operator()(const FrameTpl & frame) const { return (typeMask & frame.type) && (name == frame.name); } }; } template class JointCollectionTpl> const typename ModelTpl:: Vector3 ModelTpl::gravity981((Scalar)0,(Scalar)0,(Scalar)-9.81); template class JointCollectionTpl> inline std::ostream& operator<<(std::ostream & os, const ModelTpl & model) { typedef typename ModelTpl::Index Index; os << "Nb joints = " << model.njoints << " (nq="<< model.nq<<",nv="< class JointCollectionTpl> inline void ModelTpl:: appendBodyToJoint(const ModelTpl::JointIndex joint_index, const Inertia & Y, const SE3 & body_placement) { const Inertia & iYf = Y.se3Action(body_placement); inertias[joint_index] += iYf; nbodies++; } template class JointCollectionTpl> inline int ModelTpl:: addBodyFrame(const std::string & body_name, const JointIndex & parentJoint, const SE3 & body_placement, int previousFrame) { if(previousFrame < 0) { // FIXED_JOINT is required because the parent can be the universe and its // type is FIXED_JOINT previousFrame = (int)getFrameId(names[parentJoint], (FrameType)(JOINT | FIXED_JOINT)); } assert((size_t)previousFrame < frames.size() && "Frame index out of bound"); return addFrame(Frame(body_name, parentJoint, (FrameIndex)previousFrame, body_placement, BODY)); } template class JointCollectionTpl> inline typename ModelTpl::JointIndex ModelTpl:: getBodyId(const std::string & name) const { return getFrameId(name, BODY); } template class JointCollectionTpl> inline bool ModelTpl:: existBodyName(const std::string & name) const { return existFrame(name, BODY); } template class JointCollectionTpl> inline typename ModelTpl::JointIndex ModelTpl:: getJointId(const std::string & name) const { typedef std::vector::iterator::difference_type it_diff_t; it_diff_t res = std::find(names.begin(),names.end(),name) - names.begin(); assert((res class JointCollectionTpl> inline bool ModelTpl:: existJointName(const std::string & name) const { return (names.end() != std::find(names.begin(),names.end(),name)); } template class JointCollectionTpl> inline const std::string & ModelTpl:: getJointName(const JointIndex index) const { assert( index < (ModelTpl::JointIndex)joints.size() ); return names[index]; } template class JointCollectionTpl> inline typename ModelTpl::FrameIndex ModelTpl:: getFrameId(const std::string & name, const FrameType & type) const { typename container::aligned_vector::const_iterator it = std::find_if(frames.begin() ,frames.end() ,details::FilterFrame(name, type)); assert(it != frames.end() && "Frame not found"); assert((std::find_if( boost::next(it), frames.end(), details::FilterFrame(name, type)) == frames.end()) && "Several frames match the filter"); return FrameIndex(it - frames.begin()); } template class JointCollectionTpl> inline bool ModelTpl:: existFrame(const std::string & name, const FrameType & type) const { return std::find_if(frames.begin(), frames.end(), details::FilterFrame(name, type)) != frames.end(); } template class JointCollectionTpl> inline int ModelTpl:: addFrame(const Frame & frame) { if(!existFrame(frame.name, frame.type)) { frames.push_back(frame); nframes++; return nframes - 1; } else { return -1; } } template class JointCollectionTpl> inline void ModelTpl:: addJointIndexToParentSubtrees(const JointIndex joint_id) { for(JointIndex parent = parents[joint_id]; parent>0; parent = parents[parent]) subtrees[parent].push_back(joint_id); } } // namespace pinocchio /// @endcond #endif // ifndef __pinocchio_model_hxx__