CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
vector_display.h
Go to the documentation of this file.
1 //========================================================================
2 // This software is free: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License Version 3,
4 // as published by the Free Software Foundation.
5 //
6 // This software is distributed in the hope that it will be useful,
7 // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // GNU Lesser General Public License for more details.
10 //
11 // You should have received a copy of the GNU Lesser General Public License
12 // Version 3 in the file COPYING that came with this distribution.
13 // If not, see <http://www.gnu.org/licenses/>.
14 //========================================================================
20 //========================================================================
21 
22 #include <QWidget>
23 #include <QGLWidget>
24 #include <QMutex>
25 #include <QPainter>
26 #include <QPaintEvent>
27 #include <vector>
28 
29 #ifndef VECTOR_LIDAR_DISPLAY_H
30 #define VECTOR_LIDAR_DISPLAY_H
31 
32 #include "geometry.h"
33 //#include "gltext.h"
34 
35 using namespace std;
36 
37 #define BACKGROUND_COLOR 1.0,1.0,1.0,1.0
38 
39 class VectorDisplay : public QGLWidget
40 {
41  Q_OBJECT
42 
43 public:
44  class Color{
45  public:
46  float r,g,b;
47  Color(){r=g=b=0.0;}
48  Color(float _r, float _g, float _b);
49  Color(uint32_t col);
50  float red(){return r;};
51  float green(){return g;};
52  float blue(){return b;};
53  };
54 
55 private:
56  static const double minZValue = -10;
57  static const double maxZValue = 10;
58 
59  QMutex graphicsMutex;
60  vector<line2f> lines;
61  vector<vector2f> points;
62  vector<vector2f> circles;
63  vector<Color> lineColors;
64  vector<Color> pointColors;
65  vector<Color> circleColors;
66 
67  float lineThickness;
68  float pointsSize;
69 
70  vector2d robotLoc;
71  double robotAngle;
72  double displayWindow;
73 
74  double viewScale;
75  double viewXOffset;
76  double viewYOffset;
77 
78  bool followRobot;
79  bool showRobot;
80 
81  bool leftButton;
82  bool midButton;
83  bool rightButton;
84 
85  int mouseStartX;
86  int mouseStartY;
87  //Callback for setting location, GoTo point, etc.
88  void (*ptrCallback)(vector2d,vector2d,double,int);
89  vector2d setLocation;
90 
91 private slots:
92  void redrawHandler();
93 signals:
94  void redraw();
95 
96 protected:
97  void paintEvent ( QPaintEvent * event );
98  void wheelEvent ( QWheelEvent * event );
99  void mouseMoveEvent ( QMouseEvent * event );
100  void keyPressEvent ( QKeyEvent * event );
101  void mousePressEvent( QMouseEvent * event );
102  void mouseReleaseEvent( QMouseEvent * event );
103  void resizeEvent ( QResizeEvent * event );
104  void initializeGL();
105  void resizeGL(int width, int height);
106  void setupViewport(int width, int height);
107  QSize sizeHint () const {return QSize(580,1000);}
108 
109  template <class num> void drawQuad(GVector::vector2d<num> loc1, GVector::vector2d<num> loc2, num z=0.0);
110  void drawQuad(double x1, double y1, double x2, double y2, double z=0.0)
111  {drawQuad(vector2d(x1,y1),vector2d(x2,y2),z);}
112  template <class num> void drawArc(GVector::vector2d<num> loc, num r1, num r2, num theta1, num theta2, num z=0.0, num dTheta = -1);
113  void drawArc(double x, double y, double r1, double r2, double theta1, double theta2, double z=0.0, double dTheta = -1)
114  {drawArc(vector2d(x,y),r1,r2,theta1,theta2,z,dTheta);}
115  void drawCircles(float lineThickness);
116  void drawLines(float lineThickness);
117  void drawPoints(float pointsSize);
118  template <class num> void drawLine(Line2d<num> &line, num lineWidth);
119  template <class num> void drawLine(GVector::vector2d<num> &p0, GVector::vector2d<num> &p1, num lineWidth);
120  template <class num> void drawPoint(GVector::vector2d< num > loc, float pointSize);
121 
122 public:
123  VectorDisplay(QWidget *parent = 0);
124  void updateLines(vector<line2f> _lines, vector<Color> _lineColors = vector<Color>());
125  void updatePoints(vector< vector2f > _points, vector<Color> _pointColors = vector<Color>());
126  void updateCircles(vector< vector2f > _circles, vector<Color> _circleColors = vector<Color>());
127  void updateDisplay(vector2d _robotLoc, double _robotAngle, double _displayWindow,
128  vector<line2f> _lines, vector<vector2f> _points, vector<vector2f> _circles,
129  vector<Color> _lineColors = vector<Color>(),
130  vector<Color> _pointColors = vector<Color>(),
131  vector<Color> _circleColors = vector<Color>());
132  void resetView();
137  void setCallback(void (*_ptrCallback)(vector2d,vector2d,double,int) ){ptrCallback = _ptrCallback;}
138 };
139 
140 #endif //VECTOR_LIDAR_DISPLAY_H
void setCallback(void(*_ptrCallback)(vector2d, vector2d, double, int))
Definition: line.h:33