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_
mapviz_plugins::LaserScanPlugin::CalculateColor
QColor CalculateColor(const StampedPoint &point, bool has_intensity)
Definition: laserscan_plugin.cpp:210
mapviz_plugins::LaserScanPlugin::prev_increment_
float prev_increment_
Definition: laserscan_plugin.h:149
mapviz_plugins::LaserScanPlugin::ResetTransformedScans
void ResetTransformedScans()
Definition: laserscan_plugin.cpp:202
mapviz_plugins::LaserScanPlugin::PrintInfo
void PrintInfo(const std::string &message)
Definition: laserscan_plugin.cpp:434
mapviz_plugins::LaserScanPlugin::Scan::source_frame_
std::string source_frame_
Definition: laserscan_plugin.h:119
mapviz_plugins::LaserScanPlugin::Transform
void Transform()
Definition: laserscan_plugin.cpp:510
mapviz_plugins::LaserScanPlugin::GetConfigWidget
QWidget * GetConfigWidget(QWidget *parent)
Definition: laserscan_plugin.cpp:444
mapviz_plugins::LaserScanPlugin::ui_
Ui::laserscan_config ui_
Definition: laserscan_plugin.h:128
mapviz_plugins::LaserScanPlugin::StampedPoint
Definition: laserscan_plugin.h:105
mapviz_plugins::LaserScanPlugin::Scan::has_intensity
bool has_intensity
Definition: laserscan_plugin.h:121
mapviz_plugins::LaserScanPlugin::updatePreComputedTriginometic
void updatePreComputedTriginometic(const sensor_msgs::LaserScanConstPtr &msg)
Definition: laserscan_plugin.cpp:341
mapviz_plugins::LaserScanPlugin::min_value_
double min_value_
Definition: laserscan_plugin.h:133
mapviz_plugins::LaserScanPlugin::COLOR_RANGE
@ COLOR_RANGE
Definition: laserscan_plugin.h:61
mapviz_plugins::LaserScanPlugin::prev_angle_min_
float prev_angle_min_
Definition: laserscan_plugin.h:148
mapviz_plugins::LaserScanPlugin::precomputed_cos_
std::vector< double > precomputed_cos_
Definition: laserscan_plugin.h:145
mapviz_plugins::LaserScanPlugin::COLOR_Y
@ COLOR_Y
Definition: laserscan_plugin.h:63
mapviz_plugins::LaserScanPlugin::PointSizeChanged
void PointSizeChanged(int value)
Definition: laserscan_plugin.cpp:336
mapviz_plugins::LaserScanPlugin::point_size_
size_t point_size_
Definition: laserscan_plugin.h:135
mapviz_plugins::LaserScanPlugin::COLOR_FLAT
@ COLOR_FLAT
Definition: laserscan_plugin.h:59
mapviz_plugins::LaserScanPlugin::COLOR_X
@ COLOR_X
Definition: laserscan_plugin.h:62
mapviz_plugins::LaserScanPlugin::DrawIcon
void DrawIcon()
Definition: laserscan_plugin.cpp:168
mapviz_plugins::LaserScanPlugin::StampedPoint::color
QColor color
Definition: laserscan_plugin.h:109
tf::Point
tf::Vector3 Point
mapviz_plugins::LaserScanPlugin
Definition: laserscan_plugin.h:52
mapviz_plugins::LaserScanPlugin::prev_ranges_size_
size_t prev_ranges_size_
Definition: laserscan_plugin.h:147
mapviz_plugins::LaserScanPlugin::ColorTransformerChanged
void ColorTransformerChanged(int index)
Definition: laserscan_plugin.cpp:629
mapviz_plugins::LaserScanPlugin::PrintError
void PrintError(const std::string &message)
Definition: laserscan_plugin.cpp:429
mapviz_plugins::LaserScanPlugin::StampedPoint::transformed_point
tf::Point transformed_point
Definition: laserscan_plugin.h:108
mapviz_plugins::LaserScanPlugin::LaserScanPlugin
LaserScanPlugin()
Definition: laserscan_plugin.cpp:62
swri_transform_util::Transform
mapviz_plugins::LaserScanPlugin::GetScanTransform
bool GetScanTransform(const Scan &scan, swri_transform_util::Transform &transform)
Definition: laserscan_plugin.cpp:363
mapviz_plugins::LaserScanPlugin::SaveConfig
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
Definition: laserscan_plugin.cpp:673
mapviz_plugins::LaserScanPlugin::Scan::color
QColor color
Definition: laserscan_plugin.h:117
mapviz_plugins::LaserScanPlugin::Scan::points
std::vector< StampedPoint > points
Definition: laserscan_plugin.h:118
mapviz_plugins::LaserScanPlugin::~LaserScanPlugin
virtual ~LaserScanPlugin()
Definition: laserscan_plugin.cpp:158
mapviz_plugins::LaserScanPlugin::BufferSizeChanged
void BufferSizeChanged(int value)
Definition: laserscan_plugin.cpp:323
mapviz_plugins::LaserScanPlugin::ClearHistory
void ClearHistory()
Definition: laserscan_plugin.cpp:162
mapviz_plugins::LaserScanPlugin::COLOR_INTENSITY
@ COLOR_INTENSITY
Definition: laserscan_plugin.h:60
mapviz_plugins::LaserScanPlugin::AlphaEdited
void AlphaEdited(double val)
Definition: laserscan_plugin.cpp:668
mapviz_plugins::LaserScanPlugin::StampedPoint::range
float range
Definition: laserscan_plugin.h:110
mapviz_plugins::LaserScanPlugin::alpha_
double alpha_
Definition: laserscan_plugin.h:132
mapviz_plugins::LaserScanPlugin::StampedPoint::point
tf::Point point
Definition: laserscan_plugin.h:107
mapviz_plugins::LaserScanPlugin::UseRainbowChanged
void UseRainbowChanged(int check_state)
Definition: laserscan_plugin.cpp:491
ros::Time
mapviz_plugins::LaserScanPlugin::Scan::transformed
bool transformed
Definition: laserscan_plugin.h:120
mapviz_plugins::LaserScanPlugin::MinValueChanged
void MinValueChanged(double value)
Definition: laserscan_plugin.cpp:311
mapviz_plugins::LaserScanPlugin::buffer_size_
size_t buffer_size_
Definition: laserscan_plugin.h:136
mapviz_plugins::LaserScanPlugin::UpdateColors
void UpdateColors()
Definition: laserscan_plugin.cpp:261
mapviz_plugins::LaserScanPlugin::MaxValueChanged
void MaxValueChanged(double value)
Definition: laserscan_plugin.cpp:317
mapviz_plugins::LaserScanPlugin::max_value_
double max_value_
Definition: laserscan_plugin.h:134
mapviz::MapvizPlugin
mapviz_plugins::LaserScanPlugin::scans_
std::deque< Scan > scans_
Definition: laserscan_plugin.h:143
mapviz_plugins::LaserScanPlugin::Scan
Definition: laserscan_plugin.h:114
mapviz_plugins::LaserScanPlugin::precomputed_sin_
std::vector< double > precomputed_sin_
Definition: laserscan_plugin.h:146
mapviz_plugins::LaserScanPlugin::TopicEdited
void TopicEdited()
Definition: laserscan_plugin.cpp:286
mapviz_plugins::LaserScanPlugin::SelectTopic
void SelectTopic()
Definition: laserscan_plugin.cpp:274
mapviz_plugins::LaserScanPlugin::has_message_
bool has_message_
Definition: laserscan_plugin.h:138
mapviz_plugins::LaserScanPlugin::Scan::stamp
ros::Time stamp
Definition: laserscan_plugin.h:116
mapviz_plugins::LaserScanPlugin::StampedPoint::intensity
float intensity
Definition: laserscan_plugin.h:111
mapviz_plugins::LaserScanPlugin::topic_
std::string topic_
Definition: laserscan_plugin.h:131
mapviz_plugins::LaserScanPlugin::laserScanCallback
void laserScanCallback(const sensor_msgs::LaserScanConstPtr &scan)
Definition: laserscan_plugin.cpp:369
mapviz_plugins::LaserScanPlugin::COLOR_Z
@ COLOR_Z
Definition: laserscan_plugin.h:64
mapviz_plugins::LaserScanPlugin::PrintWarning
void PrintWarning(const std::string &message)
Definition: laserscan_plugin.cpp:439
mapviz_plugins::LaserScanPlugin::LoadConfig
void LoadConfig(const YAML::Node &node, const std::string &path)
Definition: laserscan_plugin.cpp:543
mapviz_plugins
Definition: attitude_indicator_plugin.h:61
mapviz_plugins::LaserScanPlugin::Shutdown
void Shutdown()
Definition: laserscan_plugin.h:70
mapviz_plugins::LaserScanPlugin::config_widget_
QWidget * config_widget_
Definition: laserscan_plugin.h:129
ros::Subscriber
mapviz_plugins::LaserScanPlugin::Initialize
bool Initialize(QGLWidget *canvas)
Definition: laserscan_plugin.cpp:451
mapviz_plugins::LaserScanPlugin::laserscan_sub_
ros::Subscriber laserscan_sub_
Definition: laserscan_plugin.h:144
mapviz_plugin.h
mapviz_plugins::LaserScanPlugin::Draw
void Draw(double x, double y, double scale)
Definition: laserscan_plugin.cpp:460


mapviz_plugins
Author(s): Marc Alban
autogenerated on Sun Sep 8 2024 02:27:14