From ddb9b546ace55ca0bdf53fab3cfc9f7bcc579262 Mon Sep 17 00:00:00 2001 From: Chuck Ellison Date: Tue, 17 Sep 2024 16:49:02 -0500 Subject: [PATCH 1/2] Clicking Nodes\Links brings them up in viewer --- guilib/include/rtabmap/gui/DatabaseViewer.h | 3 + guilib/include/rtabmap/gui/GraphViewer.h | 8 ++ guilib/src/DatabaseViewer.cpp | 117 +++++++++++++++++++- guilib/src/GraphViewer.cpp | 116 ++++++++++++++++++- guilib/src/ui/DatabaseViewer.ui | 6 + 5 files changed, 247 insertions(+), 3 deletions(-) diff --git a/guilib/include/rtabmap/gui/DatabaseViewer.h b/guilib/include/rtabmap/gui/DatabaseViewer.h index f33a97622d..36e6255a80 100644 --- a/guilib/include/rtabmap/gui/DatabaseViewer.h +++ b/guilib/include/rtabmap/gui/DatabaseViewer.h @@ -75,6 +75,7 @@ class RTABMAP_GUI_EXPORT DatabaseViewer : public QMainWindow bool openDatabase(const QString & path, const ParametersMap & overridenParameters = ParametersMap()); bool isSavedMaximized() const {return savedMaximized_;} void showCloseButton(bool visible = true); + int idToIndex(int id); protected: virtual void showEvent(QShowEvent* anEvent); @@ -133,6 +134,8 @@ private Q_SLOTS: void graphLinkSelected(int, int); void sliderAValueChanged(int); void sliderBValueChanged(int); + void spinBoxAValueChanged(int); + void spinBoxBValueChanged(int); void sliderAMoved(int); void sliderBMoved(int); void update3dView(); diff --git a/guilib/include/rtabmap/gui/GraphViewer.h b/guilib/include/rtabmap/gui/GraphViewer.h index 9e8996a582..85aab1ef2e 100644 --- a/guilib/include/rtabmap/gui/GraphViewer.h +++ b/guilib/include/rtabmap/gui/GraphViewer.h @@ -33,8 +33,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include #include #include +#include "rtabmap/gui/DatabaseViewer.h" #include #include #include @@ -125,12 +128,16 @@ class RTABMAP_GUI_EXPORT GraphViewer : public QGraphicsView { bool isEnsureFrameVisible() const; // setters + void setDatabase(DatabaseViewer* db_); + void setSlider_A(QSlider *slider_A); + void setSlider_B(QSlider *slider_B); void setWorkingDirectory(const QString & path); void setNodeVisible(bool visible); void setNodeRadius(float radius); void setLinkWidth(float width); void setNodeColor(const QColor & color); void setNodeOdomCacheColor(const QColor & color); + void highlightCurrentNode(int value); void setCurrentGoalColor(const QColor & color); void setNeighborColor(const QColor & color); void setGlobalLoopClosureColor(const QColor & color); @@ -235,6 +242,7 @@ public Q_SLOTS: bool _mouseTracking; ViewPlane _viewPlane; bool _ensureFrameVisible; + NodeItem* previousNode; }; } /* namespace rtabmap */ diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp index 12129a748f..08bab589bd 100644 --- a/guilib/src/DatabaseViewer.cpp +++ b/guilib/src/DatabaseViewer.cpp @@ -351,6 +351,12 @@ DatabaseViewer::DatabaseViewer(const QString & ini, QWidget * parent) : connect(ui_->horizontalSlider_B, SIGNAL(valueChanged(int)), this, SLOT(sliderBValueChanged(int))); connect(ui_->horizontalSlider_A, SIGNAL(sliderMoved(int)), this, SLOT(sliderAMoved(int))); connect(ui_->horizontalSlider_B, SIGNAL(sliderMoved(int)), this, SLOT(sliderBMoved(int))); + + ui_->spinBox_A->setEnabled(false); + ui_->spinBox_B->setEnabled(false); + connect(ui_->spinBox_A, SIGNAL(valueChanged(int)), this, SLOT(spinBoxAValueChanged(int))); + connect(ui_->spinBox_B, SIGNAL(valueChanged(int)), this, SLOT(spinBoxBValueChanged(int))); + connect(ui_->toolButton_edit_priorA, SIGNAL(clicked(bool)), this, SLOT(editConstraint())); connect(ui_->toolButton_edit_priorB, SIGNAL(clicked(bool)), this, SLOT(editConstraint())); connect(ui_->toolButton_remove_priorA, SIGNAL(clicked(bool)), this, SLOT(rejectConstraint())); @@ -848,6 +854,9 @@ bool DatabaseViewer::openDatabase(const QString & path, const ParametersMap & ov } databaseFileName_ = UFile::getName(path.toStdString()); ui_->graphViewer->setWorkingDirectory(pathDatabase_); + ui_->graphViewer->setDatabase(this); + ui_->graphViewer->setSlider_A(ui_->horizontalSlider_A); + ui_->graphViewer->setSlider_B(ui_->horizontalSlider_B); // look if there are saved parameters ParametersMap parameters = dbDriver_->getLastParameters(); @@ -1151,11 +1160,19 @@ bool DatabaseViewer::closeDatabase() ui_->horizontalSlider_A->setMaximum(0); ui_->horizontalSlider_B->setEnabled(false); ui_->horizontalSlider_B->setMaximum(0); - ui_->label_idA->setText("NaN"); - ui_->label_idB->setText("NaN"); sliderAValueChanged(0); sliderBValueChanged(0); + ui_->spinBox_A->setEnabled(false); + ui_->spinBox_A->setMaximum(0); + ui_->spinBox_B->setEnabled(false); + ui_->spinBox_B->setMaximum(0); + spinBoxAValueChanged(0); + spinBoxBValueChanged(0); + + ui_->label_idA->setText("NaN"); + ui_->label_idB->setText("NaN"); + constraintsViewer_->clear(); constraintsViewer_->refreshView(); @@ -2130,11 +2147,24 @@ void DatabaseViewer::updateIds() ui_->horizontalSlider_B->setSliderPosition(0); sliderAValueChanged(0); sliderBValueChanged(0); + + ui_->spinBox_A->setMinimum(0); + ui_->spinBox_B->setMinimum(0); + ui_->spinBox_A->setMaximum(ids_.size()-1); + ui_->spinBox_B->setMaximum(ids_.size()-1); + ui_->spinBox_A->setEnabled(true); + ui_->spinBox_B->setEnabled(true); + spinBoxAValueChanged(0); + spinBoxBValueChanged(0); } else { ui_->horizontalSlider_A->setEnabled(false); ui_->horizontalSlider_B->setEnabled(false); + + ui_->spinBox_A->setEnabled(false); + ui_->spinBox_B->setEnabled(false); + ui_->label_idA->setText("NaN"); ui_->label_idB->setText("NaN"); } @@ -4592,6 +4622,10 @@ void DatabaseViewer::graphLinkSelected(int from, int to) void DatabaseViewer::sliderAValueChanged(int value) { + ui_->spinBox_A->blockSignals(true); + ui_->spinBox_A->setValue(value); + ui_->spinBox_A->blockSignals(false); + this->update(value, ui_->label_indexA, ui_->label_parentsA, @@ -4619,6 +4653,10 @@ void DatabaseViewer::sliderAValueChanged(int value) void DatabaseViewer::sliderBValueChanged(int value) { + ui_->spinBox_B->blockSignals(true); + ui_->spinBox_B->setValue(value); + ui_->spinBox_B->blockSignals(false); + this->update(value, ui_->label_indexB, ui_->label_parentsB, @@ -4644,6 +4682,71 @@ void DatabaseViewer::sliderBValueChanged(int value) true); } +void DatabaseViewer::spinBoxAValueChanged(int value) +{ + ui_->horizontalSlider_A->blockSignals(true); + ui_->horizontalSlider_A->blockSignals(false); + + this->update(value, + ui_->label_indexA, + ui_->label_parentsA, + ui_->label_childrenA, + ui_->label_weightA, + ui_->label_labelA, + ui_->label_stampA, + ui_->graphicsView_A, + ui_->label_idA, + ui_->label_mapA, + ui_->label_poseA, + ui_->label_optposeA, + ui_->label_velA, + ui_->label_calibA, + ui_->label_scanA, + ui_->label_gravityA, + ui_->label_priorA, + ui_->toolButton_edit_priorA, + ui_->toolButton_remove_priorA, + ui_->label_gpsA, + ui_->label_gtA, + ui_->label_sensorsA, + true); +} + +void DatabaseViewer::spinBoxBValueChanged(int value) +{ + ui_->horizontalSlider_B->blockSignals(true); + ui_->horizontalSlider_B->setValue(value); + ui_->horizontalSlider_B->blockSignals(false); + + this->update(value, + ui_->label_indexB, + ui_->label_parentsB, + ui_->label_childrenB, + ui_->label_weightB, + ui_->label_labelB, + ui_->label_stampB, + ui_->graphicsView_B, + ui_->label_idB, + ui_->label_mapB, + ui_->label_poseB, + ui_->label_optposeB, + ui_->label_velB, + ui_->label_calibB, + ui_->label_scanB, + ui_->label_gravityB, + ui_->label_priorB, + ui_->toolButton_edit_priorB, + ui_->toolButton_remove_priorB, + ui_->label_gpsB, + ui_->label_gtB, + ui_->label_sensorsB, + true); +} + +int DatabaseViewer::idToIndex(int id){ + return idToIndex_.value(id); +} + void DatabaseViewer::update(int value, QLabel * labelIndex, QLabel * labelParents, @@ -6326,6 +6429,16 @@ void DatabaseViewer::updateConstraintView( ui_->horizontalSlider_B->setValue(idToIndex_.value(link.to())); ui_->horizontalSlider_A->blockSignals(false); ui_->horizontalSlider_B->blockSignals(false); + + ui_->spinBox_A->blockSignals(true); + ui_->spinBox_B->blockSignals(true); + if(link.from()>0) + ui_->spinBox_A->setValue(idToIndex_.value(link.from())); + if(link.to() > 0) + ui_->spinBox_B->setValue(idToIndex_.value(link.to())); + ui_->spinBox_A->blockSignals(false); + ui_->spinBox_B->blockSignals(false); + if(link.from()>0) this->update(idToIndex_.value(link.from()), ui_->label_indexA, diff --git a/guilib/src/GraphViewer.cpp b/guilib/src/GraphViewer.cpp index bbd6618775..37ee4aaad9 100644 --- a/guilib/src/GraphViewer.cpp +++ b/guilib/src/GraphViewer.cpp @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "rtabmap/gui/GraphViewer.h" - +#include "ui_DatabaseViewer.h" #include #include #include @@ -70,6 +70,16 @@ namespace rtabmap { class NodeItem: public QGraphicsEllipseItem { public: + //static database object used to provide more access from NodeItem + static rtabmap::DatabaseViewer* db_object; + static QSlider* slider_A; + static QSlider* slider_B; + static bool show_border; + + QPen noBorder; + QPen border; + bool node_selected = false; + // in meter NodeItem(int id, int mapId, const Transform & pose, float radius, int weight, GraphViewer::ViewPlane plane, float linkWidth) : QGraphicsEllipseItem(QRectF(-radius*100.0f,-radius*100.0f,radius*100.0f*2.0f,radius*100.0f*2.0f)), @@ -85,6 +95,7 @@ class NodeItem: public QGraphicsEllipseItem float r,p,yaw; pose.getEulerAngles(r, p, yaw); radius*=100.0f; + _radius = radius; _line = new QGraphicsLineItem(0,0,-radius*sin(yaw),-radius*cos(yaw), this); QPen pen = _line->pen(); pen.setWidth(linkWidth*100.0f); @@ -101,6 +112,12 @@ class NodeItem: public QGraphicsEllipseItem b.setColor(color); this->setBrush(b); + noBorder = QPen(color); + border = QPen(Qt::red); + border.setWidth((int)_radius/2 + 1); + noBorder.setWidth(0); + this->setPen(QPen(noBorder)); + QPen pen = _line->pen(); pen.setColor(QColor(255-color.red(), 255-color.green(), 255-color.blue())); _line->setPen(pen); @@ -113,6 +130,14 @@ class NodeItem: public QGraphicsEllipseItem radius*=100.0f; this->setRect(-radius, -radius, radius*2.0f, radius*2.0f); _line->setLine(0,0,-radius*sin(yaw),-radius*cos(yaw)); + + border.setWidth((int)radius/2 + 1); + noBorder.setWidth(0); + + if(node_selected && NodeItem::show_border) + this->setPen(QPen(border)); + else + this->setPen(QPen(noBorder)); } int id() const {return _id;}; @@ -162,14 +187,37 @@ class NodeItem: public QGraphicsEllipseItem QGraphicsEllipseItem::hoverEnterEvent(event); } + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) + { + if(_swapAtoB) + { + slider_A->setValue(id()); + _swapAtoB = false; + } + else + { + slider_B->setValue(id()); + _swapAtoB = true; + } + QGraphicsEllipseItem::mousePressEvent(event); + } + private: int _id; int _mapId; int _weight; + float _radius; Transform _pose; + bool _swapAtoB; QGraphicsLineItem * _line; }; +//Define static variables +DatabaseViewer* NodeItem::db_object = nullptr; +QSlider* NodeItem::slider_A = nullptr; +QSlider* NodeItem::slider_B = nullptr; +bool NodeItem::show_border = true; + class NodeGPSItem: public NodeItem { public: @@ -196,6 +244,11 @@ class NodeGPSItem: public NodeItem class LinkItem: public QGraphicsLineItem { public: + + static DatabaseViewer* db_object; + static QSlider* slider_A; + static QSlider* slider_B; + // in meter LinkItem(int from, int to, const Transform & poseA, const Transform & poseB, const Link & link, bool interSessionClosure, GraphViewer::ViewPlane plane) : _from(from), @@ -272,6 +325,12 @@ class LinkItem: public QGraphicsLineItem QGraphicsLineItem::hoverEnterEvent(event); } + virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) + { + slider_A->setValue(db_object->idToIndex(_from)); + slider_B->setValue(db_object->idToIndex(_to)); + } + private: int _from; int _to; @@ -281,6 +340,11 @@ class LinkItem: public QGraphicsLineItem bool _interSession; }; + +QSlider* LinkItem::slider_A = nullptr; +QSlider* LinkItem::slider_B = nullptr; +DatabaseViewer* LinkItem::db_object = nullptr; + GraphViewer::GraphViewer(QWidget * parent) : QGraphicsView(parent), _nodeColor(Qt::blue), @@ -466,6 +530,8 @@ GraphViewer::GraphViewer(QWidget * parent) : this->restoreDefaults(); this->fitInView(this->sceneRect(), Qt::KeepAspectRatio); + + previousNode = nullptr; } GraphViewer::~GraphViewer() @@ -1400,6 +1466,21 @@ bool GraphViewer::isEnsureFrameVisible() const return _ensureFrameVisible; } +void GraphViewer::setDatabase(DatabaseViewer* db_){ + NodeItem::db_object = db_; + LinkItem::db_object = db_; +} + +void GraphViewer::setSlider_A(QSlider *slider_A){ + NodeItem::slider_A = slider_A; + LinkItem::slider_A = slider_A; +} + +void GraphViewer::setSlider_B(QSlider *slider_B){ + NodeItem::slider_B = slider_B; + LinkItem::slider_B = slider_B; +} + void GraphViewer::setWorkingDirectory(const QString & path) { _workingDirectory = path; @@ -1459,6 +1540,7 @@ void GraphViewer::setNodeColor(const QColor & color) iter.value()->setColor(_nodeColor); } } + void GraphViewer::setNodeOdomCacheColor(const QColor & color) { _nodeOdomCacheColor = color; @@ -1470,6 +1552,27 @@ void GraphViewer::setNodeOdomCacheColor(const QColor & color) } } } + +void GraphViewer::highlightCurrentNode(int value){ + + QMap::iterator iter = _nodeItems.find(value); + if(iter != _nodeItems.end()){ + NodeItem* node = iter.value(); + if(previousNode != nullptr){ + previousNode->node_selected = false; + if(NodeItem::show_border){ + previousNode->setPen(QPen(previousNode->noBorder)); + } + + } + previousNode = node; + node->node_selected = true; + if(NodeItem::show_border){ + node->setPen(QPen(node->border)); + } + } +} + void GraphViewer::setCurrentGoalColor(const QColor & color) { _currentGoalColor = color; @@ -1908,6 +2011,7 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) menu.addSeparator(); QAction * aSetNodeSize = menu.addAction(tr("Set node radius...")); + QAction * aToggleNodeBorder = menu.addAction(tr("Toggle node border...")); QAction * aSetLinkSize = menu.addAction(tr("Set link width...")); QAction * aChangeMaxLinkLength = menu.addAction(tr("Set maximum link length...")); menu.addSeparator(); @@ -2387,6 +2491,16 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) setNodeRadius(value); } } + else if(r == aToggleNodeBorder){ + + if(NodeItem::show_border){ + NodeItem::show_border = false; + previousNode->setPen(QPen(previousNode->noBorder)); + } else { + NodeItem::show_border = true; + previousNode->setPen(QPen(previousNode->border)); + } + } else if(r == aSetLinkSize) { bool ok; diff --git a/guilib/src/ui/DatabaseViewer.ui b/guilib/src/ui/DatabaseViewer.ui index aef27723fa..d8ea66a57b 100644 --- a/guilib/src/ui/DatabaseViewer.ui +++ b/guilib/src/ui/DatabaseViewer.ui @@ -773,6 +773,9 @@ + + + @@ -838,6 +841,9 @@ + + + From 1554b4fc3dd84813bd69c52d096d182d58678c33 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sat, 21 Sep 2024 18:03:05 -0700 Subject: [PATCH 2/2] Removed duplicated feature, kept spin box and single click node event. Removed unrelated border option crashing. --- guilib/include/rtabmap/gui/DatabaseViewer.h | 6 +- guilib/include/rtabmap/gui/GraphViewer.h | 10 +- guilib/src/DatabaseViewer.cpp | 152 +++++--------------- guilib/src/GraphViewer.cpp | 122 +--------------- guilib/src/ui/DatabaseViewer.ui | 36 ++--- 5 files changed, 55 insertions(+), 271 deletions(-) diff --git a/guilib/include/rtabmap/gui/DatabaseViewer.h b/guilib/include/rtabmap/gui/DatabaseViewer.h index 36e6255a80..cb5e2029ca 100644 --- a/guilib/include/rtabmap/gui/DatabaseViewer.h +++ b/guilib/include/rtabmap/gui/DatabaseViewer.h @@ -52,6 +52,7 @@ class QGraphicsView; class QLabel; class QToolButton; class QDialog; +class QSpinBox; namespace rtabmap { @@ -75,7 +76,6 @@ class RTABMAP_GUI_EXPORT DatabaseViewer : public QMainWindow bool openDatabase(const QString & path, const ParametersMap & overridenParameters = ParametersMap()); bool isSavedMaximized() const {return savedMaximized_;} void showCloseButton(bool visible = true); - int idToIndex(int id); protected: virtual void showEvent(QShowEvent* anEvent); @@ -134,8 +134,6 @@ private Q_SLOTS: void graphLinkSelected(int, int); void sliderAValueChanged(int); void sliderBValueChanged(int); - void spinBoxAValueChanged(int); - void spinBoxBValueChanged(int); void sliderAMoved(int); void sliderBMoved(int); void update3dView(); @@ -164,7 +162,7 @@ private Q_SLOTS: void updateIds(); void update(int value, - QLabel * labelIndex, + QSpinBox * spinBoxIndex, QLabel * labelParents, QLabel * labelChildren, QLabel * weight, diff --git a/guilib/include/rtabmap/gui/GraphViewer.h b/guilib/include/rtabmap/gui/GraphViewer.h index 85aab1ef2e..945788d6e6 100644 --- a/guilib/include/rtabmap/gui/GraphViewer.h +++ b/guilib/include/rtabmap/gui/GraphViewer.h @@ -33,11 +33,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include -#include #include #include -#include "rtabmap/gui/DatabaseViewer.h" #include #include #include @@ -128,16 +125,12 @@ class RTABMAP_GUI_EXPORT GraphViewer : public QGraphicsView { bool isEnsureFrameVisible() const; // setters - void setDatabase(DatabaseViewer* db_); - void setSlider_A(QSlider *slider_A); - void setSlider_B(QSlider *slider_B); void setWorkingDirectory(const QString & path); void setNodeVisible(bool visible); void setNodeRadius(float radius); void setLinkWidth(float width); void setNodeColor(const QColor & color); void setNodeOdomCacheColor(const QColor & color); - void highlightCurrentNode(int value); void setCurrentGoalColor(const QColor & color); void setNeighborColor(const QColor & color); void setGlobalLoopClosureColor(const QColor & color); @@ -182,7 +175,7 @@ public Q_SLOTS: protected: virtual void wheelEvent ( QWheelEvent * event ); virtual void mouseMoveEvent(QMouseEvent * event); - virtual void mouseDoubleClickEvent(QMouseEvent * event); + virtual void mousePressEvent(QMouseEvent * event); virtual void contextMenuEvent(QContextMenuEvent * event); private: @@ -242,7 +235,6 @@ public Q_SLOTS: bool _mouseTracking; ViewPlane _viewPlane; bool _ensureFrameVisible; - NodeItem* previousNode; }; } /* namespace rtabmap */ diff --git a/guilib/src/DatabaseViewer.cpp b/guilib/src/DatabaseViewer.cpp index d8a4eea18a..478443e48c 100644 --- a/guilib/src/DatabaseViewer.cpp +++ b/guilib/src/DatabaseViewer.cpp @@ -351,11 +351,10 @@ DatabaseViewer::DatabaseViewer(const QString & ini, QWidget * parent) : connect(ui_->horizontalSlider_B, SIGNAL(valueChanged(int)), this, SLOT(sliderBValueChanged(int))); connect(ui_->horizontalSlider_A, SIGNAL(sliderMoved(int)), this, SLOT(sliderAMoved(int))); connect(ui_->horizontalSlider_B, SIGNAL(sliderMoved(int)), this, SLOT(sliderBMoved(int))); - - ui_->spinBox_A->setEnabled(false); - ui_->spinBox_B->setEnabled(false); - connect(ui_->spinBox_A, SIGNAL(valueChanged(int)), this, SLOT(spinBoxAValueChanged(int))); - connect(ui_->spinBox_B, SIGNAL(valueChanged(int)), this, SLOT(spinBoxBValueChanged(int))); + ui_->spinBox_indexA->setEnabled(false); + ui_->spinBox_indexB->setEnabled(false); + connect(ui_->spinBox_indexA, SIGNAL(valueChanged(int)), this, SLOT(sliderAValueChanged(int))); + connect(ui_->spinBox_indexB, SIGNAL(valueChanged(int)), this, SLOT(sliderBValueChanged(int))); connect(ui_->toolButton_edit_priorA, SIGNAL(clicked(bool)), this, SLOT(editConstraint())); connect(ui_->toolButton_edit_priorB, SIGNAL(clicked(bool)), this, SLOT(editConstraint())); @@ -854,9 +853,6 @@ bool DatabaseViewer::openDatabase(const QString & path, const ParametersMap & ov } databaseFileName_ = UFile::getName(path.toStdString()); ui_->graphViewer->setWorkingDirectory(pathDatabase_); - ui_->graphViewer->setDatabase(this); - ui_->graphViewer->setSlider_A(ui_->horizontalSlider_A); - ui_->graphViewer->setSlider_B(ui_->horizontalSlider_B); // look if there are saved parameters ParametersMap parameters = dbDriver_->getLastParameters(); @@ -1160,18 +1156,15 @@ bool DatabaseViewer::closeDatabase() ui_->horizontalSlider_A->setMaximum(0); ui_->horizontalSlider_B->setEnabled(false); ui_->horizontalSlider_B->setMaximum(0); + ui_->label_idA->setText("NaN"); + ui_->label_idB->setText("NaN"); sliderAValueChanged(0); sliderBValueChanged(0); - ui_->spinBox_A->setEnabled(false); - ui_->spinBox_A->setMaximum(0); - ui_->spinBox_B->setEnabled(false); - ui_->spinBox_B->setMaximum(0); - spinBoxAValueChanged(0); - spinBoxBValueChanged(0); - - ui_->label_idA->setText("NaN"); - ui_->label_idB->setText("NaN"); + ui_->spinBox_indexA->setEnabled(false); + ui_->spinBox_indexA->setMaximum(0); + ui_->spinBox_indexB->setEnabled(false); + ui_->spinBox_indexB->setMaximum(0); constraintsViewer_->clear(); constraintsViewer_->refreshView(); @@ -2137,6 +2130,13 @@ void DatabaseViewer::updateIds() if(ids_.size()) { + ui_->spinBox_indexA->setMinimum(0); + ui_->spinBox_indexB->setMinimum(0); + ui_->spinBox_indexA->setMaximum(ids_.size()-1); + ui_->spinBox_indexB->setMaximum(ids_.size()-1); + ui_->spinBox_indexA->setEnabled(true); + ui_->spinBox_indexB->setEnabled(true); + ui_->horizontalSlider_A->setMinimum(0); ui_->horizontalSlider_B->setMinimum(0); ui_->horizontalSlider_A->setMaximum(ids_.size()-1); @@ -2147,23 +2147,14 @@ void DatabaseViewer::updateIds() ui_->horizontalSlider_B->setSliderPosition(0); sliderAValueChanged(0); sliderBValueChanged(0); - - ui_->spinBox_A->setMinimum(0); - ui_->spinBox_B->setMinimum(0); - ui_->spinBox_A->setMaximum(ids_.size()-1); - ui_->spinBox_B->setMaximum(ids_.size()-1); - ui_->spinBox_A->setEnabled(true); - ui_->spinBox_B->setEnabled(true); - spinBoxAValueChanged(0); - spinBoxBValueChanged(0); } else { ui_->horizontalSlider_A->setEnabled(false); ui_->horizontalSlider_B->setEnabled(false); - ui_->spinBox_A->setEnabled(false); - ui_->spinBox_B->setEnabled(false); + ui_->spinBox_indexA->setEnabled(false); + ui_->spinBox_indexB->setEnabled(false); ui_->label_idA->setText("NaN"); ui_->label_idB->setText("NaN"); @@ -4622,12 +4613,8 @@ void DatabaseViewer::graphLinkSelected(int from, int to) void DatabaseViewer::sliderAValueChanged(int value) { - ui_->spinBox_A->blockSignals(true); - ui_->spinBox_A->setValue(value); - ui_->spinBox_A->blockSignals(false); - this->update(value, - ui_->label_indexA, + ui_->spinBox_indexA, ui_->label_parentsA, ui_->label_childrenA, ui_->label_weightA, @@ -4653,73 +4640,8 @@ void DatabaseViewer::sliderAValueChanged(int value) void DatabaseViewer::sliderBValueChanged(int value) { - ui_->spinBox_B->blockSignals(true); - ui_->spinBox_B->setValue(value); - ui_->spinBox_B->blockSignals(false); - - this->update(value, - ui_->label_indexB, - ui_->label_parentsB, - ui_->label_childrenB, - ui_->label_weightB, - ui_->label_labelB, - ui_->label_stampB, - ui_->graphicsView_B, - ui_->label_idB, - ui_->label_mapB, - ui_->label_poseB, - ui_->label_optposeB, - ui_->label_velB, - ui_->label_calibB, - ui_->label_scanB, - ui_->label_gravityB, - ui_->label_priorB, - ui_->toolButton_edit_priorB, - ui_->toolButton_remove_priorB, - ui_->label_gpsB, - ui_->label_gtB, - ui_->label_sensorsB, - true); -} - -void DatabaseViewer::spinBoxAValueChanged(int value) -{ - ui_->horizontalSlider_A->blockSignals(true); - ui_->horizontalSlider_A->blockSignals(false); - - this->update(value, - ui_->label_indexA, - ui_->label_parentsA, - ui_->label_childrenA, - ui_->label_weightA, - ui_->label_labelA, - ui_->label_stampA, - ui_->graphicsView_A, - ui_->label_idA, - ui_->label_mapA, - ui_->label_poseA, - ui_->label_optposeA, - ui_->label_velA, - ui_->label_calibA, - ui_->label_scanA, - ui_->label_gravityA, - ui_->label_priorA, - ui_->toolButton_edit_priorA, - ui_->toolButton_remove_priorA, - ui_->label_gpsA, - ui_->label_gtA, - ui_->label_sensorsA, - true); -} - -void DatabaseViewer::spinBoxBValueChanged(int value) -{ - ui_->horizontalSlider_B->blockSignals(true); - ui_->horizontalSlider_B->setValue(value); - ui_->horizontalSlider_B->blockSignals(false); - this->update(value, - ui_->label_indexB, + ui_->spinBox_indexB, ui_->label_parentsB, ui_->label_childrenB, ui_->label_weightB, @@ -4743,12 +4665,8 @@ void DatabaseViewer::spinBoxBValueChanged(int value) true); } -int DatabaseViewer::idToIndex(int id){ - return idToIndex_.value(id); -} - void DatabaseViewer::update(int value, - QLabel * labelIndex, + QSpinBox * spinBoxIndex, QLabel * labelParents, QLabel * labelChildren, QLabel * weight, @@ -4774,7 +4692,9 @@ void DatabaseViewer::update(int value, lastSliderIndexBrowsed_ = value; UTimer timer; - labelIndex->setText(QString::number(value)); + spinBoxIndex->blockSignals(true); + spinBoxIndex->setValue(value); + spinBoxIndex->blockSignals(false); labelParents->clear(); labelChildren->clear(); weight->clear(); @@ -6095,7 +6015,9 @@ void DatabaseViewer::updateWordsMatching(const std::vector & inliers) void DatabaseViewer::sliderAMoved(int value) { - ui_->label_indexA->setText(QString::number(value)); + ui_->spinBox_indexA->blockSignals(true); + ui_->spinBox_indexA->setValue(value); + ui_->spinBox_indexA->blockSignals(false); if(value>=0 && value < ids_.size()) { ui_->label_idA->setText(QString::number(ids_.at(value))); @@ -6108,7 +6030,9 @@ void DatabaseViewer::sliderAMoved(int value) void DatabaseViewer::sliderBMoved(int value) { - ui_->label_indexB->setText(QString::number(value)); + ui_->spinBox_indexB->blockSignals(true); + ui_->spinBox_indexB->setValue(value); + ui_->spinBox_indexB->blockSignals(false); if(value>=0 && value < ids_.size()) { ui_->label_idB->setText(QString::number(ids_.at(value))); @@ -6450,19 +6374,9 @@ void DatabaseViewer::updateConstraintView( ui_->horizontalSlider_B->setValue(idToIndex_.value(link.to())); ui_->horizontalSlider_A->blockSignals(false); ui_->horizontalSlider_B->blockSignals(false); - - ui_->spinBox_A->blockSignals(true); - ui_->spinBox_B->blockSignals(true); - if(link.from()>0) - ui_->spinBox_A->setValue(idToIndex_.value(link.from())); - if(link.to() > 0) - ui_->spinBox_B->setValue(idToIndex_.value(link.to())); - ui_->spinBox_A->blockSignals(false); - ui_->spinBox_B->blockSignals(false); - if(link.from()>0) this->update(idToIndex_.value(link.from()), - ui_->label_indexA, + ui_->spinBox_indexA, ui_->label_parentsA, ui_->label_childrenA, ui_->label_weightA, @@ -6487,7 +6401,7 @@ void DatabaseViewer::updateConstraintView( if(link.to()>0) { this->update(idToIndex_.value(link.to()), - ui_->label_indexB, + ui_->spinBox_indexB, ui_->label_parentsB, ui_->label_childrenB, ui_->label_weightB, diff --git a/guilib/src/GraphViewer.cpp b/guilib/src/GraphViewer.cpp index 37ee4aaad9..a237fc70f2 100644 --- a/guilib/src/GraphViewer.cpp +++ b/guilib/src/GraphViewer.cpp @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "rtabmap/gui/GraphViewer.h" -#include "ui_DatabaseViewer.h" + #include #include #include @@ -70,16 +70,6 @@ namespace rtabmap { class NodeItem: public QGraphicsEllipseItem { public: - //static database object used to provide more access from NodeItem - static rtabmap::DatabaseViewer* db_object; - static QSlider* slider_A; - static QSlider* slider_B; - static bool show_border; - - QPen noBorder; - QPen border; - bool node_selected = false; - // in meter NodeItem(int id, int mapId, const Transform & pose, float radius, int weight, GraphViewer::ViewPlane plane, float linkWidth) : QGraphicsEllipseItem(QRectF(-radius*100.0f,-radius*100.0f,radius*100.0f*2.0f,radius*100.0f*2.0f)), @@ -95,7 +85,6 @@ class NodeItem: public QGraphicsEllipseItem float r,p,yaw; pose.getEulerAngles(r, p, yaw); radius*=100.0f; - _radius = radius; _line = new QGraphicsLineItem(0,0,-radius*sin(yaw),-radius*cos(yaw), this); QPen pen = _line->pen(); pen.setWidth(linkWidth*100.0f); @@ -112,12 +101,6 @@ class NodeItem: public QGraphicsEllipseItem b.setColor(color); this->setBrush(b); - noBorder = QPen(color); - border = QPen(Qt::red); - border.setWidth((int)_radius/2 + 1); - noBorder.setWidth(0); - this->setPen(QPen(noBorder)); - QPen pen = _line->pen(); pen.setColor(QColor(255-color.red(), 255-color.green(), 255-color.blue())); _line->setPen(pen); @@ -130,14 +113,6 @@ class NodeItem: public QGraphicsEllipseItem radius*=100.0f; this->setRect(-radius, -radius, radius*2.0f, radius*2.0f); _line->setLine(0,0,-radius*sin(yaw),-radius*cos(yaw)); - - border.setWidth((int)radius/2 + 1); - noBorder.setWidth(0); - - if(node_selected && NodeItem::show_border) - this->setPen(QPen(border)); - else - this->setPen(QPen(noBorder)); } int id() const {return _id;}; @@ -187,37 +162,14 @@ class NodeItem: public QGraphicsEllipseItem QGraphicsEllipseItem::hoverEnterEvent(event); } - virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) - { - if(_swapAtoB) - { - slider_A->setValue(id()); - _swapAtoB = false; - } - else - { - slider_B->setValue(id()); - _swapAtoB = true; - } - QGraphicsEllipseItem::mousePressEvent(event); - } - private: int _id; int _mapId; int _weight; - float _radius; Transform _pose; - bool _swapAtoB; QGraphicsLineItem * _line; }; -//Define static variables -DatabaseViewer* NodeItem::db_object = nullptr; -QSlider* NodeItem::slider_A = nullptr; -QSlider* NodeItem::slider_B = nullptr; -bool NodeItem::show_border = true; - class NodeGPSItem: public NodeItem { public: @@ -244,11 +196,6 @@ class NodeGPSItem: public NodeItem class LinkItem: public QGraphicsLineItem { public: - - static DatabaseViewer* db_object; - static QSlider* slider_A; - static QSlider* slider_B; - // in meter LinkItem(int from, int to, const Transform & poseA, const Transform & poseB, const Link & link, bool interSessionClosure, GraphViewer::ViewPlane plane) : _from(from), @@ -325,12 +272,6 @@ class LinkItem: public QGraphicsLineItem QGraphicsLineItem::hoverEnterEvent(event); } - virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event ) - { - slider_A->setValue(db_object->idToIndex(_from)); - slider_B->setValue(db_object->idToIndex(_to)); - } - private: int _from; int _to; @@ -340,11 +281,6 @@ class LinkItem: public QGraphicsLineItem bool _interSession; }; - -QSlider* LinkItem::slider_A = nullptr; -QSlider* LinkItem::slider_B = nullptr; -DatabaseViewer* LinkItem::db_object = nullptr; - GraphViewer::GraphViewer(QWidget * parent) : QGraphicsView(parent), _nodeColor(Qt::blue), @@ -530,8 +466,6 @@ GraphViewer::GraphViewer(QWidget * parent) : this->restoreDefaults(); this->fitInView(this->sceneRect(), Qt::KeepAspectRatio); - - previousNode = nullptr; } GraphViewer::~GraphViewer() @@ -1466,21 +1400,6 @@ bool GraphViewer::isEnsureFrameVisible() const return _ensureFrameVisible; } -void GraphViewer::setDatabase(DatabaseViewer* db_){ - NodeItem::db_object = db_; - LinkItem::db_object = db_; -} - -void GraphViewer::setSlider_A(QSlider *slider_A){ - NodeItem::slider_A = slider_A; - LinkItem::slider_A = slider_A; -} - -void GraphViewer::setSlider_B(QSlider *slider_B){ - NodeItem::slider_B = slider_B; - LinkItem::slider_B = slider_B; -} - void GraphViewer::setWorkingDirectory(const QString & path) { _workingDirectory = path; @@ -1540,7 +1459,6 @@ void GraphViewer::setNodeColor(const QColor & color) iter.value()->setColor(_nodeColor); } } - void GraphViewer::setNodeOdomCacheColor(const QColor & color) { _nodeOdomCacheColor = color; @@ -1552,27 +1470,6 @@ void GraphViewer::setNodeOdomCacheColor(const QColor & color) } } } - -void GraphViewer::highlightCurrentNode(int value){ - - QMap::iterator iter = _nodeItems.find(value); - if(iter != _nodeItems.end()){ - NodeItem* node = iter.value(); - if(previousNode != nullptr){ - previousNode->node_selected = false; - if(NodeItem::show_border){ - previousNode->setPen(QPen(previousNode->noBorder)); - } - - } - previousNode = node; - node->node_selected = true; - if(NodeItem::show_border){ - node->setPen(QPen(node->border)); - } - } -} - void GraphViewer::setCurrentGoalColor(const QColor & color) { _currentGoalColor = color; @@ -1912,7 +1809,7 @@ void GraphViewer::mouseMoveEvent(QMouseEvent * event) QGraphicsView::mouseMoveEvent(event); } -void GraphViewer::mouseDoubleClickEvent(QMouseEvent * event) +void GraphViewer::mousePressEvent(QMouseEvent * event) { QGraphicsItem *item = this->scene()->itemAt(mapToScene(event->pos()), QTransform()); if(item) @@ -1929,12 +1826,12 @@ void GraphViewer::mouseDoubleClickEvent(QMouseEvent * event) } else { - QGraphicsView::mouseDoubleClickEvent(event); + QGraphicsView::mousePressEvent(event); } } else { - QGraphicsView::mouseDoubleClickEvent(event); + QGraphicsView::mousePressEvent(event); } } @@ -2011,7 +1908,6 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) menu.addSeparator(); QAction * aSetNodeSize = menu.addAction(tr("Set node radius...")); - QAction * aToggleNodeBorder = menu.addAction(tr("Toggle node border...")); QAction * aSetLinkSize = menu.addAction(tr("Set link width...")); QAction * aChangeMaxLinkLength = menu.addAction(tr("Set maximum link length...")); menu.addSeparator(); @@ -2491,16 +2387,6 @@ void GraphViewer::contextMenuEvent(QContextMenuEvent * event) setNodeRadius(value); } } - else if(r == aToggleNodeBorder){ - - if(NodeItem::show_border){ - NodeItem::show_border = false; - previousNode->setPen(QPen(previousNode->noBorder)); - } else { - NodeItem::show_border = true; - previousNode->setPen(QPen(previousNode->border)); - } - } else if(r == aSetLinkSize) { bool ok; diff --git a/guilib/src/ui/DatabaseViewer.ui b/guilib/src/ui/DatabaseViewer.ui index d8ea66a57b..c968958d23 100644 --- a/guilib/src/ui/DatabaseViewer.ui +++ b/guilib/src/ui/DatabaseViewer.ui @@ -61,7 +61,7 @@ 0 0 - 417 + 419 389 @@ -392,7 +392,7 @@ 0 0 - 416 + 418 389 @@ -745,9 +745,9 @@ - - - indexA + + + false @@ -773,9 +773,6 @@ - - - @@ -813,9 +810,9 @@ - - - indexB + + + false @@ -841,9 +838,6 @@ - - - @@ -1647,7 +1641,7 @@ 0 0 - 318 + 314 188 @@ -1803,8 +1797,8 @@ 0 0 - 518 - 1007 + 276 + 1201 @@ -2464,8 +2458,8 @@ 0 - -42 - 298 + 0 + 294 272 @@ -2639,8 +2633,8 @@ 0 0 - 432 - 196 + 181 + 485