2011-06-05 14:45:39 +00:00
|
|
|
/*
|
2014-08-11 17:00:55 +00:00
|
|
|
Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
#include "rtabmap/gui/ImageView.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
#include <QtGui/QWheelEvent>
|
|
|
|
|
#include <QtCore/qmath.h>
|
2015-03-16 19:51:22 +00:00
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QFileDialog>
|
2011-06-05 14:45:39 +00:00
|
|
|
#include <QtCore/QDir>
|
2015-03-16 19:51:22 +00:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QGraphicsEffect>
|
|
|
|
|
#include <QInputDialog>
|
2015-03-30 10:47:38 -04:00
|
|
|
#include <QVBoxLayout>
|
2013-04-30 20:16:01 +00:00
|
|
|
#include "rtabmap/utilite/ULogger.h"
|
2012-06-24 17:19:34 +00:00
|
|
|
#include "rtabmap/gui/KeypointItem.h"
|
2015-05-13 19:54:23 -04:00
|
|
|
#include "rtabmap/core/util2d.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
|
|
|
ImageView::ImageView(QWidget * parent) :
|
2015-03-30 10:47:38 -04:00
|
|
|
QWidget(parent),
|
2013-12-11 00:12:44 +00:00
|
|
|
_savedFileName((QDir::homePath()+ "/") + "picture" + ".png"),
|
2015-05-04 17:45:05 -04:00
|
|
|
_alpha(50),
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageItem(0),
|
|
|
|
|
_imageDepthItem(0)
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_graphicsView = new QGraphicsView(this);
|
|
|
|
|
_graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
|
|
|
|
_graphicsView->setScene(new QGraphicsScene(this));
|
|
|
|
|
_graphicsView->setVisible(false);
|
|
|
|
|
|
|
|
|
|
this->setLayout(new QVBoxLayout(this));
|
|
|
|
|
this->layout()->addWidget(_graphicsView);
|
|
|
|
|
this->layout()->setContentsMargins(0,0,0,0);
|
2011-07-23 03:55:05 +00:00
|
|
|
|
|
|
|
|
_menu = new QMenu(tr(""), this);
|
|
|
|
|
_showImage = _menu->addAction(tr("Show image"));
|
|
|
|
|
_showImage->setCheckable(true);
|
|
|
|
|
_showImage->setChecked(true);
|
2013-12-11 00:12:44 +00:00
|
|
|
_showImageDepth = _menu->addAction(tr("Show image depth"));
|
|
|
|
|
_showImageDepth->setCheckable(true);
|
|
|
|
|
_showImageDepth->setChecked(false);
|
2011-07-23 03:55:05 +00:00
|
|
|
_showFeatures = _menu->addAction(tr("Show features"));
|
|
|
|
|
_showFeatures->setCheckable(true);
|
|
|
|
|
_showFeatures->setChecked(true);
|
2012-04-07 19:08:54 +00:00
|
|
|
_showLines = _menu->addAction(tr("Show lines"));
|
|
|
|
|
_showLines->setCheckable(true);
|
2013-03-12 15:43:36 +00:00
|
|
|
_showLines->setChecked(true);
|
2015-03-30 10:47:38 -04:00
|
|
|
_graphicsViewMode = _menu->addAction(tr("Graphics view"));
|
|
|
|
|
_graphicsViewMode->setCheckable(true);
|
|
|
|
|
_graphicsViewMode->setChecked(false);
|
|
|
|
|
_graphicsViewScaled = _menu->addAction(tr("Scale image"));
|
|
|
|
|
_graphicsViewScaled->setCheckable(true);
|
|
|
|
|
_graphicsViewScaled->setChecked(true);
|
|
|
|
|
_graphicsViewScaled->setEnabled(false);
|
2015-05-04 17:45:05 -04:00
|
|
|
_setAlpha = _menu->addAction(tr("Set transparency..."));
|
2011-07-23 03:55:05 +00:00
|
|
|
_saveImage = _menu->addAction(tr("Save picture..."));
|
2015-04-16 11:45:47 -04:00
|
|
|
_saveImage->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
connect(_graphicsView->scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &)));
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImageView::~ImageView() {
|
2013-12-11 00:12:44 +00:00
|
|
|
clear();
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-04 17:27:44 -05:00
|
|
|
void ImageView::saveSettings(QSettings & settings, const QString & group) const
|
|
|
|
|
{
|
|
|
|
|
if(!group.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
settings.beginGroup(group);
|
|
|
|
|
}
|
|
|
|
|
settings.setValue("image_shown", this->isImageShown());
|
|
|
|
|
settings.setValue("depth_shown", this->isImageDepthShown());
|
|
|
|
|
settings.setValue("features_shown", this->isFeaturesShown());
|
|
|
|
|
settings.setValue("lines_shown", this->isLinesShown());
|
|
|
|
|
settings.setValue("alpha", this->getAlpha());
|
2015-03-30 10:47:38 -04:00
|
|
|
settings.setValue("graphics_view", this->isGraphicsViewMode());
|
|
|
|
|
settings.setValue("graphics_view_scale", this->isGraphicsViewScaled());
|
2015-03-04 17:27:44 -05:00
|
|
|
if(!group.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::loadSettings(QSettings & settings, const QString & group)
|
|
|
|
|
{
|
|
|
|
|
if(!group.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
settings.beginGroup(group);
|
|
|
|
|
}
|
|
|
|
|
this->setImageShown(settings.value("image_shown", this->isImageShown()).toBool());
|
|
|
|
|
this->setImageDepthShown(settings.value("depth_shown", this->isImageDepthShown()).toBool());
|
|
|
|
|
this->setFeaturesShown(settings.value("features_shown", this->isFeaturesShown()).toBool());
|
|
|
|
|
this->setLinesShown(settings.value("lines_shown", this->isLinesShown()).toBool());
|
|
|
|
|
this->setAlpha(settings.value("alpha", this->getAlpha()).toInt());
|
2015-03-30 10:47:38 -04:00
|
|
|
this->setGraphicsViewMode(settings.value("graphics_view", this->isGraphicsViewMode()).toBool());
|
|
|
|
|
this->setGraphicsViewScaled(settings.value("graphics_view_scale", this->isGraphicsViewScaled()).toBool());
|
2015-03-04 17:27:44 -05:00
|
|
|
if(!group.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-26 14:15:04 -04:00
|
|
|
QRectF ImageView::sceneRect() const
|
|
|
|
|
{
|
|
|
|
|
return _graphicsView->scene()->sceneRect();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 18:11:34 -05:00
|
|
|
bool ImageView::isImageShown() const
|
2011-07-23 03:55:05 +00:00
|
|
|
{
|
|
|
|
|
return _showImage->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 18:11:34 -05:00
|
|
|
bool ImageView::isImageDepthShown() const
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
|
|
|
|
return _showImageDepth->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 18:11:34 -05:00
|
|
|
bool ImageView::isFeaturesShown() const
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2011-07-23 03:55:05 +00:00
|
|
|
return _showFeatures->isChecked();
|
|
|
|
|
}
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
bool ImageView::isGraphicsViewMode() const
|
|
|
|
|
{
|
|
|
|
|
return _graphicsViewMode->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageView::isGraphicsViewScaled() const
|
|
|
|
|
{
|
|
|
|
|
return _graphicsViewScaled->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-31 15:45:38 -04:00
|
|
|
const QColor & ImageView::getBackgroundColor() const
|
|
|
|
|
{
|
|
|
|
|
return _graphicsView->backgroundBrush().color();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
void ImageView::setFeaturesShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
_showFeatures->setChecked(shown);
|
2014-08-11 15:23:06 +00:00
|
|
|
for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2014-08-11 15:23:06 +00:00
|
|
|
iter.value()->setVisible(_showFeatures->isChecked());
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setImageShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
_showImage->setChecked(shown);
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageItem)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageItem->setVisible(_showImage->isChecked());
|
2013-12-11 00:12:44 +00:00
|
|
|
this->updateOpacity();
|
|
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setImageDepthShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
_showImageDepth->setChecked(shown);
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageDepthItem)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageDepthItem->setVisible(_showImageDepth->isChecked());
|
2013-12-11 00:12:44 +00:00
|
|
|
this->updateOpacity();
|
|
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 18:11:34 -05:00
|
|
|
bool ImageView::isLinesShown() const
|
2012-04-07 19:08:54 +00:00
|
|
|
{
|
|
|
|
|
return _showLines->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
void ImageView::setLinesShown(bool shown)
|
|
|
|
|
{
|
|
|
|
|
_showLines->setChecked(shown);
|
2015-03-30 10:47:38 -04:00
|
|
|
for(int i=0; i<_lines.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
_lines.at(i)->setVisible(_showLines->isChecked());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float ImageView::viewScale() const
|
|
|
|
|
{
|
|
|
|
|
if(_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
return _graphicsView->transform().m11();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
float scale, offsetX, offsetY;
|
2015-04-16 11:45:47 -04:00
|
|
|
computeScaleOffsets(this->rect(), scale, offsetX, offsetY);
|
2015-03-30 10:47:38 -04:00
|
|
|
return scale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setGraphicsViewMode(bool on)
|
|
|
|
|
{
|
|
|
|
|
_graphicsViewMode->setChecked(on);
|
|
|
|
|
_graphicsView->setVisible(on);
|
|
|
|
|
_graphicsViewScaled->setEnabled(on);
|
|
|
|
|
|
|
|
|
|
if(on)
|
|
|
|
|
{
|
|
|
|
|
for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->scene()->addItem(iter.value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->scene()->addItem(*iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//update images
|
|
|
|
|
if(_imageItem)
|
|
|
|
|
{
|
|
|
|
|
_imageItem->setPixmap(_image);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_imageItem = _graphicsView->scene()->addPixmap(_image);
|
|
|
|
|
_imageItem->setVisible(_showImage->isChecked());
|
|
|
|
|
_showImage->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_imageDepthItem)
|
|
|
|
|
{
|
|
|
|
|
_imageDepthItem->setPixmap(_imageDepth);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_imageDepthItem = _graphicsView->scene()->addPixmap(_imageDepth);
|
|
|
|
|
_imageDepthItem->setVisible(_showImageDepth->isChecked());
|
|
|
|
|
_showImageDepth->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
this->updateOpacity();
|
|
|
|
|
|
|
|
|
|
if(_graphicsViewScaled->isChecked())
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->resetTransform();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setGraphicsViewScaled(bool scaled)
|
|
|
|
|
{
|
|
|
|
|
_graphicsViewScaled->setChecked(scaled);
|
|
|
|
|
|
|
|
|
|
if(scaled)
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->resetTransform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setBackgroundColor(const QColor & color)
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->setBackgroundBrush(QBrush(color));
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 11:45:47 -04:00
|
|
|
void ImageView::computeScaleOffsets(const QRect & targetRect, float & scale, float & offsetX, float & offsetY) const
|
2015-03-30 10:47:38 -04:00
|
|
|
{
|
|
|
|
|
scale = 1.0f;
|
|
|
|
|
offsetX = 0.0f;
|
|
|
|
|
offsetY = 0.0f;
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->scene()->sceneRect().isNull())
|
|
|
|
|
{
|
|
|
|
|
float w = _graphicsView->scene()->width();
|
|
|
|
|
float h = _graphicsView->scene()->height();
|
2015-04-16 11:45:47 -04:00
|
|
|
float widthRatio = float(targetRect.width()) / w;
|
|
|
|
|
float heightRatio = float(targetRect.height()) / h;
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
//printf("w=%f, h=%f, wR=%f, hR=%f, sW=%d, sH=%d\n", w, h, widthRatio, heightRatio, this->rect().width(), this->rect().height());
|
|
|
|
|
if(widthRatio < heightRatio)
|
|
|
|
|
{
|
|
|
|
|
scale = widthRatio;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
scale = heightRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//printf("ratio=%f\n",ratio);
|
|
|
|
|
|
|
|
|
|
w *= scale;
|
|
|
|
|
h *= scale;
|
|
|
|
|
|
2015-04-16 11:45:47 -04:00
|
|
|
if(w < targetRect.width())
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-04-16 11:45:47 -04:00
|
|
|
offsetX = (targetRect.width() - w)/2.0f;
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
2015-04-16 11:45:47 -04:00
|
|
|
if(h < targetRect.height())
|
2015-03-30 10:47:38 -04:00
|
|
|
{
|
2015-04-16 11:45:47 -04:00
|
|
|
offsetY = (targetRect.height() - h)/2.0f;
|
2015-03-30 10:47:38 -04:00
|
|
|
}
|
|
|
|
|
//printf("offsetX=%f, offsetY=%f\n",offsetX, offsetY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 11:45:47 -04:00
|
|
|
void ImageView::sceneRectChanged(const QRectF & rect)
|
|
|
|
|
{
|
|
|
|
|
_saveImage->setEnabled(rect.isValid());
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
void ImageView::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if(_graphicsViewMode->isChecked())
|
|
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(!_graphicsView->scene()->sceneRect().isNull())
|
|
|
|
|
{
|
|
|
|
|
//Scale
|
|
|
|
|
float ratio, offsetX, offsetY;
|
2015-04-16 11:45:47 -04:00
|
|
|
this->computeScaleOffsets(event->rect(), ratio, offsetX, offsetY);
|
2015-03-30 10:47:38 -04:00
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
|
|
//Background
|
|
|
|
|
painter.save();
|
|
|
|
|
painter.setBrush(_graphicsView->backgroundBrush());
|
2015-04-16 11:45:47 -04:00
|
|
|
painter.drawRect(event->rect());
|
2015-03-30 10:47:38 -04:00
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
painter.translate(offsetX, offsetY);
|
|
|
|
|
painter.scale(ratio, ratio);
|
|
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
|
if(_showImage->isChecked() && !_image.isNull() &&
|
|
|
|
|
_showImageDepth->isChecked() && !_imageDepth.isNull())
|
|
|
|
|
{
|
|
|
|
|
painter.setOpacity(0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_showImage->isChecked() && !_image.isNull())
|
|
|
|
|
{
|
|
|
|
|
painter.drawPixmap(QPoint(0,0), _image);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_showImageDepth->isChecked() && !_imageDepth.isNull())
|
|
|
|
|
{
|
|
|
|
|
painter.drawPixmap(QPoint(0,0), _imageDepth);
|
|
|
|
|
}
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
if(_showFeatures->isChecked())
|
|
|
|
|
{
|
|
|
|
|
for(QMultiMap<int, rtabmap::KeypointItem *>::iterator iter = _features.begin(); iter != _features.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
QColor color = iter.value()->pen().color();
|
|
|
|
|
painter.save();
|
|
|
|
|
painter.setPen(color);
|
|
|
|
|
painter.setBrush(color);
|
|
|
|
|
painter.drawEllipse(iter.value()->rect());
|
|
|
|
|
painter.restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(_showLines->isChecked())
|
|
|
|
|
{
|
|
|
|
|
for(QList<QGraphicsLineItem*>::iterator iter = _lines.begin(); iter != _lines.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
QColor color = (*iter)->pen().color();
|
|
|
|
|
painter.save();
|
|
|
|
|
painter.setPen(color);
|
|
|
|
|
painter.drawLine((*iter)->line());
|
|
|
|
|
painter.restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::resizeEvent(QResizeEvent* event)
|
|
|
|
|
{
|
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
|
if(_graphicsView->isVisible() && _graphicsViewScaled->isChecked())
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-23 03:55:05 +00:00
|
|
|
void ImageView::contextMenuEvent(QContextMenuEvent * e)
|
|
|
|
|
{
|
|
|
|
|
QAction * action = _menu->exec(e->globalPos());
|
|
|
|
|
if(action == _saveImage)
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2015-04-16 11:45:47 -04:00
|
|
|
if(!_graphicsView->scene()->sceneRect().isNull())
|
|
|
|
|
{
|
|
|
|
|
QString text;
|
2011-06-05 14:45:39 +00:00
|
|
|
#ifdef QT_SVG_LIB
|
2015-04-16 11:45:47 -04:00
|
|
|
text = QFileDialog::getSaveFileName(this, tr("Save figure to ..."), _savedFileName, "*.png *.xpm *.jpg *.pdf *.svg");
|
2011-06-05 14:45:39 +00:00
|
|
|
#else
|
2015-04-16 11:45:47 -04:00
|
|
|
text = QFileDialog::getSaveFileName(this, tr("Save figure to ..."), _savedFileName, "*.png *.xpm *.jpg *.pdf");
|
2011-06-05 14:45:39 +00:00
|
|
|
#endif
|
2015-04-16 11:45:47 -04:00
|
|
|
if(!text.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
_savedFileName = text;
|
|
|
|
|
QImage img(_graphicsView->sceneRect().width(), _graphicsView->sceneRect().height(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
|
QPainter p(&img);
|
|
|
|
|
if(_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->scene()->render(&p, _graphicsView->sceneRect(), _graphicsView->sceneRect());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this->render(&p, QPoint(), _graphicsView->sceneRect().toRect());
|
|
|
|
|
}
|
|
|
|
|
img.save(text);
|
|
|
|
|
}
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
else if(action == _showFeatures)
|
|
|
|
|
{
|
|
|
|
|
this->setFeaturesShown(_showFeatures->isChecked());
|
2015-01-23 11:17:42 -05:00
|
|
|
emit configChanged();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
else if(action == _showImage)
|
|
|
|
|
{
|
|
|
|
|
this->setImageShown(_showImage->isChecked());
|
2015-01-23 11:17:42 -05:00
|
|
|
emit configChanged();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
else if(action == _showImageDepth)
|
|
|
|
|
{
|
|
|
|
|
this->setImageDepthShown(_showImageDepth->isChecked());
|
2015-01-23 11:17:42 -05:00
|
|
|
emit configChanged();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
else if(action == _showLines)
|
2011-07-23 03:55:05 +00:00
|
|
|
{
|
2013-12-11 00:12:44 +00:00
|
|
|
this->setLinesShown(_showLines->isChecked());
|
2015-01-23 11:17:42 -05:00
|
|
|
emit configChanged();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
else if(action == _graphicsViewMode)
|
|
|
|
|
{
|
|
|
|
|
this->setGraphicsViewMode(_graphicsViewMode->isChecked());
|
|
|
|
|
emit configChanged();
|
|
|
|
|
}
|
|
|
|
|
else if(action == _graphicsViewScaled)
|
|
|
|
|
{
|
|
|
|
|
this->setGraphicsViewScaled(_graphicsViewScaled->isChecked());
|
|
|
|
|
emit configChanged();
|
|
|
|
|
}
|
2015-01-23 15:16:05 -05:00
|
|
|
else if(action == _setAlpha)
|
|
|
|
|
{
|
|
|
|
|
bool ok = false;
|
2015-05-04 17:45:05 -04:00
|
|
|
int value = QInputDialog::getInt(this, tr("Set features and lines transparency"), tr("alpha (0-255)"), _alpha, 0, 255, 10, &ok);
|
2015-01-23 15:16:05 -05:00
|
|
|
if(ok)
|
|
|
|
|
{
|
|
|
|
|
this->setAlpha(value);
|
|
|
|
|
emit configChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
|
|
|
|
|
if(action == _showImage || action ==_showImageDepth)
|
|
|
|
|
{
|
|
|
|
|
this->updateOpacity();
|
2015-01-23 11:17:42 -05:00
|
|
|
emit configChanged();
|
2011-07-23 03:55:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-11 00:12:44 +00:00
|
|
|
void ImageView::updateOpacity()
|
2011-07-23 03:55:05 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageItem && _imageDepthItem)
|
2011-07-23 03:55:05 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageItem->isVisible() && _imageDepthItem->isVisible())
|
2012-04-07 19:08:54 +00:00
|
|
|
{
|
2013-12-11 00:12:44 +00:00
|
|
|
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect();
|
|
|
|
|
effect->setOpacity(0.5);
|
2015-05-03 18:16:55 -04:00
|
|
|
_imageDepthItem->setGraphicsEffect(effect);
|
2012-04-07 19:08:54 +00:00
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
else
|
2011-07-23 03:55:05 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageDepthItem->setGraphicsEffect(0);
|
2011-07-23 03:55:05 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
else if(_imageDepthItem)
|
2014-12-18 16:54:46 -05:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageDepthItem->setGraphicsEffect(0);
|
2014-12-18 16:54:46 -05:00
|
|
|
}
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-05 11:39:30 -04:00
|
|
|
void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords, const cv::Mat & depth, const QColor & color)
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
qDeleteAll(_features);
|
|
|
|
|
_features.clear();
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
for(std::multimap<int, cv::KeyPoint>::const_iterator iter = refWords.begin(); iter != refWords.end(); ++iter )
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2015-05-13 19:54:23 -04:00
|
|
|
addFeature(iter->first, iter->second, depth.empty()?0:util2d::getDepth(depth, iter->second.pt.x, iter->second.pt.y, false), color);
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
this->update();
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-05 11:39:30 -04:00
|
|
|
void ImageView::setFeatures(const std::vector<cv::KeyPoint> & features, const cv::Mat & depth, const QColor & color)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2014-08-11 15:23:06 +00:00
|
|
|
qDeleteAll(_features);
|
2013-12-11 00:12:44 +00:00
|
|
|
_features.clear();
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
for(unsigned int i = 0; i< features.size(); ++i )
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-05-13 19:54:23 -04:00
|
|
|
addFeature(i, features[i], depth.empty()?0:util2d::getDepth(depth, features[i].pt.x, features[i].pt.y, false), color);
|
2015-03-30 10:47:38 -04:00
|
|
|
}
|
2014-12-18 16:54:46 -05:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
2014-12-18 16:54:46 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-05 11:39:30 -04:00
|
|
|
void ImageView::addFeature(int id, const cv::KeyPoint & kpt, float depth, QColor color)
|
2014-12-18 16:54:46 -05:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
color.setAlpha(this->getAlpha());
|
2015-05-05 11:39:30 -04:00
|
|
|
rtabmap::KeypointItem * item = new rtabmap::KeypointItem(id, kpt, depth, color);
|
2015-03-30 10:47:38 -04:00
|
|
|
_features.insert(id, item);
|
|
|
|
|
item->setVisible(isFeaturesShown());
|
|
|
|
|
item->setZValue(1);
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_graphicsView->isVisible())
|
2014-12-18 16:54:46 -05:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_graphicsView->scene()->addItem(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
void ImageView::addLine(float x1, float y1, float x2, float y2, QColor color)
|
|
|
|
|
{
|
|
|
|
|
color.setAlpha(this->getAlpha());
|
|
|
|
|
QGraphicsLineItem * item = new QGraphicsLineItem(x1, y1, x2, y2);
|
|
|
|
|
item->setPen(QPen(color));
|
|
|
|
|
_lines.push_back(item);
|
|
|
|
|
item->setVisible(isLinesShown());
|
|
|
|
|
item->setZValue(1);
|
|
|
|
|
|
|
|
|
|
if(_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->scene()->addItem(item);
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setImage(const QImage & image)
|
|
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_image = QPixmap::fromImage(image);
|
|
|
|
|
if(_graphicsView->isVisible())
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageItem)
|
|
|
|
|
{
|
|
|
|
|
_imageItem->setPixmap(_image);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_imageItem = _graphicsView->scene()->addPixmap(_image);
|
|
|
|
|
_imageItem->setVisible(_showImage->isChecked());
|
|
|
|
|
_showImage->setEnabled(true);
|
|
|
|
|
this->updateOpacity();
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
this->setSceneRect(image.rect());
|
|
|
|
|
this->update();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setImageDepth(const QImage & imageDepth)
|
|
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_imageDepth = QPixmap::fromImage(imageDepth);
|
|
|
|
|
if(_graphicsView->isVisible())
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageDepthItem)
|
|
|
|
|
{
|
|
|
|
|
_imageDepthItem->setPixmap(_imageDepth);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_imageDepthItem = _graphicsView->scene()->addPixmap(_imageDepth);
|
|
|
|
|
_imageDepthItem->setVisible(_showImageDepth->isChecked());
|
|
|
|
|
_showImageDepth->setEnabled(true);
|
|
|
|
|
this->updateOpacity();
|
|
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
this->setSceneRect(imageDepth.rect());
|
|
|
|
|
this->update();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
void ImageView::setFeatureColor(int id, QColor color)
|
2014-08-11 15:23:06 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
color.setAlpha(getAlpha());
|
2014-08-11 15:23:06 +00:00
|
|
|
QList<KeypointItem*> items = _features.values(id);
|
|
|
|
|
if(items.size())
|
|
|
|
|
{
|
|
|
|
|
for(int i=0; i<items.size(); ++i)
|
|
|
|
|
{
|
2014-12-18 16:54:46 -05:00
|
|
|
items[i]->setColor(color);
|
2014-08-11 15:23:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UWARN("Not found feature %d", id);
|
|
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
2014-08-11 15:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
void ImageView::setFeaturesColor(QColor color)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
color.setAlpha(getAlpha());
|
2014-08-11 15:23:06 +00:00
|
|
|
for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
iter.value()->setColor(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
2014-08-11 15:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 15:16:05 -05:00
|
|
|
void ImageView::setAlpha(int alpha)
|
|
|
|
|
{
|
|
|
|
|
UASSERT(alpha >=0 && alpha <= 255);
|
|
|
|
|
_alpha = alpha;
|
|
|
|
|
for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
QColor c = iter.value()->pen().color();
|
|
|
|
|
c.setAlpha(_alpha);
|
|
|
|
|
iter.value()->setPen(QPen(c));
|
|
|
|
|
iter.value()->setBrush(QBrush(c));
|
|
|
|
|
}
|
2015-03-30 10:47:38 -04:00
|
|
|
|
|
|
|
|
for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
|
|
|
|
|
{
|
|
|
|
|
QColor c = (*iter)->pen().color();
|
|
|
|
|
c.setAlpha(_alpha);
|
|
|
|
|
(*iter)->setPen(QPen(c));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::setSceneRect(const QRectF & rect)
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->scene()->setSceneRect(rect);
|
|
|
|
|
|
|
|
|
|
if(_graphicsViewScaled->isChecked())
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_graphicsView->resetTransform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
2015-01-23 15:16:05 -05:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 15:23:06 +00:00
|
|
|
void ImageView::clearLines()
|
|
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
qDeleteAll(_lines);
|
|
|
|
|
_lines.clear();
|
|
|
|
|
|
|
|
|
|
if(!_graphicsView->isVisible())
|
2014-08-11 15:23:06 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
this->update();
|
2014-08-11 15:23:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageView::clear()
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(_features);
|
2013-12-11 00:12:44 +00:00
|
|
|
_features.clear();
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
qDeleteAll(_lines);
|
|
|
|
|
_lines.clear();
|
|
|
|
|
|
|
|
|
|
if(_imageItem)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_graphicsView->scene()->removeItem(_imageItem);
|
|
|
|
|
delete _imageItem;
|
|
|
|
|
_imageItem = 0;
|
2013-12-11 00:12:44 +00:00
|
|
|
_showImage->setEnabled(false);
|
|
|
|
|
}
|
2015-04-16 11:45:47 -04:00
|
|
|
_image = QPixmap();
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
if(_imageDepthItem)
|
2013-12-11 00:12:44 +00:00
|
|
|
{
|
2015-03-30 10:47:38 -04:00
|
|
|
_graphicsView->scene()->removeItem(_imageDepthItem);
|
|
|
|
|
delete _imageDepthItem;
|
|
|
|
|
_imageDepthItem = 0;
|
2013-12-11 00:12:44 +00:00
|
|
|
_showImageDepth->setEnabled(false);
|
|
|
|
|
}
|
2015-04-16 11:45:47 -04:00
|
|
|
_imageDepth = QPixmap();
|
2015-03-30 10:47:38 -04:00
|
|
|
|
2015-05-26 14:15:04 -04:00
|
|
|
_graphicsView->scene()->setSceneRect(QRectF());
|
|
|
|
|
_graphicsView->setScene(_graphicsView->scene());
|
|
|
|
|
|
2015-03-30 10:47:38 -04:00
|
|
|
if(!_graphicsView->isVisible())
|
|
|
|
|
{
|
|
|
|
|
this->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize ImageView::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return _graphicsView->sizeHint();
|
2013-12-11 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|