Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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 }
00127
00128
00129 #include <pluginlib/class_list_macros.h>
00130 PLUGINLIB_EXPORT_CLASS(hector_veil_geotiff_plugin::VeilMapWriter, hector_geotiff::MapWriterPluginInterface)
00131