LaserView.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef GAZEBO_GUI_VIEWERS_LASERVIEW_HH_
18 #define GAZEBO_GUI_VIEWERS_LASERVIEW_HH_
19 
20 #include <string>
21 #include <vector>
22 #include <mutex>
23 
24 #include "gazebo/common/Time.hh"
25 #include "gazebo/msgs/msgs.hh"
26 
28 
29 #include "gazebo/gui/qt.h"
31 #include "gazebo/util/system.hh"
32 
33 namespace gazebo
34 {
35  namespace gui
36  {
37  class GZ_GUI_VISIBLE LaserView : public TopicView
38  {
39  Q_OBJECT
40 
43  public: explicit LaserView(QWidget *_parent = NULL);
44 
46  public: virtual ~LaserView();
47 
48  // Documentation inherited
49  public: virtual void SetTopic(const std::string &_topicName);
50 
51  // Documentation inherited
52  private: virtual void UpdateImpl();
53 
56  protected: virtual void resizeEvent(QResizeEvent *_event);
57 
60  private: void OnScan(ConstLaserScanStampedPtr &_msg);
61 
63  private slots: void OnFitInView();
64 
66  private slots: void OnDegree(bool _toggled);
67 
69  private: class LaserItem : public QGraphicsItem
70  {
72  public: LaserItem();
73 
75  public: void Clear();
76 
79  public: unsigned int GetRangeCount();
80 
83  public: void AddRange(double _range);
84 
88  public: void SetRange(unsigned int _index, double _range);
89 
91  public: QRectF GetBoundingRect() const;
92 
96  public: double GetHoverRange() const;
97 
101  public: double GetHoverAngle() const;
102 
109  public: void Update(double _angleMin, double _angleMax,
110  double _angleStep, double _rangeMax,
111  double _rangeMin);
112 
114  public: void UpdateGeometry();
115 
118  private: virtual QRectF boundingRect() const;
119 
127  private: virtual void paint(QPainter *_painter,
128  const QStyleOptionGraphicsItem *_option,
129  QWidget *_widget);
130 
134  private: virtual void hoverEnterEvent(
135  QGraphicsSceneHoverEvent *_event);
136 
140  private: virtual void hoverLeaveEvent(
141  QGraphicsSceneHoverEvent *_event);
142 
146  private: void hoverMoveEvent(QGraphicsSceneHoverEvent *_event);
147 
149  private: std::vector<QPointF> points;
150 
152  private: std::vector<QPointF> noHitPoints;
153 
156  private: std::vector<double> ranges;
157 
159  private: double angleMin;
160 
162  private: double angleMax;
163 
165  private: double angleStep;
166 
168  private: double rangeMax;
169 
171  private: double rangeMin;
172 
174  private: double indexAngle;
175 
177  private: double scale;
178 
180  public: bool radians;
181 
183  private: mutable std::mutex mutex;
184 
186  private: bool dirty = false;
187  };
188 
191  private: class CustomView : public QGraphicsView
192  {
195  public: explicit CustomView(QWidget *_parent)
196  : QGraphicsView(_parent), viewZoomed(false) {}
197 
200  private: void wheelEvent(QWheelEvent *_event)
201  {
202  this->viewZoomed = true;
203  _event->delta() > 0 ? this->scale(1.15, 1.15) :
204  this->scale(1.0 / 1.15, 1.0 / 1.15);
205  _event->accept();
206  }
207 
209  public: bool viewZoomed;
210  };
211 
213  private: LaserItem *laserItem;
214 
216  private: CustomView *view;
217 
219  private: bool firstMsg;
220 
222  private: QLineEdit *rangeEdit;
223 
225  private: QLineEdit *angleEdit;
226 
228  private: QSpinBox *vertScanSpin;
229  };
230  }
231 }
232 #endif
Forward declarations for transport.
Base class for widgets that display topic data.
Definition: TopicView.hh:78
#define NULL
Definition: CommonTypes.hh:31
Definition: LaserView.hh:37