added option to reduceGraph and detectMoreLoopClosures tools

This commit is contained in:
matlabbe
2026-07-10 20:06:54 -07:00
parent 15109dfa9e
commit 8f63846b66
3 changed files with 63 additions and 4 deletions

View File

@@ -231,14 +231,14 @@ void DBDriverSqlite3::startChangeTracking()
} }
if(uStrNumCmp(_version, "0.24.0") < 0) if(uStrNumCmp(_version, "0.24.0") < 0)
{ {
UWARN("Database change tracking to \"%s\" was requested but the database " UERROR("Database change tracking to \"%s\" was requested but the database "
"version is %s (< 0.24.0). Older schemas lack the primary keys required " "version is %s (< 0.24.0). Older schemas lack the primary keys required "
"by the SQLite session extension, so change tracking is disabled.", "by the SQLite session extension, so change tracking is disabled.",
_trackChangesOutput.c_str(), _version.c_str()); _trackChangesOutput.c_str(), _version.c_str());
} }
else if(!sqlite3_compileoption_used("ENABLE_SESSION")) else if(!sqlite3_compileoption_used("ENABLE_SESSION"))
{ {
UWARN("Database change tracking to \"%s\" was requested but the linked SQLite " UERROR("Database change tracking to \"%s\" was requested but the linked SQLite "
"library was not built with the session extension (ENABLE_SESSION); " "library was not built with the session extension (ENABLE_SESSION); "
"change tracking is disabled.", _trackChangesOutput.c_str()); "change tracking is disabled.", _trackChangesOutput.c_str());
} }
@@ -250,7 +250,7 @@ void DBDriverSqlite3::startChangeTracking()
} }
else else
{ {
UWARN("Could not create a SQLite session to track database changes to \"%s\".", UERROR("Could not create a SQLite session to track database changes to \"%s\".",
_trackChangesOutput.c_str()); _trackChangesOutput.c_str());
_session = 0; _session = 0;
} }
@@ -273,7 +273,7 @@ bool DBDriverSqlite3::trackDatabaseChanges(const std::string & outputUrl)
#else #else
if(!outputUrl.empty()) if(!outputUrl.empty())
{ {
UWARN("Database change tracking to \"%s\" was requested but rtabmap was built " UERROR("Database change tracking to \"%s\" was requested but rtabmap was built "
"against a SQLite library without the session extension; it is disabled.", "against a SQLite library without the session extension; it is disabled.",
outputUrl.c_str()); outputUrl.c_str());
} }

View File

