00001 #include <pcl/point_types.h> 00002 #include <pcl/io/pcd_io.h> 00003 #include <pcl/filters/passthrough.h> 00004 #include <pcl/surface/concave_hull.h> 00005 #include <pcl/console/parse.h> 00006 00007 using namespace pcl::console; 00008 typedef pcl::PointXYZ PointT; 00009 00010 int main( int argc, char** argv ) 00011 { 00012 // Parameter parsing 00013 if( argc != 3 ) 00014 { 00015 std::cerr << "Syntax is: " << argv[0] << " {input_pointcloud_filename.pcd} {output_pointcloud_filename.pcd}" << std::endl; 00016 return(-1); 00017 } 00018 00019 // Read input cloud 00020 pcl::PointCloud<PointT>::Ptr input_cloud (new pcl::PointCloud<PointT>); 00021 pcl::PCDReader reader; 00022 pcl::PCDWriter writer; 00023 reader.read ( argv[1], *input_cloud); 00024 std::cerr << "Loaded cloud with points: " << input_cloud->points.size() << std::endl; 00025 00026 00027 pcl::PointCloud<PointT>::Ptr filtered_cloud (new pcl::PointCloud<PointT>); 00028 pcl::PassThrough<PointT> filter; 00029 filter.setInputCloud (input_cloud); 00030 filter.setFilterFieldName ("z"); 00031 filter.setFilterLimits (-0.5, 0.5); 00032 // filter.setKeepOrganized (true); 00033 // filter.setUserFilterValue (1000.0); 00034 filter.filter (*filtered_cloud); 00035 00036 pcl::PointCloud<PointT> alpha_shape; 00037 pcl::PointCloud<PointT>::Ptr voronoi_centers (new pcl::PointCloud<PointT>); 00038 std::vector<pcl::Vertices> polygons_alpha; 00039 00040 pcl::ConcaveHull<PointT> concave_hull; 00041 concave_hull.setInputCloud (filtered_cloud); 00042 concave_hull.setAlpha (1.0); 00043 concave_hull.setVoronoiCenters (voronoi_centers); 00044 concave_hull.reconstruct (alpha_shape, polygons_alpha); 00045 00046 //write back filtered cloud 00047 std::cerr << "Saving cloud to: " << std::string(argv[2]) << " with points: " << alpha_shape.points.size() << std::endl; 00048 writer.write(std::string(argv[2]), alpha_shape, false); 00049 return(0); 00050 }