supporting_plane_extraction_node.cpp
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_environment_perception
00012  * ROS package name: cob_3d_mapping_semantics
00013  * Description:
00014  *
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *
00017  * Author: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00018  * Supervised by: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00019  *
00020  * Date of creation: 11/2012
00021  * ToDo:
00022  *
00023  *
00024  *
00025  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00026  *
00027  * Redistribution and use in source and binary forms, with or without
00028  * modification, are permitted provided that the following conditions are met:
00029  *
00030  *     * Redistributions of source code must retain the above copyright
00031  *       notice, this list of conditions and the following disclaimer.
00032  *     * Redistributions in binary form must reproduce the above copyright
00033  *       notice, this list of conditions and the following disclaimer in the
00034  *       documentation and/or other materials provided with the distribution.
00035  *     * Neither the name of the Fraunhofer Institute for Manufacturing
00036  *       Engineering and Automation (IPA) nor the names of its
00037  *       contributors may be used to endorse or promote products derived from
00038  *       this software without specific prior written permission.
00039  *
00040  * This program is free software: you can redistribute it and/or modify
00041  * it under the terms of the GNU Lesser General Public License LGPL as
00042  * published by the Free Software Foundation, either version 3 of the
00043  * License, or (at your option) any later version.
00044  *
00045  * This program is distributed in the hope that it will be useful,
00046  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00047  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00048  * GNU Lesser General Public License LGPL for more details.
00049  *
00050  * You should have received a copy of the GNU Lesser General Public
00051  * License LGPL along with this program.
00052  * If not, see <http://www.gnu.org/licenses/>.
00053  *
00054  ****************************************************************/
00055 
00056 //##################
00057 //#### includes ####
00058 #include <algorithm>
00059 
00060 // ROS includes
00061 #include <ros/ros.h>
00062 #include <rosbag/bag.h>
00063 #include <dynamic_reconfigure/server.h>
00064 
00065 // ros message includes
00066 #include <sensor_msgs/PointCloud.h>
00067 #include <visualization_msgs/Marker.h>
00068 #include <visualization_msgs/MarkerArray.h>
00069 
00070 // PCL includes
00071 #include <pcl/point_cloud.h>
00072 #include <pcl/point_types.h>
00073 #include <pcl/ros/conversions.h>
00074 #include <pcl/io/pcd_io.h>
00075 
00076 //internal includes
00077 #include <cob_3d_mapping_msgs/ShapeArray.h>
00078 #include <cob_3d_mapping_msgs/GetGeometryMap.h>
00079 #include <cob_3d_mapping_msgs/GetObjectsOfClass.h>
00080 #include <cob_3d_mapping_msgs/GetTables.h>
00081 #include <cob_3d_mapping_semantics/supporting_plane_extraction.h>
00082 #include <cob_3d_mapping_semantics/supporting_plane_extraction_nodeConfig.h>
00083 #include <cob_3d_mapping_common/ros_msg_conversions.h>
00084 
00085 using namespace cob_3d_mapping;
00086 
00087 class SupportingPlaneExtractionNode
00088 {
00089 public:
00090 
00091   // Constructor
00092   SupportingPlaneExtractionNode () :
00093     n_("~")
00094   {
00095     config_server_.setCallback(boost::bind(&SupportingPlaneExtractionNode::dynReconfCallback, this, _1, _2));
00096 
00097     sa_sub_ = n_.subscribe ("shape_array", 10, &SupportingPlaneExtractionNode::callbackShapeArray, this);
00098     sa_pub_ = n_.advertise<cob_3d_mapping_msgs::ShapeArray> ("shape_array_pub", 1);
00099   }
00100 
00101   // Destructor
00102   ~SupportingPlaneExtractionNode ()
00103   {
00105   }
00106 
00117   void
00118   dynReconfCallback(cob_3d_mapping_semantics::supporting_plane_extraction_nodeConfig &config, uint32_t level)
00119   {
00120     ROS_INFO("[supporting_plane_extraction]: received new parameters");
00121     spe_.setDistanceMin (config.distance_min);
00122     spe_.setDistanceMax (config.distance_max);
00123     spe_.setAreaMin (config.area_min);
00124     spe_.setAreaMax (config.area_max);
00125   }
00126 
00135   void
00136   callbackShapeArray (const cob_3d_mapping_msgs::ShapeArray::ConstPtr sa_ptr)
00137   {
00138     cob_3d_mapping_msgs::ShapeArray sup_planes;
00139     sup_planes.header = sa_ptr->header;
00140     processShapeArray(*sa_ptr, sup_planes);
00141     sa_pub_.publish (sup_planes);
00142     //ROS_INFO("Found %u tables", (unsigned int)tables.shapes.size());
00143   }
00144 
00145 
00154   bool
00155   getTablesService (cob_3d_mapping_msgs::GetObjectsOfClassRequest &req,
00156                     cob_3d_mapping_msgs::GetObjectsOfClassResponse &res)
00157   {
00158     ROS_INFO("service get_tables started....");
00159 
00160     cob_3d_mapping_msgs::ShapeArray sa;
00161     if (getMapService (sa))
00162     {
00163       processShapeArray(sa, res.objects);
00164       ROS_INFO("Found %u tables", (unsigned int)res.objects.shapes.size());
00165       return true;
00166     }
00167     else
00168       return false;
00169   }
00170 
00171 
00177   bool
00178   getMapService (cob_3d_mapping_msgs::ShapeArray& sa)
00179   {
00180     ROS_INFO("Waiting for service server to start.");
00181     ros::service::waitForService ("get_geometry_map", 10); //will wait for infinite time
00182 
00183     ROS_INFO("Server started, polling map.");
00184 
00185     //build message
00186     cob_3d_mapping_msgs::GetGeometryMapRequest req;
00187     cob_3d_mapping_msgs::GetGeometryMapResponse res;
00188 
00189     if (ros::service::call ("get_geometry_map", req, res))
00190     {
00191       ROS_INFO("Service call finished.");
00192     }
00193     else
00194     {
00195       ROS_INFO("Service call failed.");
00196       return 0;
00197     }
00198     sa = res.map;
00199     return true;
00200   }
00201 
00202 
00211   void
00212   processShapeArray(const cob_3d_mapping_msgs::ShapeArray& sa, cob_3d_mapping_msgs::ShapeArray& sup_planes)
00213   {
00214     std::vector<Polygon::Ptr> polys;
00215     for (unsigned int i = 0; i < sa.shapes.size (); i++)
00216     {
00217       if(sa.shapes[i].type != cob_3d_mapping_msgs::Shape::POLYGON) continue;
00218       Polygon::Ptr poly_ptr (new Polygon());
00219       fromROSMsg(sa.shapes[i], *poly_ptr);
00220       polys.push_back(poly_ptr);
00221     }
00222 
00223     Polygon sp;
00224     if(!spe_.getSupportingPlane(polys, sp)) return;
00225     cob_3d_mapping_msgs::Shape s;
00226     s.header = sa.header;
00227     toROSMsg(sp, s);
00228     s.color.r = 1.0;
00229     s.color.g = 0;
00230     s.color.b = 0;
00231     ROS_INFO("Found a supporting plane");
00232     sup_planes.shapes.push_back (s);
00233   }
00234 
00235   ros::NodeHandle n_;
00236 
00237 protected:
00238   ros::Subscriber sa_sub_;
00239   ros::Publisher sa_pub_;
00240 
00244   dynamic_reconfigure::Server<cob_3d_mapping_semantics::supporting_plane_extraction_nodeConfig> config_server_;
00245 
00246   SupportingPlaneExtraction spe_;
00247 
00248 };
00249 
00250 int
00251 main (int argc, char** argv)
00252 {
00253   ros::init (argc, argv, "supporting_plane_extraction_node");
00254 
00255   SupportingPlaneExtractionNode sem_exn_node;
00256   ros::spin ();
00257 }


cob_3d_mapping_semantics
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:03:34