30 #ifndef FILTERS_FILTER_BASE_H_ 31 #define FILTERS_FILTER_BASE_H_ 38 #include "boost/scoped_ptr.hpp" 39 #include <boost/algorithm/string.hpp> 68 if (!node_handle.getParam(param_name, config))
70 ROS_ERROR(
"Could not find parameter %s on the server, are you sure that it was pushed up correctly?", param_name.c_str());
100 virtual bool update(
const T& data_in, T& data_out)=0;
121 bool getParam(
const std::string& name, std::string& value)
const 123 string_map_t::const_iterator it =
params_.find(name);
134 auto tmp = it->second;
135 value = std::string(tmp);
143 bool getParam(
const std::string& name,
bool& value)
const 145 string_map_t::const_iterator it =
params_.find(name);
156 auto tmp = it->second;
165 bool getParam(
const std::string&name,
double& value)
const 167 string_map_t::const_iterator it =
params_.find(name);
178 auto tmp = it->second;
187 bool getParam(
const std::string&name,
int& value)
const 189 string_map_t::const_iterator it =
params_.find(name);
200 auto tmp = it->second;
209 bool getParam(
const std::string&name,
unsigned int& value)
const 214 if (signed_value < 0)
216 value = signed_value;
224 bool getParam(
const std::string&name, std::vector<double>& value)
const 226 string_map_t::const_iterator it =
params_.find(name);
241 for (
int i = 0; i < double_array.
size(); ++i){
248 value.push_back(double_value);
258 bool getParam(
const std::string&name, std::vector<std::string>& value)
const 260 string_map_t::const_iterator it =
params_.find(name);
275 for (
unsigned int i = 0; i < string_array.
size(); ++i){
281 value.push_back(string_array[i]);
293 string_map_t::const_iterator it =
params_.find(name);
299 auto tmp = it->second;
322 ROS_ERROR(
"Filter didn't have name defined, other strings are not allowed");
326 std::string name = config[
"name"];
330 ROS_ERROR(
"Filter %s didn't have type defined, other strings are not allowed", name.c_str());
334 std::string type = config[
"type"];
338 ROS_DEBUG(
"Configuring Filter of Type: %s with name %s", type.c_str(), name.c_str());
347 ROS_ERROR(
"A filter configuration must be a map with fields name, type, and params");
371 ROS_DEBUG(
"Loading param %s\n", it->first.c_str());
372 params_[it->first] = it->second;
382 template <
typename T>
396 if (!node_handle.getParam(param_name, config))
398 ROS_ERROR(
"Could not find parameter %s on the server, are you sure that it was pushed up correctly?", param_name.c_str());
401 return configure(number_of_channels, config);
412 ROS_DEBUG(
"FilterBase being configured with XmlRpc xml: %s type: %d", config.
toXml().c_str(), config.
getType());
418 number_of_channels_ = number_of_channels;
419 ROS_DEBUG(
"MultiChannelFilterBase configured with %d channels", number_of_channels_);
432 ROS_ERROR(
"MultiChannelFilterBase configure should be called with a number of channels argument, assuming 1");
444 virtual bool update(
const std::vector<T>& data_in, std::vector<T>& data_out)=0;
446 virtual bool update(
const T& data_in, T& data_out)
448 ROS_ERROR(
"THIS IS A MULTI FILTER DON'T CALL SINGLE FORM OF UPDATE");
465 #endif //#ifndef FILTERS_FILTER_BASE_H_ bool configure(const std::string ¶m_name, ros::NodeHandle node_handle=ros::NodeHandle())
Configure the filter from the parameter server.
bool getParam(const std::string &name, std::vector< double > &value) const
Get a filter parameter as a std::vector<double>
ValueStruct::iterator iterator
bool getParam(const std::string &name, std::vector< std::string > &value) const
Get a filter parameter as a std::vector<string>
A Base filter class to provide a standard interface for all filters.
std::string filter_name_
The name of the filter.
bool configure(unsigned int number_of_channels, const std::string ¶m_name, ros::NodeHandle node_handle=ros::NodeHandle())
Configure the filter from the parameter server.
std::map< std::string, XmlRpc::XmlRpcValue > string_map_t
const std::string & getName() const
Get the name of the filter as a string.
FilterBase()
Default constructor used by Filter Factories.
bool configured_
Whether the filter has been configured.
bool getParam(const std::string &name, bool &value) const
Get a filter parameter as a boolean.
virtual bool update(const T &data_in, T &data_out)=0
Update the filter and return the data seperately This is an inefficient way to do this and can be ove...
bool configure(XmlRpc::XmlRpcValue &config)
The public method to configure a filter from XML.
Type const & getType() const
std::string getType()
Get the type of the filter as a string.
bool configure(unsigned int number_of_channels, XmlRpc::XmlRpcValue &config)
The public method to configure a filter from XML.
bool loadConfiguration(XmlRpc::XmlRpcValue &config)
string_map_t params_
Storage of the parsed xml parameters.
unsigned int number_of_channels_
How many parallel inputs for which the filter is to be configured.
bool getParam(const std::string &name, std::string &value) const
Get a filter parameter as a string.
virtual bool update(const T &data_in, T &data_out)
Update the filter and return the data seperately This is an inefficient way to do this and can be ove...
virtual bool configure()=0
Pure virtual function for the sub class to configure the filter This function must be implemented in ...
virtual ~FilterBase()
Virtual Destructor.
bool getParam(const std::string &name, int &value) const
Get a filter parameter as a int.
std::string toXml() const
std::string filter_type_
The type of the filter (Used by FilterChain for Factory construction)
bool getParam(const std::string &name, double &value) const
Get a filter parameter as a double.
bool getParam(const std::string &name, XmlRpc::XmlRpcValue &value) const
Get a filter parameter as a XmlRpcValue.
bool setNameAndType(XmlRpc::XmlRpcValue &config)
Set the name and type of the filter from the parameter server.
bool configure(XmlRpc::XmlRpcValue &config)
A method to hide the base class method and warn if improperly called.
bool getParam(const std::string &name, unsigned int &value) const
Get a filter parameter as an unsigned int.
bool hasMember(const std::string &name) const