Skip to content

Commit

Permalink
patch for #4144 including backwards compatability. Also added check t…
Browse files Browse the repository at this point in the history
…o give nice error and quit if invalid filter name, instead of throwing exception

--HG--
branch : filters
extra : convert_revision : svn%3Aeb33c2ac-9c88-4c90-87e0-44a10359b0c3/stacks/common/trunk/filters%4030358
  • Loading branch information
tfoote committed Jun 22, 2010
1 parent 75d5903 commit f7a402c
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 32 deletions.
26 changes: 13 additions & 13 deletions default_plugins.xml
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
<class_libraries>
<library path="lib/libmedian">
<class name="MultiChannelMedianFilterDouble" type="filters::MultiChannelMedianFilter<double>"
<class name="filters/MultiChannelMedianFilterDouble" type="filters::MultiChannelMedianFilter<double>"
base_class_type="filters::MultiChannelFilterBase<double>">
<description>
This is a median filter which works on a stream of std::vector of doubles.
</description>
</class>
<class name="MedianFilterDouble" type="filters::MedianFilter<double>"
<class name="filters/MedianFilterDouble" type="filters::MedianFilter<double>"
base_class_type="filters::FilterBase<double>">
<description>
This is a median filter which works on a stream of doubles.
</description>
</class>
<class name="MultiChannelMedianFilterFloat" type="filters::MultiChannelMedianFilter<float>"
<class name="filters/MultiChannelMedianFilterFloat" type="filters::MultiChannelMedianFilter<float>"
base_class_type="filters::MultiChannelFilterBase<float>">
<description>
This is a median filter which works on a stream of std::vector of floats.
</description>
</class>
<class name="MedianFilterFloat" type="filters::MedianFilter<float>"
<class name="filters/MedianFilterFloat" type="filters::MedianFilter<float>"
base_class_type="filters::FilterBase<float>">
<description>
This is a median filter which works on a stream of floats.
</description>
</class>
</library>
<library path="lib/libmean">
<class name="MeanFilterDouble" type="filters::MeanFilter<double>"
<class name="filters/MeanFilterDouble" type="filters::MeanFilter<double>"
base_class_type="filters::FilterBase<double>">
<description>
This is a mean filter which works on a stream of doubles.
</description>
</class>
<class name="MeanFilterFloat" type="filters::MeanFilter<float>"
<class name="filters/MeanFilterFloat" type="filters::MeanFilter<float>"
base_class_type="filters::FilterBase<float>">
<description>
This is a mean filter which works on a stream of floats.
</description>
</class>
<class name="MultiChannelMeanFilterDouble" type="filters::MultiChannelMeanFilter<double>"
<class name="filters/MultiChannelMeanFilterDouble" type="filters::MultiChannelMeanFilter<double>"
base_class_type="filters::MultiChannelFilterBase<double>">
<description>
This is a mean filter which works on a stream of vectors of doubles.
</description>
</class>
<class name="MultiChannelMeanFilterFloat" type="filters::MultiChannelMeanFilter<float>"
<class name="filters/MultiChannelMeanFilterFloat" type="filters::MultiChannelMeanFilter<float>"
base_class_type="filters::MultiChannelFilterBase<float>">
<description>
This is a mean filter which works on a stream of vectors of floats.
</description>
</class>
</library>
<library path="lib/libtest_param">
<class name="ParamTest" type="filters::ParamTest<double>"
<class name="filters/ParamTest" type="filters::ParamTest<double>"
base_class_type="filters::FilterBase<double>">
<description>
This is a filter designed to test parameter readings. It's not useful.
</description>
</class>
</library>
<library path="lib/libincrement">
<class name="IncrementFilterInt" type="filters::IncrementFilter<int>"
<class name="filters/IncrementFilterInt" type="filters::IncrementFilter<int>"
base_class_type="filters::FilterBase<int>">
<description>
This is a increment filter which works on a stream of ints.
</description>
</class>
<class name="MultiChannelIncrementFilterInt" type="filters::MultiChannelIncrementFilter<int>"
<class name="filters/MultiChannelIncrementFilterInt" type="filters::MultiChannelIncrementFilter<int>"
base_class_type="filters::MultiChannelFilterBase<int>">
<description>
This is a increment filter which works on a stream of vectors of ints.
</description>
</class>
</library>
<library path="lib/libtransfer_function">
<class name="MultiChannelTransferFunctionFilterDouble" type="filters::MultiChannelTransferFunctionFilter<double>"
<class name="filters/MultiChannelTransferFunctionFilterDouble" type="filters::MultiChannelTransferFunctionFilter<double>"
base_class_type="filters::MultiChannelFilterBase<double>">
<description>
This is a transfer filter which works on a stream of doubles.
</description>
</class>
<class name="TransferFunctionFilterDouble" type="filters::SingleChannelTransferFunctionFilter<double>"
<class name="filters/TransferFunctionFilterDouble" type="filters::SingleChannelTransferFunctionFilter<double>"
base_class_type="filters::FilterBase<double>">
<description>
This is a transfer filter which works on a stream of doubles.
Expand Down
69 changes: 68 additions & 1 deletion include/filters/filter_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,43 @@ class FilterChain
return false;
}
}


