mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 17:40:23 +08:00
Merged pcl_integration branch to trunk
git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@1014 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QGraphicsEffect>
|
||||
#include "rtabmap/utilite/ULogger.h"
|
||||
#include "rtabmap/gui/KeypointItem.h"
|
||||
|
||||
@@ -34,7 +35,9 @@ ImageView::ImageView(QWidget * parent) :
|
||||
QGraphicsView(parent),
|
||||
_zoom(250),
|
||||
_minZoom(250),
|
||||
_savedFileName((QDir::homePath()+ "/") + "picture" + ".png")
|
||||
_savedFileName((QDir::homePath()+ "/") + "picture" + ".png"),
|
||||
_image(0),
|
||||
_imageDepth(0)
|
||||
{
|
||||
this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
this->setScene(new QGraphicsScene(this));
|
||||
@@ -44,6 +47,9 @@ ImageView::ImageView(QWidget * parent) :
|
||||
_showImage = _menu->addAction(tr("Show image"));
|
||||
_showImage->setCheckable(true);
|
||||
_showImage->setChecked(true);
|
||||
_showImageDepth = _menu->addAction(tr("Show image depth"));
|
||||
_showImageDepth->setCheckable(true);
|
||||
_showImageDepth->setChecked(false);
|
||||
_showFeatures = _menu->addAction(tr("Show features"));
|
||||
_showFeatures->setCheckable(true);
|
||||
_showFeatures->setChecked(true);
|
||||
@@ -54,7 +60,7 @@ ImageView::ImageView(QWidget * parent) :
|
||||
}
|
||||
|
||||
ImageView::~ImageView() {
|
||||
|
||||
clear();
|
||||
}
|
||||
|
||||
void ImageView::resetZoom()
|
||||
@@ -68,6 +74,11 @@ bool ImageView::isImageShown()
|
||||
return _showImage->isChecked();
|
||||
}
|
||||
|
||||
bool ImageView::isImageDepthShown()
|
||||
{
|
||||
return _showImageDepth->isChecked();
|
||||
}
|
||||
|
||||
bool ImageView::isFeaturesShown()
|
||||
{
|
||||
return _showFeatures->isChecked();
|
||||
@@ -76,7 +87,30 @@ bool ImageView::isFeaturesShown()
|
||||
void ImageView::setFeaturesShown(bool shown)
|
||||
{
|
||||
_showFeatures->setChecked(shown);
|
||||
this->updateItemsShown();
|
||||
for(int i=0; i<_features.size(); ++i)
|
||||
{
|
||||
_features[i]->setVisible(_showFeatures->isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::setImageShown(bool shown)
|
||||
{
|
||||
_showImage->setChecked(shown);
|
||||
if(_image)
|
||||
{
|
||||
_image->setVisible(_showImage->isChecked());
|
||||
this->updateOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::setImageDepthShown(bool shown)
|
||||
{
|
||||
_showImageDepth->setChecked(shown);
|
||||
if(_imageDepth)
|
||||
{
|
||||
_imageDepth->setVisible(_showImageDepth->isChecked());
|
||||
this->updateOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageView::isLinesShown()
|
||||
@@ -87,7 +121,14 @@ bool ImageView::isLinesShown()
|
||||
void ImageView::setLinesShown(bool shown)
|
||||
{
|
||||
_showLines->setChecked(shown);
|
||||
this->updateItemsShown();
|
||||
QList<QGraphicsItem*> items = this->scene()->items();
|
||||
for(int i=0; i<items.size(); ++i)
|
||||
{
|
||||
if( qgraphicsitem_cast<QGraphicsLineItem*>(items.at(i)))
|
||||
{
|
||||
items.at(i)->setVisible(_showLines->isChecked());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::contextMenuEvent(QContextMenuEvent * e)
|
||||
@@ -110,28 +151,46 @@ void ImageView::contextMenuEvent(QContextMenuEvent * e)
|
||||
img.save(text);
|
||||
}
|
||||
}
|
||||
else if(action == _showFeatures || action == _showImage || action == _showLines)
|
||||
else if(action == _showFeatures)
|
||||
{
|
||||
this->updateItemsShown();
|
||||
this->setFeaturesShown(_showFeatures->isChecked());
|
||||
}
|
||||
else if(action == _showImage)
|
||||
{
|
||||
this->setImageShown(_showImage->isChecked());
|
||||
}
|
||||
else if(action == _showImageDepth)
|
||||
{
|
||||
this->setImageDepthShown(_showImageDepth->isChecked());
|
||||
}
|
||||
else if(action == _showLines)
|
||||
{
|
||||
this->setLinesShown(_showLines->isChecked());
|
||||
}
|
||||
|
||||
if(action == _showImage || action ==_showImageDepth)
|
||||
{
|
||||
this->updateOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::updateItemsShown()
|
||||
void ImageView::updateOpacity()
|
||||
{
|
||||
QList<QGraphicsItem*> items = this->scene()->items();
|
||||
for(int i=0; i<items.size(); ++i)
|
||||
if(_image && _imageDepth)
|
||||
{
|
||||
if(qgraphicsitem_cast<KeypointItem*>(items.at(i)))
|
||||
if(_image->isVisible() && _imageDepth->isVisible())
|
||||
{
|
||||
items.at(i)->setVisible(_showFeatures->isChecked());
|
||||
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect();
|
||||
QGraphicsOpacityEffect * effect2 = new QGraphicsOpacityEffect();
|
||||
effect->setOpacity(0.5);
|
||||
effect2->setOpacity(0.5);
|
||||
_image->setGraphicsEffect(effect);
|
||||
_imageDepth->setGraphicsEffect(effect2);
|
||||
}
|
||||
else if( qgraphicsitem_cast<QGraphicsLineItem*>(items.at(i)))
|
||||
else
|
||||
{
|
||||
items.at(i)->setVisible(_showLines->isChecked());
|
||||
}
|
||||
else if(qgraphicsitem_cast<QGraphicsPixmapItem*>(items.at(i)))
|
||||
{
|
||||
items.at(i)->setVisible(_showImage->isChecked());
|
||||
_image->setGraphicsEffect(0);
|
||||
_imageDepth->setGraphicsEffect(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,4 +234,94 @@ void ImageView::wheelEvent(QWheelEvent * e)
|
||||
this->setMatrix(matrix);
|
||||
}
|
||||
|
||||
void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords)
|
||||
{
|
||||
for(int i=0; i<_features.size(); ++i)
|
||||
{
|
||||
scene()->removeItem(_features[i]);
|
||||
delete _features[i];
|
||||
}
|
||||
_features.clear();
|
||||
|
||||
rtabmap::KeypointItem * item = 0;
|
||||
int alpha = 70;
|
||||
for(std::multimap<int, cv::KeyPoint>::const_iterator i = refWords.begin(); i != refWords.end(); ++i )
|
||||
{
|
||||
const cv::KeyPoint & r = (*i).second;
|
||||
int id = (*i).first;
|
||||
QString info = QString( "WordRef = %1\n"
|
||||
"Laplacian = %2\n"
|
||||
"Dir = %3\n"
|
||||
"Hessian = %4\n"
|
||||
"X = %5\n"
|
||||
"Y = %6\n"
|
||||
"Size = %7").arg(id).arg(1).arg(r.angle).arg(r.response).arg(r.pt.x).arg(r.pt.y).arg(r.size);
|
||||
float radius = r.size*1.2/9.*2;
|
||||
|
||||
item = new rtabmap::KeypointItem(r.pt.x-radius, r.pt.y-radius, radius*2, info, QColor(255, 255, 0, alpha));
|
||||
|
||||
scene()->addItem(item);
|
||||
_features.append(item);
|
||||
item->setVisible(_showFeatures->isChecked());
|
||||
item->setZValue(1);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::setImage(const QImage & image)
|
||||
{
|
||||
if(_image)
|
||||
{
|
||||
_image->setPixmap(QPixmap::fromImage(image));
|
||||
}
|
||||
else
|
||||
{
|
||||
_image = scene()->addPixmap(QPixmap::fromImage(image));
|
||||
_image->setVisible(_showImage->isChecked());
|
||||
_showImage->setEnabled(true);
|
||||
this->updateOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::setImageDepth(const QImage & imageDepth)
|
||||
{
|
||||
if(_imageDepth)
|
||||
{
|
||||
_imageDepth->setPixmap(QPixmap::fromImage(imageDepth));
|
||||
}
|
||||
else
|
||||
{
|
||||
_imageDepth = scene()->addPixmap(QPixmap::fromImage(imageDepth));
|
||||
_imageDepth->setVisible(_showImageDepth->isChecked());
|
||||
_showImageDepth->setEnabled(true);
|
||||
this->updateOpacity();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageView::clear()
|
||||
{
|
||||
for(int i=0; i<_features.size(); ++i)
|
||||
{
|
||||
scene()->removeItem(_features[i]);
|
||||
delete _features[i];
|
||||
}
|
||||
_features.clear();
|
||||
|
||||
if(_image)
|
||||
{
|
||||
scene()->removeItem(_image);
|
||||
delete _image;
|
||||
_image = 0;
|
||||
_showImage->setEnabled(false);
|
||||
}
|
||||
|
||||
if(_imageDepth)
|
||||
{
|
||||
scene()->removeItem(_imageDepth);
|
||||
delete _imageDepth;
|
||||
_imageDepth = 0;
|
||||
_showImageDepth->setEnabled(false);
|
||||
}
|
||||
scene()->clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user