Skip to content

Commit a6d9425

Browse files
committed
DBViewer: support doubleclick on node or link in graphview to update correpsonding image view and constraints view, also added "Show pixel depth" menu option in ImageView to show pixel depth and pixel coordinate in map frame.
1 parent e299505 commit a6d9425

File tree

6 files changed

+131
-4
lines changed

6 files changed

+131
-4
lines changed

guilib/include/rtabmap/gui/DatabaseViewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ private Q_SLOTS:
128128
void updateAllLandmarkCovariances();
129129
void refineLinks();
130130
void resetAllChanges();
131+
void graphNodeSelected(int);
132+
void graphLinkSelected(int, int);
131133
void sliderAValueChanged(int);
132134
void sliderBValueChanged(int);
133135
void sliderAMoved(int);

guilib/include/rtabmap/gui/GraphViewer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ class RTABMAP_GUI_EXPORT GraphViewer : public QGraphicsView {
166166
Q_SIGNALS:
167167
void configChanged();
168168
void mapShownRequested();
169+
void nodeSelected(int);
170+
void linkSelected(int, int);
169171

170172
public Q_SLOTS:
171173
void restoreDefaults();
172174

173175
protected:
174176
virtual void wheelEvent ( QWheelEvent * event );
175177
virtual void mouseMoveEvent(QMouseEvent * event);
178+
virtual void mouseDoubleClickEvent(QMouseEvent * event);
176179
virtual void contextMenuEvent(QContextMenuEvent * event);
177180

178181
private:

guilib/include/rtabmap/gui/ImageView.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3737
#include <opencv2/features2d/features2d.hpp>
3838
#include <map>
3939
#include "rtabmap/utilite/UCv2Qt.h"
40+
#include <rtabmap/core/CameraModel.h>
4041

4142
class QAction;
4243
class QMenu;
@@ -96,7 +97,7 @@ class RTABMAP_GUI_EXPORT ImageView : public QWidget {
9697
void setFeatures(const std::vector<cv::KeyPoint> & features, const cv::Mat & depth = cv::Mat(), const QColor & color = Qt::yellow);
9798
void addFeature(int id, const cv::KeyPoint & kpt, float depth, QColor color);
9899
void addLine(float x1, float y1, float x2, float y2, QColor color, const QString & text = QString());
99-
void setImage(const QImage & image);
100+
void setImage(const QImage & image, const std::vector<CameraModel> & models = std::vector<CameraModel>(), const Transform & pose = Transform());
100101
void setImageDepth(const cv::Mat & imageDepth);
101102
void setImageDepth(const QImage & image);
102103
void setFeatureColor(int id, QColor color);
@@ -121,6 +122,7 @@ class RTABMAP_GUI_EXPORT ImageView : public QWidget {
121122
virtual void paintEvent(QPaintEvent *event);
122123
virtual void resizeEvent(QResizeEvent* event);
123124
virtual void contextMenuEvent(QContextMenuEvent * e);
125+
virtual void mouseMoveEvent(QMouseEvent * event);
124126

125127
private Q_SLOTS:
126128
void sceneRectChanged(const QRectF &rect);
@@ -164,6 +166,7 @@ private Q_SLOTS:
164166
QAction * _colorMapBlueToRed;
165167
QAction * _colorMapMinRange;
166168
QAction * _colorMapMaxRange;
169+
QAction * _mouseTracking;
167170
QMenu * _featureMenu;
168171
QMenu * _scaleMenu;
169172

@@ -175,6 +178,8 @@ private Q_SLOTS:
175178
QPixmap _image;
176179
QPixmap _imageDepth;
177180
cv::Mat _imageDepthCv;
181+
std::vector<CameraModel> _models;
182+
Transform _pose;
178183
};
179184

180185
}

guilib/src/DatabaseViewer.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ DatabaseViewer::DatabaseViewer(const QString & ini, QWidget * parent) :
268268
connect(ui_->dockWidget_statistics->toggleViewAction(), SIGNAL(triggered()), this, SLOT(updateStatistics()));
269269
connect(ui_->dockWidget_info->toggleViewAction(), SIGNAL(triggered()), this, SLOT(updateInfo()));
270270

271+
connect(ui_->graphViewer, SIGNAL(nodeSelected(int)), this , SLOT(graphNodeSelected(int)));
272+
connect(ui_->graphViewer, SIGNAL(linkSelected(int,int)), this , SLOT(graphLinkSelected(int,int)));
271273

272274
connect(ui_->parameters_toolbox, SIGNAL(parametersChanged(const QStringList &)), this, SLOT(notifyParametersChanged(const QStringList &)));
273275

@@ -4547,6 +4549,20 @@ void DatabaseViewer::resetAllChanges()
45474549
}
45484550
}
45494551

