structure_extraction_node.cpp
Go to the documentation of this file.
00001 
00064 //##################
00065 //#### includes ####
00066 //#include <algorithm>
00067 
00068 // ROS includes
00069 #include <ros/ros.h>
00070 #include <dynamic_reconfigure/server.h>
00071 
00072 // ros message includes
00073 #include <visualization_msgs/Marker.h>
00074 #include <visualization_msgs/MarkerArray.h>
00075 
00076 //internal includes
00077 #include <cob_3d_mapping_msgs/ShapeArray.h>
00078 #include <cob_3d_mapping_semantics/structure_extraction.h>
00079 #include <cob_3d_mapping_semantics/structure_extraction_nodeConfig.h>
00080 #include <cob_3d_mapping_common/ros_msg_conversions.h>
00081 
00082 using namespace cob_3d_mapping;
00083 
00084 class StructureExtractionNode
00085 {
00086 public:
00087 
00088   // Constructor
00089   StructureExtractionNode () :
00090     target_frame_id_ ("/map"),
00091     remove_floor_("false"),
00092     colorize_("false")
00093   {
00094     config_server_.setCallback(boost::bind(&StructureExtractionNode::dynReconfCallback, this, _1, _2));
00095 
00096     sa_sub_ = n_.subscribe ("shape_array", 10, &StructureExtractionNode::callbackShapeArray, this);
00097     sa_pub_ = n_.advertise<cob_3d_mapping_msgs::ShapeArray> ("shape_array_pub", 1);
00098   }
00099 
00100   // Destructor
00101   ~StructureExtractionNode ()
00102   {
00104   }
00105 
00116   void
00117   dynReconfCallback(cob_3d_mapping_semantics::structure_extraction_nodeConfig &config, uint32_t level)
00118   {
00119     ROS_INFO("[table_extraction]: received new parameters");
00120     target_frame_id_ = config.target_frame_id;
00121     se_.setFloorHeight (config.floor_height);
00122     se_.setCeilingHeight (config.ceiling_height);
00123     remove_floor_ = config.remove_floor;
00124     colorize_ = config.colorize;
00125   }
00126 
00135   void
00136   callbackShapeArray (const cob_3d_mapping_msgs::ShapeArray::ConstPtr sa_ptr)
00137   {
00138     if(sa_ptr->header.frame_id != target_frame_id_)
00139     {
00140       ROS_ERROR("Frame IDs do not match, aborting...");
00141       return;
00142     }
00143     cob_3d_mapping_msgs::ShapeArray sa_out;
00144     sa_out.header = sa_ptr->header;
00145     sa_out.header.frame_id = target_frame_id_ ;
00146     for (unsigned int i = 0; i < sa_ptr->shapes.size (); i++)
00147     {
00148       Polygon::Ptr poly_ptr (new Polygon());
00149       fromROSMsg(sa_ptr->shapes[i], *poly_ptr);
00150       se_.setInputPolygon(poly_ptr);
00151       unsigned int label;
00152       se_.classify(label);
00153       if(colorize_)
00154       {
00155         switch (label)
00156         {
00157           case 1:
00158             poly_ptr->color_[0] = 1;
00159             poly_ptr->color_[1] = 1;
00160             poly_ptr->color_[2] = 1;
00161             poly_ptr->color_[3] = 0.5;
00162             break;
00163           case 2:
00164             poly_ptr->color_[0] = 0.5;
00165             poly_ptr->color_[1] = 0.5;
00166             poly_ptr->color_[2] = 0.5;
00167             poly_ptr->color_[3] = 1;
00168             break;
00169           case 3:
00170             poly_ptr->color_[0] = 0;
00171             poly_ptr->color_[1] = 0;
00172             poly_ptr->color_[2] = 1;
00173             poly_ptr->color_[3] = 1;
00174             break;
00175         }
00176       }
00177       cob_3d_mapping_msgs::Shape s;
00178       s.header = sa_ptr->header;
00179       s.header.frame_id = target_frame_id_;
00180       toROSMsg(*poly_ptr,s);
00181       if(label == 2 && remove_floor_)
00182         {}//std::cout << "removing floor" << std::endl;
00183       else
00184         sa_out.shapes.push_back (s);
00185     }
00186     sa_pub_.publish (sa_out);
00187   }
00188 
00189 
00190   ros::NodeHandle n_;
00191 
00192 protected:
00193   ros::Subscriber sa_sub_;
00194   ros::Publisher sa_pub_;
00195 
00199   dynamic_reconfigure::Server<cob_3d_mapping_semantics::structure_extraction_nodeConfig> config_server_;
00200 
00201   StructureExtraction se_;
00202 
00203   std::string target_frame_id_;
00204   bool remove_floor_;
00205   bool colorize_;
00206 
00207 };
00208 
00209 int
00210 main (int argc, char** argv)
00211 {
00212   ros::init (argc, argv, "structure_extraction_node");
00213 
00214   StructureExtractionNode sem_exn_node;
00215   ros::spin ();
00216 }


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