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 bool incrementalMemory =
true;
138 Parameters::parse(parameters, Parameters::kMemIncrementalMemory(), incrementalMemory);
139 if(!incrementalMemory)
143 progressState->
callback(
"Database is in localization mode, setting it to mapping mode to recover...");
149 rtabmap.
init(parameters, databasePath);
151 bool rgbdEnabled = Parameters::defaultRGBDEnabled();
153 bool odometryIgnored = !rgbdEnabled;
154 DBReader dbReader(backupPath, 0, odometryIgnored);
161 progressState->
callback(
uFormat(
"Recovering data of \"%s\"...", backupPath.c_str()));
167 status =
uFormat(
"Skipping node %d as it doesn't have odometry pose set.", data.
id());
173 status =
uFormat(
"High variance detected, triggering a new map...");
178 status =
uFormat(
"Failed processing node %d.", data.
id());
190 progressState->
callback(
uFormat(
"Processed %d/%d nodes...", ++processed, (
int)ids.size()));
197 rtabmap.
close(
false);
199 *errorMsg =
uFormat(
"Recovery canceled, renaming back \"%s\" to \"%s\".", backupPath.c_str(), databasePath.c_str());
209 progressState->
callback(
uFormat(
"Closing database \"%s\"...", databasePath.c_str()));
212 progressState->
callback(
uFormat(
"Closing database \"%s\"... done!", databasePath.c_str()));
214 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
std::pair< std::string, std::string > ParametersPair
static int erase(const std::string &filePath)
std::map< std::string, std::string > ParametersMap
void init(const ParametersMap ¶meters, const std::string &databasePath="", bool loadDatabaseParameters=false)
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 getAllLinks(std::multimap< int, Link > &links, bool ignoreNullLinks=true, bool withLandmarks=false) const
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)
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,...)
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)