hector_veil_geotiff_plugin.cpp
Go to the documentation of this file.
00001 //=================================================================================================
00002 // Copyright (c) 2012, Johannes Meyer, TU Darmstadt
00003 // All rights reserved.
00004 
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //     * Redistributions of source code must retain the above copyright
00008 //       notice, this list of conditions and the following disclaimer.
00009 //     * Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //     * Neither the name of the Flight Systems and Automatic Control group,
00013 //       TU Darmstadt, nor the names of its contributors may be used to
00014 //       endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE 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 #include <hector_geotiff/map_writer_interface.h>
00030 #include <hector_geotiff/map_writer_plugin_interface.h>
00031 
00032 #include <ros/ros.h>
00033 #include <nav_msgs/GetMap.h>
00034 
00035 #include <pluginlib/class_loader.h>
00036 #include <fstream>
00037 
00038 #include <boost/date_time/posix_time/posix_time.hpp>
00039 #include <boost/date_time/gregorian/formatters.hpp>
00040 
00041 #include <boost/tokenizer.hpp>
00042 
00043 #include <hector_worldmodel_msgs/GetObjectModel.h>
00044 
00045 namespace hector_veil_geotiff_plugin {
00046 
00047 using namespace hector_geotiff;
00048 
00049 class SemanticMapWriterPlugin : public MapWriterPluginInterface
00050 {
00051 public:
00052   SemanticMapWriterPlugin();
00053   virtual ~SemanticMapWriterPlugin();
00054 
00055   virtual void initialize(const std::string& name);
00056   virtual void draw(MapWriterInterface *interface) = 0;
00057 
00058 protected:
00059 
00060   ros::NodeHandle nh_;
00061   ros::ServiceClient service_client_;
00062   ros::ServiceClient service_client_no_;
00063 
00064 
00065   bool initialized_;
00066   std::string name_;
00067   bool draw_all_objects_;
00068   std::string class_id_;
00069   std::string pkg_path;
00070 
00071 };
00072 
00073 SemanticMapWriterPlugin::SemanticMapWriterPlugin()
00074   : initialized_(false)
00075 {}
00076 
00077 SemanticMapWriterPlugin::~SemanticMapWriterPlugin()
00078 {}
00079 
00080 void SemanticMapWriterPlugin::initialize(const std::string& name)
00081 {
00082     ros::NodeHandle plugin_nh("~/" + name);
00083     std::string service_name_;
00084 
00085     plugin_nh.param("service_name", service_name_, std::string("worldmodel/get_object_model"));
00086     plugin_nh.param("draw_all_objects", draw_all_objects_, false);
00087     plugin_nh.param("class_id", class_id_, std::string());
00088 
00089     service_client_ = nh_.serviceClient<hector_worldmodel_msgs::GetObjectModel>(service_name_);
00090 
00091     initialized_ = true;
00092     this->name_ = name;
00093     ROS_INFO_NAMED(name_, "Successfully initialized hector_geotiff MapWriter plugin %s.", name_.c_str());
00094 }
00095 
00096 class VeilMapWriter : public SemanticMapWriterPlugin
00097 {
00098 public:
00099   virtual ~VeilMapWriter() {}
00100 
00101   void draw(MapWriterInterface *interface)
00102   {
00103     if (!initialized_) return;
00104 
00105     hector_worldmodel_msgs::GetObjectModel data;
00106     if (!service_client_.call(data)) {
00107       ROS_ERROR_NAMED(name_, "Cannot draw veil, service %s failed", service_client_.getService().c_str());
00108       return;
00109     }
00110 
00111     int counter =0;
00112     for(hector_worldmodel_msgs::ObjectModel::_objects_type::const_iterator it = data.response.model.objects.begin(); it != data.response.model.objects.end(); ++it) {
00113       const hector_worldmodel_msgs::Object& object = *it;
00114       if (!class_id_.empty() && object.info.class_id != class_id_) continue;
00115       Eigen::Vector2f coords;
00116       coords.x() = object.pose.pose.position.x;
00117       coords.y() = object.pose.pose.position.y;
00118       interface->drawObjectOfInterest(coords, boost::lexical_cast<std::string>(++counter), MapWriterInterface::Color(180,0,200));
00119 
00120 
00121     }
00122   }
00123 };
00124 
00125 
00126 } // namespace
00127 
00128 //register this planner as a MapWriterPluginInterface plugin
00129 #include <pluginlib/class_list_macros.h>
00130 PLUGINLIB_EXPORT_CLASS(hector_veil_geotiff_plugin::VeilMapWriter, hector_geotiff::MapWriterPluginInterface)
00131 


hector_veil_geotiff_plugin
Author(s):
autogenerated on Mon Aug 15 2016 03:58:15