MultiBodyNameMap.cpp 2.3 KB

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