MultiBodyNameMap.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "MultiBodyNameMap.hpp"
  2. namespace btInverseDynamics
  3. {
  4. MultiBodyNameMap::MultiBodyNameMap() {}
  5. int MultiBodyNameMap::addBody(const int index, const std::string& name)
  6. {
  7. if (m_index_to_body_name.count(index) > 0)
  8. {
  9. bt_id_error_message("trying to add index %d again\n", index);
  10. return -1;
  11. }
  12. if (m_body_name_to_index.count(name) > 0)
  13. {
  14. bt_id_error_message("trying to add name %s again\n", name.c_str());
  15. return -1;
  16. }
  17. m_index_to_body_name[index] = name;
  18. m_body_name_to_index[name] = index;
  19. return 0;
  20. }
  21. int MultiBodyNameMap::addJoint(const int index, const std::string& name)
  22. {
  23. if (m_index_to_joint_name.count(index) > 0)
  24. {
  25. bt_id_error_message("trying to add index %d again\n", index);
  26. return -1;
  27. }
  28. if (m_joint_name_to_index.count(name) > 0)
  29. {
  30. bt_id_error_message("trying to add name %s again\n", name.c_str());
  31. return -1;
  32. }
  33. m_index_to_joint_name[index] = name;
  34. m_joint_name_to_index[name] = index;
  35. return 0;
  36. }
  37. int MultiBodyNameMap::getBodyName(const int index, std::string* name) const
  38. {
  39. std::map<int, std::string>::const_iterator it = m_index_to_body_name.find(index);
  40. if (it == m_index_to_body_name.end())
  41. {
  42. bt_id_error_message("index %d not known\n", index);
  43. return -1;
  44. }
  45. *name = it->second;
  46. return 0;
  47. }
  48. int MultiBodyNameMap::getJointName(const int index, std::string* name) const
  49. {
  50. std::map<int, std::string>::const_iterator it = m_index_to_joint_name.find(index);
  51. if (it == m_index_to_joint_name.end())
  52. {
  53. bt_id_error_message("index %d not known\n", index);
  54. return -1;
  55. }
  56. *name = it->second;
  57. return 0;
  58. }
  59. int MultiBodyNameMap::getBodyIndex(const std::string& name, int* index) const
  60. {
  61. std::map<std::string, int>::const_iterator it = m_body_name_to_index.find(name);
  62. if (it == m_body_name_to_index.end())
  63. {
  64. bt_id_error_message("name %s not known\n", name.c_str());
  65. return -1;
  66. }
  67. *index = it->second;
  68. return 0;
  69. }
  70. int MultiBodyNameMap::getJointIndex(const std::string& name, int* index) const
  71. {
  72. std::map<std::string, int>::const_iterator it = m_joint_name_to_index.find(name);
  73. if (it == m_joint_name_to_index.end())
  74. {
  75. bt_id_error_message("name %s not known\n", name.c_str());
  76. return -1;
  77. }
  78. *index = it->second;
  79. return 0;
  80. }
  81. } // namespace btInverseDynamics