Go to the documentation of this file.00001 #include "filter_table_alg.h"
00002
00003 FilterTableAlgorithm::FilterTableAlgorithm(void)
00004 {
00005 this->max_z_=0.8;
00006 this->sac_dist_thr_=0.001;
00007 this->filter_final_ratio_=0.6;
00008 this->rad_radius_search_=0.1;
00009 }
00010
00011 FilterTableAlgorithm::~FilterTableAlgorithm(void)
00012 {
00013 }
00014
00015 void FilterTableAlgorithm::config_update(Config& new_cfg, uint32_t level)
00016 {
00017 this->lock();
00018
00019 if(this->config_.max_z != new_cfg.max_z)
00020 {
00021 this->set_max_z(new_cfg.max_z);
00022 }
00023 if(this->config_.sac_dist_thr != new_cfg.sac_dist_thr)
00024 {
00025 this->set_sac_dist_thr(new_cfg.sac_dist_thr);
00026 }
00027 if(this->config_.filter_final_ratio != new_cfg.filter_final_ratio)
00028 {
00029 this->set_filter_final_ratio(new_cfg.filter_final_ratio);
00030 }
00031 if(this->config_.rad_radius_search != new_cfg.rad_radius_search)
00032 {
00033 this->set_rad_radius_search(new_cfg.rad_radius_search);
00034 }
00035
00036
00037
00038 this->config_=new_cfg;
00039
00040 this->unlock();
00041 }
00042
00043
00044 pcl::PointCloud<pcl::PointXYZRGB>::Ptr FilterTableAlgorithm::filter_table(const sensor_msgs::PointCloud2::ConstPtr &cloud_blob)
00045 {
00046 sensor_msgs::PointCloud2::Ptr cloud_filtered_blob (new sensor_msgs::PointCloud2);
00047 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>), cloud_p (new pcl::PointCloud<pcl::PointXYZRGB>);
00048
00049
00050
00051
00052
00053
00054 pcl::fromROSMsg (*cloud_blob, *cloud_filtered);
00055
00056 pcl::PassThrough<pcl::PointXYZRGB> pass;
00057 pass.setInputCloud (cloud_filtered);
00058 pass.setFilterFieldName ("z");
00059 pass.setFilterLimits (0.0, this->max_z_);
00060 pass.filter (*cloud_filtered);
00061
00062 std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height << " data points." << std::endl;
00063 pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ());
00064 pcl::PointIndices::Ptr inliers (new pcl::PointIndices ());
00065
00066
00067 pcl::SACSegmentation<pcl::PointXYZRGB> seg;
00068
00069 seg.setOptimizeCoefficients (true);
00070
00071 seg.setModelType (pcl::SACMODEL_PLANE);
00072 seg.setMethodType (pcl::SAC_RANSAC);
00073 seg.setMaxIterations (1000);
00074 seg.setDistanceThreshold (this->sac_dist_thr_);
00075
00076
00077 pcl::ExtractIndices<pcl::PointXYZRGB> extract;
00078
00079 int i = 0, nr_points = (int) cloud_filtered->points.size ();
00080
00081 while (cloud_filtered->points.size () > this->filter_final_ratio_ * nr_points)
00082 {
00083
00084 seg.setInputCloud (cloud_filtered);
00085 seg.segment (*inliers, *coefficients);
00086 if (inliers->indices.size () == 0)
00087 {
00088 std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
00089 break;
00090 }
00091
00092
00093
00094
00095
00096 for(int j=0:j<inliers->indices.size();j++)
00097 {
00098
00099
00100 }
00101
00102
00103
00104
00105
00106
00107 extract.setInputCloud (cloud_filtered);
00108 extract.setIndices (inliers);
00109 extract.setNegative (false);
00110 extract.filter (*cloud_p);
00111 std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;
00112
00113
00114 extract.setNegative (true);
00115 extract.filter (*cloud_filtered);
00116
00117 i++;
00118 }
00119
00120
00121 pcl::RadiusOutlierRemoval<pcl::PointXYZRGB> rad;
00122 rad.setInputCloud(cloud_filtered);
00123 rad.setRadiusSearch(this->rad_radius_search_);
00124 rad.setMinNeighborsInRadius(10000);
00125 rad.filter(*cloud_filtered);
00126 return cloud_filtered;
00127 }