1 #include "MultiBodyTreeInitCache.hpp"
3 namespace btInverseDynamics
5 MultiBodyTree::InitCache::InitCache()
13 int MultiBodyTree::InitCache::addBody(const int body_index, const int parent_index,
14 const JointType joint_type,
15 const vec3& parent_r_parent_body_ref,
16 const mat33& body_T_parent_ref,
17 const vec3& body_axis_of_motion, const idScalar mass,
18 const vec3& body_r_body_com, const mat33& body_I_body,
19 const int user_int, void* user_ptr)
28 // does not add a degree of freedom
38 bt_id_error_message("unknown joint type %d\n", joint_type);
42 if (-1 == parent_index)
44 if (m_root_index >= 0)
46 bt_id_error_message("trying to add body %d as root, but already added %d as root body\n",
47 body_index, m_root_index);
50 m_root_index = body_index;
54 joint.m_child = body_index;
55 joint.m_parent = parent_index;
56 joint.m_type = joint_type;
57 joint.m_parent_pos_parent_child_ref = parent_r_parent_body_ref;
58 joint.m_child_T_parent_ref = body_T_parent_ref;
59 joint.m_child_axis_of_motion = body_axis_of_motion;
63 body.m_body_pos_body_com = body_r_body_com;
64 body.m_body_I_body = body_I_body;
66 m_inertias.push_back(body);
67 m_joints.push_back(joint);
68 m_user_int.push_back(user_int);
69 m_user_ptr.push_back(user_ptr);
72 int MultiBodyTree::InitCache::getInertiaData(const int index, InertiaData* inertia) const
74 if (index < 0 || index > static_cast<int>(m_inertias.size()))
76 bt_id_error_message("index out of range\n");
80 *inertia = m_inertias[index];
84 int MultiBodyTree::InitCache::getUserInt(const int index, int* user_int) const
86 if (index < 0 || index > static_cast<int>(m_user_int.size()))
88 bt_id_error_message("index out of range\n");
91 *user_int = m_user_int[index];
95 int MultiBodyTree::InitCache::getUserPtr(const int index, void** user_ptr) const
97 if (index < 0 || index > static_cast<int>(m_user_ptr.size()))
99 bt_id_error_message("index out of range\n");
102 *user_ptr = m_user_ptr[index];
106 int MultiBodyTree::InitCache::getJointData(const int index, JointData* joint) const
108 if (index < 0 || index > static_cast<int>(m_joints.size()))
110 bt_id_error_message("index out of range\n");
113 *joint = m_joints[index];
117 int MultiBodyTree::InitCache::buildIndexSets()
119 // NOTE: This function assumes that proper indices were provided
120 // User2InternalIndex from utils can be used to facilitate this.
122 m_parent_index.resize(numBodies());
123 for (idArrayIdx j = 0; j < m_joints.size(); j++)
125 const JointData& joint = m_joints[j];
126 m_parent_index[joint.m_child] = joint.m_parent;
131 } // namespace btInverseDynamics