//CHeck for backwards compatible declarations
if (std::string(config[i]["type"]).find("/") == std::string::npos)
{
ROS_WARN("Deprecation Warning: No '/' detected in FilterType, Please update to 1.2 plugin syntax. ");
std::vector<std::string> libs = loader_.getDeclaredClasses();
for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
{
size_t position = it->find(std::string(config[i]["type"]));
if (position != std::string::npos)
{
ROS_WARN("Replaced %s with %s", std::string(config[i]["type"]).c_str(), it->c_str());
config[i]["type"] = *it;
}
}
}
//Make sure the filter chain has a valid type
std::vector<std::string> libs = loader_.getDeclaredClasses();
bool found = false;
for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
{
if (*it == std::string(config[i]["type"]))
{
found = true;
break;
}
}
if (!found)
{
ROS_ERROR("Couldn't find filter of type %s", std::string(config[i]["type"]).c_str());
return false;
}

}
}


bool result = true;

Expand Down Expand Up @@ -397,6 +431,39 @@ class MultiChannelFilterChain
return false;
}
}
//CHeck for backwards compatible declarations
if (std::string(config[i]["type"]).find("/") == std::string::npos)
{
ROS_WARN("Deprecation Warning: No '/' detected in FilterType, Please update to 1.2 plugin syntax. ");
std::vector<std::string> libs = loader_.getDeclaredClasses();
for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
{
size_t position = it->find(std::string(config[i]["type"]));
if (position != std::string::npos)
{
ROS_WARN("Replaced %s with %s", std::string(config[i]["type"]).c_str(), it->c_str());
config[i]["type"] = *it;
}
}
}
//Make sure the filter chain has a valid type
std::vector<std::string> libs = loader_.getDeclaredClasses();
bool found = false;
for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); ++it)
{
if (*it == std::string(config[i]["type"]))
{
found = true;
break;
}
}
if (!found)
{
ROS_ERROR("Couldn't find filter of type %s", std::string(config[i]["type"]).c_str());
return false;
}


}
}

Expand Down
4 changes: 2 additions & 2 deletions src/increment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@



PLUGINLIB_REGISTER_CLASS(IncrementFilterInt, filters::IncrementFilter<int>, filters::FilterBase<int>)
PLUGINLIB_REGISTER_CLASS(MultiChannelIncrementFilterInt, filters::MultiChannelIncrementFilter<int>, filters::MultiChannelFilterBase<int>)
PLUGINLIB_DECLARE_CLASS(filters, IncrementFilterInt, filters::IncrementFilter<int>, filters::FilterBase<int>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelIncrementFilterInt, filters::MultiChannelIncrementFilter<int>, filters::MultiChannelFilterBase<int>)

8 changes: 4 additions & 4 deletions src/mean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@



PLUGINLIB_REGISTER_CLASS(MeanFilterDouble, filters::MeanFilter<double>, filters::FilterBase<double>)
PLUGINLIB_REGISTER_CLASS(MeanFilterFloat, filters::MeanFilter<float>, filters::FilterBase<float>)
PLUGINLIB_REGISTER_CLASS(MultiChannelMeanFilterDouble, filters::MultiChannelMeanFilter<double>, filters::MultiChannelFilterBase<double>)
PLUGINLIB_REGISTER_CLASS(MultiChannelMeanFilterFloat, filters::MultiChannelMeanFilter<float>, filters::MultiChannelFilterBase<float>)
PLUGINLIB_DECLARE_CLASS(filters, MeanFilterDouble, filters::MeanFilter<double>, filters::FilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, MeanFilterFloat, filters::MeanFilter<float>, filters::FilterBase<float>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelMeanFilterDouble, filters::MultiChannelMeanFilter<double>, filters::MultiChannelFilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelMeanFilterFloat, filters::MultiChannelMeanFilter<float>, filters::MultiChannelFilterBase<float>)

