laserscan_plugin.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #ifndef MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
00031 #define MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_
00032 
00033 // C++ standard libraries
00034 #include <string>
00035 #include <deque>
00036 #include <vector>
00037 
00038 #include <mapviz/mapviz_plugin.h>
00039 
00040 // QT libraries
00041 #include <QGLWidget>
00042 #include <QColor>
00043 
00044 // ROS libraries
00045 #include <sensor_msgs/LaserScan.h>
00046 
00047 // QT autogenerated files
00048 #include "ui_laserscan_config.h"
00049 
00050 namespace mapviz_plugins
00051 {
00052   class LaserScanPlugin : public mapviz::MapvizPlugin
00053   {
00054     Q_OBJECT
00055 
00056     public:
00057       enum
00058       {
00059         COLOR_FLAT = 0,
00060         COLOR_INTENSITY = 1,
00061         COLOR_RANGE = 2,
00062         COLOR_X = 3,
00063         COLOR_Y = 4,
00064         COLOR_Z = 5
00065       };
00066       LaserScanPlugin();
00067       virtual ~LaserScanPlugin();
00068 
00069       bool Initialize(QGLWidget* canvas);
00070       void Shutdown()
00071       {
00072       }
00073 
00074       void ClearHistory();
00075 
00076       void Draw(double x, double y, double scale);
00077 
00078       void Transform();
00079 
00080       void LoadConfig(const YAML::Node& node, const std::string& path);
00081       void SaveConfig(YAML::Emitter& emitter, const std::string& path);
00082 
00083       QWidget* GetConfigWidget(QWidget* parent);
00084 
00085     protected:
00086       void PrintError(const std::string& message);
00087       void PrintInfo(const std::string& message);
00088       void PrintWarning(const std::string& message);
00089 
00090     protected Q_SLOTS:
00091       void SelectTopic();
00092       void TopicEdited();
00093       void AlphaEdited(double val);
00094       void ColorTransformerChanged(int index);
00095       void MinValueChanged(double value);
00096       void MaxValueChanged(double value);
00097       void PointSizeChanged(int value);
00098       void BufferSizeChanged(int value);
00099       void UseRainbowChanged(int check_state);
00100       void UpdateColors();    
00101       void DrawIcon();
00102 
00103     private:
00104       struct StampedPoint
00105       {
00106         tf::Point point;
00107         tf::Point transformed_point;
00108         QColor color;
00109         float range;
00110         float intensity;
00111       };
00112 
00113       struct Scan
00114       {
00115         ros::Time stamp;
00116         QColor color;
00117         std::vector<StampedPoint> points;
00118         std::string source_frame_;
00119         bool transformed;
00120         bool has_intensity;
00121       };
00122 
00123       void laserScanCallback(const sensor_msgs::LaserScanConstPtr& scan);
00124       QColor CalculateColor(const StampedPoint& point, bool has_intensity);
00125       void updatePreComputedTriginometic(const sensor_msgs::LaserScanConstPtr& msg);
00126 
00127       Ui::laserscan_config ui_;
00128       QWidget* config_widget_;
00129 
00130       std::string topic_;
00131       double alpha_;
00132       double min_value_;
00133       double max_value_;
00134       size_t point_size_;
00135       size_t buffer_size_;
00136 
00137       bool has_message_;
00138 
00139       // Use a list instead of a deque for scans to facilitate removing
00140       // timed-out scans in the middle of the list in case I ever re-implement
00141       // decay time (evenator)
00142       std::deque<Scan> scans_;
00143       ros::Subscriber laserscan_sub_;
00144       std::vector<double> precomputed_cos_;
00145       std::vector<double> precomputed_sin_;
00146       size_t prev_ranges_size_;
00147       float  prev_angle_min_;
00148       float  prev_increment_;
00149   };
00150 }
00151 
00152 #endif  // MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_


mapviz_plugins
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 18:51:07