remove_outliers.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <pcl/point_types.h>
00003 #include <pcl/filters/radius_outlier_removal.h>
00004 #include <pcl/filters/conditional_removal.h>
00005 
00006 int
00007  main (int argc, char** argv)
00008 {
00009   if (argc != 2)
00010   {
00011     std::cerr << "please specify command line arg '-r' or '-c'" << std::endl;
00012     exit(0);
00013   }
00014   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
00015   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
00016 
00017   // Fill in the cloud data
00018   cloud->width  = 5;
00019   cloud->height = 1;
00020   cloud->points.resize (cloud->width * cloud->height);
00021 
00022   for (size_t i = 0; i < cloud->points.size (); ++i)
00023   {
00024     cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
00025     cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
00026     cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
00027   }
00028 
00029   if (strcmp(argv[1], "-r") == 0){
00030     pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
00031     // build the filter
00032     outrem.setInputCloud(cloud);
00033     outrem.setRadiusSearch(0.8);
00034     outrem.setMinNeighborsInRadius (2);
00035     // apply filter
00036     outrem.filter (*cloud_filtered);
00037   }
00038   else if (strcmp(argv[1], "-c") == 0){
00039     // build the condition
00040     pcl::ConditionAnd<pcl::PointXYZ>::Ptr range_cond (new
00041       pcl::ConditionAnd<pcl::PointXYZ> ());
00042     range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
00043       pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::GT, 0.0)));
00044     range_cond->addComparison (pcl::FieldComparison<pcl::PointXYZ>::ConstPtr (new
00045       pcl::FieldComparison<pcl::PointXYZ> ("z", pcl::ComparisonOps::LT, 0.8)));
00046     // build the filter
00047     pcl::ConditionalRemoval<pcl::PointXYZ> condrem (range_cond);
00048     condrem.setInputCloud (cloud);
00049     condrem.setKeepOrganized(true);
00050     // apply filter
00051     condrem.filter (*cloud_filtered);
00052   }
00053   else{
00054     std::cerr << "please specify command line arg '-r' or '-c'" << std::endl;
00055     exit(0);
00056   }
00057   std::cerr << "Cloud before filtering: " << std::endl;
00058   for (size_t i = 0; i < cloud->points.size (); ++i)
00059     std::cerr << "    " << cloud->points[i].x << " "
00060                         << cloud->points[i].y << " "
00061                         << cloud->points[i].z << std::endl;
00062   // display pointcloud after filtering
00063   std::cerr << "Cloud after filtering: " << std::endl;
00064   for (size_t i = 0; i < cloud_filtered->points.size (); ++i)
00065     std::cerr << "    " << cloud_filtered->points[i].x << " "
00066                         << cloud_filtered->points[i].y << " "
00067                         << cloud_filtered->points[i].z << std::endl;
00068   return (0);
00069 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:17:39