使用ConditionalRemoval移除离群点

无需解释,这个滤波器删除点云中不符合用户指定的一个或者多个条件的数据点。

关键成员函数

(1)void setKeepOrganized(bool val)

(2)void setUserFilterValue(float value)

(3)void setCondition(ConditionBasePtr condition)

(函数用法见教程)

条件方程式表达:

创建条件对象

pcl::ConditionAnd::Ptr range_cond(new pcl::ConditionAnd);

AND condition.

void pcl::ConditionBase< PointT >::addComparison ( ComparisonBaseConstPtr  comparison )  
例子://添加在Z字段上大于0的比较算子

range_cond->addComparison(pcl::FieldComparison::ConstPtr (new- pcl::FieldComparison("z",pcl::ComparisonOps::GT,0.0)));

OR condition.

void pcl::ConditionBase< PointT >::addComparison ( ComparisonBaseConstPtr  comparison )  
说明:

class pcl::FieldComparison< PointT >

pcl::FieldComparison< PointT >::FieldComparison ( std::string  field_name,
    ComparisonOps::CompareOp  op,
    double  compare_val 
  )

Construct a FieldComparison

Parameters:
field_name the name of the field that contains the data we want to compare
op the operator to use when making the comparison
compare_val the constant value to compare the field value too

创建滤波器对象ConditionalRemoval:

(1)构造函数

pcl::ConditionalRemoval< PointT >::ConditionalRemoval ( int  extract_removed_indices = false )

the default constructor. 

All ConditionalRemovals require a condition which can be set using the setCondition method 

pcl::ConditionalRemoval< PointT >::ConditionalRemoval ( ConditionBasePtr  condition,
    bool  extract_removed_indices = false 
  )

a constructor that includes the condition. 

Parameters:
condition the condition that each point must satisfy to avoid being removed by the filter
extract_removed_indices extract filtered indices from indices vector 
(2)
virtual void pcl::PCLBase< PointT >::setInputCloud ( const PointCloudConstPtr &  cloud )

Provide a pointer to the input dataset. 


(3)

void pcl::ConditionalRemoval< PointT >::setKeepOrganized ( bool  val )

Set whether the filtered points should be kept and set to the value given through setUserFilterValue (default: NaN), or removed from the PointCloud, thus potentially breaking its organized structure.

By default, points are removed.

(4)
void pcl::Filter< PointT >::filter ( PointCloud &  output )

Calls the filtering method and returns the filtered dataset in output. 

(1)(

附:

EQ 就是 EQUAL等于
GT 就是 GREATER THAN大于
LT 就是 LESS THAN小于
GE 就是 GREATER THAN OR EQUAL 大于等于
LE 就是 LESS THAN OR EQUAL 小于等于
 
  
 
  
#include
#include
#include
#include
#include
using namespace std;
int main()
{
	pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
	pcl::PointCloud::Ptr cloud_filtered(new pcl::PointCloud);
	cloud->width=5;
	cloud->height=1;
	cloud->points.resize(cloud->width*cloud->height);
	for(size_t i=0;ipoints.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);
	}
	//创建条件限定下的滤波器
	pcl::ConditionAnd::Ptr range_cond(new pcl::ConditionAnd);
	pcl::FieldComparison::ConstPtr cond_1(new pcl::FieldComparison("z",pcl::ComparisonOps::GT,0.0));
	range_cond->addComparison(cond_1);
	pcl::FieldComparison::ConstPtr cond_2(new pcl::FieldComparison("z",pcl::ComparisonOps::LT,0.8));
	range_cond->addComparison(cond_2);
	//创建滤波器并用条件定义对象初始化
	pcl::ConditionalRemoval condrem(range_cond);
	condrem.setInputCloud(cloud);
	condrem.setKeepOrganized(true);
	condrem.filter(*cloud_filtered);
	std::cerr<<"cloud before filtering:"<points.size();i++)
		std::cerr<<' '<points[i].x<<' '<points[i].y<<' '<points[i].z<points.size();i++)
		std::cerr<<' '<points[i].x<<' '<points[i].y<<' '<points[i].z< 
  

 
  

你可能感兴趣的:(PCL点云处理)