30 #ifndef FILTERS_FILTER_CHAIN_HPP_
31 #define FILTERS_FILTER_CHAIN_HPP_
55 std::string lib_string =
"";
57 for (
unsigned int i = 0 ; i < libs.size(); i ++)
59 lib_string = lib_string + std::string(
", ") + libs[i];
61 ROS_DEBUG(
"In FilterChain ClassLoader found the following libs: %s", lib_string.c_str());
77 if(node.getParam(param_name +
"/filter_chain", config))
79 std::string resolved_name = node.resolveName(param_name).c_str();
80 ROS_WARN(
"Filter chains no longer check implicit nested 'filter_chain' parameter. This node is configured to look directly at '%s'. Please move your chain description from '%s/filter_chain' to '%s'", resolved_name.c_str(), resolved_name.c_str(), resolved_name.c_str());
82 else if(!node.getParam(param_name, config))
84 ROS_DEBUG(
"Could not load the filter chain configuration from parameter %s, are you sure it was pushed to the parameter server? Assuming that you meant to leave it empty.", param_name.c_str());
88 return this->
configure(config, node.getNamespace());
92 bool update(
const T& data_in, T& data_out)
101 else if (list_size == 1)
103 else if (list_size == 2)
106 if (result ==
false) {
return false; };
119 if (result ==
false) {
return false; };
121 if (list_size % 2 == 1)
148 ROS_ERROR(
"%s: The filter chain specification must be a list. but is of of XmlRpcType %d", filter_ns.c_str(), config.
getType());
149 ROS_ERROR(
"The xml passed in is formatted as follows:\n %s", config.
toXml().c_str());
155 for (
int i = 0; i < config.
size(); ++i)
159 ROS_ERROR(
"%s: Filters must be specified as maps, but they are XmlRpcType:%d", filter_ns.c_str(), config[i].
getType());
162 else if (!config[i].hasMember(
"type"))
164 ROS_ERROR(
"%s: Could not add a filter because no type was given", filter_ns.c_str());
167 else if (!config[i].hasMember(
"name"))
169 ROS_ERROR(
"%s: Could not add a filter because no name was given", filter_ns.c_str());
175 for (
int j = i + 1; j < config.
size(); ++j)
179 ROS_ERROR(
"%s: Filters must be specified as maps, but they are XmlRpcType:%d", filter_ns.c_str(), config[j].
getType());
183 if(!config[j].hasMember(
"name")
187 ROS_ERROR(
"%s: Filters names must be strings, but they are XmlRpcTypes:%d and %d", filter_ns.c_str(), config[i].
getType(), config[j].
getType());
191 std::string namei = config[i][
"name"];
192 std::string namej = config[j][
"name"];
195 ROS_ERROR(
"%s: A self_filter with the name %s already exists", filter_ns.c_str(), namei.c_str());
201 if (std::string(config[i][
"type"]).find(
"/") == std::string::npos)
203 ROS_ERROR(
"Bad filter type %s. Filter type must be of form <package_name>/<filter_name>", std::string(config[i][
"type"]).c_str());
209 for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
211 if (*it == std::string(config[i][
"type"]))
219 ROS_ERROR(
"Couldn't find filter of type %s", std::string(config[i][
"type"]).c_str());
230 for (
int i = 0; i < config.
size(); ++i)
238 std::shared_ptr<filters::FilterBase<T>> ptr(p);
239 result = result && ptr->configure(config[i]);
241 std::string type = config[i][
"type"];
242 std::string name = config[i][
"name"];
243 ROS_DEBUG(
"%s: Configured %s:%s filter at %p\n", filter_ns.c_str(), type.c_str(),
256 std::vector<std::shared_ptr<filters::FilterBase<T>>>
getFilters()
const
274 template <
typename T>
283 std::string lib_string =
"";
285 for (
unsigned int i = 0 ; i < libs.size(); i ++)
287 lib_string = lib_string + std::string(
", ") + libs[i];
289 ROS_DEBUG(
"In MultiChannelFilterChain ClassLoader found the following libs: %s", lib_string.c_str());
299 if(node.getParam(param_name +
"/filter_chain", config))
301 std::string resolved_name = node.resolveName(param_name).c_str();
302 ROS_WARN(
"Filter chains no longer check implicit nested 'filter_chain' parameter. This node is configured to look directly at '%s'. Please move your chain description from '%s/filter_chain' to '%s'", resolved_name.c_str(), resolved_name.c_str(), resolved_name.c_str());
304 else if(!node.getParam(param_name, config))
306 ROS_ERROR(
"Could not load the configuration for %s, are you sure it was pushed to the parameter server? Assuming that you meant to leave it blank.", param_name.c_str());
317 bool update(
const std::vector<T>& data_in, std::vector<T>& data_out)
326 else if (list_size == 1)
328 else if (list_size == 2)
331 if (result ==
false) {
return false; };
344 if (result ==
false) {
return false; };
346 if (list_size % 2 == 1)
383 ROS_ERROR(
"The filter chain specification must be a list. but is of of XmlRpcType %d", config.
getType());
384 ROS_ERROR(
"The xml passed in is formatted as follows:\n %s", config.
toXml().c_str());
390 for (
int i = 0; i < config.
size(); ++i)
394 ROS_ERROR(
"Filters must be specified as maps, but they are XmlRpcType:%d", config[i].getType());
397 else if (!config[i].hasMember(
"type"))
399 ROS_ERROR(
"Could not add a filter because no type was given");
402 else if (!config[i].hasMember(
"name"))
404 ROS_ERROR(
"Could not add a filter because no name was given");
410 for (
int j = i + 1; j < config.
size(); ++j)
414 ROS_ERROR(
"Filters must be specified as maps");
418 if(!config[j].hasMember(
"name")
422 ROS_ERROR(
"Filters names must be strings");
426 std::string namei = config[i][
"name"];
427 std::string namej = config[j][
"name"];
430 std::string name = config[i][
"name"];
431 ROS_ERROR(
"A self_filter with the name %s already exists", name.c_str());
436 if (std::string(config[i][
"type"]).find(
"/") == std::string::npos)
438 ROS_WARN(
"Deprecation Warning: No '/' detected in FilterType, Please update to 1.2 plugin syntax. ");
440 for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
442 size_t position = it->find(std::string(config[i][
"type"]));
443 if (position != std::string::npos)
445 ROS_WARN(
"Replaced %s with %s", std::string(config[i][
"type"]).c_str(), it->c_str());
446 config[i][
"type"] = *it;
453 for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
455 if (*it == std::string(config[i][
"type"]))
463 ROS_ERROR(
"Couldn't find filter of type %s", std::string(config[i][
"type"]).c_str());
478 for (
int i = 0; i < config.
size(); ++i)
486 std::shared_ptr<filters::MultiChannelFilterBase<T>> ptr(p);
487 result = result && ptr->configure(size, config[i]);
489 std::string type = config[i][
"type"];
490 std::string name = config[i][
"name"];
491 ROS_DEBUG(
"Configured %s:%s filter at %p\n", type.c_str(),
504 std::vector<std::shared_ptr<filters::MultiChannelFilterBase<T>>>
getFilters()
const
521 #endif //#ifndef FILTERS_FILTER_CHAIN_HPP_