Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00057 int
00058   main (int argc, char** argv)
00059 {
00060   
00061   pcl::PCDReader reader;
00062   pcl::PassThrough<PointT> pass;
00063   pcl::NormalEstimation<PointT, pcl::Normal> ne;
00064   pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg;
00065   pcl::PCDWriter writer;
00066   pcl::ExtractIndices<PointT> extract;
00067   pcl::ExtractIndices<pcl::Normal> extract_normals;
00068   pcl::KdTreeFLANN<PointT>::Ptr tree (new pcl::KdTreeFLANN<PointT> ());
00069 
00070   
00071   pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT> ());
00072   pcl::PointCloud<PointT>::Ptr cloud_filtered (new pcl::PointCloud<PointT> ());
00073   pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal> ());
00074   pcl::ModelCoefficients::Ptr coefficients_plane (new pcl::ModelCoefficients ()), coefficients_cylinder (new pcl::ModelCoefficients ());
00075   pcl::PointIndices::Ptr inliers_plane (new pcl::PointIndices ()), inliers_cylinder (new pcl::PointIndices ());
00076 
00077   
00078   reader.read ("data/table_scene_mug_stereo_textured.pcd", *cloud);
00079   ROS_INFO ("PointCloud has: %zu data points.", cloud->points.size ());
00080 
00081   
00082   pass.setInputCloud (cloud);
00083   pass.setFilterFieldName ("z");
00084   pass.setFilterLimits (0, 1.2);
00085   pass.filter (*cloud_filtered);
00086   ROS_INFO ("PointCloud after filtering has: %zu data points.", cloud_filtered->points.size ());
00087 
00088   
00089   ne.setSearchMethod (tree);
00090   ne.setInputCloud (cloud_filtered);
00091   ne.setKSearch (50);
00092   ne.compute (*cloud_normals);
00093 
00094   
00095   seg.setOptimizeCoefficients (true);
00096   seg.setModelType (pcl::SACMODEL_NORMAL_PLANE);
00097   seg.setNormalDistanceWeight (0.01);
00098   seg.setMethodType (pcl::SAC_RANSAC);
00099   seg.setMaxIterations (100);
00100   seg.setDistanceThreshold (0.02);
00101   seg.setInputCloud (cloud_filtered);
00102   seg.setInputNormals (cloud_normals);
00103   
00104   seg.segment (*inliers_plane, *coefficients_plane);
00105   std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl;
00106 
00107   
00108   extract.setInputCloud (cloud_filtered);
00109   extract.setIndices (inliers_plane);
00110   extract.setNegative (false);
00111 
00112   
00113   pcl::PointCloud<PointT>::Ptr cloud_plane (new pcl::PointCloud<PointT> ());
00114   extract.filter (*cloud_plane);
00115   ROS_INFO ("PointCloud representing the planar component: %zu data points.", cloud_plane->points.size ());
00116   writer.write ("table_scene_mug_stereo_textured_plane.pcd", *cloud_plane, false);
00117 
00118   
00119   pcl::PointCloud<PointT>::Ptr cloud_cylinder (new pcl::PointCloud<PointT> ());
00120   extract.setNegative (true);
00121   extract.filter (*cloud_cylinder);
00122   extract.filter (*cloud_cylinder);
00123   ROS_INFO ("PointCloud representing the cylindrical component: %zu data points.", cloud_cylinder->points.size ());
00124   writer.write ("table_scene_mug_stereo_textured_cylinder.pcd", *cloud_cylinder, false);
00125 
00126   return (0);
00127 }
00128