laserscan_plugin.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #ifndef MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
31 #define MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
32 
33 // C++ standard libraries
34 #include <string>
35 #include <deque>
36 #include <vector>
37 
38 #include <mapviz/mapviz_plugin.h>
39 
40 // QT libraries
41 #include <QGLWidget>
42 #include <QColor>
43 
44 // ROS libraries
45 #include <sensor_msgs/LaserScan.h>
46 
47 // QT autogenerated files
48 #include "ui_laserscan_config.h"
49 
50 namespace mapviz_plugins
51 {
53  {
54  Q_OBJECT
55 
56  public:
57  enum
58  {
62  COLOR_X = 3,
63  COLOR_Y = 4,
64  COLOR_Z = 5
65  };
67  virtual ~LaserScanPlugin();
68 
69  bool Initialize(QGLWidget* canvas);
70  void Shutdown()
71  {
72  }
73 
74  void ClearHistory();
75 
76  void Draw(double x, double y, double scale);
77 
78  void Transform();
79 
80  void LoadConfig(const YAML::Node& node, const std::string& path);
81  void SaveConfig(YAML::Emitter& emitter, const std::string& path);
82 
83  QWidget* GetConfigWidget(QWidget* parent);
84 
85  protected:
86  void PrintError(const std::string& message);
87  void PrintInfo(const std::string& message);
88  void PrintWarning(const std::string& message);
89 
90  protected Q_SLOTS:
91  void SelectTopic();
92  void TopicEdited();
93  void AlphaEdited(double val);
94  void ColorTransformerChanged(int index);
95  void MinValueChanged(double value);
96  void MaxValueChanged(double value);
97  void PointSizeChanged(int value);
98  void BufferSizeChanged(int value);
99  void UseRainbowChanged(int check_state);
100  void UpdateColors();
101  void DrawIcon();
102  void ResetTransformedScans();
103 
104  private:
106  {
109  QColor color;
110  float range;
111  float intensity;
112  };
113 
114  struct Scan
115  {
117  QColor color;
118  std::vector<StampedPoint> points;
119  std::string source_frame_;
122  };
123 
124  void laserScanCallback(const sensor_msgs::LaserScanConstPtr& scan);
125  QColor CalculateColor(const StampedPoint& point, bool has_intensity);
126  void updatePreComputedTriginometic(const sensor_msgs::LaserScanConstPtr& msg);
127 
128  Ui::laserscan_config ui_;
129  QWidget* config_widget_;
130 
131  std::string topic_;
132  double alpha_;
133  double min_value_;
134  double max_value_;
135  size_t point_size_;
136  size_t buffer_size_;
137 
139 
140  // Use a list instead of a deque for scans to facilitate removing
141  // timed-out scans in the middle of the list in case I ever re-implement
142  // decay time (evenator)
143  std::deque<Scan> scans_;
145  std::vector<double> precomputed_cos_;
146  std::vector<double> precomputed_sin_;
150  bool GetScanTransform(const Scan &scan, swri_transform_util::Transform& transform);
151  };
152 }
153 
154 #endif // MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
void laserScanCallback(const sensor_msgs::LaserScanConstPtr &scan)
std::vector< StampedPoint > points
void PrintWarning(const std::string &message)
tf::Vector3 Point
QWidget * GetConfigWidget(QWidget *parent)
std::vector< double > precomputed_cos_
void Draw(double x, double y, double scale)
std::vector< double > precomputed_sin_
void LoadConfig(const YAML::Node &node, const std::string &path)
QColor CalculateColor(const StampedPoint &point, bool has_intensity)
void PrintInfo(const std::string &message)
void PrintError(const std::string &message)
bool Initialize(QGLWidget *canvas)
void updatePreComputedTriginometic(const sensor_msgs::LaserScanConstPtr &msg)
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
void UseRainbowChanged(int check_state)
bool GetScanTransform(const Scan &scan, swri_transform_util::Transform &transform)


mapviz_plugins
Author(s): Marc Alban
autogenerated on Fri Dec 16 2022 03:59:33