Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load DataPointsFilters config from a YAML::Node object #570

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pointmatcher/DataPointsFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,27 @@ template<typename T>
PointMatcher<T>::DataPointsFilters::DataPointsFilters()
{}

//! Construct a chain from a YAML file
template<typename T>
PointMatcher<T>::DataPointsFilters::DataPointsFilters(std::istream& in)
PointMatcher<T>::DataPointsFilters::DataPointsFilters(const YAML::Node& doc)
{
YAML::Node doc = YAML::Load(in);

// Fix for issue #6: compilation on gcc 4.4.4
//PointMatcher<T> pm;
const PointMatcher & pm = PointMatcher::get();

for(YAML::const_iterator moduleIt = doc.begin(); moduleIt != doc.end(); ++moduleIt)
{
const YAML::Node& module(*moduleIt);
this->push_back(pm.REG(DataPointsFilter).createFromYAML(module));
}
}

//! Construct a chain from a YAML file
template<typename T>
PointMatcher<T>::DataPointsFilters::DataPointsFilters(std::istream& in) :
DataPointsFilters(YAML::Load(in))
{
}

//! Init the chain
template<typename T>
void PointMatcher<T>::DataPointsFilters::init()
Expand Down
28 changes: 21 additions & 7 deletions pointmatcher/ICP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ void PointMatcher<T>::ICPChainBase::setDefault()

//! Construct an ICP algorithm from a YAML file
template<typename T>
void PointMatcher<T>::ICPChainBase::loadFromYaml(std::istream& in)
void PointMatcher<T>::ICPChainBase::loadFromYamlNode(const YAML::Node& doc)
{
this->cleanup();

YAML::Node doc = YAML::Load(in);
typedef set<string> StringSet;
StringSet usedModuleTypes;

// Fix for issue #6: compilation on gcc 4.4.4
//PointMatcher<T> pm;
const PointMatcher & pm = PointMatcher::get();
Expand All @@ -140,14 +139,14 @@ void PointMatcher<T>::ICPChainBase::loadFromYaml(std::istream& in)
this->transformations.push_back(std::make_shared<typename TransformationsImpl<T>::RigidTransformation>());
else
this->transformations.push_back(std::make_shared<typename TransformationsImpl<T>::SimilarityTransformation>());

usedModuleTypes.insert(createModulesFromRegistrar("transformationCheckers", doc, pm.REG(TransformationChecker), transformationCheckers));
usedModuleTypes.insert(createModuleFromRegistrar("inspector", doc, pm.REG(Inspector),inspector));


// FIXME: this line cause segfault when there is an error in the yaml file...
//loadAdditionalYAMLContent(doc);

// check YAML entries that do not correspend to any module
for(YAML::const_iterator moduleTypeIt = doc.begin(); moduleTypeIt != doc.end(); ++moduleTypeIt)
{
Expand All @@ -158,6 +157,15 @@ void PointMatcher<T>::ICPChainBase::loadFromYaml(std::istream& in)
(boost::format("Module type %1% does not exist") % moduleType).str()
);
}

}

//! Construct an ICP algorithm from a YAML file
template<typename T>
void PointMatcher<T>::ICPChainBase::loadFromYaml(std::istream& in)
{
YAML::Node doc = YAML::Load(in);
loadFromYamlNode(doc);
}

//! Return the remaining number of points in reading after prefiltering but before the iterative process
Expand Down Expand Up @@ -528,6 +536,12 @@ void PointMatcher<T>::ICPSequence::setDefault()
}
}

template<typename T>
void PointMatcher<T>::ICPSequence::loadFromYamlNode(const YAML::Node& doc)
{
ICPChainBase::loadFromYamlNode(doc);
}

template<typename T>
void PointMatcher<T>::ICPSequence::loadFromYaml(std::istream& in)
{
Expand Down
3 changes: 3 additions & 0 deletions pointmatcher/PointMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ struct PointMatcher
struct DataPointsFilters: public std::vector<std::shared_ptr<DataPointsFilter> >
{
DataPointsFilters();
DataPointsFilters(const YAML::Node& doc);
DataPointsFilters(std::istream& in);
void init();
void apply(DataPoints& cloud);
Expand Down Expand Up @@ -670,6 +671,7 @@ struct PointMatcher
virtual void setDefault();

virtual void loadFromYaml(std::istream& in);
virtual void loadFromYamlNode(const YAML::Node& doc);
unsigned getPrefilteredReadingPtsCount() const;
unsigned getPrefilteredReferencePtsCount() const;

Expand Down Expand Up @@ -746,6 +748,7 @@ struct PointMatcher
void clearMap();
virtual void setDefault();
virtual void loadFromYaml(std::istream& in);
virtual void loadFromYamlNode(const YAML::Node& doc);
PM_DEPRECATED("Use getPrefilteredInternalMap instead. "
"Function now always returns map with filter chain applied. "
"This may have altered your program behavior."
Expand Down
Loading