UPlot.h
Go to the documentation of this file.
1 /*
2 * utilite is a cross-platform library with
3 * useful utilities for fast and small developing.
4 * Copyright (C) 2010 Mathieu Labbe
5 *
6 * utilite is free library: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * utilite is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef UPLOT_H_
21 #define UPLOT_H_
22 
23 #include "rtabmap/gui/RtabmapGuiExp.h" // DLL export/import defines
24 
25 #include <QFrame>
26 #include <QtCore/QList>
27 #include <QtCore/QMap>
28 #include <QtGui/QPen>
29 #include <QtGui/QBrush>
30 #include <QGraphicsEllipseItem>
31 #include <QtCore/QMutex>
32 #include <QLabel>
33 #include <QPushButton>
34 #include <QtCore/QTime>
35 
36 class QGraphicsView;
37 class QGraphicsScene;
38 class QGraphicsItem;
39 class QFormLayout;
40 class QScrollArea;
41 
46 class RTABMAPGUI_EXP UPlotItem : public QGraphicsEllipseItem
47 {
48 public:
52  UPlotItem(qreal dataX, qreal dataY, qreal width=2);
56  UPlotItem(const QPointF & data, qreal width=2);
57  virtual ~UPlotItem();
58 
59 public:
60  void setNextItem(UPlotItem * nextItem);
61  void setPreviousItem(UPlotItem * previousItem);
62  void setData(const QPointF & data);
63 
64  UPlotItem * nextItem() const {return _nextItem;}
65  UPlotItem * previousItem() const {return _previousItem;};
66  const QPointF & data() const {return _data;}
67 
68 protected:
69  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
70  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
71  virtual void focusInEvent(QFocusEvent * event);
72  virtual void focusOutEvent(QFocusEvent * event);
73  virtual void keyReleaseEvent(QKeyEvent * keyEvent);
74 
75  virtual void showDescription(bool shown);
76 private:
77  void init(qreal dataX, qreal dataY);
78 
79 private:
80  QPointF _data;
83  QGraphicsTextItem * _text;
84  QGraphicsRectItem * _textBackground;
85 };
86 
87 class UPlot;
88 
92 class RTABMAPGUI_EXP UPlotCurve : public QObject
93 {
94  Q_OBJECT
95 
96 public:
100  UPlotCurve(const QString & name, QObject * parent = 0);
104  UPlotCurve(const QString & name, const QVector<UPlotItem *> data, QObject * parent = 0);
108  UPlotCurve(const QString & name, const QVector<qreal> & x, const QVector<qreal> & y, QObject * parent = 0);
109  virtual ~UPlotCurve();
110 
114  const QPen & pen() const {return _pen;}
118  const QBrush & brush() const {return _brush;}
119 
123  void setPen(const QPen & pen);
127  void setBrush(const QBrush & brush);
128 
129  void setItemsColor(const QColor & color);
130  QColor itemsColor() const {return _itemsColor;}
131 
135  QString name() const {return _name;}
139  int itemsSize() const;
140  QPointF getItemData(int index);
141  bool isVisible() const {return _visible;}
142  void setData(QVector<UPlotItem*> & data); // take the ownership
143  void getData(QVector<qreal> & x, QVector<qreal> & y) const; // only call in Qt MainThread
144  void getData(QMap<qreal,qreal> & data) const; // only call in Qt MainThread
145  void draw(QPainter * painter, const QRect & limits);
146 
147 public Q_SLOTS:
152  virtual void clear();
157  void setVisible(bool visible);
162  void setXIncrement(qreal increment);
167  void setXStart(qreal val);
172  void addValue(UPlotItem * data); // take the ownership
178  void addValue(qreal y);
183  void addValue(qreal x, qreal y);
190  void addValue(const QString & y);
196  void addValues(QVector<UPlotItem *> & data); // take the ownership
201  void addValues(const QVector<qreal> & xs, const QVector<qreal> & ys);
207  void addValues(const QVector<qreal> & ys);
208  void addValues(const QVector<int> & ys); // for convenience
214  void addValues(const std::vector<qreal> & ys); // for convenience
215  void addValues(const std::vector<int> & ys); // for convenience
216 
217  void setData(const QVector<qreal> & x, const QVector<qreal> & y);
218  void setData(const std::vector<qreal> & x, const std::vector<qreal> & y);
219  void setData(const QVector<qreal> & y);
220  void setData(const std::vector<qreal> & y);
221 
222 Q_SIGNALS:
227  void dataChanged(const UPlotCurve *);
228 
229 protected:
230  friend class UPlot;
231  void attach(UPlot * plot);
232  void detach(UPlot * plot);
233  void updateMinMax();
234  const QVector<qreal> & getMinMax() const {return _minMax;}
235  int removeItem(int index);
236  void _addValue(UPlotItem * data);;
237  virtual bool isMinMaxValid() const {return _minMax.size();}
238  virtual void update(qreal scaleX, qreal scaleY, qreal offsetX, qreal offsetY, qreal xDir, qreal yDir, int maxItemsKept);
239  QList<QGraphicsItem *> _items;
241 
242 private:
243  void removeItem(UPlotItem * item);
244 
245 private:
246  QString _name;
247  QPen _pen;
248  QBrush _brush;
249  qreal _xIncrement;
250  qreal _xStart;
251  bool _visible;
253  QVector<qreal> _minMax; // minX, maxX, minY, maxY
254  QGraphicsRectItem * _rootItem;
255  QColor _itemsColor;
256 };
257 
258 
263 {
264  Q_OBJECT
265 
266 public:
270  UPlotCurveThreshold(const QString & name, qreal thesholdValue, Qt::Orientation orientation = Qt::Horizontal, QObject * parent = 0);
271  virtual ~UPlotCurveThreshold();
272 
273 public Q_SLOTS:
277  void setThreshold(qreal threshold);
281  void setOrientation(Qt::Orientation orientation);
282 
283 protected:
284  friend class UPlot;
285  virtual void update(qreal scaleX, qreal scaleY, qreal offsetX, qreal offsetY, qreal xDir, qreal yDir, int maxItemsKept);
286  virtual bool isMinMaxValid() const {return false;}
287 
288 private:
289  Qt::Orientation _orientation;
290 };
291 
295 class RTABMAPGUI_EXP UPlotAxis : public QWidget
296 {
297 public:
301  UPlotAxis(Qt::Orientation orientation = Qt::Horizontal, qreal min=0, qreal max=1, QWidget * parent = 0);
302  virtual ~UPlotAxis();
303 
304 public:
309  void setAxis(qreal & min, qreal & max);
313  int border() const {return _border;}
317  int step() const {return _step;}
321  int count() const {return _count;}
325  void setReversed(bool reversed); // Vertical :bottom->up, horizontal :right->left
326 
327 protected:
328  virtual void paintEvent(QPaintEvent * event);
329 
330 private:
331  Qt::Orientation _orientation;
332  qreal _min;
333  qreal _max;
334  int _count;
335  int _step;
336  bool _reversed;
338  int _border;
339 };
340 
341 
345 class RTABMAPGUI_EXP UPlotLegendItem : public QPushButton
346 {
347  Q_OBJECT
348 
349 public:
353  UPlotLegendItem(UPlotCurve * curve, QWidget * parent = 0);
354  virtual ~UPlotLegendItem();
355  const UPlotCurve * curve() const {return _curve;}
356  QPixmap createSymbol(const QPen & pen, const QBrush & brush);
357  void showStdDevMeanMax(bool shown);
358 
359 Q_SIGNALS:
360  void legendItemRemoved(const UPlotCurve *);
361  void moveUpRequest(UPlotLegendItem *);
362  void moveDownRequest(UPlotLegendItem *);
363 
364 private Q_SLOTS:
365  void updateStdDevMeanMax();
366 
367 protected:
368  virtual void contextMenuEvent(QContextMenuEvent * event);
369 
370 private:
372  QMenu * _menu;
373  QAction * _aChangeText;
374  QAction * _aResetText;
375  QAction * _aChangeColor;
376  QAction * _aCopyToClipboard;
378  QAction * _aRemoveCurve;
379  QAction * _aMoveUp;
380  QAction * _aMoveDown;
381 };
382 
386 class RTABMAPGUI_EXP UPlotLegend : public QWidget
387 {
388  Q_OBJECT
389 
390 public:
394  UPlotLegend(QWidget * parent = 0);
395  virtual ~UPlotLegend();
396 
397  void setFlat(bool on);
398  bool isFlat() const {return _flat;}
399  void addItem(UPlotCurve * curve);
400  bool remove(const UPlotCurve * curve);
401  QString getAllCurveDataAsText() const;
402 
403 private Q_SLOTS:
404  void removeLegendItem(const UPlotCurve * curve);
405  void moveUp(UPlotLegendItem * item);
406  void moveDown(UPlotLegendItem * item);
407 
408 Q_SIGNALS:
409  void legendItemRemoved(const UPlotCurve * curve);
410  void legendItemToggled(const UPlotCurve * curve, bool toggled);
411  void legendItemMoved(const UPlotCurve * curve, int);
412 
413 protected:
414  virtual void contextMenuEvent(QContextMenuEvent * event);
415 
416 private Q_SLOTS:
417  void redirectToggled(bool);
418 
419 private:
420  bool _flat;
421  QMenu * _menu;
422  QAction * _aUseFlatButtons;
425  QLayout * _contentLayout;
426  QScrollArea * _scrollArea;
427 };
428 
429 
433 class RTABMAPGUI_EXP UOrientableLabel : public QLabel
434 {
435  Q_OBJECT
436 
437 public:
441  UOrientableLabel(const QString & text, Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0);
442  virtual ~UOrientableLabel();
446  Qt::Orientation orientation() const {return _orientation;}
450  void setOrientation(Qt::Orientation orientation);
451  QSize sizeHint() const;
452  QSize minimumSizeHint() const;
453 protected:
454  virtual void paintEvent(QPaintEvent* event);
455 private:
456  Qt::Orientation _orientation;
457 };
458 
489 class RTABMAPGUI_EXP UPlot : public QWidget
490 {
491  Q_OBJECT
492 
493 public:
497  UPlot(QWidget * parent = 0);
498  virtual ~UPlot();
499 
503  UPlotCurve * addCurve(const QString & curveName, const QColor & color = QColor());
507  bool addCurve(UPlotCurve * curve, bool ownershipTransferred = true);
511  QStringList curveNames();
512  bool contains(const QString & curveName);
513  void removeCurves();
514  QString getAllCurveDataAsText() const;
518  UPlotCurveThreshold * addThreshold(const QString & name, qreal value, Qt::Orientation orientation = Qt::Horizontal);
519  QString title() const {return this->objectName();}
520  QPen getRandomPenColored();
521  void showLegend(bool shown);
522  void showGrid(bool shown);
523  void showRefreshRate(bool shown);
524  void trackMouse(bool tracking);
525  void keepAllData(bool kept);
526  void showXAxis(bool shown) {_horizontalAxis->setVisible(shown);}
527  void showYAxis(bool shown) {_verticalAxis->setVisible(shown);}
528  void setVariableXAxis() {_fixedAxis[0] = false;}
529  void setVariableYAxis() {_fixedAxis[1] = false;}
530  void setFixedXAxis(qreal x1, qreal x2);
531  void setFixedYAxis(qreal y1, qreal y2);
532  void setMaxVisibleItems(int maxVisibleItems);
533  void setTitle(const QString & text);
534  void setXLabel(const QString & text);
535  void setYLabel(const QString & text, Qt::Orientation orientation = Qt::Vertical);
536  void setWorkingDirectory(const QString & workingDirectory);
537  void setGraphicsView(bool on);
538  void setBackgroundColor(const QColor & color);
539  QRectF sceneRect() const;
540 
541 public Q_SLOTS:
546  void removeCurve(const UPlotCurve * curve);
547  void showCurve(const UPlotCurve * curve, bool shown);
548  void updateAxis(); //reset axis and recompute it with all curves minMax
553  void clearData();
554 
555  void frameData(bool xAxis = true, bool yAxis = false);
556 
557 private Q_SLOTS:
558  void captureScreen();
559  void updateAxis(const UPlotCurve * curve);
560  void moveCurve(const UPlotCurve *, int index);
561 
562 protected:
563  virtual void contextMenuEvent(QContextMenuEvent * event);
564  virtual void paintEvent(QPaintEvent * event);
565  virtual void resizeEvent(QResizeEvent * event);
566  virtual void mousePressEvent(QMouseEvent * event);
567  virtual void mouseMoveEvent(QMouseEvent * event);
568  virtual void mouseReleaseEvent(QMouseEvent * event);
569  virtual void mouseDoubleClickEvent(QMouseEvent * event);
570 
571 private:
572  friend class UPlotCurve;
573  void addItem(QGraphicsItem * item);
574 
575 private:
576  void replot(QPainter * painter);
577  bool updateAxis(qreal x, qreal y);
578  bool updateAxis(qreal x1, qreal x2, qreal y1, qreal y2);
579  void setupUi();
580  void createActions();
581  void createMenus();
582  void selectScreenCaptureFormat();
583  bool mousePosToValue(const QPoint & pos, qreal & x, qreal & y);
584 
585 private:
587  QGraphicsView * _view;
588  QGraphicsItem * _sceneRoot;
590  qreal _axisMaximums[4]; // {x1->x2, y1->y2}
591  bool _axisMaximumsSet[4]; // {x1->x2, y1->y2}
592  bool _fixedAxis[2];
597  QList<QGraphicsLineItem *> hGridLines;
598  QList<QGraphicsLineItem *> vGridLines;
599  QList<UPlotCurve*> _curves;
600  QLabel * _title;
601  QLabel * _xLabel;
603  QLabel * _refreshRate;
611  QColor _bgColor;
612 
613  QMenu * _menu;
614  QAction * _aShowLegend;
615  QAction * _aShowGrid;
616  QAction * _aKeepAllData;
617  QAction * _aLimit0;
618  QAction * _aLimit10;
619  QAction * _aLimit50;
620  QAction * _aLimit100;
621  QAction * _aLimit500;
622  QAction * _aLimit1000;
623  QAction * _aLimitCustom;
624  QAction * _aAddVerticalLine;
626  QAction * _aChangeTitle;
627  QAction * _aChangeXLabel;
628  QAction * _aChangeYLabel;
630  QAction * _aYLabelVertical;
631  QAction * _aShowRefreshRate;
632  QAction * _aMouseTracking;
633  QAction * _aSaveFigure;
635  QAction * _aClearData;
636  QAction * _aGraphicsView;
637 };
638 
639 #endif /* UPLOT_H_ */
QString _autoScreenCaptureFormat
Definition: UPlot.h:608
#define RTABMAPGUI_EXP
Definition: RtabmapGuiExp.h:38
QGraphicsTextItem * _text
Definition: UPlot.h:83
UPlot * _plot
Definition: UPlot.h:240
QAction * _aChangeYLabel
Definition: UPlot.h:628
QGraphicsItem * _sceneRoot
Definition: UPlot.h:588
UPlotAxis * _verticalAxis
Definition: UPlot.h:593
virtual void update(qreal scaleX, qreal scaleY, qreal offsetX, qreal offsetY, qreal xDir, qreal yDir, int maxItemsKept)
Definition: UPlot.cpp:690
QList< UPlotCurve * > _curves
Definition: UPlot.h:599
QPen _pen
Definition: UPlot.h:247
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
QAction * _aKeepAllData
Definition: UPlot.h:616
QAction * _aLimit500
Definition: UPlot.h:621
QLabel * _refreshRate
Definition: UPlot.h:603
bool _flat
Definition: UPlot.h:420
QColor _bgColor
Definition: UPlot.h:611
QAction * _aLimit100
Definition: UPlot.h:620
def init(descriptorDim, matchThreshold, iterations, cuda, model_path)
QAction * _aGraphicsView
Definition: UPlot.h:636
QGraphicsRectItem * _textBackground
Definition: UPlot.h:84
QLabel * _xLabel
Definition: UPlot.h:601
qreal _xIncrement
Definition: UPlot.h:249
int step() const
Definition: UPlot.h:317
QAction * _aAddVerticalLine
Definition: UPlot.h:624
UPlotItem * _nextItem
Definition: UPlot.h:82
qreal _max
Definition: UPlot.h:333
UPlotItem * _previousItem
Definition: UPlot.h:81
QAction * _aClearData
Definition: UPlot.h:635
QAction * _aShowStdDevMeanMax
Definition: UPlot.h:377
QAction * _aMouseTracking
Definition: UPlot.h:632
UOrientableLabel * _yLabel
Definition: UPlot.h:602
const QVector< qreal > & getMinMax() const
Definition: UPlot.h:234
QWidget * _graphicsViewHolder
Definition: UPlot.h:589
Qt::Orientation _orientation
Definition: UPlot.h:331
QTime _refreshIntervalTime
Definition: UPlot.h:605
QAction * _aChangeBackgroundColor
Definition: UPlot.h:629
UPlotCurve * _curve
Definition: UPlot.h:371
UPlotItem * previousItem() const
Definition: UPlot.h:65
QAction * _aShowGrid
Definition: UPlot.h:615
QString title() const
Definition: UPlot.h:519
QString _workingDirectory
Definition: UPlot.h:604
QAction * _aLimitCustom
Definition: UPlot.h:623
const QBrush & brush() const
Definition: UPlot.h:118
Definition: UPlot.h:489
bool _visible
Definition: UPlot.h:251
QAction * _aCopyAllCurvesToClipboard
Definition: UPlot.h:423
QAction * _aLimit10
Definition: UPlot.h:618
void showYAxis(bool shown)
Definition: UPlot.h:527
UPlotAxis * _horizontalAxis
Definition: UPlot.h:594
int _count
Definition: UPlot.h:334
const QPointF & data() const
Definition: UPlot.h:66
QAction * _aRemoveCurve
Definition: UPlot.h:378
void setVariableYAxis()
Definition: UPlot.h:529
qreal _xStart
Definition: UPlot.h:250
virtual bool isMinMaxValid() const
Definition: UPlot.h:237
Qt::Orientation _orientation
Definition: UPlot.h:456
QMenu * _menu
Definition: UPlot.h:372
QAction * _aChangeText
Definition: UPlot.h:373
int count() const
Definition: UPlot.h:321
QScrollArea * _scrollArea
Definition: UPlot.h:426
QAction * _aShowRefreshRate
Definition: UPlot.h:631
QAction * _aLimit1000
Definition: UPlot.h:622
bool _valuesShown
Definition: UPlot.h:252
QAction * _aAddHorizontalLine
Definition: UPlot.h:625
QMenu * _menu
Definition: UPlot.h:421
QGraphicsView * _view
Definition: UPlot.h:587
QPoint _mouseCurrentPos
Definition: UPlot.h:610
QColor _itemsColor
Definition: UPlot.h:255
QAction * _aChangeColor
Definition: UPlot.h:375
int _maxVisibleItems
Definition: UPlot.h:596
const QPen & pen() const
Definition: UPlot.h:114
QAction * _aShowAllStdDevMeanMax
Definition: UPlot.h:424
QList< QGraphicsItem * > _items
Definition: UPlot.h:239
void addValue(int pos, float val, float *vals, T *point, T *points, int n)
virtual bool isMinMaxValid() const
Definition: UPlot.h:286
QMenu * _menu
Definition: UPlot.h:613
QAction * _aYLabelVertical
Definition: UPlot.h:630
QGraphicsRectItem * _rootItem
Definition: UPlot.h:254
QPoint _mousePressedPos
Definition: UPlot.h:609
int border() const
Definition: UPlot.h:313
QList< QGraphicsLineItem * > vGridLines
Definition: UPlot.h:598
QAction * _aCopyToClipboard
Definition: UPlot.h:376
int _step
Definition: UPlot.h:335
QAction * _aAutoScreenCapture
Definition: UPlot.h:634
qreal _min
Definition: UPlot.h:332
QAction * _aChangeXLabel
Definition: UPlot.h:627
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
int _penStyleCount
Definition: UPlot.h:595
bool isFlat() const
Definition: UPlot.h:398
int _gradMaxDigits
Definition: UPlot.h:337
UPlotLegend * _legend
Definition: UPlot.h:586
QAction * _aLimit0
Definition: UPlot.h:617
QLabel * _title
Definition: UPlot.h:600
QAction * _aMoveUp
Definition: UPlot.h:379
QAction * _aSaveFigure
Definition: UPlot.h:633
QString _name
Definition: UPlot.h:246
Qt::Orientation orientation() const
Definition: UPlot.h:446
bool isVisible() const
Definition: UPlot.h:141
QAction * _aChangeTitle
Definition: UPlot.h:626
QTime _refreshStartTime
Definition: UPlot.h:607
UPlotItem * nextItem() const
Definition: UPlot.h:64
QBrush _brush
Definition: UPlot.h:248
QAction * _aMoveDown
Definition: UPlot.h:380
QAction * _aUseFlatButtons
Definition: UPlot.h:422
int _border
Definition: UPlot.h:338
void setVariableXAxis()
Definition: UPlot.h:528
QVector< qreal > _minMax
Definition: UPlot.h:253
bool _reversed
Definition: UPlot.h:336
const UPlotCurve * curve() const
Definition: UPlot.h:355
QString name() const
Definition: UPlot.h:135
int _lowestRefreshRate
Definition: UPlot.h:606
QAction * _aShowLegend
Definition: UPlot.h:614
QAction * _aResetText
Definition: UPlot.h:374
void showXAxis(bool shown)
Definition: UPlot.h:526
QColor itemsColor() const
Definition: UPlot.h:130
QPointF _data
Definition: UPlot.h:80
QList< QGraphicsLineItem * > hGridLines
Definition: UPlot.h:597
Qt::Orientation _orientation
Definition: UPlot.h:289
QAction * _aLimit50
Definition: UPlot.h:619
GLM_FUNC_DECL detail::tmat4x4< T, P > orientation(detail::tvec3< T, P > const &Normal, detail::tvec3< T, P > const &Up)
QLayout * _contentLayout
Definition: UPlot.h:425


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:37:06