ImageView.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include "rtabmap/gui/ImageView.h"
29 
30 #include <QtGui/QWheelEvent>
31 #include <QtCore/qmath.h>
32 #include <QMenu>
33 #include <QFileDialog>
34 #include <QtCore/QDir>
35 #include <QAction>
36 #include <QActionGroup>
37 #include <QGraphicsEffect>
38 #include <QInputDialog>
39 #include <QVBoxLayout>
40 #include <QColorDialog>
41 #include <QPrinter>
42 #include <QGraphicsRectItem>
43 #include <QToolTip>
46 #include "rtabmap/core/util2d.h"
48 
49 #include <QtGlobal>
50 #if QT_VERSION >= 0x050000
51  #include <QStandardPaths>
52 #endif
53 
54 namespace rtabmap {
55 
56 //LineItem
57 class LineItem : public QGraphicsLineItem
58 {
59 public:
60  LineItem(float x1, float y1, float x2, float y2, const QString & text = QString(), QGraphicsItem * parent = 0) :
61  QGraphicsLineItem(x1, y1, x2, y2, parent),
62  _text(text),
63  _placeHolder(0)
64  {
65  this->setAcceptHoverEvents(true);
66  this->setFlag(QGraphicsItem::ItemIsFocusable, true);
67  _width = pen().width();
68  }
69  virtual ~LineItem()
70  {
71  delete _placeHolder;
72  }
73 
74  void setWidth(int width)
75  {
76  _width = width;
77  this->setPen(QPen(pen().color(), _width));
78  }
79 
80 protected:
81  virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event )
82  {
83  QGraphicsScene * scene = this->scene();
84  if(scene && scene->focusItem() == 0)
85  {
86  this->showDescription();
87  }
88  else
89  {
90  this->setPen(QPen(pen().color(), _width+2));
91  }
92  QGraphicsLineItem::hoverEnterEvent(event);
93  }
94 
95  virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event )
96  {
97  if(!this->hasFocus())
98  {
99  this->hideDescription();
100  }
101  QGraphicsLineItem::hoverEnterEvent(event);
102  }
103 
104  virtual void focusInEvent ( QFocusEvent * event )
105  {
106  this->showDescription();
107  QGraphicsLineItem::focusInEvent(event);
108  }
109 
110  virtual void focusOutEvent ( QFocusEvent * event )
111  {
112  this->hideDescription();
113  QGraphicsLineItem::focusOutEvent(event);
114  }
115 
116 private:
118  {
119  if(!_text.isEmpty())
120  {
121  if(!_placeHolder)
122  {
123  _placeHolder = new QGraphicsRectItem (this);
124  _placeHolder->setVisible(false);
125  if(qGray(pen().color().rgb() > 255/2))
126  {
127  _placeHolder->setBrush(QBrush(QColor ( 0,0,0, 170 )));
128  }
129  else
130  {
131  _placeHolder->setBrush(QBrush(QColor ( 255, 255, 255, 170 )));
132  }
133  QGraphicsTextItem * text = new QGraphicsTextItem(_placeHolder);
134  text->setDefaultTextColor(this->pen().color().rgb());
135  text->setPlainText(_text);
136  _placeHolder->setRect(text->boundingRect());
137  }
138 
139  if(_placeHolder->parentItem())
140  {
141  _placeHolder->setParentItem(0); // Make it a to level item
142  }
143  _placeHolder->setZValue(this->zValue()+1);
144  _placeHolder->setPos(this->mapFromScene(0,0));
145  _placeHolder->setVisible(true);
146  }
147  QPen pen = this->pen();
148  this->setPen(QPen(pen.color(), _width+2));
149  }
151  {
152  if(_placeHolder)
153  {
154  _placeHolder->setVisible(false);
155  }
156  this->setPen(QPen(pen().color(), _width));
157  }
158 
159 private:
160  QString _text;
161  QGraphicsRectItem * _placeHolder;
162  int _width;
163 };
164 
165 QIcon ImageView::createIcon(const QColor & color)
166 {
167  QPixmap pixmap(50, 50);
168  pixmap.fill(color);
169  return QIcon(pixmap);
170 }
171 
172 ImageView::ImageView(QWidget * parent) :
173  QWidget(parent),
174  _alpha(100),
175  _featuresSize(0.0f),
176  _linesWidth(0),
177  _defaultBgColor(Qt::black),
178  _defaultFeatureColor(Qt::yellow),
179  _defaultMatchingFeatureColor(Qt::magenta),
180  _defaultMatchingLineColor(Qt::cyan),
181  _depthColorMapMinRange(0),
182  _depthColorMapMaxRange(0),
183  _imageItem(0),
184  _imageDepthItem(0)
185 {
186 #if QT_VERSION >= 0x050000
187  _savedFileName = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
188 #endif
189  QDir dir;
190  if(!dir.exists(_savedFileName))
191  {
192  _savedFileName = QDir::homePath()+ "/picture.png";
193  }
194  else
195  {
196  _savedFileName += "/picture.png";
197  }
198 
199  _graphicsView = new QGraphicsView(this);
200  _graphicsView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
201  _graphicsView->setScene(new QGraphicsScene(this));
202  _graphicsView->setVisible(false);
203 
204  this->setLayout(new QVBoxLayout(this));
205  this->layout()->addWidget(_graphicsView);
206  this->layout()->setContentsMargins(0,0,0,0);
207 
208  _menu = new QMenu(tr(""), this);
209  _showImage = _menu->addAction(tr("Show image"));
210  _showImage->setCheckable(true);
211  _showImage->setChecked(true);
212  _showImageDepth = _menu->addAction(tr("Show image depth"));
213  _showImageDepth->setCheckable(true);
214  _showImageDepth->setChecked(false);
215  _featureMenu = _menu->addMenu("Features");
216  _showFeatures = _featureMenu->addAction(tr("Show features"));
217  _showFeatures->setCheckable(true);
218  _showFeatures->setChecked(true);
219  _setFeaturesSize = _featureMenu->addAction(tr("Set features size..."));
220  _showLines = _featureMenu->addAction(tr("Show lines"));
221  _showLines->setCheckable(true);
222  _showLines->setChecked(true);
223  _setLinesWidth = _featureMenu->addAction(tr("Set lines width..."));
224  _setFeatureColor = _featureMenu->addAction(tr("Set default feature color"));
226  _setFeatureColor->setIconVisibleInMenu(true);
227  _setMatchingFeatureColor = _featureMenu->addAction(tr("Set default correspondence color"));
229  _setMatchingFeatureColor->setIconVisibleInMenu(true);
230  _setMatchingLineColor = _featureMenu->addAction(tr("Set default line color"));
232  _setMatchingLineColor->setIconVisibleInMenu(true);
233  _setAlpha = _featureMenu->addAction(tr("Set transparency..."));
234  _graphicsViewMode = _menu->addAction(tr("Graphics view"));
235  _graphicsViewMode->setCheckable(true);
236  _graphicsViewMode->setChecked(false);
237  _scaleMenu = _menu->addMenu("Scale image");
238  _scaleMenu->setEnabled(false);
239  _graphicsViewScaled = _scaleMenu->addAction(tr("Fit in view"));
240  _graphicsViewScaled->setCheckable(true);
241  _graphicsViewScaled->setChecked(true);
242  _graphicsViewScaledToHeight = _scaleMenu->addAction(tr("Fit height"));
243  _graphicsViewScaledToHeight->setCheckable(true);
244  _graphicsViewScaledToHeight->setChecked(false);
245  _graphicsViewNoScaling = _scaleMenu->addAction(tr("No scale"));
246  _graphicsViewNoScaling->setCheckable(true);
247  _graphicsViewNoScaling->setChecked(false);
248  QActionGroup * group = new QActionGroup(this);
249  group->addAction(_graphicsViewScaled);
250  group->addAction(_graphicsViewScaledToHeight);
251  group->addAction(_graphicsViewNoScaling);
252  QMenu * colorMap = _menu->addMenu("Depth color map");
253  _colorMapWhiteToBlack = colorMap->addAction(tr("White to black"));
254  _colorMapWhiteToBlack->setCheckable(true);
255  _colorMapWhiteToBlack->setChecked(false);
256  _colorMapBlackToWhite = colorMap->addAction(tr("Black to white"));
257  _colorMapBlackToWhite->setCheckable(true);
258  _colorMapBlackToWhite->setChecked(false);
259  _colorMapRedToBlue = colorMap->addAction(tr("Red to blue"));
260  _colorMapRedToBlue->setCheckable(true);
261  _colorMapRedToBlue->setChecked(true);
262  _colorMapBlueToRed = colorMap->addAction(tr("Blue to red"));
263  _colorMapBlueToRed->setCheckable(true);
264  _colorMapBlueToRed->setChecked(false);
265  _colorMapMinRange = colorMap->addAction(tr("Min Range..."));
266  _colorMapMaxRange = colorMap->addAction(tr("Max Range..."));
267  group = new QActionGroup(this);
268  group->addAction(_colorMapWhiteToBlack);
269  group->addAction(_colorMapBlackToWhite);
270  group->addAction(_colorMapRedToBlue);
271  group->addAction(_colorMapBlueToRed);
272  group->addAction(_colorMapMaxRange);
273  _mouseTracking = _menu->addAction(tr("Show pixel depth"));
274  _mouseTracking->setCheckable(true);
275  _mouseTracking->setChecked(false);
276  _saveImage = _menu->addAction(tr("Save picture..."));
277  _saveImage->setEnabled(false);
278 
279  setMouseTracking(true);
280 
281  connect(_graphicsView->scene(), SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &)));
282 }
283 
285  clear();
286 }
287 
288 void ImageView::saveSettings(QSettings & settings, const QString & group) const
289 {
290  if(!group.isEmpty())
291  {
292  settings.beginGroup(group);
293  }
294  settings.setValue("image_shown", this->isImageShown());
295  settings.setValue("depth_shown", this->isImageDepthShown());
296  settings.setValue("features_shown", this->isFeaturesShown());
297  settings.setValue("features_size", this->getFeaturesSize());
298  settings.setValue("lines_shown", this->isLinesShown());
299  settings.setValue("lines_width", this->getLinesWidth());
300  settings.setValue("alpha", this->getAlpha());
301  settings.setValue("bg_color", this->getDefaultBackgroundColor());
302  settings.setValue("feature_color", this->getDefaultFeatureColor());
303  settings.setValue("matching_feature_color", this->getDefaultMatchingFeatureColor());
304  settings.setValue("matching_line_color", this->getDefaultMatchingLineColor());
305  settings.setValue("graphics_view", this->isGraphicsViewMode());
306  settings.setValue("graphics_view_scale", this->isGraphicsViewScaled());
307  settings.setValue("graphics_view_scale_to_height", this->isGraphicsViewScaledToHeight());
308  settings.setValue("colormap", _colorMapWhiteToBlack->isChecked()?0:_colorMapBlackToWhite->isChecked()?1:_colorMapRedToBlue->isChecked()?2:3);
309  settings.setValue("colormap_min_range", this->getDepthColorMapMinRange());
310  settings.setValue("colormap_max_range", this->getDepthColorMapMaxRange());
311  if(!group.isEmpty())
312  {
313  settings.endGroup();
314  }
315 }
316 
317 void ImageView::loadSettings(QSettings & settings, const QString & group)
318 {
319  if(!group.isEmpty())
320  {
321  settings.beginGroup(group);
322  }
323  this->setImageShown(settings.value("image_shown", this->isImageShown()).toBool());
324  this->setImageDepthShown(settings.value("depth_shown", this->isImageDepthShown()).toBool());
325  this->setFeaturesShown(settings.value("features_shown", this->isFeaturesShown()).toBool());
326  this->setFeaturesSize(settings.value("features_size", this->getFeaturesSize()).toInt());
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());
330  this->setDefaultBackgroundColor(settings.value("bg_color", this->getDefaultBackgroundColor()).value<QColor>());
331  this->setDefaultFeatureColor(settings.value("feature_color", this->getDefaultFeatureColor()).value<QColor>());
332  this->setDefaultMatchingFeatureColor(settings.value("matching_feature_color", this->getDefaultMatchingFeatureColor()).value<QColor>());
333  this->setDefaultMatchingLineColor(settings.value("matching_line_color", this->getDefaultMatchingLineColor()).value<QColor>());
334  this->setGraphicsViewMode(settings.value("graphics_view", this->isGraphicsViewMode()).toBool());
335  this->setGraphicsViewScaled(settings.value("graphics_view_scale", this->isGraphicsViewScaled()).toBool());
336  this->setGraphicsViewScaledToHeight(settings.value("graphics_view_scale_to_height", this->isGraphicsViewScaledToHeight()).toBool());
337  int colorMap = settings.value("colormap", 2).toInt();
338  _colorMapWhiteToBlack->setChecked(colorMap==0);
339  _colorMapBlackToWhite->setChecked(colorMap==1);
340  _colorMapRedToBlue->setChecked(colorMap==2);
341  _colorMapBlueToRed->setChecked(colorMap==3);
342  this->setDepthColorMapRange(
343  settings.value("colormap_min_range", this->getDepthColorMapMinRange()).toFloat(),
344  settings.value("colormap_max_range", settings.value("colormap_range" /*backward compatibility*/, this->getDepthColorMapMaxRange())).toFloat());
345  if(!group.isEmpty())
346  {
347  settings.endGroup();
348  }
349 }
350 
351 QRectF ImageView::sceneRect() const
352 {
353  return _graphicsView->scene()->sceneRect();
354 }
355 
357 {
358  return _showImage->isChecked();
359 }
360 
362 {
363  return _showImageDepth->isChecked();
364 }
365 
367 {
368  return _showFeatures->isChecked();
369 }
370 
372 {
373  return _graphicsViewMode->isChecked();
374 }
375 
377 {
378  return _graphicsViewScaled->isChecked();
379 }
380 
382 {
383  return _graphicsViewScaledToHeight->isChecked();
384 }
385 
387 {
388  return _defaultBgColor;
389 }
390 const QColor & ImageView::getDefaultFeatureColor() const
391 {
392  return _defaultFeatureColor;
393 }
395 {
397 }
399 {
401 }
402 
403 const QColor & ImageView::getBackgroundColor() const
404 {
405  return _graphicsView->backgroundBrush().color();
406 }
407 
409 {
410  return _depthColorMapMinRange;
411 }
412 
414 {
415  return _depthColorMapMaxRange;
416 }
417 
419 {
421  if(_colorMapBlackToWhite->isChecked())
422  {
423  colorMap = uCvQtDepthBlackToWhite;
424  }
425  else if(_colorMapRedToBlue->isChecked())
426  {
427  colorMap = uCvQtDepthRedToBlue;
428  }
429  else if(_colorMapBlueToRed->isChecked())
430  {
431  colorMap = uCvQtDepthBlueToRed;
432  }
433  return colorMap;
434 }
435 
436 
438 {
439  _showFeatures->setChecked(shown);
440  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
441  {
442  iter.value()->setVisible(_showFeatures->isChecked());
443  }
444 
445  if(!_graphicsView->isVisible())
446  {
447  this->update();
448  }
449 }
450 
451 void ImageView::setImageShown(bool shown)
452 {
453  _showImage->setChecked(shown);
454  if(_imageItem)
455  {
456  _imageItem->setVisible(_showImage->isChecked());
457  this->updateOpacity();
458  }
459 
460  if(!_graphicsView->isVisible())
461  {
462  this->update();
463  }
464 }
465 
467 {
468  _showImageDepth->setChecked(shown);
469  if(_imageDepthItem)
470  {
471  _imageDepthItem->setVisible(_showImageDepth->isChecked());
472  this->updateOpacity();
473  }
474 
475  if(!_graphicsView->isVisible())
476  {
477  this->update();
478  }
479 }
480 
482 {
483  return _showLines->isChecked();
484 }
485 
486 void ImageView::setLinesShown(bool shown)
487 {
488  _showLines->setChecked(shown);
489  for(int i=0; i<_lines.size(); ++i)
490  {
491  _lines.at(i)->setVisible(_showLines->isChecked());
492  }
493 
494  if(!_graphicsView->isVisible())
495  {
496  this->update();
497  }
498 }
499 
500 float ImageView::viewScale() const
501 {
502  if(_graphicsView->isVisible())
503  {
504  return _graphicsView->transform().m11();
505  }
506  else
507  {
508  float scale, offsetX, offsetY;
509  computeScaleOffsets(this->rect(), scale, offsetX, offsetY);
510  return scale;
511  }
512 }
513 
515 {
516  _graphicsViewMode->setChecked(on);
517  _graphicsView->setVisible(on);
518  _scaleMenu->setEnabled(on);
519 
520  if(on)
521  {
522  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
523  {
524  if(iter.value()->scene() != _graphicsView->scene())
525  {
526  _graphicsView->scene()->addItem(iter.value());
527  }
528  }
529 
530  for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
531  {
532  if((*iter)->scene() != _graphicsView->scene())
533  {
534  _graphicsView->scene()->addItem(*iter);
535  }
536  }
537 
538  //update images
539  if(_imageItem)
540  {
541  _imageItem->setPixmap(_image);
542  }
543  else
544  {
545  _imageItem = _graphicsView->scene()->addPixmap(_image);
546  _imageItem->setVisible(_showImage->isChecked());
547  }
548 
549  if(_imageDepthItem)
550  {
551  _imageDepthItem->setPixmap(_imageDepth);
552  }
553  else
554  {
555  _imageDepthItem = _graphicsView->scene()->addPixmap(_imageDepth);
556  _imageDepthItem->setVisible(_showImageDepth->isChecked());
557  }
558  this->updateOpacity();
559 
560  if(_graphicsViewScaled->isChecked())
561  {
562  _graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
563  }
564  else if(_graphicsViewScaledToHeight->isChecked())
565  {
566  QRectF rect = _graphicsView->sceneRect();
567  rect.setWidth(1);
568  _graphicsView->fitInView(rect, Qt::KeepAspectRatio);
569  }
570  else
571  {
572  _graphicsView->resetTransform();
573  }
574  }
575  else
576  {
577  this->update();
578  }
579 }
580 
582 {
583  _graphicsViewScaled->setChecked(scaled);
584 
585  if(scaled)
586  {
587  _graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
588  }
589  else
590  {
591  _graphicsView->resetTransform();
592  }
593 
594  if(!_graphicsView->isVisible())
595  {
596  this->update();
597  }
598 }
599 
601 {
602  _graphicsViewScaledToHeight->setChecked(scaled);
603 
604  if(scaled)
605  {
606  QRectF rect = _graphicsView->sceneRect();
607  rect.setWidth(1);
608  _graphicsView->fitInView(rect, Qt::KeepAspectRatio);
609  }
610  else
611  {
612  _graphicsView->resetTransform();
613  }
614 
615  if(!_graphicsView->isVisible())
616  {
617  this->update();
618  }
619 }
620 
621 void ImageView::setDefaultBackgroundColor(const QColor & color)
622 {
623  _defaultBgColor = color;
624  setBackgroundColor(color);
625 }
626 
627 void ImageView::setDefaultFeatureColor(const QColor & color)
628 {
629  QColor previousColor = _defaultFeatureColor;
630  _defaultFeatureColor = color;
631  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
632  {
633  if(QColor(iter.value()->pen().color().rgb()) == previousColor)
634  {
635  QColor c = _defaultFeatureColor;
636  c.setAlpha(_alpha);
637  iter.value()->setPen(QPen(c));
638  iter.value()->setBrush(QBrush(c));
639  }
640  }
641  if(!_graphicsView->isVisible())
642  {
643  this->update();
644  }
645 }
647 {
648  QColor previousColor = _defaultMatchingFeatureColor;
650  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
651  {
652  if(QColor(iter.value()->pen().color().rgb()) == previousColor)
653  {
655  c.setAlpha(_alpha);
656  iter.value()->setPen(QPen(c));
657  iter.value()->setBrush(QBrush(c));
658  }
659  }
660 
661  for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
662  {
663  if(QColor((*iter)->pen().color().rgb()) == previousColor)
664  {
666  c.setAlpha(_alpha);
667  (*iter)->setPen(QPen(c));
668  }
669  }
670  if(!_graphicsView->isVisible())
671  {
672  this->update();
673  }
674 }
675 void ImageView::setDefaultMatchingLineColor(const QColor & color)
676 {
677  QColor previousColor = _defaultMatchingLineColor;
679  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
680  {
681  if(QColor(iter.value()->pen().color().rgb()) == previousColor)
682  {
683  QColor c = _defaultMatchingLineColor;
684  c.setAlpha(_alpha);
685  iter.value()->setPen(QPen(c));
686  iter.value()->setBrush(QBrush(c));
687  }
688  }
689 
690  for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
691  {
692  if(QColor((*iter)->pen().color().rgb()) == previousColor)
693  {
694  QColor c = _defaultMatchingLineColor;
695  c.setAlpha(_alpha);
696  (*iter)->setPen(QPen(c));
697  }
698  }
699  if(!_graphicsView->isVisible())
700  {
701  this->update();
702  }
703 }
704 
705 void ImageView::setBackgroundColor(const QColor & color)
706 {
707  _graphicsView->setBackgroundBrush(QBrush(color));
708 
709  if(!_graphicsView->isVisible())
710  {
711  this->update();
712  }
713 }
714 
716 {
719 }
720 
721 
722 void ImageView::computeScaleOffsets(const QRect & targetRect, float & scale, float & offsetX, float & offsetY) const
723 {
724  scale = 1.0f;
725  offsetX = 0.0f;
726  offsetY = 0.0f;
727 
728  if(!_graphicsView->scene()->sceneRect().isNull())
729  {
730  float w = _graphicsView->scene()->width();
731  float h = _graphicsView->scene()->height();
732  float widthRatio = float(targetRect.width()) / w;
733  float heightRatio = float(targetRect.height()) / h;
734 
735  //printf("w=%f, h=%f, wR=%f, hR=%f, sW=%d, sH=%d\n", w, h, widthRatio, heightRatio, this->rect().width(), this->rect().height());
736  if(widthRatio < heightRatio)
737  {
738  scale = widthRatio;
739  }
740  else
741  {
742  scale = heightRatio;
743  }
744 
745  //printf("ratio=%f\n",ratio);
746 
747  w *= scale;
748  h *= scale;
749 
750  if(w < targetRect.width())
751  {
752  offsetX = (targetRect.width() - w)/2.0f;
753  }
754  if(h < targetRect.height())
755  {
756  offsetY = (targetRect.height() - h)/2.0f;
757  }
758  //printf("offsetX=%f, offsetY=%f\n",offsetX, offsetY);
759  }
760 }
761 
762 void ImageView::sceneRectChanged(const QRectF & rect)
763 {
764  _saveImage->setEnabled(rect.isValid());
765 }
766 
767 void ImageView::paintEvent(QPaintEvent *event)
768 {
769  if(_graphicsViewMode->isChecked())
770  {
771  QWidget::paintEvent(event);
772  }
773  else
774  {
775  if(!_graphicsView->scene()->sceneRect().isNull())
776  {
777  //Scale
778  float ratio, offsetX, offsetY;
779  this->computeScaleOffsets(event->rect(), ratio, offsetX, offsetY);
780  QPainter painter(this);
781 
782  //Background
783  painter.save();
784  painter.setBrush(_graphicsView->backgroundBrush());
785  painter.drawRect(event->rect());
786  painter.restore();
787 
788  painter.translate(offsetX, offsetY);
789  painter.scale(ratio, ratio);
790 
791  painter.save();
792  if(_showImage->isChecked() && !_image.isNull() &&
793  _showImageDepth->isChecked() && !_imageDepth.isNull())
794  {
795  painter.setOpacity(0.5);
796  }
797 
798  if(_showImage->isChecked() && !_image.isNull())
799  {
800  painter.drawPixmap(QPoint(0,0), _image);
801  }
802 
803  if(_showImageDepth->isChecked() && !_imageDepth.isNull())
804  {
805  painter.drawPixmap(QPoint(0,0), _imageDepth);
806  }
807  painter.restore();
808 
809  if(_showFeatures->isChecked())
810  {
811  for(QMultiMap<int, rtabmap::KeypointItem *>::iterator iter = _features.begin(); iter != _features.end(); ++iter)
812  {
813  QColor color = iter.value()->pen().color();
814  painter.save();
815  painter.setPen(color);
816  painter.setBrush(color);
817  painter.drawEllipse(iter.value()->rect());
818  painter.restore();
819  }
820  }
821 
822  if(_showLines->isChecked())
823  {
824  for(QList<QGraphicsLineItem*>::iterator iter = _lines.begin(); iter != _lines.end(); ++iter)
825  {
826  painter.save();
827  painter.setPen(QPen((*iter)->pen().color(), _linesWidth));
828  painter.drawLine((*iter)->line());
829  painter.restore();
830  }
831  }
832  }
833  }
834 }
835 
836 void ImageView::resizeEvent(QResizeEvent* event)
837 {
838  QWidget::resizeEvent(event);
839  if(_graphicsView->isVisible())
840  {
841  if(_graphicsViewScaled->isChecked())
842  {
843  _graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
844  }
845  else if(_graphicsViewScaledToHeight->isChecked())
846  {
847  QRectF rect = _graphicsView->sceneRect();
848  rect.setWidth(1);
849  _graphicsView->fitInView(rect, Qt::KeepAspectRatio);
850  }
851  }
852 }
853 
854 void ImageView::contextMenuEvent(QContextMenuEvent * e)
855 {
859  _setFeatureColor->setIconVisibleInMenu(true);
860  _setMatchingFeatureColor->setIconVisibleInMenu(true);
861  _setMatchingLineColor->setIconVisibleInMenu(true);
862 
863  QAction * action = _menu->exec(e->globalPos());
864  if(action == _saveImage)
865  {
866  if(!_graphicsView->scene()->sceneRect().isNull())
867  {
868  QString text;
869  QString extensions = "*.png *.xpm *.jpg";
870  if(_graphicsView->isVisible())
871  {
872  extensions += " *.pdf";
873  }
874 #ifdef QT_SVG_LIB
875  extensions += " *.svg";
876 #endif
877  text = QFileDialog::getSaveFileName(this, tr("Save figure to ..."), _savedFileName, extensions);
878 
879  if(!text.isEmpty())
880  {
881  if(QFileInfo(text).suffix() == "")
882  {
883  //use png by default
884  text += ".png";
885  }
886 
888  if(QFileInfo(text).suffix().compare("pdf") == 0)
889  {
890  QPrinter printer(QPrinter::HighResolution);
891  printer.setPageOrientation(QPageLayout::Portrait);
892  printer.setOutputFileName( text );
893  QPainter p(&printer);
894  p.begin(&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);
898  p.scale(scale, scale);
899  _graphicsView->scene()->render(&p, _graphicsView->sceneRect(), _graphicsView->sceneRect());
900  p.end();
901  }
902  else
903  {
904  QImage img(_graphicsView->sceneRect().width(), _graphicsView->sceneRect().height(), QImage::Format_ARGB32_Premultiplied);
905  QPainter p(&img);
906  if(_graphicsView->isVisible())
907  {
908  _graphicsView->scene()->render(&p, _graphicsView->sceneRect(), _graphicsView->sceneRect());
909  }
910  else
911  {
912  this->render(&p, QPoint(), _graphicsView->sceneRect().toRect());
913  }
914  img.save(text);
915  }
916  }
917  }
918  }
919  else if(action == _showFeatures)
920  {
921  this->setFeaturesShown(_showFeatures->isChecked());
922  Q_EMIT configChanged();
923  }
924  else if(action == _setFeatureColor ||
927  {
928  QColor color;
930  {
932  }
933  else if(action == _setMatchingLineColor)
934  {
936  }
937  else //if(action == _setFeatureColor)
938  {
939  color = _defaultFeatureColor;
940  }
941  color = QColorDialog::getColor(color, this);
942  if(color.isValid())
943  {
944 
946  {
947  this->setDefaultMatchingFeatureColor(color);
948  }
949  else if(action == _setMatchingLineColor)
950  {
951  this->setDefaultMatchingLineColor(color);
952  }
953  else //if(action == _setFeatureColor)
954  {
955  this->setDefaultFeatureColor(color);
956  }
957  }
958  }
959  else if(action == _showImage)
960  {
961  this->setImageShown(_showImage->isChecked());
962  Q_EMIT configChanged();
963  }
964  else if(action == _showImageDepth)
965  {
966  this->setImageDepthShown(_showImageDepth->isChecked());
967  Q_EMIT configChanged();
968  }
969  else if(action == _showLines)
970  {
971  this->setLinesShown(_showLines->isChecked());
972  Q_EMIT configChanged();
973  }
974  else if(action == _graphicsViewMode)
975  {
976  this->setGraphicsViewMode(_graphicsViewMode->isChecked());
977  Q_EMIT configChanged();
978  }
979  else if(action == _graphicsViewScaled)
980  {
981  this->setGraphicsViewScaled(_graphicsViewScaled->isChecked());
982  Q_EMIT configChanged();
983  }
985  {
987  Q_EMIT configChanged();
988  }
990  {
991  if(!_imageDepthCv.empty())
993  Q_EMIT configChanged();
994  }
995  else if(action == _colorMapMinRange)
996  {
997  bool ok = false;
998  double value = QInputDialog::getDouble(this, tr("Set depth colormap min range"), tr("Range (m), 0=no limit"), _depthColorMapMinRange, 0, 9999, 1, &ok);
999  if(ok)
1000  {
1002  if(!_imageDepthCv.empty())
1004  Q_EMIT configChanged();
1005  }
1006  }
1007  else if(action == _colorMapMaxRange)
1008  {
1009  bool ok = false;
1010  double value = QInputDialog::getDouble(this, tr("Set depth colormap max range"), tr("Range (m), 0=no limit"), _depthColorMapMaxRange, 0, 9999, 1, &ok);
1011  if(ok)
1012  {
1014  if(!_imageDepthCv.empty())
1016  Q_EMIT configChanged();
1017  }
1018  }
1019  else if(action == _setAlpha)
1020  {
1021  bool ok = false;
1022  int value = QInputDialog::getInt(this, tr("Set features and lines transparency"), tr("alpha (0-255)"), _alpha, 0, 255, 10, &ok);
1023  if(ok)
1024  {
1025  this->setAlpha(value);
1026  Q_EMIT configChanged();
1027  }
1028  }
1029  else if(action == _setFeaturesSize)
1030  {
1031  bool ok = false;
1032  int value = QInputDialog::getInt(this, tr("Set features size"), tr("Size (0 means actual keypoint size)"), _featuresSize, 0, 999, 1, &ok);
1033  if(ok)
1034  {
1035  this->setFeaturesSize(value);
1036  Q_EMIT configChanged();
1037  }
1038  }
1039  else if(action == _setLinesWidth)
1040  {
1041  bool ok = false;
1042  int value = QInputDialog::getInt(this, tr("Set lines width"), tr("Width"), _linesWidth, 0, 999, 1, &ok);
1043  if(ok)
1044  {
1045  this->setLinesWidth(value);
1046  Q_EMIT configChanged();
1047  }
1048  }
1049 
1051  {
1052  this->updateOpacity();
1053  Q_EMIT configChanged();
1054  }
1055 }
1056 
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(), 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"));
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 
1117 {
1119  {
1120  if(_imageItem->isVisible() && _imageDepthItem->isVisible())
1121  {
1122  QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect();
1123  effect->setOpacity(0.5);
1124  _imageDepthItem->setGraphicsEffect(effect);
1125  }
1126  else
1127  {
1128  _imageDepthItem->setGraphicsEffect(0);
1129  }
1130  }
1131  else if(_imageDepthItem)
1132  {
1133  _imageDepthItem->setGraphicsEffect(0);
1134  }
1135 }
1136 
1137 void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords, const cv::Mat & depth, const QColor & color)
1138 {
1139  clearFeatures();
1140 
1141  float xRatio = 0;
1142  float yRatio = 0;
1143  if (this->sceneRect().isValid() && !depth.empty() && int(this->sceneRect().height()) % depth.rows == 0 && int(this->sceneRect().width()) % depth.cols == 0)
1144  {
1145  UDEBUG("depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows, this->sceneRect().width(), this->sceneRect().height());
1146  xRatio = float(depth.cols)/float(this->sceneRect().width());
1147  yRatio = float(depth.rows)/float(this->sceneRect().height());
1148  UDEBUG("xRatio=%f yRatio=%f", xRatio, yRatio);
1149  }
1150 
1151  for(std::multimap<int, cv::KeyPoint>::const_iterator iter = refWords.begin(); iter != refWords.end(); ++iter )
1152  {
1153  if (xRatio > 0 && yRatio > 0)
1154  {
1155  addFeature(iter->first, iter->second, util2d::getDepth(depth, iter->second.pt.x*xRatio, iter->second.pt.y*yRatio, false), color);
1156  }
1157  else
1158  {
1159  addFeature(iter->first, iter->second, 0, color);
1160  }
1161  }
1162 
1163  if(!_graphicsView->isVisible())
1164  {
1165  this->update();
1166  }
1167 }
1168 
1169 void ImageView::setFeatures(const std::vector<cv::KeyPoint> & features, const cv::Mat & depth, const QColor & color)
1170 {
1171  clearFeatures();
1172 
1173  float xRatio = 0;
1174  float yRatio = 0;
1175  if (this->sceneRect().isValid() && !depth.empty() && int(this->sceneRect().height()) % depth.rows == 0 && int(this->sceneRect().width()) % depth.cols == 0)
1176  {
1177  UDEBUG("depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows, this->sceneRect().width(), this->sceneRect().height());
1178  xRatio = float(depth.cols) / float(this->sceneRect().width());
1179  yRatio = float(depth.rows) / float(this->sceneRect().height());
1180  UDEBUG("xRatio=%f yRatio=%f", xRatio, yRatio);
1181  }
1182 
1183  for(unsigned int i = 0; i< features.size(); ++i )
1184  {
1185  if(xRatio > 0 && yRatio > 0)
1186  {
1187  addFeature(i, features[i], util2d::getDepth(depth, features[i].pt.x*xRatio, features[i].pt.y*yRatio, false), color);
1188  }
1189  else
1190  {
1191  addFeature(i, features[i], 0, color);
1192  }
1193  }
1194 
1195  if(!_graphicsView->isVisible())
1196  {
1197  this->update();
1198  }
1199 }
1200 
1201 void ImageView::addFeature(int id, const cv::KeyPoint & kpt, float depth, QColor color)
1202 {
1203  color.setAlpha(this->getAlpha());
1204  rtabmap::KeypointItem * item = new rtabmap::KeypointItem(id, kpt, depth, color);
1205  if(_featuresSize>0.0f)
1206  {
1207  item->setRect(kpt.pt.x-_featuresSize/2.0f, kpt.pt.y-_featuresSize/2.0f, _featuresSize, _featuresSize);
1208  }
1209  _features.insert(id, item);
1210  item->setVisible(isFeaturesShown());
1211  item->setZValue(1);
1212 
1213  if(_graphicsView->isVisible())
1214  {
1215  _graphicsView->scene()->addItem(item);
1216  }
1217 }
1218 
1219 void ImageView::addLine(float x1, float y1, float x2, float y2, QColor color, const QString & text)
1220 {
1221  color.setAlpha(this->getAlpha());
1222  LineItem * item = new LineItem(x1, y1, x2, y2, text);
1223  item->setPen(QPen(color));
1224  item->setWidth(_linesWidth);
1225  _lines.push_back(item);
1226  item->setVisible(isLinesShown());
1227  item->setZValue(1);
1228 
1229  if(_graphicsView->isVisible())
1230  {
1231  _graphicsView->scene()->addItem(item);
1232  }
1233 }
1234 
1235 void ImageView::setImage(const QImage & image, const std::vector<CameraModel> & models, const Transform & pose)
1236 {
1237  _image = QPixmap::fromImage(image);
1238  _models = models;
1239  _pose = pose;
1240  if(_graphicsView->isVisible())
1241  {
1242  if(_imageItem)
1243  {
1244  _imageItem->setPixmap(_image);
1245  }
1246  else
1247  {
1248  _imageItem = _graphicsView->scene()->addPixmap(_image);
1249  _imageItem->setVisible(_showImage->isChecked());
1250  this->updateOpacity();
1251  }
1252  }
1253 
1254  if(image.rect().isValid())
1255  {
1256  this->setSceneRect(image.rect());
1257  }
1258  else if(!_graphicsView->isVisible())
1259  {
1260  this->update();
1261  }
1262 }
1263 
1264 void ImageView::setImageDepth(const cv::Mat & imageDepth)
1265 {
1266  _imageDepthCv = imageDepth;
1268 }
1269 
1270 void ImageView::setImageDepth(const QImage & imageDepth)
1271 {
1272  _imageDepth = QPixmap::fromImage(imageDepth);
1273 
1274  UASSERT(_imageDepth.width() && _imageDepth.height());
1275 
1276  if( _image.width() > 0 &&
1277  _image.width() > _imageDepth.width() &&
1278  _image.height() > _imageDepth.height())
1279  {
1280  // scale depth to rgb
1281  _imageDepth = _imageDepth.scaled(_image.size());
1282  }
1283 
1284  if(_graphicsView->isVisible())
1285  {
1286  if(_imageDepthItem)
1287  {
1288  _imageDepthItem->setPixmap(_imageDepth);
1289  }
1290  else
1291  {
1292  _imageDepthItem = _graphicsView->scene()->addPixmap(_imageDepth);
1293  _imageDepthItem->setVisible(_showImageDepth->isChecked());
1294  this->updateOpacity();
1295  }
1296  }
1297  else
1298  {
1299  if(_image.isNull())
1300  {
1301  this->setSceneRect(imageDepth.rect());
1302  }
1303  this->update();
1304  }
1305 }
1306 
1307 void ImageView::setFeatureColor(int id, QColor color)
1308 {
1309  color.setAlpha(getAlpha());
1310  QList<KeypointItem*> items = _features.values(id);
1311  if(items.size())
1312  {
1313  for(int i=0; i<items.size(); ++i)
1314  {
1315  items[i]->setColor(color);
1316  }
1317  }
1318  else
1319  {
1320  UWARN("Not found feature %d", id);
1321  }
1322 
1323  if(!_graphicsView->isVisible())
1324  {
1325  this->update();
1326  }
1327 }
1328 
1330 {
1331  color.setAlpha(getAlpha());
1332  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
1333  {
1334  iter.value()->setColor(color);
1335  }
1336 
1337  if(!_graphicsView->isVisible())
1338  {
1339  this->update();
1340  }
1341 }
1342 
1343 void ImageView::setAlpha(int alpha)
1344 {
1345  UASSERT(alpha >=0 && alpha <= 255);
1346  _alpha = alpha;
1347  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
1348  {
1349  QColor c = iter.value()->pen().color();
1350  c.setAlpha(_alpha);
1351  iter.value()->setPen(QPen(c));
1352  iter.value()->setBrush(QBrush(c));
1353  }
1354 
1355  for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
1356  {
1357  QColor c = (*iter)->pen().color();
1358  c.setAlpha(_alpha);
1359  (*iter)->setPen(QPen(c));
1360  }
1361 
1362  if(!_graphicsView->isVisible())
1363  {
1364  this->update();
1365  }
1366 }
1367 
1369 {
1370  _featuresSize = size;
1371  for(QMultiMap<int, KeypointItem*>::iterator iter=_features.begin(); iter!=_features.end(); ++iter)
1372  {
1373  const cv::KeyPoint & kpt = iter.value()->keypoint();
1374  if(size <= 0.0f)
1375  {
1376  size = kpt.size==0?3:kpt.size;
1377  }
1378  float sizef = size;
1379  iter.value()->setRect(kpt.pt.x-sizef/2.0f, kpt.pt.y-sizef/2.0f, sizef, sizef);
1380  }
1381 
1382  if(!_graphicsView->isVisible())
1383  {
1384  this->update();
1385  }
1386 }
1387 
1389 {
1390  _linesWidth = width;
1391  for(QList<QGraphicsLineItem*>::iterator iter=_lines.begin(); iter!=_lines.end(); ++iter)
1392  {
1393  if(dynamic_cast<LineItem*>(*iter))
1394  {
1395  ((LineItem*)(*iter))->setWidth(_linesWidth);
1396  }
1397  }
1398  if(!_graphicsView->isVisible())
1399  {
1400  this->update();
1401  }
1402 }
1403 
1404 void ImageView::setSceneRect(const QRectF & rect)
1405 {
1406  _graphicsView->scene()->setSceneRect(rect);
1407 
1408  if(_graphicsViewScaled->isChecked())
1409  {
1410  _graphicsView->fitInView(_graphicsView->sceneRect(), Qt::KeepAspectRatio);
1411  }
1412  else if(_graphicsViewScaledToHeight->isChecked())
1413  {
1414  QRectF rect = _graphicsView->sceneRect();
1415  rect.setWidth(1);
1416  _graphicsView->fitInView(rect, Qt::KeepAspectRatio);
1417  }
1418  else
1419  {
1420  _graphicsView->resetTransform();
1421  }
1422 
1423  if(!_graphicsView->isVisible())
1424  {
1425  this->update();
1426  }
1427 }
1428 
1430 {
1431  qDeleteAll(_lines);
1432  _lines.clear();
1433 
1434  if(!_graphicsView->isVisible())
1435  {
1436  this->update();
1437  }
1438 }
1439 
1441 {
1442  qDeleteAll(_features);
1443  _features.clear();
1444 
1445  if(!_graphicsView->isVisible())
1446  {
1447  this->update();
1448  }
1449 }
1450 
1452 {
1453  clearFeatures();
1454 
1455  qDeleteAll(_lines);
1456  _lines.clear();
1457 
1458  if(_imageItem)
1459  {
1460  _graphicsView->scene()->removeItem(_imageItem);
1461  delete _imageItem;
1462  _imageItem = 0;
1463  }
1464  _image = QPixmap();
1465  _models.clear();
1466  _pose.setNull();
1467 
1468  if(_imageDepthItem)
1469  {
1470  _graphicsView->scene()->removeItem(_imageDepthItem);
1471  delete _imageDepthItem;
1472  _imageDepthItem = 0;
1473  }
1474  _imageDepth = QPixmap();
1475 
1476  _graphicsView->scene()->setSceneRect(QRectF());
1477  _graphicsView->setScene(_graphicsView->scene());
1478 
1479  if(!_graphicsView->isVisible())
1480  {
1481  this->update();
1482  }
1483 }
1484 
1485 QSize ImageView::sizeHint() const
1486 {
1487  return _graphicsView->sizeHint();
1488 }
1489 
1490 }
w
RowVector3d w
int
int
glm::min
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
rtabmap::ImageView::getDepthColorMapMinRange
float getDepthColorMapMinRange() const
Definition: ImageView.cpp:408
compare
bool compare
rtabmap::ImageView::_setLinesWidth
QAction * _setLinesWidth
Definition: ImageView.h:158
rtabmap::ImageView::setLinesWidth
void setLinesWidth(int width)
Definition: ImageView.cpp:1388
rtabmap::ImageView::_image
QPixmap _image
Definition: ImageView.h:178
rtabmap::ImageView::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
Definition: ImageView.cpp:836
update
def update(text)
rtabmap::LineItem::_placeHolder
QGraphicsRectItem * _placeHolder
Definition: ImageView.cpp:161
rtabmap::ImageView::_showFeatures
QAction * _showFeatures
Definition: ImageView.h:150
ImageView.h
rtabmap::ImageView::setImageDepthShown
void setImageDepthShown(bool shown)
Definition: ImageView.cpp:466
rtabmap::ImageView::computeScaleOffsets
void computeScaleOffsets(const QRect &targetRect, float &scale, float &offsetX, float &offsetY) const
Definition: ImageView.cpp:722
rtabmap::ImageView::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *e)
Definition: ImageView.cpp:854
rtabmap::ImageView::_setFeatureColor
QAction * _setFeatureColor
Definition: ImageView.h:152
rtabmap::ImageView::_showImage
QAction * _showImage
Definition: ImageView.h:148
rtabmap::ImageView::_graphicsView
QGraphicsView * _graphicsView
Definition: ImageView.h:173
x1
x1
arg::arg
constexpr arg(const char *name=nullptr)
rtabmap::ImageView::createIcon
QIcon createIcon(const QColor &color)
Definition: ImageView.cpp:165
alpha
RealScalar alpha
rtabmap::LineItem::~LineItem
virtual ~LineItem()
Definition: ImageView.cpp:69
uCvQtDepthRedToBlue
@ uCvQtDepthRedToBlue
Definition: UCv2Qt.h:33
c
Scalar Scalar * c
h
const double h
rtabmap::ImageView::setGraphicsViewScaledToHeight
void setGraphicsViewScaledToHeight(bool scaled)
Definition: ImageView.cpp:600
size
Index size
this
this
rtabmap::ImageView::_colorMapWhiteToBlack
QAction * _colorMapWhiteToBlack
Definition: ImageView.h:163
rtabmap::ImageView::setDefaultFeatureColor
void setDefaultFeatureColor(const QColor &color)
Definition: ImageView.cpp:627
rtabmap::ImageView::addLine
void addLine(float x1, float y1, float x2, float y2, QColor color, const QString &text=QString())
Definition: ImageView.cpp:1219
rtabmap::ImageView::sceneRect
QRectF sceneRect() const
Definition: ImageView.cpp:351
rtabmap::ImageView::_linesWidth
int _linesWidth
Definition: ImageView.h:139
rtabmap::ImageView::viewScale
float viewScale() const
Definition: ImageView.cpp:500
rtabmap::LineItem::hoverLeaveEvent
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: ImageView.cpp:95
rtabmap::ImageView::_showImageDepth
QAction * _showImageDepth
Definition: ImageView.h:149
rtabmap::ImageView::_defaultFeatureColor
QColor _defaultFeatureColor
Definition: ImageView.h:141
rtabmap::LineItem::focusInEvent
virtual void focusInEvent(QFocusEvent *event)
Definition: ImageView.cpp:104
rtabmap::ImageView::_imageDepthItem
QGraphicsPixmapItem * _imageDepthItem
Definition: ImageView.h:177
uCvQtDepthColorMap
uCvQtDepthColorMap
Definition: UCv2Qt.h:30
rtabmap_netvlad.img
img
Definition: rtabmap_netvlad.py:78
rtabmap::ImageView::_scaleMenu
QMenu * _scaleMenu
Definition: ImageView.h:171
rtabmap::ImageView::clearLines
void clearLines()
Definition: ImageView.cpp:1429
rtabmap::ImageView::_showLines
QAction * _showLines
Definition: ImageView.h:151
rtabmap::ImageView::setSceneRect
void setSceneRect(const QRectF &rect)
Definition: ImageView.cpp:1404
y
Matrix3f y
rtabmap::ImageView::isGraphicsViewScaled
bool isGraphicsViewScaled() const
Definition: ImageView.cpp:376
rtabmap::ImageView::setImageShown
void setImageShown(bool shown)
Definition: ImageView.cpp:451
rtabmap::ImageView::setDefaultMatchingLineColor
void setDefaultMatchingLineColor(const QColor &color)
Definition: ImageView.cpp:675
rtabmap::ImageView::_colorMapMaxRange
QAction * _colorMapMaxRange
Definition: ImageView.h:168
rtabmap::KeypointItem
Definition: KeypointItem.h:41
rtabmap::Transform::setNull
void setNull()
Definition: Transform.cpp:152
rtabmap::ImageView::_setMatchingFeatureColor
QAction * _setMatchingFeatureColor
Definition: ImageView.h:153
rtabmap::ImageView::addFeature
void addFeature(int id, const cv::KeyPoint &kpt, float depth, QColor color)
Definition: ImageView.cpp:1201
rtabmap::ImageView::configChanged
void configChanged()
rtabmap::ImageView::getDepthColorMapMaxRange
float getDepthColorMapMaxRange() const
Definition: ImageView.cpp:413
uCvQtDepthBlueToRed
@ uCvQtDepthBlueToRed
Definition: UCv2Qt.h:34
rtabmap::ImageView::_colorMapMinRange
QAction * _colorMapMinRange
Definition: ImageView.h:167
rtabmap::Transform::isNull
bool isNull() const
Definition: Transform.cpp:107
rtabmap::ImageView::saveSettings
void saveSettings(QSettings &settings, const QString &group="") const
Definition: ImageView.cpp:288
KeypointItem.h
rtabmap::ImageView::_graphicsViewMode
QAction * _graphicsViewMode
Definition: ImageView.h:159
rtabmap::ImageView::getDefaultFeatureColor
const QColor & getDefaultFeatureColor() const
Definition: ImageView.cpp:390
rtabmap::ImageView::getFeaturesSize
int getFeaturesSize() const
Definition: ImageView.h:66
rtabmap::ImageView::loadSettings
void loadSettings(QSettings &settings, const QString &group="")
Definition: ImageView.cpp:317
rtabmap::ImageView::_setFeaturesSize
QAction * _setFeaturesSize
Definition: ImageView.h:157
rtabmap::ImageView::_setAlpha
QAction * _setAlpha
Definition: ImageView.h:156
rtabmap::ImageView::_menu
QMenu * _menu
Definition: ImageView.h:147
rtabmap::ImageView::setBackgroundColor
void setBackgroundColor(const QColor &color)
Definition: ImageView.cpp:705
rtabmap::util3d::transformPoint
cv::Point3f RTABMAP_CORE_EXPORT transformPoint(const cv::Point3f &pt, const Transform &transform)
Definition: util3d_transforms.cpp:211
rtabmap::ImageView::isGraphicsViewScaledToHeight
bool isGraphicsViewScaledToHeight() const
Definition: ImageView.cpp:381
rtabmap::ImageView::setLinesShown
void setLinesShown(bool shown)
Definition: ImageView.cpp:486
rtabmap::ImageView::_imageDepth
QPixmap _imageDepth
Definition: ImageView.h:179
rtabmap::ImageView::setImage
void setImage(const QImage &image, const std::vector< CameraModel > &models=std::vector< CameraModel >(), const Transform &pose=Transform())
Definition: ImageView.cpp:1235
rtabmap::ImageView::_defaultBgColor
QColor _defaultBgColor
Definition: ImageView.h:140
rtabmap::ImageView::_depthColorMapMaxRange
float _depthColorMapMaxRange
Definition: ImageView.h:145
util3d_transforms.h
rtabmap::ImageView::ImageView
ImageView(QWidget *parent=0)
Definition: ImageView.cpp:172
scale
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
rtabmap::ImageView::_colorMapRedToBlue
QAction * _colorMapRedToBlue
Definition: ImageView.h:165
rtabmap::ImageView::_lines
QList< QGraphicsLineItem * > _lines
Definition: ImageView.h:175
rtabmap::LineItem::showDescription
void showDescription()
Definition: ImageView.cpp:117
rtabmap::ImageView::_graphicsViewScaledToHeight
QAction * _graphicsViewScaledToHeight
Definition: ImageView.h:161
rtabmap::LineItem
Definition: ImageView.cpp:57
rtabmap::ImageView::_models
std::vector< CameraModel > _models
Definition: ImageView.h:181
rtabmap::LineItem::setWidth
void setWidth(int width)
Definition: ImageView.cpp:74
arg
rtabmap::ImageView::setGraphicsViewScaled
void setGraphicsViewScaled(bool scaled)
Definition: ImageView.cpp:581
glm::max
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
x2
x2
rtabmap::ImageView::getDefaultMatchingFeatureColor
const QColor & getDefaultMatchingFeatureColor() const
Definition: ImageView.cpp:394
rtabmap::ImageView::clearFeatures
void clearFeatures()
Definition: ImageView.cpp:1440
rtabmap::ImageView::_colorMapBlueToRed
QAction * _colorMapBlueToRed
Definition: ImageView.h:166
rtabmap::ImageView::isGraphicsViewMode
bool isGraphicsViewMode() const
Definition: ImageView.cpp:371
rtabmap::ImageView::_defaultMatchingLineColor
QColor _defaultMatchingLineColor
Definition: ImageView.h:143
UASSERT
#define UASSERT(condition)
rtabmap::ImageView::~ImageView
virtual ~ImageView()
Definition: ImageView.cpp:284
z
z
x
x
iterator::value
object value
p
Point3_ p(2)
rtabmap::LineItem::hoverEnterEvent
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: ImageView.cpp:81
rtabmap::util2d::getDepth
float RTABMAP_CORE_EXPORT getDepth(const cv::Mat &depthImage, float x, float y, bool smoothing, float depthErrorRatio=0.02f, bool estWithNeighborsIfNull=false)
Definition: util2d.cpp:947
action
action
rtabmap::LineItem::_width
int _width
Definition: ImageView.cpp:162
rtabmap::LineItem::focusOutEvent
virtual void focusOutEvent(QFocusEvent *event)
Definition: ImageView.cpp:110
UWARN
#define UWARN(...)
rtabmap::ImageView::_saveImage
QAction * _saveImage
Definition: ImageView.h:155
rtabmap::ImageView::getDepthColorMap
uCvQtDepthColorMap getDepthColorMap() const
Definition: ImageView.cpp:418
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
rtabmap::ImageView::_savedFileName
QString _savedFileName
Definition: ImageView.h:136
uCvQtDepthWhiteToBlack
@ uCvQtDepthWhiteToBlack
Definition: UCv2Qt.h:31
y1
CEPHES_EXTERN_EXPORT double y1(double x)
rtabmap::ImageView::_colorMapBlackToWhite
QAction * _colorMapBlackToWhite
Definition: ImageView.h:164
rtabmap::ImageView::_featureMenu
QMenu * _featureMenu
Definition: ImageView.h:170
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
rtabmap::ImageView::setImageDepth
void setImageDepth(const cv::Mat &imageDepth)
Definition: ImageView.cpp:1264
ULogger.h
ULogger class and convenient macros.
rtabmap::ImageView::_alpha
int _alpha
Definition: ImageView.h:137
rtabmap::Transform
Definition: Transform.h:41
rtabmap::LineItem::LineItem
LineItem(float x1, float y1, float x2, float y2, const QString &text=QString(), QGraphicsItem *parent=0)
Definition: ImageView.cpp:60
util2d.h
rtabmap::LineItem::hideDescription
void hideDescription()
Definition: ImageView.cpp:150
rtabmap::ImageView::setDefaultMatchingFeatureColor
void setDefaultMatchingFeatureColor(const QColor &color)
Definition: ImageView.cpp:646
extensions
list extensions
rtabmap::ImageView::_defaultMatchingFeatureColor
QColor _defaultMatchingFeatureColor
Definition: ImageView.h:142
rtabmap::ImageView::_featuresSize
int _featuresSize
Definition: ImageView.h:138
rtabmap::ImageView::_graphicsViewNoScaling
QAction * _graphicsViewNoScaling
Definition: ImageView.h:162
rtabmap::ImageView::sizeHint
virtual QSize sizeHint() const
Definition: ImageView.cpp:1485
iter
iterator iter(handle obj)
rtabmap::ImageView::_imageDepthCv
cv::Mat _imageDepthCv
Definition: ImageView.h:180
rtabmap::ImageView::updateOpacity
void updateOpacity()
Definition: ImageView.cpp:1116
rtabmap::ImageView::getDefaultBackgroundColor
const QColor & getDefaultBackgroundColor() const
Definition: ImageView.cpp:386
ratio
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size ratio
rtabmap::ImageView::_imageItem
QGraphicsPixmapItem * _imageItem
Definition: ImageView.h:176
rtabmap::ImageView::setDepthColorMapRange
void setDepthColorMapRange(float min, float max)
Definition: ImageView.cpp:715
rtabmap::ImageView::isImageDepthShown
bool isImageDepthShown() const
Definition: ImageView.cpp:361
rtabmap::ImageView::getDefaultMatchingLineColor
const QColor & getDefaultMatchingLineColor() const
Definition: ImageView.cpp:398
v
Array< int, Dynamic, 1 > v
UDEBUG
#define UDEBUG(...)
rtabmap::ImageView::_depthColorMapMinRange
float _depthColorMapMinRange
Definition: ImageView.h:144
rtabmap::ImageView::setDefaultBackgroundColor
void setDefaultBackgroundColor(const QColor &color)
Definition: ImageView.cpp:621
rtabmap::ImageView::isLinesShown
bool isLinesShown() const
Definition: ImageView.cpp:481
rtabmap::ImageView::_mouseTracking
QAction * _mouseTracking
Definition: ImageView.h:169
rtabmap::ImageView::isImageShown
bool isImageShown() const
Definition: ImageView.cpp:356
rtabmap::ImageView::getAlpha
int getAlpha() const
Definition: ImageView.h:65
rtabmap::ImageView::_pose
Transform _pose
Definition: ImageView.h:182
rtabmap::ImageView::isFeaturesShown
bool isFeaturesShown() const
Definition: ImageView.cpp:366
rtabmap::LineItem::_text
QString _text
Definition: ImageView.cpp:160
rtabmap::ImageView::setFeaturesShown
void setFeaturesShown(bool shown)
Definition: ImageView.cpp:437
rtabmap::ImageView::setAlpha
void setAlpha(int alpha)
Definition: ImageView.cpp:1343
float
float
rtabmap::ImageView::getLinesWidth
int getLinesWidth() const
Definition: ImageView.h:67
rtabmap::ImageView::_features
QMultiMap< int, rtabmap::KeypointItem * > _features
Definition: ImageView.h:174
rtabmap::ImageView::_setMatchingLineColor
QAction * _setMatchingLineColor
Definition: ImageView.h:154
uCvMat2QImage
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack, float depthMin=0, float depthMax=0)
Definition: UCv2Qt.h:47
uCvQtDepthBlackToWhite
@ uCvQtDepthBlackToWhite
Definition: UCv2Qt.h:32
rtabmap::ImageView::setFeatures
void setFeatures(const std::multimap< int, cv::KeyPoint > &refWords, const cv::Mat &depth=cv::Mat(), const QColor &color=Qt::yellow)
Definition: ImageView.cpp:1137
rtabmap::ImageView::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: ImageView.cpp:1057
rtabmap::ImageView::clear
void clear()
Definition: ImageView.cpp:1451
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::ImageView::_graphicsViewScaled
QAction * _graphicsViewScaled
Definition: ImageView.h:160
rtabmap::ImageView::setFeaturesColor
void setFeaturesColor(QColor color)
Definition: ImageView.cpp:1329
rtabmap::ImageView::getBackgroundColor
const QColor & getBackgroundColor() const
Definition: ImageView.cpp:403
value
value
i
int i
rtabmap::ImageView::setFeaturesSize
void setFeaturesSize(int size)
Definition: ImageView.cpp:1368
text
text
rtabmap::ImageView::sceneRectChanged
void sceneRectChanged(const QRectF &rect)
Definition: ImageView.cpp:762
rtabmap::ImageView::setGraphicsViewMode
void setGraphicsViewMode(bool on)
Definition: ImageView.cpp:514
rtabmap::ImageView::setFeatureColor
void setFeatureColor(int id, QColor color)
Definition: ImageView.cpp:1307
rtabmap::ImageView::paintEvent
virtual void paintEvent(QPaintEvent *event)
Definition: ImageView.cpp:767


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:11