Skip to content

Commit

Permalink
added code to highlight selected nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Perez authored and Chuck Ellison committed Sep 23, 2024
1 parent 1554b4f commit 331b346
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions guilib/include/rtabmap/gui/GraphViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class RTABMAP_GUI_EXPORT GraphViewer : public QGraphicsView {
void setNodeVisible(bool visible);
void setNodeRadius(float radius);
void setLinkWidth(float width);
void setNodeA(const int value);
void setNodeB(const int value);
void setNodeColor(const QColor & color);
void setNodeColorA(const QColor & color);
void setNodeColorB(const QColor & color);
void setNodeOdomCacheColor(const QColor & color);
void setCurrentGoalColor(const QColor & color);
void setNeighborColor(const QColor & color);
Expand Down Expand Up @@ -181,6 +185,8 @@ public Q_SLOTS:
private:
QString _workingDirectory;
QColor _nodeColor;
QColor _nodeColorA;
QColor _nodeColorB;
QColor _nodeOdomCacheColor;
QColor _currentGoalColor;
QColor _neighborColor;
Expand All @@ -206,6 +212,8 @@ public Q_SLOTS:
QGraphicsItem * _localPathRoot;
QGraphicsItem * _gtGraphRoot;
QGraphicsItem * _gpsGraphRoot;
NodeItem* _currentNodeA;
NodeItem* _currentNodeB;
QMap<int, NodeItem*> _nodeItems;
QMultiMap<int, LinkItem*> _linkItems;
QMap<int, NodeItem*> _gtNodeItems;
Expand Down
4 changes: 4 additions & 0 deletions guilib/src/DatabaseViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,8 @@ void DatabaseViewer::graphLinkSelected(int from, int to)

void DatabaseViewer::sliderAValueChanged(int value)
{
ui_->graphViewer->setNodeA(ids_.at(value));

this->update(value,
ui_->spinBox_indexA,
ui_->label_parentsA,
Expand Down Expand Up @@ -4640,6 +4642,8 @@ void DatabaseViewer::sliderAValueChanged(int value)

void DatabaseViewer::sliderBValueChanged(int value)
{
ui_->graphViewer->setNodeB(ids_.at(value));

this->update(value,
ui_->spinBox_indexB,
ui_->label_parentsB,
Expand Down
78 changes: 78 additions & 0 deletions guilib/src/GraphViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class LinkItem: public QGraphicsLineItem
GraphViewer::GraphViewer(QWidget * parent) :
QGraphicsView(parent),
_nodeColor(Qt::blue),
_nodeColorA(Qt::yellow),
_nodeColorB(Qt::magenta),
_nodeOdomCacheColor(Qt::darkGreen),
_currentGoalColor(Qt::darkMagenta),
_neighborColor(Qt::blue),
Expand Down Expand Up @@ -321,6 +323,9 @@ GraphViewer::GraphViewer(QWidget * parent) :
_viewPlane(XY),
_ensureFrameVisible(true)
{
_currentNodeA = nullptr;
_currentNodeB = nullptr;

this->setScene(new QGraphicsScene(this));
this->setDragMode(QGraphicsView::ScrollHandDrag);
_workingDirectory = QDir::homePath();
Expand Down Expand Up @@ -1459,6 +1464,38 @@ void GraphViewer::setNodeColor(const QColor & color)
iter.value()->setColor(_nodeColor);
}
}
void GraphViewer::setNodeColorA(const QColor & color)
{
_nodeColorA = color;
QPen border = QPen(_nodeColorA);
if(_currentNodeA != nullptr)
{
if(_currentNodeA->id() != 0)
{
if(_nodeItems.contains(_currentNodeA->id()))
{
border.setWidth(_linkWidth*100.0f);
_currentNodeA->setPen(border);
}
}
}
}
void GraphViewer::setNodeColorB(const QColor & color)
{
_nodeColorB = color;
QPen border = QPen(_nodeColorB);
if(_currentNodeB != nullptr)
{
if(_currentNodeB->id() != 0)
{
if(_nodeItems.contains(_currentNodeB->id()))
{
border.setWidth(_linkWidth*100.0f);
_currentNodeB->setPen(border);
}
}
}
}
void GraphViewer::setNodeOdomCacheColor(const QColor & color)
{
_nodeOdomCacheColor = color;
Expand All @@ -1470,6 +1507,47 @@ void GraphViewer::setNodeOdomCacheColor(const QColor & color)
}
}
}
void GraphViewer::setNodeA(int value){

QPen border = QPen(_nodeColorA);
QMap<int, NodeItem*>::iterator iter = _nodeItems.find(value);
if(iter != _nodeItems.end()){
if(_currentNodeA != nullptr){
if(_currentNodeA->id() != 0)
{
if(_nodeItems.contains(_currentNodeA->id()))
{
border.setWidth(0);
_currentNodeA->setPen(border);
}
}
}
_currentNodeA = iter.value();
border.setWidth(_linkWidth*100.0f);
_currentNodeA->setPen(QPen(border));
}
}
void GraphViewer::setNodeB(int value){

QPen border = QPen(_nodeColorB);
QMap<int, NodeItem*>::iterator iter = _nodeItems.find(value);

if(iter != _nodeItems.end()){
if(_currentNodeB != nullptr){
if(_currentNodeB->id() != 0)
{
if(_nodeItems.contains(_currentNodeB->id()))
{
border.setWidth(0);
_currentNodeB->setPen(border);
}
}
}
_currentNodeB = iter.value();
border.setWidth(_linkWidth*100.0f);
_currentNodeB->setPen(QPen(border));
}
}
void GraphViewer::setCurrentGoalColor(const QColor & color)
{
_currentGoalColor = color;
Expand Down

0 comments on commit 331b346

Please sign in to comment.