GraphViewer: added hide/show graphs and paths options

This commit is contained in:
matlabbe
2016-04-13 12:57:28 -04:00
parent 809f5dd4df
commit 7c0db617cf
2 changed files with 144 additions and 18 deletions
+12 -1
View File
@@ -98,6 +98,10 @@ public:
bool isLocalRadiusVisible() const; bool isLocalRadiusVisible() const;
float getLoopClosureOutlierThr() const {return _loopClosureOutlierThr;} float getLoopClosureOutlierThr() const {return _loopClosureOutlierThr;}
float getMaxLinkLength() const {return _maxLinkLength;} float getMaxLinkLength() const {return _maxLinkLength;}
bool isGraphVisible() const;
bool isGlobalPathVisible() const;
bool isLocalPathVisible() const;
bool isGtGraphVisible() const;
// setters // setters
void setWorkingDirectory(const QString & path); void setWorkingDirectory(const QString & path);
@@ -124,6 +128,10 @@ public:
void setLocalRadiusVisible(bool visible); void setLocalRadiusVisible(bool visible);
void setLoopClosureOutlierThr(float value); void setLoopClosureOutlierThr(float value);
void setMaxLinkLength(float value); void setMaxLinkLength(float value);
void setGraphVisible(bool visible);
void setGlobalPathVisible(bool visible);
void setLocalPathVisible(bool visible);
void setGtGraphVisible(bool visible);
signals: signals:
void configChanged(); void configChanged();
@@ -153,6 +161,10 @@ private:
QColor _loopInterSessionColor; QColor _loopInterSessionColor;
bool _intraInterSessionColors; bool _intraInterSessionColors;
QGraphicsItem * _root; QGraphicsItem * _root;
QGraphicsItem * _graphRoot;
QGraphicsItem * _globalPathRoot;
QGraphicsItem * _localPathRoot;
QGraphicsItem * _gtGraphRoot;
QMap<int, NodeItem*> _nodeItems; QMap<int, NodeItem*> _nodeItems;
QMultiMap<int, LinkItem*> _linkItems; QMultiMap<int, LinkItem*> _linkItems;
QMap<int, NodeItem*> _gtNodeItems; QMap<int, NodeItem*> _gtNodeItems;
@@ -168,7 +180,6 @@ private:
QGraphicsEllipseItem * _localRadius; QGraphicsEllipseItem * _localRadius;
float _loopClosureOutlierThr; float _loopClosureOutlierThr;
float _maxLinkLength; float _maxLinkLength;
int _coordinateSystem;
}; };
} /* namespace rtabmap */ } /* namespace rtabmap */
+132 -17
View File
@@ -195,10 +195,13 @@ GraphViewer::GraphViewer(QWidget * parent) :
_loopInterSessionColor(Qt::green), _loopInterSessionColor(Qt::green),
_intraInterSessionColors(false), _intraInterSessionColors(false),
_root(0), _root(0),
_graphRoot(0),
_globalPathRoot(0),
_nodeRadius(0.01f), _nodeRadius(0.01f),
_linkWidth(0), _linkWidth(0),
_gridMap(0), _gridMap(0),
_referential(0), _referential(0),
_originReferential(0),
_gridCellSize(0.0f), _gridCellSize(0.0f),
_localRadius(0), _localRadius(0),
_loopClosureOutlierThr(0), _loopClosureOutlierThr(0),
@@ -245,6 +248,22 @@ GraphViewer::GraphViewer(QWidget * parent) :
_gridMap->setZValue(0); _gridMap->setZValue(0);
_gridMap->setParentItem(_root); _gridMap->setParentItem(_root);
_graphRoot = (QGraphicsItem *)this->scene()->addEllipse(QRectF(-0.0001,-0.0001,0.0001,0.0001));
_graphRoot->setZValue(2);
_graphRoot->setParentItem(_root);
_globalPathRoot = (QGraphicsItem *)this->scene()->addEllipse(QRectF(-0.0001,-0.0001,0.0001,0.0001));
_globalPathRoot->setZValue(3);
_globalPathRoot->setParentItem(_root);
_localPathRoot = (QGraphicsItem *)this->scene()->addEllipse(QRectF(-0.0001,-0.0001,0.0001,0.0001));
_localPathRoot->setZValue(4);
_localPathRoot->setParentItem(_root);
_gtGraphRoot = (QGraphicsItem *)this->scene()->addEllipse(QRectF(-0.0001,-0.0001,0.0001,0.0001));
_gtGraphRoot->setZValue(2);
_gtGraphRoot->setParentItem(_root);
this->restoreDefaults(); this->restoreDefaults();
this->fitInView(this->sceneRect(), Qt::KeepAspectRatio); this->fitInView(this->sceneRect(), Qt::KeepAspectRatio);
@@ -258,6 +277,9 @@ void GraphViewer::updateGraph(const std::map<int, Transform> & poses,
const std::multimap<int, Link> & constraints, const std::multimap<int, Link> & constraints,
const std::map<int, int> & mapIds) const std::map<int, int> & mapIds)
{ {
bool wasVisible = _graphRoot->isVisible();
_graphRoot->show();
bool wasEmpty = _nodeItems.size() == 0 && _linkItems.size() == 0; bool wasEmpty = _nodeItems.size() == 0 && _linkItems.size() == 0;
UDEBUG("poses=%d constraints=%d", (int)poses.size(), (int)constraints.size()); UDEBUG("poses=%d constraints=%d", (int)poses.size(), (int)constraints.size());
//Hide nodes and links //Hide nodes and links
@@ -289,7 +311,7 @@ void GraphViewer::updateGraph(const std::map<int, Transform> & poses,
this->scene()->addItem(item); this->scene()->addItem(item);
item->setZValue(20); item->setZValue(20);
item->setColor(_nodeColor); item->setColor(_nodeColor);
item->setParentItem(_root); item->setParentItem(_graphRoot);
_nodeItems.insert(iter->first, item); _nodeItems.insert(iter->first, item);
} }
} }
@@ -344,7 +366,7 @@ void GraphViewer::updateGraph(const std::map<int, Transform> & poses,
linkItem->setPen(p); linkItem->setPen(p);
linkItem->setZValue(10); linkItem->setZValue(10);
this->scene()->addItem(linkItem); this->scene()->addItem(linkItem);
linkItem->setParentItem(_root); linkItem->setParentItem(_graphRoot);
_linkItems.insert(idFrom, linkItem); _linkItems.insert(idFrom, linkItem);
} }
} }
@@ -464,11 +486,15 @@ void GraphViewer::updateGraph(const std::map<int, Transform> & poses,
this->fitInView(rect.adjusted(-rect.width()/2.0f, -rect.height()/2.0f, rect.width()/2.0f, rect.height()/2.0f), Qt::KeepAspectRatio); this->fitInView(rect.adjusted(-rect.width()/2.0f, -rect.height()/2.0f, rect.width()/2.0f, rect.height()/2.0f), Qt::KeepAspectRatio);
} }
_graphRoot->setVisible(wasVisible);
UDEBUG("_nodeItems=%d, _linkItems=%d", _nodeItems.size(), _linkItems.size()); UDEBUG("_nodeItems=%d, _linkItems=%d", _nodeItems.size(), _linkItems.size());
} }
void GraphViewer::updateGTGraph(const std::map<int, Transform> & poses) void GraphViewer::updateGTGraph(const std::map<int, Transform> & poses)
{ {
bool wasVisible = _gtGraphRoot->isVisible();
_gtGraphRoot->show();
bool wasEmpty = _gtNodeItems.size() == 0 && _gtLinkItems.size() == 0; bool wasEmpty = _gtNodeItems.size() == 0 && _gtLinkItems.size() == 0;
UDEBUG("poses=%d", (int)poses.size()); UDEBUG("poses=%d", (int)poses.size());
//Hide nodes and links //Hide nodes and links
@@ -500,7 +526,7 @@ void GraphViewer::updateGTGraph(const std::map<int, Transform> & poses)
this->scene()->addItem(item); this->scene()->addItem(item);
item->setZValue(20); item->setZValue(20);
item->setColor(_gtPathColor); item->setColor(_gtPathColor);
item->setParentItem(_root); item->setParentItem(_gtGraphRoot);
_gtNodeItems.insert(iter->first, item); _gtNodeItems.insert(iter->first, item);
} }
@@ -537,7 +563,7 @@ void GraphViewer::updateGTGraph(const std::map<int, Transform> & poses)
linkItem->setPen(p); linkItem->setPen(p);
linkItem->setZValue(10); linkItem->setZValue(10);
this->scene()->addItem(linkItem); this->scene()->addItem(linkItem);
linkItem->setParentItem(_root); linkItem->setParentItem(_gtGraphRoot);
_gtLinkItems.insert(iterPrevious->first, linkItem); _gtLinkItems.insert(iterPrevious->first, linkItem);
} }
if(linkItem) if(linkItem)
@@ -585,6 +611,8 @@ void GraphViewer::updateGTGraph(const std::map<int, Transform> & poses)
} }
} }
_gtGraphRoot->setVisible(wasVisible);
UDEBUG("_gtNodeItems=%d, _gtLinkItems=%d", _gtNodeItems.size(), _gtLinkItems.size()); UDEBUG("_gtNodeItems=%d, _gtLinkItems=%d", _gtNodeItems.size(), _gtLinkItems.size());
} }
@@ -670,7 +698,7 @@ void GraphViewer::setGlobalPath(const std::vector<std::pair<int, Transform> > &
item->setColor(_globalPathColor); item->setColor(_globalPathColor);
this->scene()->addItem(item); this->scene()->addItem(item);
item->setZValue(15); item->setZValue(15);
item->setParentItem(_root); item->setParentItem(_globalPathRoot);
_globalPathLinkItems.insert(idFrom, item); _globalPathLinkItems.insert(idFrom, item);
} }
} }
@@ -707,6 +735,9 @@ void GraphViewer::setLocalRadius(float radius)
void GraphViewer::updateLocalPath(const std::vector<int> & localPath) void GraphViewer::updateLocalPath(const std::vector<int> & localPath)
{ {
bool wasVisible = _localPathRoot->isVisible();
_localPathRoot->show();
for(QMultiMap<int, LinkItem*>::iterator iter = _localPathLinkItems.begin(); iter!=_localPathLinkItems.end(); ++iter) for(QMultiMap<int, LinkItem*>::iterator iter = _localPathLinkItems.begin(); iter!=_localPathLinkItems.end(); ++iter)
{ {
iter.value()->hide(); iter.value()->hide();
@@ -746,7 +777,7 @@ void GraphViewer::updateLocalPath(const std::vector<int> & localPath)
item->setColor(_localPathColor); item->setColor(_localPathColor);
this->scene()->addItem(item); this->scene()->addItem(item);
item->setZValue(16); // just over the global path item->setZValue(16); // just over the global path
item->setParentItem(_root); item->setParentItem(_localPathRoot);
_localPathLinkItems.insert(idFrom, item); _localPathLinkItems.insert(idFrom, item);
} }
} }
@@ -766,6 +797,7 @@ void GraphViewer::updateLocalPath(const std::vector<int> & localPath)
++iter; ++iter;
} }
} }
_localPathRoot->setVisible(wasVisible);
} }
void GraphViewer::clearGraph() void GraphViewer::clearGraph()
@@ -838,6 +870,10 @@ void GraphViewer::saveSettings(QSettings & settings, const QString & group) cons
settings.setValue("local_radius_visible", this->isLocalRadiusVisible()); settings.setValue("local_radius_visible", this->isLocalRadiusVisible());
settings.setValue("loop_closure_outlier_thr", this->getLoopClosureOutlierThr()); settings.setValue("loop_closure_outlier_thr", this->getLoopClosureOutlierThr());
settings.setValue("max_link_length", this->getMaxLinkLength()); settings.setValue("max_link_length", this->getMaxLinkLength());
settings.setValue("graph_visible", this->isGraphVisible());
settings.setValue("global_path_visible", this->isGlobalPathVisible());
settings.setValue("local_path_visible", this->isLocalPathVisible());
settings.setValue("gt_graph_visible", this->isGtGraphVisible());
if(!group.isEmpty()) if(!group.isEmpty())
{ {
settings.endGroup(); settings.endGroup();
@@ -873,6 +909,10 @@ void GraphViewer::loadSettings(QSettings & settings, const QString & group)
this->setIntraInterSessionColorsEnabled(settings.value("intra_inter_session_colors_enabled", this->isIntraInterSessionColorsEnabled()).toBool()); this->setIntraInterSessionColorsEnabled(settings.value("intra_inter_session_colors_enabled", this->isIntraInterSessionColorsEnabled()).toBool());
this->setLoopClosureOutlierThr(settings.value("loop_closure_outlier_thr", this->getLoopClosureOutlierThr()).toDouble()); this->setLoopClosureOutlierThr(settings.value("loop_closure_outlier_thr", this->getLoopClosureOutlierThr()).toDouble());
this->setMaxLinkLength(settings.value("max_link_length", this->getMaxLinkLength()).toDouble()); this->setMaxLinkLength(settings.value("max_link_length", this->getMaxLinkLength()).toDouble());
this->setGraphVisible(settings.value("graph_visible", this->isGraphVisible()).toBool());
this->setGlobalPathVisible(settings.value("global_path_visible", this->isGlobalPathVisible()).toBool());
this->setLocalPathVisible(settings.value("local_path_visible", this->isLocalPathVisible()).toBool());
this->setGtGraphVisible(settings.value("gt_graph_visible", this->isGtGraphVisible()).toBool());
if(!group.isEmpty()) if(!group.isEmpty())
{ {
settings.endGroup(); settings.endGroup();
@@ -895,6 +935,22 @@ bool GraphViewer::isLocalRadiusVisible() const
{ {
return _localRadius->isVisible(); return _localRadius->isVisible();
} }
bool GraphViewer::isGraphVisible() const
{
return _graphRoot->isVisible();
}
bool GraphViewer::isGlobalPathVisible() const
{
return _globalPathRoot->isVisible();
}
bool GraphViewer::isLocalPathVisible() const
{
return _localPathRoot->isVisible();
}
bool GraphViewer::isGtGraphVisible() const
{
return _gtGraphRoot->isVisible();
}
void GraphViewer::setWorkingDirectory(const QString & path) void GraphViewer::setWorkingDirectory(const QString & path)
{ {
@@ -1114,6 +1170,22 @@ void GraphViewer::setMaxLinkLength(float value)
{ {
_maxLinkLength = value; _maxLinkLength = value;
} }
void GraphViewer::setGraphVisible(bool visible)
{
_graphRoot->setVisible(!_graphRoot->isVisible());
}
void GraphViewer::setGlobalPathVisible(bool visible)
{
_globalPathRoot->setVisible(!_globalPathRoot->isVisible());
}
void GraphViewer::setLocalPathVisible(bool visible)
{
_localPathRoot->setVisible(!_localPathRoot->isVisible());
}
void GraphViewer::setGtGraphVisible(bool visible)
{
_gtGraphRoot->setVisible(!_gtGraphRoot->isVisible());
}
void GraphViewer::restoreDefaults() void GraphViewer::restoreDefaults()
{ {
@@ -1127,9 +1199,12 @@ void GraphViewer::restoreDefaults()
setVirtualLoopClosureColor(Qt::magenta); setVirtualLoopClosureColor(Qt::magenta);
setNeighborMergedColor(QColor(255,170,0)); setNeighborMergedColor(QColor(255,170,0));
setGridMapVisible(true); setGridMapVisible(true);
setGraphVisible(true);
setGlobalPathVisible(true);
setLocalPathVisible(true);
setGtGraphVisible(true);
} }
void GraphViewer::wheelEvent ( QWheelEvent * event ) void GraphViewer::wheelEvent ( QWheelEvent * event )
{ {
if(event->delta() < 0) if(event->delta() < 0)
@@ -1211,10 +1286,13 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
QAction * aChangeMaxLinkLength = menu.addAction(tr("Set maximum link length...")); QAction * aChangeMaxLinkLength = menu.addAction(tr("Set maximum link length..."));
menu.addSeparator(); menu.addSeparator();
QAction * aShowHideGridMap; QAction * aShowHideGridMap;
QAction * aShowHideGraph;
QAction * aShowHideOrigin; QAction * aShowHideOrigin;
QAction * aShowHideReferential; QAction * aShowHideReferential;
QAction * aShowHideLocalRadius; QAction * aShowHideLocalRadius;
QAction * aClearGlobalPath; QAction * aShowHideGlobalPath;
QAction * aShowHideLocalPath;
QAction * aShowHideGtGraph;
if(_gridMap->isVisible()) if(_gridMap->isVisible())
{ {
aShowHideGridMap = menu.addAction(tr("Hide grid map")); aShowHideGridMap = menu.addAction(tr("Hide grid map"));
@@ -1247,15 +1325,43 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
{ {
aShowHideLocalRadius = menu.addAction(tr("Show local radius")); aShowHideLocalRadius = menu.addAction(tr("Show local radius"));
} }
if(_globalPathLinkItems.size() && _globalPathLinkItems.begin().value()->isVisible()) if(_graphRoot->isVisible())
{ {
aClearGlobalPath = menu.addAction(tr("Hide global path")); aShowHideGraph = menu.addAction(tr("Hide graph"));
} }
else else
{ {
aClearGlobalPath = menu.addAction(tr("Show global path")); aShowHideGraph = menu.addAction(tr("Show graph"));
} }
aClearGlobalPath->setEnabled(_globalPathLinkItems.size()); if(_globalPathRoot->isVisible())
{
aShowHideGlobalPath = menu.addAction(tr("Hide global path"));
}
else
{
aShowHideGlobalPath = menu.addAction(tr("Show global path"));
}
if(_localPathRoot->isVisible())
{
aShowHideLocalPath = menu.addAction(tr("Hide local path"));
}
else
{
aShowHideLocalPath = menu.addAction(tr("Show local path"));
}
if(_gtGraphRoot->isVisible())
{
aShowHideGtGraph = menu.addAction(tr("Hide ground truth graph"));
}
else
{
aShowHideGtGraph = menu.addAction(tr("Show ground truth graph"));
}
aShowHideGridMap->setEnabled(!_gridMap->pixmap().isNull());
aShowHideGraph->setEnabled(_nodeItems.size());
aShowHideGlobalPath->setEnabled(_globalPathLinkItems.size());
aShowHideLocalPath->setEnabled(_localPathLinkItems.size());
aShowHideGtGraph->setEnabled(_gtNodeItems.size());
menu.addSeparator(); menu.addSeparator();
QAction * aRestoreDefaults = menu.addAction(tr("Restore defaults")); QAction * aRestoreDefaults = menu.addAction(tr("Restore defaults"));
@@ -1524,12 +1630,21 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event)
{ {
this->restoreDefaults(); this->restoreDefaults();
} }
else if(r == aClearGlobalPath) else if(r == aShowHideGraph)
{ {
for(QMap<int, LinkItem*>::iterator iter=_globalPathLinkItems.begin(); iter!=_globalPathLinkItems.end(); ++iter) this->setGraphVisible(!this->isGraphVisible());
{ }
iter.value()->setVisible(!iter.value()->isVisible()); else if(r == aShowHideGlobalPath)
} {
this->setGlobalPathVisible(!this->isGlobalPathVisible());
}
else if(r == aShowHideLocalPath)
{
this->setLocalPathVisible(!this->isLocalPathVisible());
}
else if(r == aShowHideGtGraph)
{
this->setGtGraphVisible(!this->isGtGraphVisible());
} }
if(r) if(r)
{ {