|
From: <tf...@us...> - 2009-02-26 23:17:27
|
Revision: 11839
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=11839&view=rev
Author: tfoote
Date: 2009-02-26 23:17:15 +0000 (Thu, 26 Feb 2009)
Log Message:
-----------
standardizaing filter naming, with helper functions to load from xml
Modified Paths:
--------------
pkg/trunk/prcore/filters/include/filters/filter_base.h
pkg/trunk/prcore/filters/include/filters/mean.h
pkg/trunk/prcore/filters/include/filters/median.h
pkg/trunk/prcore/filters/include/filters/transfer_function.h
pkg/trunk/util/iir_filters/include/iir_filters/iir.h
pkg/trunk/util/laser_scan/include/laser_scan/median_filter.h
Modified: pkg/trunk/prcore/filters/include/filters/filter_base.h
===================================================================
--- pkg/trunk/prcore/filters/include/filters/filter_base.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/prcore/filters/include/filters/filter_base.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -80,6 +80,18 @@
virtual bool update(const std::vector<T>& data_in, std::vector<T>& data_out)=0;
std::string getType() {return typeid(T).name();};
+
+ bool setName(TiXmlElement * config)
+ {
+ const char *name = config->Attribute("name");
+ if (!name) return false;
+ filter_name_ = std::string(name);
+ return true;
+ };
+ inline const std::string& getName(){return filter_name_;};
+
+private:
+ std::string filter_name_;
};
Modified: pkg/trunk/prcore/filters/include/filters/mean.h
===================================================================
--- pkg/trunk/prcore/filters/include/filters/mean.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/prcore/filters/include/filters/mean.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -65,8 +65,6 @@
virtual bool update( const T & data_in, T& data_out);
virtual bool update( const std::vector<T> & data_in, std::vector<T>& data_out);
- std::string name_; //Name of the filter.
-
protected:
RealtimeVectorCircularBuffer<std::vector<T> >* data_storage_; ///< Storage for data between updates
uint32_t last_updated_row_; ///< The last row to have been updated by the filter
@@ -98,13 +96,11 @@
return false;
// Parse the name of the filter from the xml.
- const char *name = config->Attribute("name");
- if (!name)
+ if (!FilterBase<T>::setName(config))
{
fprintf(stderr, "Error: TransferFunctionFilter was not given a name.\n");
return false;
}
- name_ = std::string(name);
// Parse the params of the filter from the xml.
TiXmlElement *p = config->FirstChildElement("params");
Modified: pkg/trunk/prcore/filters/include/filters/median.h
===================================================================
--- pkg/trunk/prcore/filters/include/filters/median.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/prcore/filters/include/filters/median.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -106,8 +106,6 @@
virtual bool update(const T& data_in, T& data_out);
virtual bool update(const std::vector<T>& data_in, std::vector<T>& data_out);
- std::string name_; //Name of the filter.
-
protected:
std::vector<T> temp_storage_; ///< Preallocated storage for the list to sort
RealtimeVectorCircularBuffer<std::vector<T> >* data_storage_; ///< Storage for data between updates
@@ -145,13 +143,11 @@
return false;
// Parse the name of the filter from the xml.
- const char *name = config->Attribute("name");
- if (!name)
+ if (!FilterBase<T>::setName(config))
{
fprintf(stderr, "Error: MedianFilter was not given a name.\n");
return false;
}
- name_ = std::string(name);
// Parse the params of the filter from the xml.
TiXmlElement *p = config->FirstChildElement("params");
Modified: pkg/trunk/prcore/filters/include/filters/transfer_function.h
===================================================================
--- pkg/trunk/prcore/filters/include/filters/transfer_function.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/prcore/filters/include/filters/transfer_function.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -97,7 +97,6 @@
virtual bool update(const std::vector<T> & data_in, std::vector<T>& data_out) ;
- std::string name_; //Name of the filter.
protected:
@@ -143,33 +142,32 @@
}
// Parse the name of the filter from the xml.
- const char *name = config->Attribute("name");
- if (!name)
+ if (!FilterBase<T>::setName(config))
{
ROS_ERROR("TransferFunctionFilter was not given a name.");
return false;
}
- name_ = std::string(name);
- ROS_INFO("Configuring TransferFunctionFilter with name \"%s\".", name_.c_str());
+ ROS_INFO("Configuring TransferFunctionFilter with name \"%s\".", FilterBase<T>::getName().c_str());
+
// Parse the params of the filter from the xml.
TiXmlElement *p = config->FirstChildElement("params");
if (!p)
{
- ROS_ERROR("TransferFunctionFilter, \"%s\", was not given params.", name_.c_str());
+ ROS_ERROR("TransferFunctionFilter, \"%s\", was not given params.", FilterBase<T>::getName().c_str());
return false;
}
// Parse a and b into a std::vector<double>.
if (!urdf::queryVectorAttribute(p, "a", &a_))
{
- ROS_ERROR("TransferFunctionFilter, \"%s\", params has no attribute a.", name_.c_str());
+ ROS_ERROR("TransferFunctionFilter, \"%s\", params has no attribute a.", FilterBase<T>::getName().c_str());
return false;
}
if (!urdf::queryVectorAttribute(p, "b", &b_))
{
- ROS_ERROR("TransferFunctionFilter, \"%s\", params has no attribute b.", name_.c_str());
+ ROS_ERROR("TransferFunctionFilter, \"%s\", params has no attribute b.", FilterBase<T>::getName().c_str());
return false;
}
Modified: pkg/trunk/util/iir_filters/include/iir_filters/iir.h
===================================================================
--- pkg/trunk/util/iir_filters/include/iir_filters/iir.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/util/iir_filters/include/iir_filters/iir.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -102,8 +102,6 @@
virtual bool update(const std::vector<T> & data_in, std::vector<T>& data_out) ;
- std::string name_; //Name of the filter.
-
protected:
unsigned int number_of_channels_;
@@ -153,27 +151,25 @@
number_of_channels_=number_of_channels;
// Parse the name of the filter from the xml.
- const char *name = config->Attribute("name");
- if (!name)
+ if (!filters::FilterBase<T>::setName(config))
{
ROS_ERROR("IIRFilter was not given a name.");
return false;
}
- name_ = std::string(name);
- ROS_INFO("Configuring IIRFilter with name \"%s\".", name_.c_str());
+ ROS_INFO("Configuring IIRFilter with name \"%s\".", filters::FilterBase<T>::getName().c_str());
// Parse the params of the filter from the xml.
TiXmlElement *p = config->FirstChildElement("params");
if (!p)
{
- fprintf(stderr, "Error: IIRFilter, \"%s\", was not given params.", name_.c_str());
+ fprintf(stderr, "Error: IIRFilter, \"%s\", was not given params.", filters::FilterBase<T>::getName().c_str());
return false;
}
const char *t = p->Attribute("name");
if (!t)
{
- ROS_ERROR("IIRFilter, \"%s\", params has no attribute name.", name_.c_str());
+ ROS_ERROR("IIRFilter, \"%s\", params has no attribute name.", filters::FilterBase<T>::getName().c_str());
return false;
}
type_=std::string(t);
@@ -181,7 +177,7 @@
const char *s = p->Attribute("args");
if (!s)
{
- ROS_ERROR("IIRFilter, \"%s\", params has no attribute args.", name_.c_str());
+ ROS_ERROR("IIRFilter, \"%s\", params has no attribute args.", filters::FilterBase<T>::getName().c_str());
return false;
}
@@ -197,7 +193,7 @@
if (ros::service::call("filter_coeffs", req, res))
{
std::string xml_str("<filter type=\"TransferFunctionFilter\" name=\"");
- xml_str.append(name_);
+ xml_str.append(filters::FilterBase<T>::getName());
xml_str.append("\"> <params a=\"");
for(uint32_t i=0; i<res.a.size();i++)
{
@@ -222,7 +218,7 @@
}
else
{
- ROS_ERROR("IIRFilter, \"%s\", could not get filter coefficients to build filter.", name_.c_str());
+ ROS_ERROR("IIRFilter, \"%s\", could not get filter coefficients to build filter.", filters::FilterBase<T>::getName().c_str());
return false;
}
Modified: pkg/trunk/util/laser_scan/include/laser_scan/median_filter.h
===================================================================
--- pkg/trunk/util/laser_scan/include/laser_scan/median_filter.h 2009-02-26 22:54:08 UTC (rev 11838)
+++ pkg/trunk/util/laser_scan/include/laser_scan/median_filter.h 2009-02-26 23:17:15 UTC (rev 11839)
@@ -93,10 +93,17 @@
bool LaserMedianFilter<T>::configure(unsigned int number_of_channels, TiXmlElement * xml_doc)
{
ROS_ASSERT(number_of_channels == 1);
+ if (!filters::FilterBase<T>::setName(xml_doc))
+ {
+ ROS_ERROR("LaserMedianFilter configured without a name");
+ return false;
+ }
latest_xml_.reset( xml_doc->Clone()->ToElement());
TiXmlElement * child = latest_xml_.get()->FirstChild("filters")->ToElement();
if (!child)
return false;
+
+
range_filter_ = new filters::FilterChain<float>();
if (!range_filter_->configure(num_ranges_, child))
return false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|