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());
58 *errorMsg =
uFormat(
"File \"%s\" is not a database (*.db)!", databasePath.c_str());
61 std::list<std::string> strList =
uSplit(databasePath,
'.');
64 std::string recoveryPath;
65 recoveryPath =
uJoin(strList,
".") +
".recovery.db";
71 *errorMsg =
uFormat(
"Failed to remove temporary recovery database \"%s\", is it opened by another app?", recoveryPath.c_str());
80 *errorMsg =
uFormat(
"Failed opening database!");
86 if(parameters.empty())
89 *errorMsg =
uFormat(
"Failed getting parameters from database, recovery cannot be done.");
99 *errorMsg =
uFormat(
"Input database doesn't have any nodes saved in it.");
105 progressState->
callback(
uFormat(
"Found %d nodes to recover.", (
int)ids.size()));
108 std::multimap<int, Link> links;
110 bool corrupted =
false;
111 for(std::multimap<int, Link>::iterator iter=links.begin(); iter!=links.end(); ++iter)
114 graph::findLink(links, iter->second.to(), iter->second.from(),
false) == links.end())
124 progressState->
callback(
"Database is indeed corrupted, found one or more neighbor links missing.");
126 progressState->
callback(
"Database doesn't seem to be corrupted, still recovering it.");
132 bool incrementalMemory =
true;
133 bool dbInMemory =
false;
134 Parameters::parse(parameters, Parameters::kMemIncrementalMemory(), incrementalMemory);
136 if(!incrementalMemory)
140 progressState->
callback(
"Database is in localization mode, setting it to mapping mode to recover.");
148 progressState->
callback(
uFormat(
"Database has %s=true, setting it to false to avoid RAM problems during recovery.", Parameters::kDbSqlite3InMemory().c_str()));
154 rtabmap.
init(parameters, recoveryPath);
156 bool rgbdEnabled = Parameters::defaultRGBDEnabled();
158 bool odometryIgnored = !rgbdEnabled;
160 DBReader dbReader(databasePath, 0, odometryIgnored);
167 progressState->
callback(
uFormat(
"Recovering data of \"%s\"...", databasePath.c_str()));
173 status =
uFormat(
"Skipping node %d as it doesn't have odometry pose set.", data.
id());
179 status =
uFormat(
"High variance detected, triggering a new map...");
184 status =
uFormat(
"Failed processing node %d.", data.
id());
196 progressState->
callback(
uFormat(
"Processed %d/%d nodes...", ++processed, (
int)ids.size()));
204 rtabmap.
close(
false);
206 *errorMsg =
uFormat(
"Recovery canceled, removing temporary recovery database \"%s\".", recoveryPath.c_str());
214 progressState->
callback(
uFormat(
"Closing database \"%s\"...", recoveryPath.c_str()));
217 progressState->
callback(
uFormat(
"Closing database \"%s\"... done!", recoveryPath.c_str()));
219 if(keepCorruptedDatabase)
221 std::string backupPath;
222 backupPath =
uJoin(strList,
".") +
".backup.db";
231 *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());
246 *errorMsg =
uFormat(
"Failed remove original database file \"%s\". Is it opened by another app? The recovered database cannot be copied back to original name.",
UFile::getName(databasePath).c_str(),
UFile::getName(recoveryPath).c_str());
255 *errorMsg =
uFormat(
"Failed renaming database file from \"%s\" to \"%s\". Is it opened by another app?",
UFile::getName(recoveryPath).c_str(),
UFile::getName(databasePath).c_str());
static std::string homeDir()
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
std::multimap< int, Link >::iterator RTABMAP_EXP findLink(std::multimap< int, Link > &links, int from, int to, bool checkBothWays=true, Link::Type type=Link::kUndef)
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")
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()
bool openConnection(const std::string &url, bool overwritten=false)
void getAllLinks(std::multimap< int, Link > &links, bool ignoreNullLinks=true, bool withLandmarks=false) const
SensorData takeImage(CameraInfo *info=0)
Wrappers of STL for convenient functions.
std::list< std::string > uSplit(const std::string &str, char separator=' ')
std::string uJoin(const std::list< std::string > &strings, const std::string &separator="")
void close(bool databaseSaved=true, const std::string &ouputDatabasePath="")
virtual bool callback(const std::string &msg) const
void closeConnection(bool save=true, const std::string &outputUrl="")
void getAllNodeIds(std::set< int > &ids, bool ignoreChildren=false, bool ignoreBadSignatures=false, bool ignoreIntermediateNodes=false) const
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())
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)