一、配置好pcl 的c++环境,添加cpp文件,添加如下函数:
#include "..\export.h"
#include "pcl\pcl_base.h"
#include "pcl\point_types.h"
#include <pcl/point_cloud.h>
#include <pcl/filters/approximate_voxel_grid.h>
#ifdef __cplusplus
extern "C" { // only need to export C interface if
// used by C++ source code
#endif
//对点云进行近似体素下采样
EXPORT(void) approximateVoxelDownSample(pcl::PointCloud<pcl::PointXYZ> * in_pc, double leaf_size,
pcl::PointCloud<pcl::PointXYZ> * out_pc)
{
pcl::ApproximateVoxelGrid<pcl::PointXYZ> avoxel;
avoxel.setInputCloud(in_pc->makeShared());
avoxel.setLeafSize(leaf_size, leaf_size, leaf_size);
avoxel.filter(*out_pc);
}
#ifdef __cplusplus
}
#endif
该示例为一个简单的近似体素滤波的封装函数,输入输出为点云数据类pcl::PointCloud<pcl::PointXYZ>的指针形式。
编译该代码生成相应的c+