4552+
void DatabaseViewer::graphNodeSelected(int id)
4553+
{
4554+
if(id>0 && idToIndex_.contains(id))
4555+
ui_->horizontalSlider_A->setValue(idToIndex_.value(id));
4556+
}
4557+
4558+
void DatabaseViewer::graphLinkSelected(int from, int to)
4559+
{
4560+
if(from>0 && idToIndex_.contains(from))
4561+
ui_->horizontalSlider_A->setValue(idToIndex_.value(from));
4562+
if(to>0 && idToIndex_.contains(to))
4563+
ui_->horizontalSlider_B->setValue(idToIndex_.value(to));
4564+
}
4565+
45504566
void DatabaseViewer::sliderAValueChanged(int value)
45514567
{
45524568
this->update(value,
@@ -4685,7 +4701,12 @@ void DatabaseViewer::update(int value,
46854701
QRectF rect;
46864702
if(!img.isNull())
46874703
{
4688-
view->setImage(img);
4704+
Transform pose;
4705+
if(!graphes_.empty() && graphes_.back().find(data.id())!=graphes_.back().end())
4706+
{
4707+
pose = graphes_.back().at(data.id());
4708+
}
4709+
view->setImage(img, data.cameraModels(), pose);
46894710
rect = img.rect();
46904711
}
46914712
else

guilib/src/GraphViewer.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ void GraphViewer::mouseMoveEvent(QMouseEvent * event)
17971797
if(_mouseTracking && _viewPlane==XY && this->sceneRect().contains(scenePoint))
17981798
{
17991799
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1800-
QToolTip::showText(event->globalPosition().toPoint(), QString("%1,%2").arg(scenePoint.x()/100.0).arg(scenePoint.y()/100.0));
1800+
QToolTip::showText(event->globalPosition().toPoint(), QString("%1m %2m").arg(-scenePoint.y()/100.0).arg(-scenePoint.x()/100.0));
18011801
#else
18021802
QToolTip::showText(event->globalPos(), QString("%1m %2m").arg(-scenePoint.y()/100.0).arg(-scenePoint.x()/100.0));
18031803
#endif
@@ -1809,6 +1809,32 @@ void GraphViewer::mouseMoveEvent(QMouseEvent * event)
18091809
QGraphicsView::mouseMoveEvent(event);
18101810
}
18111811

1812+
void GraphViewer::mouseDoubleClickEvent(QMouseEvent * event)
1813+
{
1814+
QGraphicsItem *item = this->scene()->itemAt(mapToScene(event->pos()), QTransform());
1815+
if(item)
1816+
{
1817+
NodeItem *nodeItem = qgraphicsitem_cast<NodeItem*>(item);
1818+
LinkItem *linkItem = qgraphicsitem_cast<LinkItem*>(item);
1819+
if(nodeItem && nodeItem->parentItem() == _graphRoot && nodeItem->id() != 0)
1820+
{
1821+
Q_EMIT nodeSelected(nodeItem->id());
1822+
}
1823+
else if(linkItem && linkItem->parentItem() == _graphRoot && linkItem->from() != 0 && linkItem->to() != 0)
1824+
{
1825+
Q_EMIT linkSelected(linkItem->from(), linkItem->to());
1826+
}
1827+
else
1828+
{
1829+
QGraphicsView::mouseDoubleClickEvent(event);
1830+
}
1831+
}
1832+
else
1833+
{
1834+
QGraphicsView::mouseDoubleClickEvent(event);
1835+
}
1836+
}
1837+
18121838
QIcon createIcon(const QColor & color)
18131839
{
18141840
QPixmap pixmap(50, 50);

guilib/src/ImageView.cpp

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4040
#include <QColorDialog>
4141
#include <QPrinter>
4242
#include <QGraphicsRectItem>
43+
#include <QToolTip>
4344
#include "rtabmap/utilite/ULogger.h"
4445
#include "rtabmap/gui/KeypointItem.h"
4546
#include "rtabmap/core/util2d.h"
47+
#include "rtabmap/core/util3d_transforms.h"
4648

4749
#include <QtGlobal>
4850
#if QT_VERSION >= 0x050000
@@ -268,9 +270,14 @@ ImageView::ImageView(QWidget * parent) :
268270
group->addAction(_colorMapRedToBlue);
269271
group->addAction(_colorMapBlueToRed);
270272
group->addAction(_colorMapMaxRange);
273+
_mouseTracking = _menu->addAction(tr("Show pixel depth"));
274+
_mouseTracking->setCheckable(true);
275+
_mouseTracking->setChecked(false);
271276
_saveImage = _menu->addAction(tr("Save picture..."));
272277
_saveImage->setEnabled(false);
273278

279+
setMouseTracking(true);
280+
274281
connect(_graphicsView->scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &)));
275282
}
276283

@@ -1047,6 +1054,65 @@ void ImageView::contextMenuEvent(QContextMenuEvent * e)
10471054
}
10481055
}
10491056

