Skip to content

Commit dd68206

Browse files
committed
exposing neighbor merged ratio parameter to the tool
1 parent 3f6b098 commit dd68206

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

corelib/include/rtabmap/core/Memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class RTABMAP_CORE_EXPORT Memory
144144
void saveLocationData(int locationId);
145145
void removeLink(int idA, int idB);
146146
void removeRawData(int id, bool image = true, bool scan = true, bool userData = true);
147-
int reduceNode(int id, float maxDistance = 0.0f, bool keepLinkedInDb = false);
147+
int reduceNode(int id, float maxDistance = 0.0f, bool keepLinkedInDb = false, float neighborMergedRatio = 0.2);
148148

149149
//getters
150150
const std::map<int, double> & getWorkingMem() const {return _workingMem;}
@@ -278,7 +278,7 @@ class RTABMAP_CORE_EXPORT Memory
278278
void initCountId();
279279
void rehearsal(Signature * signature, Statistics * stats = 0);
280280
bool rehearsalMerge(int oldId, int newId);
281-
std::map<int, float> reduceNodeImpl(int id, float maxDistance, bool keepLinkedInDb);
281+
std::map<int, float> reduceNodeImpl(int id, float maxDistance, bool keepLinkedInDb, float neighborMergedRatio);
282282

283283
const std::map<int, Signature*> & getSignatures() const {return _signatures;}
284284

corelib/src/Memory.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,9 @@ void Memory::addSignatureToWmFromLTM(Signature * signature)
12881288
}
12891289
}
12901290

1291-
int Memory::reduceNode(int id, float maxDistance, bool keepLinkedInDb)
1291+
int Memory::reduceNode(int id, float maxDistance, bool keepLinkedInDb, float neighborMergedRatio)
12921292
{
1293-
std::map<int, float> reducedTo = reduceNodeImpl(id, maxDistance, keepLinkedInDb);
1293+
std::map<int, float> reducedTo = reduceNodeImpl(id, maxDistance, keepLinkedInDb, neighborMergedRatio);
12941294
return reducedTo.empty()?0:reducedTo.rbegin()->first;
12951295
}
12961296

@@ -1305,7 +1305,7 @@ bool canBeReduced(const Link & link, float maxDistance)
13051305
(maxDistance==0 || link.transform().getNorm() < maxDistance);
13061306
}
13071307

1308-
std::map<int, float> Memory::reduceNodeImpl(int id, float maxDistance, bool keepLinkedInDb)
1308+
std::map<int, float> Memory::reduceNodeImpl(int id, float maxDistance, bool keepLinkedInDb, float neighborMergedRatio)
13091309
{
13101310
UDEBUG("Reducing %d (max distance=%f, keep linked in db=%s)", id, maxDistance, keepLinkedInDb?"true":"false");
13111311
std::map<int, float> reducedTo;
@@ -1353,15 +1353,15 @@ std::map<int, float> Memory::reduceNodeImpl(int id, float maxDistance, bool keep
13531353
{
13541354
if(iter->second.type() == Link::kNeighborMerged)
13551355
{
1356+
s->removeLink(sTo->id());
13561357
if(maxDistance == 0.0f)
13571358
{
13581359
// online graph reduction, always skip these links
13591360
continue;
13601361
}
1361-
s->removeLink(sTo->id());
13621362
std::list<std::pair<int, Transform> > path = graph::computePath(s->id(), sTo->id(), this, false);
13631363
float pathLength = graph::computePathLength(uListToVector(path));
1364-
if(!path.empty() && iter->second.transform().getNorm() / pathLength > 0.2)
1364+
if(!path.empty() && pathLength>0.0f && iter->second.transform().getNorm() / pathLength > neighborMergedRatio)
13651365
{
13661366
// skip, reachable by another path of similar size
13671367
continue;
@@ -1429,18 +1429,6 @@ std::map<int, float> Memory::reduceNodeImpl(int id, float maxDistance, bool keep
14291429
}
14301430
}
14311431

1432-
//remove neighbor links
1433-
/*std::multimap<int, Link> linksCopy = links;
1434-
for(std::multimap<int, Link>::iterator iter=linksCopy.begin(); iter!=linksCopy.end(); ++iter)
1435-
{
1436-
if(iter->second.type() == Link::kNeighborMerged)
1437-
{
1438-
// Removing only merged neighbor links, we keep original neighbor
1439-
// links to be able to reprocess databases with correct odometry covariance.
1440-
s->removeLink(iter->first);
1441-
}
1442-
}*/
1443-
14441432
this->moveToTrash(s, keepLinkedInDb);
14451433
s = 0;
14461434
_linksChanged = true;
@@ -1451,7 +1439,7 @@ std::map<int, float> Memory::reduceNodeImpl(int id, float maxDistance, bool keep
14511439
//Nodes can be already reduced by other nodes, check if they are still there
14521440
if(getSignature(pair.first) != 0)
14531441
{
1454-
reducedTo = reduceNodeImpl(pair.first, pair.second, keepLinkedInDb);
1442+
reducedTo = reduceNodeImpl(pair.first, pair.second, keepLinkedInDb, neighborMergedRatio);
14551443
}
14561444
}
14571445
}

tools/ReduceGraph/main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void showUsage(const char * exec)
5555
" --keep_latest Merge old nodes to newer nodes, thus keeping only latest nodes.\n"
5656
" --keep_linked Keep reduced nodes linked to graph.\n"
5757
" --radius #.# Maximum loop closure distance that can be merged. Default is 1 m. Should be > 0.\n"
58+
" --ratio #.# Neighbor links with length over this ratio relative to graph distance to same node are not propagated. Default is 0.2.\n"
5859
" --udebug/--uinfo/--warn can also be used to change verbosity.\n"
5960
"\n", exec);
6061
exit(1);
@@ -73,6 +74,7 @@ int main(int argc, char * argv[])
7374
bool keepLatest = false;
7475
bool keepLinked = false;
7576
float radius = 1.0f;
77+
float ratio = 0.2f;
7678
for(int i=1; i<argc; ++i)
7779
{
7880
if(std::strcmp(argv[i], "--help") == 0)
@@ -103,6 +105,17 @@ int main(int argc, char * argv[])
103105
showUsage(argv[0]);
104106
}
105107
}
108+
else if(std::strcmp(argv[i], "--ratio") == 0)
109+
{
110+
++i;
111+
if(i < argc-1)
112+
{
113+
ratio = uStr2Float(argv[i]);
114+
}
115+
else {
116+
showUsage(argv[0]);
117+
}
118+
}
106119
}
107120
printf("Parameters:\n");
108121
printf(" radius = %f m\n", radius);
@@ -183,7 +196,7 @@ int main(int argc, char * argv[])
183196
// Nodes can be already reduced by other nodes, check if they are still there
184197
if(memory.getSignature(id) != 0)
185198
{
186-
int reducedId = memory.reduceNode(id, radius, keepLinked);
199+
int reducedId = memory.reduceNode(id, radius, keepLinked, ratio);
187200
if(reducedId > 0)
188201
{
189202
printf("Reduced node %d to node %d!\n", id, reducedId);

0 commit comments

Comments
 (0)