diff --git a/pointmatcher/DataPointsFilter.cpp b/pointmatcher/DataPointsFilter.cpp index baec06c0..ff727a5e 100644 --- a/pointmatcher/DataPointsFilter.cpp +++ b/pointmatcher/DataPointsFilter.cpp @@ -68,16 +68,13 @@ template PointMatcher::DataPointsFilters::DataPointsFilters() {} -//! Construct a chain from a YAML file template -PointMatcher::DataPointsFilters::DataPointsFilters(std::istream& in) +PointMatcher::DataPointsFilters::DataPointsFilters(const YAML::Node& doc) { - YAML::Node doc = YAML::Load(in); - // Fix for issue #6: compilation on gcc 4.4.4 //PointMatcher pm; const PointMatcher & pm = PointMatcher::get(); - + for(YAML::const_iterator moduleIt = doc.begin(); moduleIt != doc.end(); ++moduleIt) { const YAML::Node& module(*moduleIt); @@ -85,6 +82,13 @@ PointMatcher::DataPointsFilters::DataPointsFilters(std::istream& in) } } +//! Construct a chain from a YAML file +template +PointMatcher::DataPointsFilters::DataPointsFilters(std::istream& in) : + DataPointsFilters(YAML::Load(in)) +{ +} + //! Init the chain template void PointMatcher::DataPointsFilters::init() diff --git a/pointmatcher/ICP.cpp b/pointmatcher/ICP.cpp index e7cb625b..a507afb0 100644 --- a/pointmatcher/ICP.cpp +++ b/pointmatcher/ICP.cpp @@ -110,14 +110,13 @@ void PointMatcher::ICPChainBase::setDefault() //! Construct an ICP algorithm from a YAML file template -void PointMatcher::ICPChainBase::loadFromYaml(std::istream& in) +void PointMatcher::ICPChainBase::loadFromYamlNode(const YAML::Node& doc) { this->cleanup(); - YAML::Node doc = YAML::Load(in); typedef set StringSet; StringSet usedModuleTypes; - + // Fix for issue #6: compilation on gcc 4.4.4 //PointMatcher pm; const PointMatcher & pm = PointMatcher::get(); @@ -140,14 +139,14 @@ void PointMatcher::ICPChainBase::loadFromYaml(std::istream& in) this->transformations.push_back(std::make_shared::RigidTransformation>()); else this->transformations.push_back(std::make_shared::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) { @@ -158,6 +157,15 @@ void PointMatcher::ICPChainBase::loadFromYaml(std::istream& in) (boost::format("Module type %1% does not exist") % moduleType).str() ); } + +} + +//! Construct an ICP algorithm from a YAML file +template +void PointMatcher::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 @@ -528,6 +536,12 @@ void PointMatcher::ICPSequence::setDefault() } } +template +void PointMatcher::ICPSequence::loadFromYamlNode(const YAML::Node& doc) +{ + ICPChainBase::loadFromYamlNode(doc); +} + template void PointMatcher::ICPSequence::loadFromYaml(std::istream& in) { diff --git a/pointmatcher/PointMatcher.h b/pointmatcher/PointMatcher.h index 1cfcd3c9..a5256569 100644 --- a/pointmatcher/PointMatcher.h +++ b/pointmatcher/PointMatcher.h @@ -455,6 +455,7 @@ struct PointMatcher struct DataPointsFilters: public std::vector > { DataPointsFilters(); + DataPointsFilters(const YAML::Node& doc); DataPointsFilters(std::istream& in); void init(); void apply(DataPoints& cloud); @@ -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; @@ -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."