30 #include <QtGui/QWheelEvent>
31 #include <QtCore/qmath.h>
33 #include <QFileDialog>
34 #include <QtCore/QDir>
36 #include <QActionGroup>
37 #include <QGraphicsEffect>
38 #include <QInputDialog>
39 #include <QVBoxLayout>
40 #include <QColorDialog>
42 #include <QGraphicsRectItem>
50 #if QT_VERSION >= 0x050000
51 #include <QStandardPaths>
60 LineItem(
float x1,
float y1,
float x2,
float y2,
const QString & text = QString(), QGraphicsItem * parent = 0) :
61 QGraphicsLineItem(
x1,
y1,
x2, y2, parent),
65 this->setAcceptHoverEvents(
true);
66 this->setFlag(QGraphicsItem::ItemIsFocusable,
true);
77 this->setPen(QPen(pen().color(),
_width));
83 QGraphicsScene * scene = this->scene();
84 if(scene && scene->focusItem() == 0)
90 this->setPen(QPen(pen().color(),
_width+2));
92 QGraphicsLineItem::hoverEnterEvent(event);
101 QGraphicsLineItem::hoverEnterEvent(event);
107 QGraphicsLineItem::focusInEvent(event);
113 QGraphicsLineItem::focusOutEvent(event);
125 if(qGray(pen().color().rgb() > 255/2))
131 _placeHolder->setBrush(QBrush(QColor ( 255, 255, 255, 170 )));
134 text->setDefaultTextColor(this->pen().color().rgb());
147 QPen pen = this->pen();
148 this->setPen(QPen(pen.color(),
_width+2));
156 this->setPen(QPen(pen().color(),
_width));
167 QPixmap pixmap(50, 50);
169 return QIcon(pixmap);
177 _defaultBgColor(Qt::black),
178 _defaultFeatureColor(Qt::yellow),
179 _defaultMatchingFeatureColor(Qt::magenta),
180 _defaultMatchingLineColor(Qt::cyan),
181 _depthColorMapMinRange(0),
182 _depthColorMapMaxRange(0),
186 #if QT_VERSION >= 0x050000
187 _savedFileName = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
200 _graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
204 this->setLayout(
new QVBoxLayout(
this));
206 this->layout()->setContentsMargins(0,0,0,0);
208 _menu =
new QMenu(tr(
""),
this);
248 QActionGroup * group =
new QActionGroup(
this);
252 QMenu * colorMap =
_menu->addMenu(
"Depth color map");
267 group =
new QActionGroup(
this);
279 setMouseTracking(
true);
292 settings.beginGroup(group);
300 settings.setValue(
"alpha", this->
getAlpha());
321 settings.beginGroup(group);
323 this->
setImageShown(settings.value(
"image_shown",
this->isImageShown()).toBool());
327 this->
setLinesShown(settings.value(
"lines_shown",
this->isLinesShown()).toBool());
328 this->
setLinesWidth(settings.value(
"lines_width",
this->getLinesWidth()).toInt());
329 this->
setAlpha(settings.value(
"alpha",
this->getAlpha()).toInt());
337 int colorMap = settings.value(
"colormap", 2).toInt();
343 settings.value(
"colormap_min_range",
this->getDepthColorMapMinRange()).toFloat(),
344 settings.value(
"colormap_max_range", settings.value(
"colormap_range" ,
this->getDepthColorMapMaxRange())).toFloat());
508 float scale, offsetX, offsetY;
633 if(QColor(
iter.
value()->pen().color().rgb()) == previousColor)
652 if(QColor(
iter.
value()->pen().color().rgb()) == previousColor)
663 if(QColor((*iter)->pen().color().rgb()) == previousColor)
667 (*iter)->setPen(QPen(
c));
681 if(QColor(
iter.
value()->pen().color().rgb()) == previousColor)
692 if(QColor((*iter)->pen().color().rgb()) == previousColor)
696 (*iter)->setPen(QPen(
c));
732 float widthRatio =
float(targetRect.width()) /
w;
733 float heightRatio =
float(targetRect.height()) /
h;
736 if(widthRatio < heightRatio)
750 if(
w < targetRect.width())
752 offsetX = (targetRect.width() -
w)/2.0
f;
754 if(
h < targetRect.height())
756 offsetY = (targetRect.height() -
h)/2.0
f;
771 QWidget::paintEvent(event);
778 float ratio, offsetX, offsetY;
780 QPainter painter(
this);
785 painter.drawRect(event->rect());
788 painter.translate(offsetX, offsetY);
795 painter.setOpacity(0.5);
800 painter.drawPixmap(QPoint(0,0),
_image);
813 QColor color =
iter.
value()->pen().color();
815 painter.setPen(color);
816 painter.setBrush(color);
817 painter.drawEllipse(
iter.
value()->rect());
827 painter.setPen(QPen((*iter)->pen().color(),
_linesWidth));
828 painter.drawLine((*iter)->line());
838 QWidget::resizeEvent(event);
881 if(QFileInfo(
text).suffix() ==
"")
890 QPrinter printer(QPrinter::HighResolution);
891 printer.setPageOrientation(QPageLayout::Portrait);
892 printer.setOutputFileName(
text );
893 QPainter
p(&printer);
895 double xscale = printer.pageLayout().paintRectPixels(printer.resolution()).width()/double(
_graphicsView->sceneRect().width());
896 double yscale = printer.pageLayout().paintRectPixels(printer.resolution()).height()/double(
_graphicsView->sceneRect().height());
897 double scale = qMin(xscale, yscale);
941 color = QColorDialog::getColor(color,
this);
998 double value = QInputDialog::getDouble(
this, tr(
"Set depth colormap min range"), tr(
"Range (m), 0=no limit"),
_depthColorMapMinRange, 0, 9999, 1, &ok);
1010 double value = QInputDialog::getDouble(
this, tr(
"Set depth colormap max range"), tr(
"Range (m), 0=no limit"),
_depthColorMapMaxRange, 0, 9999, 1, &ok);
1022 int value = QInputDialog::getInt(
this, tr(
"Set features and lines transparency"), tr(
"alpha (0-255)"),
_alpha, 0, 255, 10, &ok);
1032 int value = QInputDialog::getInt(
this, tr(
"Set features size"), tr(
"Size (0 means actual keypoint size)"),
_featuresSize, 0, 999, 1, &ok);
1042 int value = QInputDialog::getInt(
this, tr(
"Set lines width"), tr(
"Width"),
_linesWidth, 0, 999, 1, &ok);
1065 float scale, offsetX, offsetY;
1067 float u = (
event->pos().x() - offsetX) /
scale;
1068 float v = (
event->pos().y() - offsetY) /
scale;
1069 float depthScale = 1;
1074 int ud =
int(u*depthScale);
1075 int vd =
int(
v*depthScale);
1076 if( ud>=0 && vd>=0 &&
1090 cv::Point3f pt(0,0,0);
1094 int subImageIndex = ud / subImageWidth;
1097 _models[subImageIndex].project(u,
v, depth,
x,
y,
z);
1098 pt = cv::Point3f(
x,
y,
z);
1102 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1103 QToolTip::showText(event->globalPosition().toPoint(), 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"));
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"));
1110 QToolTip::hideText();
1113 QWidget::mouseMoveEvent(event);
1122 QGraphicsOpacityEffect * effect =
new QGraphicsOpacityEffect();
1123 effect->setOpacity(0.5);
1143 if (this->
sceneRect().isValid() && !depth.empty() &&
int(
this->sceneRect().height()) % depth.rows == 0 &&
int(
this->sceneRect().width()) % depth.cols == 0)
1145 UDEBUG(
"depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows,
this->sceneRect().width(),
this->sceneRect().height());
1148 UDEBUG(
"xRatio=%f yRatio=%f", xRatio, yRatio);
1151 for(std::multimap<int, cv::KeyPoint>::const_iterator
iter = refWords.begin();
iter != refWords.end(); ++
iter )
1153 if (xRatio > 0 && yRatio > 0)
1175 if (this->
sceneRect().isValid() && !depth.empty() &&
int(
this->sceneRect().height()) % depth.rows == 0 &&
int(
this->sceneRect().width()) % depth.cols == 0)
1177 UDEBUG(
"depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows,
this->sceneRect().width(),
this->sceneRect().height());
1180 UDEBUG(
"xRatio=%f yRatio=%f", xRatio, yRatio);
1183 for(
unsigned int i = 0;
i< features.size(); ++
i )
1185 if(xRatio > 0 && yRatio > 0)
1223 item->setPen(QPen(color));
1237 _image = QPixmap::fromImage(image);
1254 if(image.rect().isValid())
1276 if(
_image.width() > 0 &&
1310 QList<KeypointItem*> items =
_features.values(
id);
1313 for(
int i=0;
i<items.size(); ++
i)
1315 items[
i]->setColor(color);
1320 UWARN(
"Not found feature %d",
id);
1357 QColor
c = (*iter)->pen().color();
1359 (*iter)->setPen(QPen(
c));
1373 const cv::KeyPoint & kpt =
iter.
value()->keypoint();
1376 size = kpt.size==0?3:kpt.size;
1379 iter.
value()->setRect(kpt.pt.x-sizef/2.0f, kpt.pt.y-sizef/2.0f, sizef, sizef);