marker_plugin.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, 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_MARKER_PLUGIN_H_
31 #define MAPVIZ_PLUGINS_MARKER_PLUGIN_H_
32 
33 // C++ standard libraries
34 #include <string>
35 #include <unordered_map>
36 
37 #include <mapviz/mapviz_plugin.h>
38 
39 // QT libraries
40 #include <QGLWidget>
41 #include <QListWidgetItem>
42 
43 // ROS libraries
44 #include <tf/transform_datatypes.h>
46 #include <visualization_msgs/MarkerArray.h>
47 
48 #include <mapviz/map_canvas.h>
49 
50 // QT autogenerated files
51 #include "ui_marker_config.h"
52 
53 namespace mapviz_plugins
54 {
55  using MarkerId = std::pair<std::string, int>;
56 
57  struct MarkerIdHash {
58  std::size_t operator () (const MarkerId &p) const {
59  std::size_t seed = 0;
60  boost::hash_combine(seed, p.first);
61  boost::hash_combine(seed, p.second);
62  return seed;
63  }
64  };
65 
66  struct MarkerNsHash {
67  std::size_t operator () (const std::string &p) const {
68  std::size_t seed = 0;
69  boost::hash_combine(seed, p);
70  return seed;
71  }
72  };
73 
75  {
76  Q_OBJECT
77 
78  public:
79  MarkerPlugin();
80  virtual ~MarkerPlugin();
81 
82  bool Initialize(QGLWidget* canvas);
83  void Shutdown() {}
84 
85  void Draw(double x, double y, double scale);
86  void Paint(QPainter* painter, double x, double y, double scale);
87 
88  void Transform();
89 
90  void LoadConfig(const YAML::Node& node, const std::string& path);
91  void SaveConfig(YAML::Emitter& emitter, const std::string& path);
92 
93  QWidget* GetConfigWidget(QWidget* parent);
94 
96  {
97  return true;
98  }
99 
100  protected:
101  void PrintError(const std::string& message);
102  void PrintInfo(const std::string& message);
103  void PrintWarning(const std::string& message);
104  void timerEvent(QTimerEvent *);
105 
106  protected Q_SLOTS:
107  void SelectTopic();
108  void TopicEdited();
109  void ClearHistory();
110 
111  private:
112  struct Color
113  {
114  float r, g, b, a;
115  };
116 
118  {
121 
123 
128 
130  };
131 
132  struct MarkerData
133  {
136 
139 
140  std::vector<StampedPoint> points;
141  std::string text;
142 
143  float scale_x;
144  float scale_y;
145  float scale_z;
146 
147  std::string source_frame;
149 
151  };
152 
153  Ui::marker_config ui_;
154  QWidget* config_widget_;
155 
156  std::string topic_;
157 
161 
162  std::unordered_map<MarkerId, MarkerData, MarkerIdHash> markers_;
163  std::unordered_map<std::string, bool, MarkerNsHash> marker_visible_;
164 
165  void handleMessage(const topic_tools::ShapeShifter::ConstPtr& msg);
166  void handleMarker(const visualization_msgs::Marker &marker);
167  void handleMarkerArray(const visualization_msgs::MarkerArray &markers);
168  void transformArrow(MarkerData& markerData,
169  const swri_transform_util::Transform& transform);
170  };
171 }
172 
173 #endif // MAPVIZ_PLUGINS_MARKER_PLUGIN_H_
std::pair< std::string, int > MarkerId
Definition: marker_plugin.h:55
std::unordered_map< std::string, bool, MarkerNsHash > marker_visible_
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
swri_transform_util::Transform local_transform
std::size_t operator()(const MarkerId &p) const
Definition: marker_plugin.h:58
std::unordered_map< MarkerId, MarkerData, MarkerIdHash > markers_
std::vector< StampedPoint > points


mapviz_plugins
Author(s): Marc Alban
autogenerated on Fri Mar 19 2021 02:44:32