concave_hull_2d.cpp
Go to the documentation of this file.
00001 #include <pcl/ModelCoefficients.h>
00002 #include <pcl/io/pcd_io.h>
00003 #include <pcl/point_types.h>
00004 #include <pcl/sample_consensus/method_types.h>
00005 #include <pcl/sample_consensus/model_types.h>
00006 #include <pcl/filters/passthrough.h>
00007 #include <pcl/filters/project_inliers.h>
00008 #include <pcl/segmentation/sac_segmentation.h>
00009 #include <pcl/surface/concave_hull.h>
00010 
00011 int
00012 main (int argc, char** argv)
00013 {
00014   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>), 
00015                                       cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>), 
00016                                       cloud_projected (new pcl::PointCloud<pcl::PointXYZ>);
00017   pcl::PCDReader reader;
00018 
00019   reader.read ("table_scene_mug_stereo_textured.pcd", *cloud);
00020   // Build a filter to remove spurious NaNs
00021   pcl::PassThrough<pcl::PointXYZ> pass;
00022   pass.setInputCloud (cloud);
00023   pass.setFilterFieldName ("z");
00024   pass.setFilterLimits (0, 1.1);
00025   pass.filter (*cloud_filtered);
00026   std::cerr << "PointCloud after filtering has: "
00027             << cloud_filtered->points.size () << " data points." << std::endl;
00028 
00029   pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
00030   pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
00031   // Create the segmentation object
00032   pcl::SACSegmentation<pcl::PointXYZ> seg;
00033   // Optional
00034   seg.setOptimizeCoefficients (true);
00035   // Mandatory
00036   seg.setModelType (pcl::SACMODEL_PLANE);
00037   seg.setMethodType (pcl::SAC_RANSAC);
00038   seg.setDistanceThreshold (0.01);
00039 
00040   seg.setInputCloud (cloud_filtered);
00041   seg.segment (*inliers, *coefficients);
00042   std::cerr << "PointCloud after segmentation has: "
00043             << inliers->indices.size () << " inliers." << std::endl;
00044 
00045   // Project the model inliers
00046   pcl::ProjectInliers<pcl::PointXYZ> proj;
00047   proj.setModelType (pcl::SACMODEL_PLANE);
00048   proj.setInputCloud (cloud_filtered);
00049   proj.setModelCoefficients (coefficients);
00050   proj.filter (*cloud_projected);
00051   std::cerr << "PointCloud after projection has: "
00052             << cloud_projected->points.size () << " data points." << std::endl;
00053 
00054   // Create a Concave Hull representation of the projected inliers
00055   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_hull (new pcl::PointCloud<pcl::PointXYZ>);
00056   pcl::ConcaveHull<pcl::PointXYZ> chull;
00057   chull.setInputCloud (cloud_projected);
00058   chull.setAlpha (0.1);
00059   chull.reconstruct (*cloud_hull);
00060 
00061   std::cerr << "Concave hull has: " << cloud_hull->points.size ()
00062             << " data points." << std::endl;
00063 
00064   pcl::PCDWriter writer;
00065   writer.write ("table_scene_mug_stereo_textured_hull.pcd", *cloud_hull, false);
00066 
00067   return (0);
00068 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:14:42