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 
45 class RTABMAPGUI_EXP UPlotItem : public QGraphicsEllipseItem
46 {
47 public:
51  UPlotItem(qreal dataX, qreal dataY, qreal width=2);
55  UPlotItem(const QPointF & data, qreal width=2);
56  virtual ~UPlotItem();
57 
58 public:
59  void setNextItem(UPlotItem * nextItem);
60  void setPreviousItem(UPlotItem * previousItem);
61  void setData(const QPointF & data);
62 
63  UPlotItem * nextItem() const {return _nextItem;}
64  UPlotItem * previousItem() const {return _previousItem;};
65  const QPointF & data() const {return _data;}
66 
67 protected:
68  virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
69  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
70  virtual void focusInEvent(QFocusEvent * event);
71  virtual void focusOutEvent(QFocusEvent * event);
72  virtual void keyReleaseEvent(QKeyEvent * keyEvent);
73 
74  virtual void showDescription(bool shown);
75 private:
76  void init(qreal dataX, qreal dataY);
77 
78 private:
79  QPointF _data;
82  QGraphicsTextItem * _text;
83  QGraphicsRectItem * _textBackground;
84 };
85 
86 class UPlot;
87 
91 class RTABMAPGUI_EXP UPlotCurve : public QObject
92 {
93  Q_OBJECT
94 
95 public:
99  UPlotCurve(const QString & name, QObject * parent = 0);
103  UPlotCurve(const QString & name, const QVector<UPlotItem *> data, QObject * parent = 0);
107  UPlotCurve(const QString & name, const QVector<float> & x, const QVector<float> & y, QObject * parent = 0);
108  virtual ~UPlotCurve();
109 
113  const QPen & pen() const {return _pen;}
117  const QBrush & brush() const {return _brush;}
118 
122  void setPen(const QPen & pen);
126  void setBrush(const QBrush & brush);
127 
128  void setItemsColor(const QColor & color);
129  QColor itemsColor() const {return _itemsColor;}
130 
134  QString name() const {return _name;}
138  int itemsSize() const;
139  QPointF getItemData(int index);
140  bool isVisible() const {return _visible;}
141  void setData(QVector<UPlotItem*> & data); // take the ownership
142  void getData(QVector<float> & x, QVector<float> & y) const; // only call in Qt MainThread
143  void getData(QMap<float,float> & data) const; // only call in Qt MainThread
144  void draw(QPainter * painter, const QRect & limits);
145 
146 public Q_SLOTS:
151  virtual void clear();
156  void setVisible(bool visible);
161  void setXIncrement(float increment);
166  void setXStart(float val);
171  void addValue(UPlotItem * data); // take the ownership
177  void addValue(float y);
182  void addValue(float x, float y);
189  void addValue(const QString & y);
195  void addValues(QVector<UPlotItem *> & data); // take the ownership
200  void addValues(const QVector<float> & xs, const QVector<float> & ys);
206  void addValues(const QVector<float> & ys);
207  void addValues(const QVector<int> & ys); // for convenience
213  void addValues(const std::vector<float> & ys); // for convenience
214  void addValues(const std::vector<int> & ys); // for convenience
215 
216  void setData(const QVector<float> & x, const QVector<float> & y);
217  void setData(const std::vector<float> & x, const std::vector<float> & y);
218  void setData(const QVector<float> & y);
219  void setData(const std::vector<float> & y);
220 
221 Q_SIGNALS:
226  void dataChanged(const UPlotCurve *);
227 
228 protected:
229  friend class UPlot;
230  void attach(UPlot * plot);
231  void detach(UPlot * plot);
232  void updateMinMax();
233  const QVector<float> & getMinMax() const {return _minMax;}
234  int removeItem(int index);
235  void _addValue(UPlotItem * data);;
236  virtual bool isMinMaxValid() const {return _minMax.size();}
237  virtual void update(float scaleX, float scaleY, float offsetX, float offsetY, float xDir, float yDir, int maxItemsKept);
238  QList<QGraphicsItem *> _items;
240 
241 private:
242  void removeItem(UPlotItem * item);
243 
244 private:
245  QString _name;
246  QPen _pen;
247  QBrush _brush;
248  float _xIncrement;
249  float _xStart;
250  bool _visible;
252  QVector<float> _minMax; // minX, maxX, minY, maxY
253  QGraphicsRectItem * _rootItem;
254  QColor _itemsColor;
255 };
256 
257 
262 {
263  Q_OBJECT
264 
265 public:
269  UPlotCurveThreshold(const QString & name, float thesholdValue, Qt::Orientation orientation = Qt::Horizontal, QObject * parent = 0);
270  virtual ~UPlotCurveThreshold();
271 
272 public Q_SLOTS:
276  void setThreshold(float threshold);
280  void setOrientation(Qt::Orientation orientation);
281 
282 protected:
283  friend class UPlot;
284  virtual void update(float scaleX, float scaleY, float offsetX, float offsetY, float xDir, float yDir, int maxItemsKept);
285  virtual bool isMinMaxValid() const {return false;}
286 
287 private:
288  Qt::Orientation _orientation;
289 };
290 
294 class RTABMAPGUI_EXP UPlotAxis : public QWidget
295 {
296 public:
300  UPlotAxis(Qt::Orientation orientation = Qt::Horizontal, float min=0, float max=1, QWidget * parent = 0);
301  virtual ~UPlotAxis();
302 
303 public:
308  void setAxis(float & min, float & max);
312  int border() const {return _border;}
316  int step() const {return _step;}
320  int count() const {return _count;}
324  void setReversed(bool reversed); // Vertical :bottom->up, horizontal :right->left
325 
326 protected:
327  virtual void paintEvent(QPaintEvent * event);
328 
329 private:
330  Qt::Orientation _orientation;
331  float _min;
332  float _max;
333  int _count;
334  int _step;
335  bool _reversed;
337  int _border;
338 };
339 
340 
344 class RTABMAPGUI_EXP UPlotLegendItem : public QPushButton
345 {
346  Q_OBJECT
347 
348 public:
352  UPlotLegendItem(UPlotCurve * curve, QWidget * parent = 0);
353  virtual ~UPlotLegendItem();
354  const UPlotCurve * curve() const {return _curve;}
355  QPixmap createSymbol(const QPen & pen, const QBrush & brush);
356 
357 Q_SIGNALS:
358  void legendItemRemoved(const UPlotCurve *);
359  void moveUpRequest(UPlotLegendItem *);
360  void moveDownRequest(UPlotLegendItem *);
361 
362 private Q_SLOTS:
363  void updateStdDev();
364 
365 protected:
366  virtual void contextMenuEvent(QContextMenuEvent * event);
367 
368 private:
370  QMenu * _menu;
371  QAction * _aChangeText;
372  QAction * _aResetText;
373  QAction * _aChangeColor;
374  QAction * _aCopyToClipboard;
375  QAction * _aShowStdDev;
376  QAction * _aRemoveCurve;
377  QAction * _aMoveUp;
378  QAction * _aMoveDown;
379 };
380 
384 class RTABMAPGUI_EXP UPlotLegend : public QWidget
385 {
386  Q_OBJECT
387 
388 public:
392  UPlotLegend(QWidget * parent = 0);
393  virtual ~UPlotLegend();
394 
395  void setFlat(bool on);
396  bool isFlat() const {return _flat;}
397  void addItem(UPlotCurve * curve);
398  bool remove(const UPlotCurve * curve);
399 
400 private Q_SLOTS:
401  void removeLegendItem(const UPlotCurve * curve);
402  void moveUp(UPlotLegendItem * item);
403  void moveDown(UPlotLegendItem * item);
404 
405 Q_SIGNALS:
406  void legendItemRemoved(const UPlotCurve * curve);
407  void legendItemToggled(const UPlotCurve * curve, bool toggled);
408  void legendItemMoved(const UPlotCurve * curve, int);
409 
410 protected:
411  virtual void contextMenuEvent(QContextMenuEvent * event);
412 
413 private Q_SLOTS:
414  void redirectToggled(bool);
415 
416 private:
417  bool _flat;
418  QMenu * _menu;
419  QAction * _aUseFlatButtons;
421 };
422 
423 
427 class RTABMAPGUI_EXP UOrientableLabel : public QLabel
428 {
429  Q_OBJECT
430 
431 public:
435  UOrientableLabel(const QString & text, Qt::Orientation orientation = Qt::Horizontal, QWidget * parent = 0);
436  virtual ~UOrientableLabel();
440  Qt::Orientation orientation() const {return _orientation;}
444  void setOrientation(Qt::Orientation orientation);
445  QSize sizeHint() const;
446  QSize minimumSizeHint() const;
447 protected:
448  virtual void paintEvent(QPaintEvent* event);
449 private:
450  Qt::Orientation _orientation;
451 };
452 
483 class RTABMAPGUI_EXP UPlot : public QWidget
484 {
485  Q_OBJECT
486 
487 public:
491  UPlot(QWidget * parent = 0);
492  virtual ~UPlot();
493 
497  UPlotCurve * addCurve(const QString & curveName, const QColor & color = QColor());
501  bool addCurve(UPlotCurve * curve, bool ownershipTransferred = true);
505  QStringList curveNames();
506  bool contains(const QString & curveName);
507  void removeCurves();
511  UPlotCurveThreshold * addThreshold(const QString & name, float value, Qt::Orientation orientation = Qt::Horizontal);
512  QString title() const {return this->objectName();}
513  QPen getRandomPenColored();
514  void showLegend(bool shown);
515  void showGrid(bool shown);
516  void showRefreshRate(bool shown);
517  void trackMouse(bool tracking);
518  void keepAllData(bool kept);
519  void showXAxis(bool shown) {_horizontalAxis->setVisible(shown);}
520  void showYAxis(bool shown) {_verticalAxis->setVisible(shown);}
521  void setVariableXAxis() {_fixedAxis[0] = false;}
522  void setVariableYAxis() {_fixedAxis[1] = false;}
523  void setFixedXAxis(float x1, float x2);
524  void setFixedYAxis(float y1, float y2);
525  void setMaxVisibleItems(int maxVisibleItems);
526  void setTitle(const QString & text);
527  void setXLabel(const QString & text);
528  void setYLabel(const QString & text, Qt::Orientation orientation = Qt::Vertical);
529  void setWorkingDirectory(const QString & workingDirectory);
530  void setGraphicsView(bool on);
531  void setBackgroundColor(const QColor & color);
532  QRectF sceneRect() const;
533 
534 public Q_SLOTS:
539  void removeCurve(const UPlotCurve * curve);
540  void showCurve(const UPlotCurve * curve, bool shown);
541  void updateAxis(); //reset axis and recompute it with all curves minMax
546  void clearData();
547 
548 private Q_SLOTS:
549  void captureScreen();
550  void updateAxis(const UPlotCurve * curve);
551  void moveCurve(const UPlotCurve *, int index);
552 
553 protected:
554  virtual void contextMenuEvent(QContextMenuEvent * event);
555  virtual void paintEvent(QPaintEvent * event);
556  virtual void resizeEvent(QResizeEvent * event);
557  virtual void mousePressEvent(QMouseEvent * event);
558  virtual void mouseMoveEvent(QMouseEvent * event);
559  virtual void mouseReleaseEvent(QMouseEvent * event);
560  virtual void mouseDoubleClickEvent(QMouseEvent * event);
561 
562 private:
563  friend class UPlotCurve;
564  void addItem(QGraphicsItem * item);
565 
566 private:
567  void replot(QPainter * painter);
568  bool updateAxis(float x, float y);
569  bool updateAxis(float x1, float x2, float y1, float y2);
570  void setupUi();
571  void createActions();
572  void createMenus();
573  void selectScreenCaptureFormat();
574  bool mousePosToValue(const QPoint & pos, float & x, float & y);
575 
576 private:
578  QGraphicsView * _view;
579  QGraphicsItem * _sceneRoot;
581  float _axisMaximums[4]; // {x1->x2, y1->y2}
582  bool _axisMaximumsSet[4]; // {x1->x2, y1->y2}
583  bool _fixedAxis[2];
588  QList<QGraphicsLineItem *> hGridLines;
589  QList<QGraphicsLineItem *> vGridLines;
590  QList<UPlotCurve*> _curves;
591  QLabel * _title;
592  QLabel * _xLabel;
594  QLabel * _refreshRate;
602  QColor _bgColor;
603 
604  QMenu * _menu;
605  QAction * _aShowLegend;
606  QAction * _aShowGrid;
607  QAction * _aKeepAllData;
608  QAction * _aLimit0;
609  QAction * _aLimit10;
610  QAction * _aLimit50;
611  QAction * _aLimit100;
612  QAction * _aLimit500;
613  QAction * _aLimit1000;
614  QAction * _aLimitCustom;
615  QAction * _aAddVerticalLine;
617  QAction * _aChangeTitle;
618  QAction * _aChangeXLabel;
619  QAction * _aChangeYLabel;
621  QAction * _aYLabelVertical;
622  QAction * _aShowRefreshRate;
623  QAction * _aMouseTracking;
624  QAction * _aSaveFigure;
626  QAction * _aClearData;
627  QAction * _aGraphicsView;
628 };
629 
630 #endif /* UPLOT_H_ */
QString _autoScreenCaptureFormat
Definition: UPlot.h:599
#define RTABMAPGUI_EXP
Definition: RtabmapGuiExp.h:38
QGraphicsTextItem * _text
Definition: UPlot.h:82
UPlot * _plot
Definition: UPlot.h:239
const QVector< float > & getMinMax() const
Definition: UPlot.h:233
QAction * _aChangeYLabel
Definition: UPlot.h:619
QGraphicsItem * _sceneRoot
Definition: UPlot.h:579
UPlotAxis * _verticalAxis
Definition: UPlot.h:584
QList< UPlotCurve * > _curves
Definition: UPlot.h:590
QPen _pen
Definition: UPlot.h:246
float _max
Definition: UPlot.h:332
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
QAction * _aKeepAllData
Definition: UPlot.h:607
QAction * _aShowStdDev
Definition: UPlot.h:375
QAction * _aLimit500
Definition: UPlot.h:612
QLabel * _refreshRate
Definition: UPlot.h:594
bool _flat
Definition: UPlot.h:417
QColor _bgColor
Definition: UPlot.h:602
QAction * _aLimit100
Definition: UPlot.h:611
QAction * _aGraphicsView
Definition: UPlot.h:627
QGraphicsRectItem * _textBackground
Definition: UPlot.h:83
QLabel * _xLabel
Definition: UPlot.h:592
int step() const
Definition: UPlot.h:316
QAction * _aAddVerticalLine
Definition: UPlot.h:615
UPlotItem * _nextItem
Definition: UPlot.h:81
UPlotItem * _previousItem
Definition: UPlot.h:80
QAction * _aClearData
Definition: UPlot.h:626
QAction * _aMouseTracking
Definition: UPlot.h:623
UOrientableLabel * _yLabel
Definition: UPlot.h:593
QWidget * _graphicsViewHolder
Definition: UPlot.h:580
Qt::Orientation _orientation
Definition: UPlot.h:330
QTime _refreshIntervalTime
Definition: UPlot.h:596
QAction * _aChangeBackgroundColor
Definition: UPlot.h:620
UPlotCurve * _curve
Definition: UPlot.h:369
UPlotItem * previousItem() const
Definition: UPlot.h:64
QAction * _aShowGrid
Definition: UPlot.h:606
QString title() const
Definition: UPlot.h:512
virtual void update(float scaleX, float scaleY, float offsetX, float offsetY, float xDir, float yDir, int maxItemsKept)
Definition: UPlot.cpp:688
QString _workingDirectory
Definition: UPlot.h:595
QAction * _aLimitCustom
Definition: UPlot.h:614
const QBrush & brush() const
Definition: UPlot.h:117
Definition: UPlot.h:483
bool _visible
Definition: UPlot.h:250
QAction * _aLimit10
Definition: UPlot.h:609
void showYAxis(bool shown)
Definition: UPlot.h:520
UPlotAxis * _horizontalAxis
Definition: UPlot.h:585
int _count
Definition: UPlot.h:333
QAction * _aCopyAllCurveToClipboard
Definition: UPlot.h:420
const QPointF & data() const
Definition: UPlot.h:65
QAction * _aRemoveCurve
Definition: UPlot.h:376
void setVariableYAxis()
Definition: UPlot.h:522
virtual bool isMinMaxValid() const
Definition: UPlot.h:236
Qt::Orientation _orientation
Definition: UPlot.h:450
QMenu * _menu
Definition: UPlot.h:370
QAction * _aChangeText
Definition: UPlot.h:371
int count() const
Definition: UPlot.h:320
QAction * _aShowRefreshRate
Definition: UPlot.h:622
QAction * _aLimit1000
Definition: UPlot.h:613
bool _valuesShown
Definition: UPlot.h:251
QAction * _aAddHorizontalLine
Definition: UPlot.h:616
QMenu * _menu
Definition: UPlot.h:418
QGraphicsView * _view
Definition: UPlot.h:578
QPoint _mouseCurrentPos
Definition: UPlot.h:601
QColor _itemsColor
Definition: UPlot.h:254
QAction * _aChangeColor
Definition: UPlot.h:373
int _maxVisibleItems
Definition: UPlot.h:587
const QPen & pen() const
Definition: UPlot.h:113
QList< QGraphicsItem * > _items
Definition: UPlot.h:238
void addValue(int pos, float val, float *vals, T *point, T *points, int n)
virtual bool isMinMaxValid() const
Definition: UPlot.h:285
QMenu * _menu
Definition: UPlot.h:604
float _xIncrement
Definition: UPlot.h:248
QAction * _aYLabelVertical
Definition: UPlot.h:621
QGraphicsRectItem * _rootItem
Definition: UPlot.h:253
QPoint _mousePressedPos
Definition: UPlot.h:600
int border() const
Definition: UPlot.h:312
QList< QGraphicsLineItem * > vGridLines
Definition: UPlot.h:589
QAction * _aCopyToClipboard
Definition: UPlot.h:374
int _step
Definition: UPlot.h:334
QAction * _aAutoScreenCapture
Definition: UPlot.h:625
QAction * _aChangeXLabel
Definition: UPlot.h:618
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
int _penStyleCount
Definition: UPlot.h:586
bool isFlat() const
Definition: UPlot.h:396
int _gradMaxDigits
Definition: UPlot.h:336
UPlotLegend * _legend
Definition: UPlot.h:577
QAction * _aLimit0
Definition: UPlot.h:608
QLabel * _title
Definition: UPlot.h:591
QAction * _aMoveUp
Definition: UPlot.h:377
QAction * _aSaveFigure
Definition: UPlot.h:624
QString _name
Definition: UPlot.h:245
Qt::Orientation orientation() const
Definition: UPlot.h:440
bool isVisible() const
Definition: UPlot.h:140
QAction * _aChangeTitle
Definition: UPlot.h:617
QTime _refreshStartTime
Definition: UPlot.h:598
UPlotItem * nextItem() const
Definition: UPlot.h:63
float _xStart
Definition: UPlot.h:249
QBrush _brush
Definition: UPlot.h:247
QAction * _aMoveDown
Definition: UPlot.h:378
QAction * _aUseFlatButtons
Definition: UPlot.h:419
int _border
Definition: UPlot.h:337
void setVariableXAxis()
Definition: UPlot.h:521
QVector< float > _minMax
Definition: UPlot.h:252
bool _reversed
Definition: UPlot.h:335
const UPlotCurve * curve() const
Definition: UPlot.h:354
QString name() const
Definition: UPlot.h:134
int _lowestRefreshRate
Definition: UPlot.h:597
QAction * _aShowLegend
Definition: UPlot.h:605
QAction * _aResetText
Definition: UPlot.h:372
void showXAxis(bool shown)
Definition: UPlot.h:519
QColor itemsColor() const
Definition: UPlot.h:129
QPointF _data
Definition: UPlot.h:79
float _min
Definition: UPlot.h:331
QList< QGraphicsLineItem * > hGridLines
Definition: UPlot.h:588
Qt::Orientation _orientation
Definition: UPlot.h:288
QAction * _aLimit50
Definition: UPlot.h:610
GLM_FUNC_DECL detail::tmat4x4< T, P > orientation(detail::tvec3< T, P > const &Normal, detail::tvec3< T, P > const &Up)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:40