10 for (TfRemapper::MappingsType::const_iterator it = mappings.begin(); it != mappings.end(); ++it) {
11 if (it->first.empty())
12 throw ros::InvalidParameterException(
"Key 'old' in each mapping has to be set to a nonempty string.");
16 this->mappings = mappings;
18 for (std::map<std::string, std::string>::const_iterator it = mappings.begin(); it != mappings.end(); ++it) {
19 if (!it->second.empty())
20 this->mappings[it->second] = it->first;
26 if(mappingsParam.getType() != XmlRpc::XmlRpcValue::TypeArray)
27 throw ros::InvalidParameterException(
"The 'mappings' parameter must be an array of dictionaries.");
29 for (
size_t i = 0; i < mappingsParam.size(); ++i) {
30 XmlRpc::XmlRpcValue mapping = mappingsParam[i];
31 if (mapping.getType() != XmlRpc::XmlRpcValue::TypeStruct)
32 throw ros::InvalidParameterException(
"The 'mappings' parameter must be an array of dictionaries.");
36 const std::string oldKey = (reverse ?
"new" :
"old");
37 const std::string newKey = (reverse ?
"old" :
"new");
38 for (XmlRpc::XmlRpcValue::iterator it = mapping.begin(); it != mapping.end(); ++it)
40 if (it->second.getType() != XmlRpc::XmlRpcValue::TypeString)
41 throw ros::InvalidParameterException(
"Dict values must be strings");
42 if (it->first == oldKey)
43 oldTopic = (
const std::string&)it->second;
44 else if (it->first == newKey)
45 newTopic = (std::string&)it->second;
47 throw ros::InvalidParameterException(
"Each dict in the mapping has to have only keys 'old' and 'new'.");
50 if (oldTopic.empty() && newTopic.empty())
51 throw ros::InvalidParameterException(
"Either 'old' or 'new' key in each mapping has to be set to a "
54 if (oldTopic == newTopic)
55 ROS_WARN_STREAM(
"Remapped topic '" << oldTopic <<
"' is the same as the old topic.");
57 if (!oldTopic.empty())
58 this->mappings[oldTopic] = newTopic;
63 tf2_msgs::TFMessage message = inMessage;
64 this->doRemapping(message);
69 for (std::vector<geometry_msgs::TransformStamped>::iterator it = message.transforms.begin();
70 it != message.transforms.end(); ) {
71 geometry_msgs::TransformStamped& transform = *it;
72 if (this->mappings.find(transform.header.frame_id) != this->mappings.end()) {
73 if (this->mappings.at(transform.header.frame_id).empty()) {
74 it = message.transforms.erase(it);
77 transform.header.frame_id = this->mappings.at(transform.header.frame_id);
80 if (this->mappings.find(transform.child_frame_id) != this->mappings.end()) {
81 if (this->mappings.at(transform.child_frame_id).empty()) {
82 it = message.transforms.erase(it);
85 transform.child_frame_id = this->mappings.at(transform.child_frame_id);
93 return this->mappings;
void doRemapping(tf2_msgs::TFMessage &message) const
Rewrite TF frame names according to the rules given in constructor.
TfRemapper()
Empty constructor with no remappings.
std::map< std::string, std::string > MappingsType
const MappingsType & getMappings() const
Get the mappings this remapper uses.