8 changes: 4 additions & 4 deletions src/median.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@


//Double precision
PLUGINLIB_REGISTER_CLASS(MedianFilterDouble, filters::MedianFilter<double>,filters::FilterBase<double>)
PLUGINLIB_REGISTER_CLASS(MultiChannelMedianFilterDouble, filters::MultiChannelMedianFilter<double>,filters::MultiChannelFilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, MedianFilterDouble, filters::MedianFilter<double>,filters::FilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelMedianFilterDouble, filters::MultiChannelMedianFilter<double>,filters::MultiChannelFilterBase<double>)

//Float precision
PLUGINLIB_REGISTER_CLASS(MedianFilterFloat, filters::MedianFilter<float>,filters::FilterBase<float>)
PLUGINLIB_REGISTER_CLASS(MultiChannelMedianFilterFloat, filters::MultiChannelMedianFilter<float>,filters::MultiChannelFilterBase<float>)
PLUGINLIB_DECLARE_CLASS(filters, MedianFilterFloat, filters::MedianFilter<float>,filters::FilterBase<float>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelMedianFilterFloat, filters::MultiChannelMedianFilter<float>,filters::MultiChannelFilterBase<float>)



Expand Down
12 changes: 6 additions & 6 deletions src/test_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
#include "filters/param_test.h"
#include "pluginlib/class_list_macros.h"

PLUGINLIB_REGISTER_CLASS(ParamTestDouble, filters::ParamTest<double>, filters::FilterBase<double>)
PLUGINLIB_REGISTER_CLASS(ParamTestInt, filters::ParamTest<int>, filters::FilterBase<int>)
PLUGINLIB_REGISTER_CLASS(ParamTestUInt, filters::ParamTest<unsigned int>, filters::FilterBase<unsigned int>)
PLUGINLIB_REGISTER_CLASS(ParamTestString, filters::ParamTest<std::string>, filters::FilterBase<std::string>)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestDouble, filters::ParamTest<double>, filters::FilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestInt, filters::ParamTest<int>, filters::FilterBase<int>)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestUInt, filters::ParamTest<unsigned int>, filters::FilterBase<unsigned int>)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestString, filters::ParamTest<std::string>, filters::FilterBase<std::string>)

PLUGINLIB_REGISTER_CLASS(ParamTestDoubleVector, filters::ParamTest<std::vector<double> >, filters::FilterBase<std::vector<double> >)
PLUGINLIB_REGISTER_CLASS(ParamTestStringVector, filters::ParamTest<std::vector<std::string> >, filters::FilterBase<std::vector<std::string> >)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestDoubleVector, filters::ParamTest<std::vector<double> >, filters::FilterBase<std::vector<double> >)
PLUGINLIB_DECLARE_CLASS(filters, ParamTestStringVector, filters::ParamTest<std::vector<std::string> >, filters::FilterBase<std::vector<std::string> >)
4 changes: 2 additions & 2 deletions src/transfer_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
#include "filters/transfer_function.h"
#include "pluginlib/class_list_macros.h"

PLUGINLIB_REGISTER_CLASS(TransferFunctionFilterDouble, filters::SingleChannelTransferFunctionFilter<double>, filters::FilterBase<double>)
PLUGINLIB_REGISTER_CLASS(MultiChannelTransferFunctionFilterDouble, filters::MultiChannelTransferFunctionFilter<double>, filters::MultiChannelFilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, TransferFunctionFilterDouble, filters::SingleChannelTransferFunctionFilter<double>, filters::FilterBase<double>)
PLUGINLIB_DECLARE_CLASS(filters, MultiChannelTransferFunctionFilterDouble, filters::MultiChannelTransferFunctionFilter<double>, filters::MultiChannelFilterBase<double>)

0 comments on commit f7a402c

Please sign in to comment.