hector_veil_geotiff_plugin.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2012, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
31 
32 #include <ros/ros.h>
33 #include <nav_msgs/GetMap.h>
34 
35 #include <pluginlib/class_loader.h>
36 #include <fstream>
37 
38 #include <boost/date_time/posix_time/posix_time.hpp>
39 #include <boost/date_time/gregorian/formatters.hpp>
40 
41 #include <boost/tokenizer.hpp>
42 
43 #include <hector_worldmodel_msgs/GetObjectModel.h>
44 
46 
47 using namespace hector_geotiff;
48 
50 {
51 public:
53  virtual ~SemanticMapWriterPlugin();
54 
55  virtual void initialize(const std::string& name);
56  virtual void draw(MapWriterInterface *interface) = 0;
57 
58 protected:
59 
63 
64 
66  std::string name_;
68  std::string class_id_;
69  std::string pkg_path;
70 
71 };
72 
74  : initialized_(false)
75 {}
76 
78 {}
79 
80 void SemanticMapWriterPlugin::initialize(const std::string& name)
81 {
82  ros::NodeHandle plugin_nh("~/" + name);
83  std::string service_name_;
84 
85  plugin_nh.param("service_name", service_name_, std::string("worldmodel/get_object_model"));
86  plugin_nh.param("draw_all_objects", draw_all_objects_, false);
87  plugin_nh.param("class_id", class_id_, std::string());
88 
89  service_client_ = nh_.serviceClient<hector_worldmodel_msgs::GetObjectModel>(service_name_);
90 
91  initialized_ = true;
92  this->name_ = name;
93  ROS_INFO_NAMED(name_, "Successfully initialized hector_geotiff MapWriter plugin %s.", name_.c_str());
94 }
95 
97 {
98 public:
99  virtual ~VeilMapWriter() {}
100 
101  void draw(MapWriterInterface *interface)
102  {
103  if (!initialized_) return;
104 
105  hector_worldmodel_msgs::GetObjectModel data;
106  if (!service_client_.call(data)) {
107  ROS_ERROR_NAMED(name_, "Cannot draw veil, service %s failed", service_client_.getService().c_str());
108  return;
109  }
110 
111  int counter =0;
112  for(hector_worldmodel_msgs::ObjectModel::_objects_type::const_iterator it = data.response.model.objects.begin(); it != data.response.model.objects.end(); ++it) {
113  const hector_worldmodel_msgs::Object& object = *it;
114  if (!class_id_.empty() && object.info.class_id != class_id_) continue;
115  Eigen::Vector2f coords;
116  coords.x() = object.pose.pose.position.x;
117  coords.y() = object.pose.pose.position.y;
118  interface->drawObjectOfInterest(coords, boost::lexical_cast<std::string>(++counter), MapWriterInterface::Color(180,0,200));
119 
120 
121  }
122  }
123 };
124 
125 
126 } // namespace
127 
128 //register this planner as a MapWriterPluginInterface plugin
131 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
#define ROS_INFO_NAMED(name,...)
ROSCONSOLE_DECL void initialize()
bool call(MReq &req, MRes &res)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
virtual void drawObjectOfInterest(const Eigen::Vector2f &coords, const std::string &txt, const Color &color)=0
#define ROS_ERROR_NAMED(name,...)
std::string getService()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)


hector_veil_geotiff_plugin
Author(s):
autogenerated on Mon Jun 10 2019 13:36:42