@@ -59,6 +59,11 @@ void showUsage()
" --intra Add only intra-session loop closures.\n" " --intra Add only intra-session loop closures.\n"
" --inter Add only inter-session loop closures.\n" " --inter Add only inter-session loop closures.\n"
" --session # Add loop closures only from/to that map session ID (use -1 for last session).\n" " --session # Add loop closures only from/to that map session ID (use -1 for last session).\n"
" --track-changes \"changes.update\"\n"
" Record the changes made to the database (added loop closures) and write a compact\n"
" delta to the given file, applied later on another copy with rtabmap-dbupdate.\n"
" Requires the database to be version 0.24 or newer. The changes are held in memory\n"
" until closing, so use this only when a small amount is added.\n"
"\n%s", Parameters::showUsage()); "\n%s", Parameters::showUsage());
exit(1); exit(1);
} }
@@ -110,12 +115,25 @@ int main(int argc, char * argv[])
bool intraSession = false; bool intraSession = false;
bool interSession = false; bool interSession = false;
int fromToMapId = -2; int fromToMapId = -2;
std::string trackChangesOutput;
for(int i=1; i<argc-1; ++i) for(int i=1; i<argc-1; ++i)
{ {
if(std::strcmp(argv[i], "--help") == 0) if(std::strcmp(argv[i], "--help") == 0)
{ {
showUsage(); showUsage();
} }
else if(std::strcmp(argv[i], "--track-changes") == 0)
{
++i;
if(i<argc-1)
{
trackChangesOutput = argv[i];
}
else
{
showUsage();
}
}
else if(std::strcmp(argv[i], "--intra") == 0) else if(std::strcmp(argv[i], "--intra") == 0)
{ {
intraSession = true; intraSession = true;
@@ -217,6 +235,10 @@ int main(int argc, char * argv[])
{ {
printf("Inter-session only\n"); printf("Inter-session only\n");
} }
if(!trackChangesOutput.empty())
{
printf("Track changes = %s\n", trackChangesOutput.c_str());
}
if(!intraSession && !interSession) if(!intraSession && !interSession)
{ {
@@ -252,6 +274,13 @@ int main(int argc, char * argv[])
rtabmap.init(parameters, dbPath); rtabmap.init(parameters, dbPath);
printf("Initialization... done! (%f sec)\n", timer.ticks()); printf("Initialization... done! (%f sec)\n", timer.ticks());
// Record the changes made below (added loop closures) into a delta, applied later with
// rtabmap-dbupdate. Started after init so the delta reflects only what this tool changes.
if(!trackChangesOutput.empty())
{
rtabmap.trackDatabaseChanges(trackChangesOutput);
}
float xMin, yMin, cellSize; float xMin, yMin, cellSize;
bool haveOptimizedMap = !rtabmap.getMemory()->load2DMap(xMin, yMin, cellSize).empty(); bool haveOptimizedMap = !rtabmap.getMemory()->load2DMap(xMin, yMin, cellSize).empty();

View File

@@ -59,6 +59,11 @@ void showUsage(const char * exec)
" --keep_linked Keep reduced nodes linked to graph.\n" " --keep_linked Keep reduced nodes linked to graph.\n"
" --pre_cleanup Remove all user loop closures linking nodes closer than %s in the graph before reducing the graph.\n" " --pre_cleanup Remove all user loop closures linking nodes closer than %s in the graph before reducing the graph.\n"
" --radius #.# Maximum loop closure distance that can be merged. Default is 1 m. Should be > 0.\n" " --radius #.# Maximum loop closure distance that can be merged. Default is 1 m. Should be > 0.\n"
" --track-changes \"changes.update\"\n"
" Record the changes made to the database (reduced nodes, removed links) and write a\n"
" compact delta to the given file, applied later on another copy with rtabmap-dbupdate.\n"
" Requires the database to be version 0.24 or newer. Changes are held in memory until\n"
" closing, so use this only when a small amount is modified.\n"
" --udebug/--uinfo/--warn can also be used to change verbosity.\n" " --udebug/--uinfo/--warn can also be used to change verbosity.\n"
"\n", exec, Parameters::kMemSTMSize().c_str()); "\n", exec, Parameters::kMemSTMSize().c_str());
exit(1); exit(1);
@@ -78,12 +83,25 @@ int main(int argc, char * argv[])
bool keepLinked = false; bool keepLinked = false;
float radius = 1.0f; float radius = 1.0f;
bool preCleanup = false; bool preCleanup = false;
std::string trackChangesOutput;
for(int i=1; i<argc; ++i) for(int i=1; i<argc; ++i)
{ {
if(std::strcmp(argv[i], "--help") == 0) if(std::strcmp(argv[i], "--help") == 0)
{ {
showUsage(argv[0]); showUsage(argv[0]);
} }
else if(std::strcmp(argv[i], "--track-changes") == 0)
{
++i;
if(i < argc-1)
{
trackChangesOutput = argv[i];
}
else
{
showUsage(argv[0]);
}
}
else if(std::strcmp(argv[i], "--keep_latest") == 0) else if(std::strcmp(argv[i], "--keep_latest") == 0)
{ {
keepLatest = true; keepLatest = true;
@@ -118,6 +136,10 @@ int main(int argc, char * argv[])
printf(" keep_latest = %s\n", keepLatest?"true":"false"); printf(" keep_latest = %s\n", keepLatest?"true":"false");
printf(" keep_linked = %s\n", keepLinked?"true":"false"); printf(" keep_linked = %s\n", keepLinked?"true":"false");
printf(" pre_cleanup = %s\n", preCleanup?"true":"false"); printf(" pre_cleanup = %s\n", preCleanup?"true":"false");
if(!trackChangesOutput.empty())
{
printf(" track-changes = %s\n", trackChangesOutput.c_str());
}
#ifdef RTABMAP_PYTHON #ifdef RTABMAP_PYTHON
rtabmap::PythonInterface pythonInterface; rtabmap::PythonInterface pythonInterface;
@@ -167,6 +189,14 @@ int main(int argc, char * argv[])
std::set<int> ids = memory.getAllSignatureIds(); std::set<int> ids = memory.getAllSignatureIds();
printf("Initialization... done! %ld nodes loaded. (%f sec)\n", ids.size(), timer.ticks()); printf("Initialization... done! %ld nodes loaded. (%f sec)\n", ids.size(), timer.ticks());
// Record the changes made below (reduced/merged nodes and removed links) into a delta,
// applied later on another copy with rtabmap-dbupdate. Started after init so the delta
// reflects only what this tool changes.
if(!trackChangesOutput.empty())
{
memory.trackDatabaseChanges(trackChangesOutput);
}
if(ids.empty()) if(ids.empty())
{ {
printf("IDs are empty?! Aborting.\n"); printf("IDs are empty?! Aborting.\n");