@@ -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+
10501116void 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