File: MultiBodyNameMap.cpp

package info (click to toggle)
bullet 3.24%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 15,164 kB
  • sloc: cpp: 246,331; lisp: 12,017; ansic: 11,175; python: 630; makefile: 136; sh: 75
file content (92 lines) | stat: -rw-r--r-- 2,242 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "MultiBodyNameMap.hpp"

namespace btInverseDynamics
{
MultiBodyNameMap::MultiBodyNameMap() {}

int MultiBodyNameMap::addBody(const int index, const std::string& name)
{
	if (m_index_to_body_name.count(index) > 0)
	{
		bt_id_error_message("trying to add index %d again\n", index);
		return -1;
	}
	if (m_body_name_to_index.count(name) > 0)
	{
		bt_id_error_message("trying to add name %s again\n", name.c_str());
		return -1;
	}

	m_index_to_body_name[index] = name;
	m_body_name_to_index[name] = index;

	return 0;
}

int MultiBodyNameMap::addJoint(const int index, const std::string& name)
{
	if (m_index_to_joint_name.count(index) > 0)
	{
		bt_id_error_message("trying to add index %d again\n", index);
		return -1;
	}
	if (m_joint_name_to_index.count(name) > 0)
	{
		bt_id_error_message("trying to add name %s again\n", name.c_str());
		return -1;
	}

	m_index_to_joint_name[index] = name;
	m_joint_name_to_index[name] = index;

	return 0;
}

int MultiBodyNameMap::getBodyName(const int index, std::string* name) const
{
	std::map<int, std::string>::const_iterator it = m_index_to_body_name.find(index);
	if (it == m_index_to_body_name.end())
	{
		bt_id_error_message("index %d not known\n", index);
		return -1;
	}
	*name = it->second;
	return 0;
}

int MultiBodyNameMap::getJointName(const int index, std::string* name) const
{
	std::map<int, std::string>::const_iterator it = m_index_to_joint_name.find(index);
	if (it == m_index_to_joint_name.end())
	{
		bt_id_error_message("index %d not known\n", index);
		return -1;
	}
	*name = it->second;
	return 0;
}

int MultiBodyNameMap::getBodyIndex(const std::string& name, int* index) const
{
	std::map<std::string, int>::const_iterator it = m_body_name_to_index.find(name);
	if (it == m_body_name_to_index.end())
	{
		bt_id_error_message("name %s not known\n", name.c_str());
		return -1;
	}
	*index = it->second;
	return 0;
}

int MultiBodyNameMap::getJointIndex(const std::string& name, int* index) const
{
	std::map<std::string, int>::const_iterator it = m_joint_name_to_index.find(name);
	if (it == m_joint_name_to_index.end())
	{
		bt_id_error_message("name %s not known\n", name.c_str());
		return -1;
	}
	*index = it->second;
	return 0;
}
}  // namespace btInverseDynamics