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 Draw(double x, double y, double scale);
00075 
00076       void Transform();
00077 
00078       void LoadConfig(const YAML::Node& node, const std::string& path);
00079       void SaveConfig(YAML::Emitter& emitter, const std::string& path);
00080 
00081       QWidget* GetConfigWidget(QWidget* parent);
00082 
00083     protected:
00084       void PrintError(const std::string& message);
00085       void PrintInfo(const std::string& message);
00086       void PrintWarning(const std::string& message);
00087 
00088     protected Q_SLOTS:
00089       void SelectTopic();
00090       void TopicEdited();
00091       void AlphaEdited();
00092       void ColorTransformerChanged(int index);
00093       void MinValueChanged(double value);
00094       void MaxValueChanged(double value);
00095       void PointSizeChanged(int value);
00096       void BufferSizeChanged(int value);
00097       void UseRainbowChanged(int check_state);
00098       void UpdateColors();    
00099       void DrawIcon();
00100 
00101     private:
00102       struct StampedPoint
00103       {
00104         tf::Point point;
00105         tf::Point transformed_point;
00106         QColor color;
00107         float range;
00108         float intensity;
00109       };
00110 
00111       struct Scan
00112       {
00113         ros::Time stamp;
00114         QColor color;
00115         std::vector<StampedPoint> points;
00116         std::string source_frame_;
00117         bool transformed;
00118         bool has_intensity;
00119       };
00120 
00121       void laserScanCallback(const sensor_msgs::LaserScanConstPtr& scan);
00122       QColor CalculateColor(const StampedPoint& point, bool has_intensity);
00123 
00124       Ui::laserscan_config ui_;
00125       QWidget* config_widget_;
00126 
00127       std::string topic_;
00128       double alpha_;
00129       double min_value_;
00130       double max_value_;
00131       size_t point_size_;
00132       size_t buffer_size_;
00133 
00134       bool has_message_;
00135 
00136       // Use a list instead of a deque for scans to facilitate removing
00137       // timed-out scans in the middle of the list in case I ever re-implement
00138       // decay time (evenator)
00139       std::deque<Scan> scans_;
00140       ros::Subscriber laserscan_sub_;
00141   };
00142 }
00143 
00144 #endif  // MAPVIZ_PLUGINS_LASERSCAN_PLUGIN_H_


mapviz_plugins
Author(s): Marc Alban
autogenerated on Thu Aug 24 2017 02:46:09