obstacle_detection_normals_alg.cpp
Go to the documentation of this file.
00001 #include "obstacle_detection_normals_alg.h"
00002 using namespace std;
00003 
00004 ObstacleDetectionNormalsAlgorithm::ObstacleDetectionNormalsAlgorithm(void)
00005 {
00006 }
00007 
00008 ObstacleDetectionNormalsAlgorithm::~ObstacleDetectionNormalsAlgorithm(void)
00009 {
00010 }
00011 
00012 void ObstacleDetectionNormalsAlgorithm::config_update(Config& new_cfg, uint32_t level)
00013 {
00014   this->lock();
00015 
00016   // save the current configuration
00017   this->config_=new_cfg;
00018   
00019   this->unlock();
00020 }
00021 
00022 // ObstacleDetectionNormalsAlgorithm Public API
00023 
00024 void ObstacleDetectionNormalsAlgorithm::cloud_all(int KSearch, float normal_z, 
00025      float normal_y, float normal_x, float min_dist, 
00026      const pcl::PointCloud<pcl::PointXYZ>& cloud, 
00027      pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr& cloud_out, pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr& cloud_obs)
00028 {
00029 
00030 //pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
00031   // Output datasets
00032   pcl::PointCloud<pcl::Normal>::Ptr output (new pcl::PointCloud<pcl::Normal>);
00033 
00034 // Normal estimation using integral Images /////////////////////////////////////////////
00035 // NOTE: Point cloud should contain width and height structure
00036 
00037 // pcl::IntegralImageNormalEstimation<pcl::PointXYZ, pcl::Normal> n;
00038 
00039 // n.setNormalEstimationMethod(n.AVERAGE_3D_GRADIENT);
00040 // n.setMaxDepthChangeFactor(0.02f);
00041 // n.setNormalSmoothingSize(10.0f);
00042 // n.setInputCloud(cloud);
00043 // n.compute(*output);
00044 
00045 // ROS Fuerte version //////////////////////////////////////////////////////////////
00046 
00047   // Create the normal estimation class, and pass the input dataset to it
00048   pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
00049   // [Multi-threat](NOTE: Point cloud should contain width and height structure):
00050   // pcl::NormaleEstimationOMP<pcl::PointXYZ, pcl::Normal> n;
00051   // n.setNumberOfThreads(8); 
00052 
00053   // To work with Pointers ::Ptr ///////////////////////////////////////////////////////////
00054   // // Set input cloud
00055   // n.setInputCloud (cloud);
00056             
00057   // // Create an empty kdtree representation, and pass it to the normal estimation object.
00058   // // Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).
00059   // pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
00060   // n.setSearchMethod (tree);
00061 
00062   // // Use all neighbors in a sphere of radius 3cm
00063   // n.setRadiusSearch (KSearch);
00064   // // [Multi-threat](NOTE: Point cloud should contain width and height structure) :
00065   // // n.setKSearch (KSearch);
00066 
00067   // double secs = ros::Time::now().toSec();
00068 
00069   // // Compute the features
00070   // n.compute (*output);
00071 
00072   // pcl::concatenateFields (*cloud, *output, *cloud_out);
00073 
00074   // double secs2 = ros::Time::now().toSec();
00075   // double diff = secs2-secs;
00076   // ROS_INFO("computation time: %2.2f",diff);
00077 
00079 
00080   std::vector<int> indices;
00081   indices.resize (cloud.points.size());
00082   for (size_t i = 0; i < indices.size (); ++i) { indices[i] = i; }
00083 
00084   pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
00085 
00086 
00087   boost::shared_ptr< vector<int> > indicesptr(new vector<int> (indices));
00088   // set normal estimation parameters
00089   n.setIndices(indicesptr);
00090   n.setSearchMethod(tree);
00091   n.setKSearch(KSearch); // Use 10 nearest neighbors to estimate the normals
00092 
00093   //estimate
00094   n.setInputCloud(cloud.makeShared());
00095   n.compute(*output);
00096 
00097   pcl::concatenateFields (cloud, *output, *cloud_out);
00098 
00099 
00100 
00101   float e=0.0;
00102 
00103   *cloud_obs=*cloud_out; 
00104 
00105   for (size_t rowIndex=0, pointIndex=0; rowIndex<cloud_out->height; ++rowIndex)
00106   {
00107     for (size_t colIndex=0; colIndex<cloud_out->width; ++colIndex, ++pointIndex)
00108     {
00109       //ROS_ERROR_STREAM(cloud_out->points[pointIndex].normal_z);
00110       if (cloud_out->points[pointIndex].z > min_dist)
00111       {
00112         if (cloud_out->points[pointIndex].normal_z < normal_z && 
00113             cloud_out->points[pointIndex].normal_y < normal_y && 
00114             cloud_out->points[pointIndex].normal_x < normal_x)
00115         {
00116           cloud_out->points[pointIndex].r=0;
00117           cloud_out->points[pointIndex].g=255;
00118           cloud_out->points[pointIndex].b=0;
00119           cloud_obs->points[pointIndex].x=std::numeric_limits<float>::quiet_NaN();;
00120           cloud_obs->points[pointIndex].y=std::numeric_limits<float>::quiet_NaN();;
00121           cloud_obs->points[pointIndex].z=std::numeric_limits<float>::quiet_NaN();;
00122         }
00123         else 
00124         {
00125           cloud_out->points[pointIndex].r=255;
00126           cloud_out->points[pointIndex].g=0;
00127           cloud_out->points[pointIndex].b=0;
00128           //error counter looking a plane without obstacles
00129           e=e+1.0;
00130         }
00131       }
00132       else
00133       {
00134         cloud_out->points[pointIndex].r=0;
00135         cloud_out->points[pointIndex].g=0;
00136         cloud_out->points[pointIndex].b=255;
00137       }
00138     }
00139   }
00140   e=(e/float(cloud_out->width*cloud_out->height))*100; 
00141   //printf("error %f",e); 
00142 }
00143 


iri_obstacle_detection_normals
Author(s): asantamaria
autogenerated on Fri Dec 6 2013 21:12:38