40 const std::string & corruptedDatabase,
41 bool keepCorruptedDatabase,
42 std::string * errorMsg,
45 UDEBUG(
"Recovering \"%s\"", corruptedDatabase.c_str());
51 *errorMsg =
uFormat(
"File \"%s\" doesn't exist!", databasePath.c_str());
55 std::string backupPath;
59 *errorMsg =
uFormat(
"File \"%s\" is not a database (*.db)!", databasePath.c_str());
62 std::list<std::string> strList =
uSplit(databasePath,
'.');
64 backupPath =
uJoin(strList,
".") +
".backup.db";
68 *errorMsg =
uFormat(
"Backup file \"%s\" already exists!", backupPath.c_str());
76 *errorMsg =
uFormat(
"Failed opening database!");
82 if(parameters.empty())
85 *errorMsg =
uFormat(
"Failed getting parameters from database, recovery cannot be done.");
95 *errorMsg =
uFormat(
"Input database doesn't have any nodes saved in it.");
101 progressState->
callback(
uFormat(
"Found %d nodes to recover.", (
int)ids.size()));
104 std::multimap<int, Link> links;
106 bool corrupted =
false;
107 for(std::multimap<int, Link>::iterator iter=links.begin(); iter!=links.end(); ++iter)
110 graph::findLink(links, iter->second.to(), iter->second.from(),
false) == links.end())
120 progressState->
callback(
"Database is indeed corrupted, found one or more neighbor links missing.");
122 progressState->
callback(
"Database doesn't seem to be corrupted, still recovering it.");
133 *errorMsg =
uFormat(
"Failed renaming database file from \"%s\" to \"%s\". Is it opened by another app?",
UFile::getName(databasePath).c_str(),
UFile::getName(backupPath).c_str());
137 rtabmap.
init(parameters, databasePath);
139 bool rgbdEnabled = Parameters::defaultRGBDEnabled();
141 bool odometryIgnored = !rgbdEnabled;
142 DBReader dbReader(backupPath, 0, odometryIgnored);
149 progressState->
callback(
uFormat(
"Recovering data of \"%s\"...", backupPath.c_str()));
155 status =
uFormat(
"Skipping node %d as it doesn't have odometry pose set.", data.
id());
161 status =
uFormat(
"High variance detected, triggering a new map...");
166 status =
uFormat(
"Failed processing node %d.", data.
id());
178 progressState->
callback(
uFormat(
"Processed %d/%d nodes...", ++processed, (
int)ids.size()));
185 rtabmap.
close(
false);
187 *errorMsg =
uFormat(
"Recovery canceled, renaming back \"%s\" to \"%s\".", backupPath.c_str(), databasePath.c_str());
197 progressState->
callback(
uFormat(
"Closing database \"%s\"...", databasePath.c_str()));
200 progressState->
callback(
uFormat(
"Closing database \"%s\"... done!", databasePath.c_str()));
202 if(!keepCorruptedDatabase)
static std::string homeDir()
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")
void getAllNodeIds(std::set< int > &ids, bool ignoreChildren=false, bool ignoreBadSignatures=false) const
void getAllLinks(std::multimap< int, Link > &links, bool ignoreNullLinks=true) const
static int erase(const std::string &filePath)
std::map< std::string, std::string > ParametersMap
std::vector< float > odomVelocity
std::string getExtension()
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
bool openConnection(const std::string &url, bool overwritten=false)
SensorData takeImage(CameraInfo *info=0)
Wrappers of STL for convenient functions.
virtual bool callback(const std::string &msg) const
std::string uJoin(const std::list< std::string > &strings, const std::string &separator="")
void close(bool databaseSaved=true, const std::string &ouputDatabasePath="")
void closeConnection(bool save=true, const std::string &outputUrl="")
bool process(const SensorData &data, Transform odomPose, const cv::Mat &odomCovariance=cv::Mat::eye(6, 6, CV_64FC1), const std::vector< float > &odomVelocity=std::vector< float >(), const std::map< std::string, float > &externalStats=std::map< std::string, float >())
Main loop of rtabmap.
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
void init(const ParametersMap ¶meters, const std::string &databasePath="")
static DBDriver * create(const ParametersMap ¶meters=ParametersMap())
std::multimap< int, Link >::iterator RTABMAP_EXP findLink(std::multimap< int, Link > &links, int from, int to, bool checkBothWays=true)
bool RTABMAP_EXP databaseRecovery(const std::string &corruptedDatabase, bool keepCorruptedDatabase=true, std::string *errorMsg=0, ProgressState *progressState=0)
ParametersMap getLastParameters() const
static int rename(const std::string &oldFilePath, const std::string &newFilePath)
std::string UTILITE_EXP uFormat(const char *fmt,...)