fov_segmentation_node.cpp
Go to the documentation of this file.
00001 
00064 //##################
00065 //#### includes ####
00066 // ROS includes
00067 #include <tf_conversions/tf_eigen.h>
00068 #include <tf/transform_listener.h>
00069 #include <cob_3d_fov_segmentation/fov_segmentationConfig.h>
00070 
00071 // internal includes
00072 #include <cob_3d_mapping_common/ros_msg_conversions.h>
00073 #include "cob_3d_fov_segmentation/fov_segmentation_node.h"
00074 
00075 using namespace tf;
00076 using namespace cob_3d_mapping;
00077 
00078 FOVSegmentationNode::FOVSegmentationNode ()
00079 {
00080   config_server_.setCallback (boost::bind (&FOVSegmentationNode::dynReconfCallback, this, _1, _2));
00081   shape_sub_ = n_.subscribe ("shape_array_in", 10, &FOVSegmentationNode::shapeCallback, this);
00082   shape_pub_ = n_.advertise<cob_3d_mapping_msgs::ShapeArray> ("shape_array_out", 1);
00083 }
00084 
00085 void
00086 FOVSegmentationNode::dynReconfCallback (cob_3d_fov_segmentation::fov_segmentationConfig &config, uint32_t level)
00087 {
00088   fov_.setSensorFoV_hor (config.sensor_fov_hor_angle);
00089   fov_.setSensorFoV_ver (config.sensor_fov_ver_angle);
00090   fov_.setSensorMaxRange (config.sensor_max_range);
00091   camera_frame_ = config.camera_frame;
00092   target_frame_ = config.target_frame;
00093 
00094   //new settings -> recalculate
00095   fov_.computeFieldOfView ();
00096 }
00097 
00098 void
00099 FOVSegmentationNode::shapeCallback (const cob_3d_mapping_msgs::ShapeArray::ConstPtr& sa)
00100 {
00101   StampedTransform st_trf;
00102   try
00103   {
00104     tf_listener_.waitForTransform (target_frame_, camera_frame_, ros::Time (0), ros::Duration (0.1));
00105     tf_listener_.lookupTransform (target_frame_, camera_frame_, ros::Time (0), st_trf);
00106   }
00107   catch (TransformException ex)
00108   {
00109     ROS_ERROR ("%s", ex.what ());
00110   }
00111   Eigen::Affine3d trafo;
00112   transformTFToEigen (st_trf, trafo);
00113   fov_.transformFOV (trafo);
00114   fov_seg_.setFOV (fov_);
00115   std::vector<Polygon::Ptr> polys;
00116   for (unsigned int i = 0; i < sa->shapes.size (); i++)
00117   {
00118     Polygon::Ptr p (new Polygon);
00119     fromROSMsg (sa->shapes[i], *p);
00120     polys.push_back (p);
00121   }
00122   //std::cout << polys[0]->contours[0][0] << std::endl;
00123   fov_seg_.setShapeArray (polys);
00124   std::vector<Polygon::Ptr> polys_out;
00125   fov_seg_.compute (polys_out);
00126   cob_3d_mapping_msgs::ShapeArray sa_out;
00127   sa_out.header = sa->header;
00128   for (unsigned int i = 0; i < polys_out.size (); i++)
00129   {
00130     cob_3d_mapping_msgs::Shape s;
00131     s.header = sa->header;
00132     toROSMsg (*polys_out[i], s);
00133     sa_out.shapes.push_back (s);
00134   }
00135   shape_pub_.publish (sa_out);
00136 }
00137 
00138 int
00139 main (int argc, char** argv)
00140 {
00141   ros::init (argc, argv, "fov_segmentation_node");
00142 
00143   FOVSegmentationNode fov;
00144 
00145   ros::Rate loop_rate (10);
00146   while (ros::ok ())
00147   {
00148     ros::spinOnce ();
00149     loop_rate.sleep ();
00150   }
00151 }
00152 


cob_3d_fov_segmentation
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:19