pointcloud2_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_POINTCLOUD2_PLUGIN_H_
31 #define MAPVIZ_PLUGINS_POINTCLOUD2_PLUGIN_H_
32 
33 // C++ standard libraries
34 #include <string>
35 #include <deque>
36 #include <vector>
37 #include <map>
38 
39 #include <mapviz/mapviz_plugin.h>
40 
41 // QT libraries
42 #include <QGLWidget>
43 #include <QColor>
44 #include <QMutex>
45 
46 // ROS libraries
47 #include <sensor_msgs/PointCloud2.h>
48 
49 // QT autogenerated files
50 #include "ui_pointcloud2_config.h"
51 
52 namespace mapviz_plugins
53 {
55  {
56  Q_OBJECT
57 
58  public:
59  struct FieldInfo
60  {
61  uint8_t datatype;
62  uint32_t offset;
63  };
64 
65  enum
66  {
68  COLOR_Z = 3
69  };
70 
72  virtual ~PointCloud2Plugin();
73 
74  bool Initialize(QGLWidget* canvas);
75  void Shutdown()
76  {
77  }
78 
79  void ClearHistory();
80 
81  void Draw(double x, double y, double scale);
82 
83  void Transform();
84 
85  void LoadConfig(const YAML::Node& node, const std::string& path);
86  void SaveConfig(YAML::Emitter& emitter, const std::string& path);
87 
88  QWidget* GetConfigWidget(QWidget* parent);
89 
90  protected:
91  void PrintError(const std::string& message);
92  void PrintInfo(const std::string& message);
93  void PrintWarning(const std::string& message);
94 
95  protected Q_SLOTS:
96  void SelectTopic();
97  void TopicEdited();
98  void AlphaEdited(double new_value);
99  void ColorTransformerChanged(int index);
100  void MinValueChanged(double value);
101  void MaxValueChanged(double value);
102  void PointSizeChanged(int value);
103  void BufferSizeChanged(int value);
104  void UseRainbowChanged(int check_state);
105  void UseAutomaxminChanged(int check_state);
106  void UpdateColors();
107  void DrawIcon();
109  void ClearPointClouds();
110  void SetSubscription(bool subscribe);
111 
112  private:
114  {
116  std::vector<float> features;
117  };
118 
119  struct Scan
120  {
122  QColor color;
123  std::vector<StampedPoint> points;
124  std::string source_frame;
126  std::map<std::string, FieldInfo> new_features;
127 
128  std::vector<float> gl_point;
129  std::vector<uint8_t> gl_color;
130  GLuint point_vbo;
131  GLuint color_vbo;
132  };
133 
134  float PointFeature(const uint8_t*, const FieldInfo&);
135  void PointCloud2Callback(const sensor_msgs::PointCloud2ConstPtr& scan);
136  QColor CalculateColor(const StampedPoint& point);
137  void UpdateMinMaxWidgets();
138 
139  Ui::PointCloud2_config ui_;
140  QWidget* config_widget_;
141 
142  std::string topic_;
143  double alpha_;
144  double max_value_;
145  double min_value_;
146  size_t point_size_;
147  size_t buffer_size_;
154  std::vector<double> max_;
155  std::vector<double> min_;
156  // Use a list instead of a deque for scans to facilitate removing
157  // timed-out scans in the middle of the list in case I ever re-implement
158  // decay time (evenator)
159  std::deque<Scan> scans_;
161 
162  QMutex scan_mutex_;
163  };
164 }
165 
166 #endif // MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
mapviz_plugins::PointCloud2Plugin::pc2_sub_
ros::Subscriber pc2_sub_
Definition: pointcloud2_plugin.h:160
mapviz_plugins::PointCloud2Plugin::GetConfigWidget
QWidget * GetConfigWidget(QWidget *parent)
Definition: pointcloud2_plugin.cpp:620
mapviz_plugins::PointCloud2Plugin::PointCloud2Plugin
PointCloud2Plugin()
Definition: pointcloud2_plugin.cpp:65
mapviz_plugins::PointCloud2Plugin::MaxValueChanged
void MaxValueChanged(double value)
Definition: pointcloud2_plugin.cpp:382
mapviz_plugins::PointCloud2Plugin::Scan::transformed
bool transformed
Definition: pointcloud2_plugin.h:125
mapviz_plugins::PointCloud2Plugin::Scan::gl_point
std::vector< float > gl_point
Definition: pointcloud2_plugin.h:128
mapviz_plugins::PointCloud2Plugin::scan_mutex_
QMutex scan_mutex_
Definition: pointcloud2_plugin.h:162
mapviz_plugins::PointCloud2Plugin::Scan::point_vbo
GLuint point_vbo
Definition: pointcloud2_plugin.h:130
mapviz_plugins::PointCloud2Plugin::Scan
Definition: pointcloud2_plugin.h:119
mapviz_plugins::PointCloud2Plugin::topic_
std::string topic_
Definition: pointcloud2_plugin.h:142
mapviz_plugins::PointCloud2Plugin::PrintWarning
void PrintWarning(const std::string &message)
Definition: pointcloud2_plugin.cpp:615
mapviz_plugins::PointCloud2Plugin::Draw
void Draw(double x, double y, double scale)
Definition: pointcloud2_plugin.cpp:636
mapviz_plugins::PointCloud2Plugin::need_new_list_
bool need_new_list_
Definition: pointcloud2_plugin.h:151
mapviz_plugins::PointCloud2Plugin::SaveConfig
void SaveConfig(YAML::Emitter &emitter, const std::string &path)
Definition: pointcloud2_plugin.cpp:862
mapviz_plugins::PointCloud2Plugin::FieldInfo::offset
uint32_t offset
Definition: pointcloud2_plugin.h:62
mapviz_plugins::PointCloud2Plugin::ClearPointClouds
void ClearPointClouds()
Definition: pointcloud2_plugin.cpp:228
mapviz_plugins::PointCloud2Plugin::SetSubscription
void SetSubscription(bool subscribe)
Definition: pointcloud2_plugin.cpp:234
mapviz_plugins::PointCloud2Plugin::TopicEdited
void TopicEdited()
Definition: pointcloud2_plugin.cpp:358
mapviz_plugins::PointCloud2Plugin::buffer_size_
size_t buffer_size_
Definition: pointcloud2_plugin.h:147
mapviz_plugins::PointCloud2Plugin::new_topic_
bool new_topic_
Definition: pointcloud2_plugin.h:148
mapviz_plugins::PointCloud2Plugin::StampedPoint::features
std::vector< float > features
Definition: pointcloud2_plugin.h:116
mapviz_plugins::PointCloud2Plugin::DrawIcon
void DrawIcon()
Definition: pointcloud2_plugin.cpp:183
mapviz_plugins::PointCloud2Plugin::CalculateColor
QColor CalculateColor(const StampedPoint &point)
Definition: pointcloud2_plugin.cpp:248
mapviz_plugins::PointCloud2Plugin::StampedPoint
Definition: pointcloud2_plugin.h:113
tf::Point
tf::Vector3 Point
mapviz_plugins::PointCloud2Plugin::Scan::new_features
std::map< std::string, FieldInfo > new_features
Definition: pointcloud2_plugin.h:126
mapviz_plugins::PointCloud2Plugin::scans_
std::deque< Scan > scans_
Definition: pointcloud2_plugin.h:159
mapviz_plugins::PointCloud2Plugin::ResetTransformedPointClouds
void ResetTransformedPointClouds()
Definition: pointcloud2_plugin.cpp:217
mapviz_plugins::PointCloud2Plugin::PrintError
void PrintError(const std::string &message)
Definition: pointcloud2_plugin.cpp:605
mapviz_plugins::PointCloud2Plugin::ClearHistory
void ClearHistory()
Definition: pointcloud2_plugin.cpp:177
mapviz_plugins::PointCloud2Plugin::point_size_
size_t point_size_
Definition: pointcloud2_plugin.h:146
mapviz_plugins::PointCloud2Plugin::FieldInfo::datatype
uint8_t datatype
Definition: pointcloud2_plugin.h:61
mapviz_plugins::PointCloud2Plugin::alpha_
double alpha_
Definition: pointcloud2_plugin.h:143
mapviz_plugins::PointCloud2Plugin::PointFeature
float PointFeature(const uint8_t *, const FieldInfo &)
Definition: pointcloud2_plugin.cpp:579
mapviz_plugins::PointCloud2Plugin::min_
std::vector< double > min_
Definition: pointcloud2_plugin.h:155
mapviz_plugins::PointCloud2Plugin::PointSizeChanged
void PointSizeChanged(int value)
Definition: pointcloud2_plugin.cpp:404
mapviz_plugins::PointCloud2Plugin::StampedPoint::point
tf::Point point
Definition: pointcloud2_plugin.h:115
mapviz_plugins::PointCloud2Plugin
Definition: pointcloud2_plugin.h:54
mapviz_plugins::PointCloud2Plugin::UseAutomaxminChanged
void UseAutomaxminChanged(int check_state)
Definition: pointcloud2_plugin.cpp:675
mapviz_plugins::PointCloud2Plugin::max_
std::vector< double > max_
Definition: pointcloud2_plugin.h:154
mapviz_plugins::PointCloud2Plugin::AlphaEdited
void AlphaEdited(double new_value)
Definition: pointcloud2_plugin.cpp:857
mapviz_plugins::PointCloud2Plugin::UpdateColors
void UpdateColors()
Definition: pointcloud2_plugin.cpp:324
mapviz_plugins::PointCloud2Plugin::Initialize
bool Initialize(QGLWidget *canvas)
Definition: pointcloud2_plugin.cpp:627
mapviz_plugins::PointCloud2Plugin::~PointCloud2Plugin
virtual ~PointCloud2Plugin()
Definition: pointcloud2_plugin.cpp:173
mapviz_plugins::PointCloud2Plugin::ui_
Ui::PointCloud2_config ui_
Definition: pointcloud2_plugin.h:139
mapviz_plugins::PointCloud2Plugin::LoadConfig
void LoadConfig(const YAML::Node &node, const std::string &path)
Definition: pointcloud2_plugin.cpp:727
mapviz_plugins::PointCloud2Plugin::COLOR_Z
@ COLOR_Z
Definition: pointcloud2_plugin.h:68
mapviz_plugins::PointCloud2Plugin::has_message_
bool has_message_
Definition: pointcloud2_plugin.h:149
mapviz_plugins::PointCloud2Plugin::Scan::color
QColor color
Definition: pointcloud2_plugin.h:122
mapviz_plugins::PointCloud2Plugin::ColorTransformerChanged
void ColorTransformerChanged(int index)
Definition: pointcloud2_plugin.cpp:816
mapviz_plugins::PointCloud2Plugin::Scan::stamp
ros::Time stamp
Definition: pointcloud2_plugin.h:121
mapviz_plugins::PointCloud2Plugin::Transform
void Transform()
Definition: pointcloud2_plugin.cpp:688
mapviz_plugins::PointCloud2Plugin::config_widget_
QWidget * config_widget_
Definition: pointcloud2_plugin.h:140
mapviz_plugins::PointCloud2Plugin::Shutdown
void Shutdown()
Definition: pointcloud2_plugin.h:75
mapviz_plugins::PointCloud2Plugin::Scan::source_frame
std::string source_frame
Definition: pointcloud2_plugin.h:124
mapviz_plugins::PointCloud2Plugin::saved_color_transformer_
std::string saved_color_transformer_
Definition: pointcloud2_plugin.h:152
mapviz_plugins::PointCloud2Plugin::BufferSizeChanged
void BufferSizeChanged(int value)
Definition: pointcloud2_plugin.cpp:388
ros::Time
mapviz_plugins::PointCloud2Plugin::FieldInfo
Definition: pointcloud2_plugin.h:59
mapviz_plugins::PointCloud2Plugin::max_value_
double max_value_
Definition: pointcloud2_plugin.h:144
mapviz_plugins::PointCloud2Plugin::Scan::gl_color
std::vector< uint8_t > gl_color
Definition: pointcloud2_plugin.h:129
mapviz_plugins::PointCloud2Plugin::UseRainbowChanged
void UseRainbowChanged(int check_state)
Definition: pointcloud2_plugin.cpp:669
mapviz_plugins::PointCloud2Plugin::UpdateMinMaxWidgets
void UpdateMinMaxWidgets()
Definition: pointcloud2_plugin.cpp:823
mapviz_plugins::PointCloud2Plugin::Scan::color_vbo
GLuint color_vbo
Definition: pointcloud2_plugin.h:131
mapviz::MapvizPlugin
mapviz_plugins::PointCloud2Plugin::SelectTopic
void SelectTopic()
Definition: pointcloud2_plugin.cpp:345
mapviz_plugins::PointCloud2Plugin::PointCloud2Callback
void PointCloud2Callback(const sensor_msgs::PointCloud2ConstPtr &scan)
Definition: pointcloud2_plugin.cpp:411
mapviz_plugins::PointCloud2Plugin::need_minmax_
bool need_minmax_
Definition: pointcloud2_plugin.h:153
mapviz_plugins::PointCloud2Plugin::num_of_feats_
size_t num_of_feats_
Definition: pointcloud2_plugin.h:150
mapviz_plugins::PointCloud2Plugin::min_value_
double min_value_
Definition: pointcloud2_plugin.h:145
mapviz_plugins
Definition: attitude_indicator_plugin.h:61
mapviz_plugins::PointCloud2Plugin::PrintInfo
void PrintInfo(const std::string &message)
Definition: pointcloud2_plugin.cpp:610
mapviz_plugins::PointCloud2Plugin::MinValueChanged
void MinValueChanged(double value)
Definition: pointcloud2_plugin.cpp:376
mapviz_plugins::PointCloud2Plugin::COLOR_FLAT
@ COLOR_FLAT
Definition: pointcloud2_plugin.h:67
mapviz_plugins::PointCloud2Plugin::Scan::points
std::vector< StampedPoint > points
Definition: pointcloud2_plugin.h:123
ros::Subscriber
mapviz_plugin.h


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