moved Rtabmap::[read,write]Parameters() and getVersion() to Parameters class (readINI(), writeINI() and getVersion()). Added Parameters::getDefaultOdometryParameters() and Parameters::isFeatureParameter() for convenience.

This commit is contained in:
matlabbe
2015-11-26 13:16:01 -05:00
parent 63c96f39a3
commit 7d521819f0
8 changed files with 160 additions and 133 deletions

View File

@@ -421,8 +421,15 @@ public:
static void parse(const ParametersMap & parameters, const std::string & key, double & value); static void parse(const ParametersMap & parameters, const std::string & key, double & value);
static void parse(const ParametersMap & parameters, const std::string & key, std::string & value); static void parse(const ParametersMap & parameters, const std::string & key, std::string & value);
static std::string getVersion();
static std::string getDefaultDatabaseName(); static std::string getDefaultDatabaseName();
static bool isFeatureParameter(const std::string & param);
static ParametersMap getDefaultOdometryParameters(bool stereo = false);
static void readINI(const std::string & configFile, ParametersMap & parameters);
static void writeINI(const std::string & configFile, const ParametersMap & parameters);
/** /**
* Get removed parameters (backward compatibility) * Get removed parameters (backward compatibility)
* <OldKeyName, <isEqual, NewKeyName> >, when isEqual=true, the old value can be safely copied to new parameter * <OldKeyName, <isEqual, NewKeyName> >, when isEqual=true, the old value can be safely copied to new parameter

View File

@@ -56,11 +56,6 @@ class RTABMAP_EXP Rtabmap
public: public:
enum VhStrategy {kVhNone, kVhEpipolar, kVhUndef}; enum VhStrategy {kVhNone, kVhEpipolar, kVhUndef};
public:
static std::string getVersion();
static void readParameters(const std::string & configFile, ParametersMap & parameters);
static void writeParameters(const std::string & configFile, const ParametersMap & parameters);
public: public:
Rtabmap(); Rtabmap();
virtual ~Rtabmap(); virtual ~Rtabmap();

View File

@@ -417,6 +417,7 @@ Feature2D * Feature2D::create(Feature2D::Type & type, const ParametersMap & para
return feature2D; return feature2D;
} }
std::vector<cv::KeyPoint> Feature2D::generateKeypoints(const cv::Mat & image, const cv::Rect & roi) const std::vector<cv::KeyPoint> Feature2D::generateKeypoints(const cv::Mat & image, const cv::Rect & roi) const
{ {
std::vector<cv::KeyPoint> keypoints; std::vector<cv::KeyPoint> keypoints;

View File

@@ -29,9 +29,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/utilite/UDirectory.h> #include <rtabmap/utilite/UDirectory.h>
#include <rtabmap/utilite/ULogger.h> #include <rtabmap/utilite/ULogger.h>
#include <rtabmap/utilite/UConversion.h> #include <rtabmap/utilite/UConversion.h>
#include <rtabmap/utilite/UStl.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <sstream> #include <sstream>
#include "SimpleIni.h"
namespace rtabmap namespace rtabmap
{ {
@@ -66,11 +68,56 @@ std::string Parameters::getDefaultWorkingDirectory()
return path; return path;
} }
std::string Parameters::getVersion()
{
return RTABMAP_VERSION;
return ""; // Second return only to avoid compiler warning with RTABMAP_VERSION not yet set.
}
std::string Parameters::getDefaultDatabaseName() std::string Parameters::getDefaultDatabaseName()
{ {
return "rtabmap.db"; return "rtabmap.db";
} }
bool Parameters::isFeatureParameter(const std::string & parameter)
{
std::string group = uSplit(parameter, '/').front();
return group.compare("SURF") == 0 ||
group.compare("SIFT") == 0 ||
group.compare("ORB") == 0 ||
group.compare("FAST") == 0 ||
group.compare("FREAK") == 0 ||
group.compare("BRIEF") == 0 ||
group.compare("GFTT") == 0 ||
group.compare("BRISK") == 0;
}
rtabmap::ParametersMap Parameters::getDefaultOdometryParameters(bool stereo)
{
rtabmap::ParametersMap odomParameters;
rtabmap::ParametersMap defaultParameters = rtabmap::Parameters::getDefaultParameters();
for(rtabmap::ParametersMap::iterator iter=defaultParameters.begin(); iter!=defaultParameters.end(); ++iter)
{
std::string group = uSplit(iter->first, '/').front();
if(uStrContains(group, "Odom") ||
(stereo && group.compare("Stereo") == 0) ||
Parameters::isFeatureParameter(iter->first) ||
group.compare("Reg") == 0 ||
group.compare("Vis") == 0)
{
if(stereo)
{
if(iter->first.compare(Parameters::kVisEstimationType()) == 0)
{
iter->second = "1"; // 3D->2D (PNP)
}
}
odomParameters.insert(*iter);
}
}
return odomParameters;
}
const std::map<std::string, std::pair<bool, std::string> > & Parameters::getRemovedParameters() const std::map<std::string, std::pair<bool, std::string> > & Parameters::getRemovedParameters()
{ {
if(removedParameters_.empty()) if(removedParameters_.empty())
@@ -252,4 +299,103 @@ void Parameters::parse(const ParametersMap & parameters, const std::string & key
} }
} }
void Parameters::readINI(const std::string & configFile, ParametersMap & parameters)
{
CSimpleIniA ini;
ini.LoadFile(configFile.c_str());
const CSimpleIniA::TKeyVal * keyValMap = ini.GetSection("Core");
if(keyValMap)
{
for(CSimpleIniA::TKeyVal::const_iterator iter=keyValMap->begin(); iter!=keyValMap->end(); ++iter)
{
std::string key = (*iter).first.pItem;
if(key.compare("Version") == 0)
{
// Compare version in ini with the current RTAB-Map version
std::vector<std::string> version = uListToVector(uSplit((*iter).second, '.'));
if(version.size() == 3)
{
if(!RTABMAP_VERSION_COMPARE(std::atoi(version[0].c_str()), std::atoi(version[1].c_str()), std::atoi(version[2].c_str())))
{
if(configFile.find(".rtabmap") != std::string::npos)
{
UWARN("Version in the config file \"%s\" is more recent (\"%s\") than "
"current RTAB-Map version used (\"%s\"). The config file will be upgraded "
"to new version.",
configFile.c_str(),
(*iter).second,
RTABMAP_VERSION);
}
else
{
UERROR("Version in the config file \"%s\" is more recent (\"%s\") than "
"current RTAB-Map version used (\"%s\"). New parameters (if there are some) will "
"be ignored.",
configFile.c_str(),
(*iter).second,
RTABMAP_VERSION);
}
}
}
}
else
{
key = uReplaceChar(key, '\\', '/'); // Ini files use \ by default for separators, so replace them
// look for old parameter name
bool addParameter = true;
std::map<std::string, std::pair<bool, std::string> >::const_iterator oldIter = Parameters::getRemovedParameters().find(key);
if(oldIter!=Parameters::getRemovedParameters().end())
{
addParameter = oldIter->second.first;
if(addParameter)
{
key = oldIter->second.second;
UWARN("Parameter migration from \"%s\" to \"%s\" (value=%s).",
oldIter->first.c_str(), oldIter->second.second.c_str(), iter->second);
}
else if(oldIter->second.second.empty())
{
UWARN("Parameter \"%s\" doesn't exist anymore.",
oldIter->first.c_str());
}
else
{
UWARN("Parameter \"%s\" doesn't exist anymore, you may want to use this similar parameter \"%s\":\"%s\".",
oldIter->first.c_str(), oldIter->second.second.c_str(), Parameters::getDescription(oldIter->second.second).c_str());
}
}
uInsert(parameters, ParametersPair(key, iter->second));
}
}
}
else
{
ULOGGER_WARN("Section \"Core\" in %s doesn't exist... "
"Ignore this warning if the ini file does not exist yet. "
"The ini file will be automatically created when this node will close.", configFile.c_str());
}
}
void Parameters::writeINI(const std::string & configFile, const ParametersMap & parameters)
{
CSimpleIniA ini;
ini.LoadFile(configFile.c_str());
// Save current version
ini.SetValue("Core", "Version", RTABMAP_VERSION, NULL, true);
for(ParametersMap::const_iterator i=parameters.begin(); i!=parameters.end(); ++i)
{
std::string key = (*i).first;
key = uReplaceChar(key, '/', '\\'); // Ini files use \ by default for separators, so replace the /
ini.SetValue("Core", key.c_str(), (*i).second.c_str(), NULL, true);
}
ini.SaveFile(configFile.c_str());
}
} }

View File

@@ -94,15 +94,7 @@ void RegistrationVis::parseParameters(const ParametersMap & parameters)
// override feature parameters // override feature parameters
for(ParametersMap::const_iterator iter=parameters.begin(); iter!=parameters.end(); ++iter) for(ParametersMap::const_iterator iter=parameters.begin(); iter!=parameters.end(); ++iter)
{ {
std::string group = uSplit(iter->first, '/').front(); if(Parameters::isFeatureParameter(iter->first))
if(group.compare("SURF") == 0 ||
group.compare("SIFT") == 0 ||
group.compare("ORB") == 0 ||
group.compare("FAST") == 0 ||
group.compare("FREAK") == 0 ||
group.compare("BRIEF") == 0 ||
group.compare("GFTT") == 0 ||
group.compare("BRISK") == 0)
{ {
uInsert(_featureParameters, ParametersPair(iter->first, iter->second)); uInsert(_featureParameters, ParametersPair(iter->first, iter->second));
} }

View File

@@ -44,8 +44,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/utilite/UConversion.h> #include <rtabmap/utilite/UConversion.h>
#include <rtabmap/utilite/UMath.h> #include <rtabmap/utilite/UMath.h>
#include "SimpleIni.h"
#include <pcl/search/kdtree.h> #include <pcl/search/kdtree.h>
#include <pcl/filters/crop_box.h> #include <pcl/filters/crop_box.h>
#include <pcl/io/pcd_io.h> #include <pcl/io/pcd_io.h>
@@ -137,12 +135,6 @@ Rtabmap::~Rtabmap() {
this->close(); this->close();
} }
std::string Rtabmap::getVersion()
{
return RTABMAP_VERSION;
return ""; // Second return only to avoid compiler warning with RTABMAP_VERSION not yet set.
}
void Rtabmap::setupLogFiles(bool overwrite) void Rtabmap::setupLogFiles(bool overwrite)
{ {
flushStatisticLogs(); flushStatisticLogs();
@@ -313,7 +305,7 @@ void Rtabmap::init(const std::string & configFile, const std::string & databaseP
if(!configFile.empty()) if(!configFile.empty())
{ {
ULOGGER_DEBUG("Read parameters from = %s", configFile.c_str()); ULOGGER_DEBUG("Read parameters from = %s", configFile.c_str());
this->readParameters(configFile, param); Parameters::readINI(configFile, param);
} }
this->init(param, databasePath); this->init(param, databasePath);
@@ -3691,110 +3683,4 @@ void Rtabmap::updateGoalIndex()
} }
} }
void Rtabmap::readParameters(const std::string & configFile, ParametersMap & parameters)
{
CSimpleIniA ini;
ini.LoadFile(configFile.c_str());
const CSimpleIniA::TKeyVal * keyValMap = ini.GetSection("Core");
if(keyValMap)
{
for(CSimpleIniA::TKeyVal::const_iterator iter=keyValMap->begin(); iter!=keyValMap->end(); ++iter)
{
std::string key = (*iter).first.pItem;
if(key.compare("Version") == 0)
{
// Compare version in ini with the current RTAB-Map version
std::vector<std::string> version = uListToVector(uSplit((*iter).second, '.'));
if(version.size() == 3)
{
if(!RTABMAP_VERSION_COMPARE(std::atoi(version[0].c_str()), std::atoi(version[1].c_str()), std::atoi(version[2].c_str())))
{
if(configFile.find(".rtabmap") != std::string::npos)
{
UWARN("Version in the config file \"%s\" is more recent (\"%s\") than "
"current RTAB-Map version used (\"%s\"). The config file will be upgraded "
"to new version.",
configFile.c_str(),
(*iter).second,
RTABMAP_VERSION);
}
else
{
UERROR("Version in the config file \"%s\" is more recent (\"%s\") than "
"current RTAB-Map version used (\"%s\"). New parameters (if there are some) will "
"be ignored.",
configFile.c_str(),
(*iter).second,
RTABMAP_VERSION);
}
}
}
}
else
{
key = uReplaceChar(key, '\\', '/'); // Ini files use \ by default for separators, so replace them
// look for old parameter name
bool addParameter = true;
std::map<std::string, std::pair<bool, std::string> >::const_iterator oldIter = Parameters::getRemovedParameters().find(key);
if(oldIter!=Parameters::getRemovedParameters().end())
{
addParameter = oldIter->second.first;
if(addParameter)
{
key = oldIter->second.second;
UWARN("Parameter migration from \"%s\" to \"%s\" (value=%s).",
oldIter->first.c_str(), oldIter->second.second.c_str(), iter->second);
}
else if(oldIter->second.second.empty())
{
UWARN("Parameter \"%s\" doesn't exist anymore.",
oldIter->first.c_str());
}
else
{
UWARN("Parameter \"%s\" doesn't exist anymore, you may want to use this similar parameter \"%s\":\"%s\".",
oldIter->first.c_str(), oldIter->second.second.c_str(), Parameters::getDescription(oldIter->second.second).c_str());
}
}
ParametersMap::iterator jter = parameters.find(key);
if(jter != parameters.end())
{
parameters.erase(jter);
}
if(addParameter)
{
parameters.insert(ParametersPair(key, iter->second));
}
}
}
}
else
{
ULOGGER_WARN("Section \"Core\" in %s doesn't exist... "
"Ignore this warning if the ini file does not exist yet. "
"The ini file will be automatically created when this node will close.", configFile.c_str());
}
}
void Rtabmap::writeParameters(const std::string & configFile, const ParametersMap & parameters)
{
CSimpleIniA ini;
ini.LoadFile(configFile.c_str());
// Save current version
ini.SetValue("Core", "Version", RTABMAP_VERSION, NULL, true);
for(ParametersMap::const_iterator i=parameters.begin(); i!=parameters.end(); ++i)
{
std::string key = (*i).first;
key = uReplaceChar(key, '/', '\\'); // Ini files use \ by default for separators, so replace the /
ini.SetValue("Core", key.c_str(), (*i).second.c_str(), NULL, true);
}
ini.SaveFile(configFile.c_str());
}
} // namespace rtabmap } // namespace rtabmap

View File

@@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "AboutDialog.h" #include "AboutDialog.h"
#include "rtabmap/core/Rtabmap.h" #include "rtabmap/core/Parameters.h"
#include "rtabmap/core/CameraRGBD.h" #include "rtabmap/core/CameraRGBD.h"
#include "rtabmap/core/CameraStereo.h" #include "rtabmap/core/CameraStereo.h"
#include "rtabmap/core/Graph.h" #include "rtabmap/core/Graph.h"
@@ -41,7 +41,7 @@ AboutDialog::AboutDialog(QWidget * parent) :
{ {
_ui = new Ui_aboutDialog(); _ui = new Ui_aboutDialog();
_ui->setupUi(this); _ui->setupUi(this);
QString version = Rtabmap::getVersion().c_str(); QString version = Parameters::getVersion().c_str();
#if DEMO_BUILD #if DEMO_BUILD
version.append(" [DEMO]"); version.append(" [DEMO]");
#endif #endif

View File

@@ -96,10 +96,10 @@ int main(int argc, char * argv[])
} }
else if(argc == 2 && strcmp(argv[1], "-v") == 0) else if(argc == 2 && strcmp(argv[1], "-v") == 0)
{ {
printf("%s\n", Rtabmap::getVersion().c_str()); printf("%s\n", Parameters::getVersion().c_str());
exit(0); exit(0);
} }
else if(argc == 2 && strcmp(argv[1], "-default_params") == 0) else if(argc == 2 && (strcmp(argv[1], "-default_params") == 0 || strcmp(argv[1], "--params") == 0))
{ {
for(ParametersMap::const_iterator iter = defaultParameters.begin(); iter!=defaultParameters.end(); ++iter) for(ParametersMap::const_iterator iter = defaultParameters.begin(); iter!=defaultParameters.end(); ++iter)
{ {