00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2014, 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_ROBOT_IMAGE_PLUGIN_H_ 00031 #define MAPVIZ_PLUGINS_ROBOT_IMAGE_PLUGIN_H_ 00032 00033 // C++ standard libraries 00034 #include <string> 00035 00036 #include <mapviz/mapviz_plugin.h> 00037 00038 // QT libraries 00039 #include <QGLWidget> 00040 #include <QObject> 00041 #include <QWidget> 00042 00043 // ROS libraries 00044 #include <ros/ros.h> 00045 #include <tf/transform_datatypes.h> 00046 00047 #include <mapviz/map_canvas.h> 00048 00049 // QT autogenerated files 00050 #include "ui_robot_image_config.h" 00051 #include "ui_topic_select.h" 00052 00053 namespace mapviz_plugins 00054 { 00055 class RobotImagePlugin : public mapviz::MapvizPlugin 00056 { 00057 Q_OBJECT 00058 00059 public: 00060 RobotImagePlugin(); 00061 virtual ~RobotImagePlugin(); 00062 00063 bool Initialize(QGLWidget* canvas); 00064 void Shutdown() {} 00065 00066 void Draw(double x, double y, double scale); 00067 00068 void Transform(); 00069 00070 void LoadConfig(const YAML::Node& node, const std::string& path); 00071 void SaveConfig(YAML::Emitter& emitter, const std::string& path); 00072 00073 QWidget* GetConfigWidget(QWidget* parent); 00074 00075 protected: 00076 void PrintError(const std::string& message); 00077 void PrintInfo(const std::string& message); 00078 void PrintWarning(const std::string& message); 00079 00080 protected Q_SLOTS: 00081 void SelectFile(); 00082 void SelectFrame(); 00083 void FrameEdited(); 00084 void WidthChanged(double value); 00085 void HeightChanged(double value); 00086 void OffsetXChanged(double value); 00087 void OffsetYChanged(double value); 00088 00089 private: 00090 Ui::robot_image_config ui_; 00091 QWidget* config_widget_; 00092 00093 double width_; //image width, if robot frame is x-forward this corresponds to robot length 00094 double height_; //image height, corresponds to robot width 00095 double offset_x_; //offset of image center from robot frame along x axis 00096 double offset_y_; //offset of image center from robot frame along y axis 00097 00098 std::string filename_; 00099 QImage image_; 00100 int dimension_; 00101 int texture_id_; 00102 bool texture_loaded_; 00103 00104 bool transformed_; 00105 00106 tf::Point top_left_; 00107 tf::Point top_right_; 00108 tf::Point bottom_left_; 00109 tf::Point bottom_right_; 00110 00111 tf::Point top_left_transformed_; 00112 tf::Point top_right_transformed_; 00113 tf::Point bottom_left_transformed_; 00114 tf::Point bottom_right_transformed_; 00115 00116 void UpdateShape(); 00117 void LoadImage(); 00118 }; 00119 } 00120 00121 #endif // MAPVIZ_PLUGINS_ROBOT_IMAGE_PLUGIN_H_