1057+
void ImageView::mouseMoveEvent(QMouseEvent * event)
1058+
{
1059+
if(_mouseTracking->isChecked() &&
1060+
!_graphicsView->scene()->sceneRect().isNull() &&
1061+
!_image.isNull() &&
1062+
!_imageDepthCv.empty() &&
1063+
(_imageDepthCv.type() == CV_16UC1 || _imageDepthCv.type() == CV_32FC1))
1064+
{
1065+
float scale, offsetX, offsetY;
1066+
computeScaleOffsets(this->rect(), scale, offsetX, offsetY);
1067+
float u = (event->pos().x() - offsetX) / scale;
1068+
float v = (event->pos().y() - offsetY) / scale;
1069+
float depthScale = 1;
1070+
if(_image.width() > _imageDepth.width())
1071+
{
1072+
depthScale = _imageDepth.width() / _image.width();
1073+
}
1074+
int ud = int(u*depthScale);
1075+
int vd = int(v*depthScale);
1076+
if( ud>=0 && vd>=0 &&
1077+
ud < _imageDepthCv.cols &&
1078+
vd < _imageDepthCv.rows)
1079+
{
1080+
float depth = 0;
1081+
if(_imageDepthCv.type() == CV_32FC1)
1082+
{
1083+
depth = _imageDepthCv.at<float>(vd, ud);
1084+
}
1085+
else
1086+
{
1087+
depth = float(_imageDepthCv.at<unsigned short>(vd, ud)) / 1000.0f;
1088+
}
1089+
1090+
cv::Point3f pt(0,0,0);
1091+
if(depth>0 && !_models.empty() && !_pose.isNull())
1092+
{
1093+
int subImageWidth = _imageDepthCv.cols / _models.size();
1094+
int subImageIndex = ud / subImageWidth;
1095+
UASSERT(subImageIndex < (int)_models.size());
1096+
float x,y,z;
1097+
_models[subImageIndex].project(u, v, depth, x, y, z);
1098+
pt = cv::Point3f(x,y,z);
1099+
pt = util3d::transformPoint(pt, _pose*_models[subImageIndex].localTransform());
1100+
}
1101+
1102+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1103+
QToolTip::showText(event->globalPosition().toPoint(), QString("%1 %2").arg(scenePoint.x()).arg(scenePoint.y()));
1104+
#else
1105+
QToolTip::showText(event->globalPos(), pt.x!=0?tr("Depth=%1m Map=(%2,%3,%4)").arg(depth).arg(pt.x).arg(pt.y).arg(pt.z):depth > 0?tr("Depth=%1m").arg(depth):tr("Depth=NA"));
1106+
#endif
1107+
}
1108+
else
1109+
{
1110+
QToolTip::hideText();
1111+
}
1112+
}
1113+
QWidget::mouseMoveEvent(event);
1114+
}
1115+
10501116
void ImageView::updateOpacity()
10511117
{
10521118
if(_imageItem && _imageDepthItem)
@@ -1166,9 +1232,11 @@ void ImageView::addLine(float x1, float y1, float x2, float y2, QColor color, co
11661232
}
11671233
}
11681234

1169-
void ImageView::setImage(const QImage & image)
1235+
void ImageView::setImage(const QImage & image, const std::vector<CameraModel> & models, const Transform & pose)
11701236
{
11711237
_image = QPixmap::fromImage(image);
1238+
_models = models;
1239+
_pose = pose;
11721240
if(_graphicsView->isVisible())
11731241
{
11741242
if(_imageItem)
@@ -1394,6 +1462,8 @@ void ImageView::clear()
13941462
_imageItem = 0;
13951463
}
13961464
_image = QPixmap();
1465+
_models.clear();
1466+
_pose.setNull();
13971467

13981468
if(_imageDepthItem)
13991469
{

0 commit comments

Comments
 (0)