00001 #include <iostream> 00002 #include <pcl/io/pcd_io.h> 00003 #include <pcl/point_types.h> 00004 #include <pcl/ModelCoefficients.h> 00005 #include <pcl/filters/project_inliers.h> 00006 00007 int 00008 main (int argc, char** argv) 00009 { 00010 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); 00011 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected (new pcl::PointCloud<pcl::PointXYZ>); 00012 00013 // Fill in the cloud data 00014 cloud->width = 5; 00015 cloud->height = 1; 00016 cloud->points.resize (cloud->width * cloud->height); 00017 00018 for (size_t i = 0; i < cloud->points.size (); ++i) 00019 { 00020 cloud->points[i].x = 1024 * rand () / (RAND_MAX + 1.0f); 00021 cloud->points[i].y = 1024 * rand () / (RAND_MAX + 1.0f); 00022 cloud->points[i].z = 1024 * rand () / (RAND_MAX + 1.0f); 00023 } 00024 00025 std::cerr << "Cloud before projection: " << std::endl; 00026 for (size_t i = 0; i < cloud->points.size (); ++i) 00027 std::cerr << " " << cloud->points[i].x << " " 00028 << cloud->points[i].y << " " 00029 << cloud->points[i].z << std::endl; 00030 00031 // Create a set of planar coefficients with X=Y=0,Z=1 00032 pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients ()); 00033 coefficients->values.resize (4); 00034 coefficients->values[0] = coefficients->values[1] = 0; 00035 coefficients->values[2] = 1.0; 00036 coefficients->values[3] = 0; 00037 00038 // Create the filtering object 00039 pcl::ProjectInliers<pcl::PointXYZ> proj; 00040 proj.setModelType (pcl::SACMODEL_PLANE); 00041 proj.setInputCloud (cloud); 00042 proj.setModelCoefficients (coefficients); 00043 proj.filter (*cloud_projected); 00044 00045 std::cerr << "Cloud after projection: " << std::endl; 00046 for (size_t i = 0; i < cloud_projected->points.size (); ++i) 00047 std::cerr << " " << cloud_projected->points[i].x << " " 00048 << cloud_projected->points[i].y << " " 00049 << cloud_projected->points[i].z << std::endl; 00050 00051 return (0); 00052 }