for (size_t i = 0; i < cloud->size(); ++i) { cloud->points[i].x=1024*rand()/(RAND_MAX+1.0f); cloud->points[i].y=1024*rand()/(RAND_MAX+1.0f); cloud->points[i].z=1024*rand()/(RAND_MAX+1.0f); } std::cout<<"cloud point before filtering"<<std::endl; for (size_t i = 0; i < cloud->size(); ++i) std::cout<<" "<<cloud->points[i].x <<" "<<cloud->points[i].y <<" "<<cloud->points[i].z <<std::endl; /**************************************************************************************** 创建直通滤波器对象,设定参数,滤波字段设置为z轴方向,可接受的范围为(0.0,1.0)即将点云中所有点的z轴坐标不在 该范围内的点过滤掉或保存,这里是过滤掉。如果要保存范围外的点,删除范围内的点,则使用setFilterLimitsNegative 设定,为true时,为删除,为false时,为保留,默认为false *****************************************************************************************/ pcl::PassThrough<pcl::PointXYZ> pass; pass.setInputCloud(cloud); pass.setFilterFieldName("z"); pass.setFilterLimits(0.0,1.0); pass.setFilterLimitsNegative(false); pass.filter(*cloud_filtered);
std::cout<<"cloud point after filtering"<<std::endl; for (size_t i = 0; i < cloud_filtered->size(); ++i) std::cout<<" "<<cloud_filtered->points[i].x <<" "<<cloud_filtered->points[i].y <<" "<<cloud_filtered->points[i].z <<std::endl; return 0; }