体素采样主要是使用 VoxelGrid 这个函数,目的是大大降低处理的点云数量,同时保持点云的形状。
效果如下:
设置叶子节点的尺寸 0.02
设置叶子节点0.05
实现klib可视化平台的算子如下:
struct FilterVoxelGrid
{
//VoxelGrid
float leaf_x = 0.1;
float leaf_y = 0.1;
float leaf_z = 0.1;
bool downsampleAllData = true;
int min_points_per_voxel = 0;
bool save_leaf_layout = false;
double limit_min = -FLT_MAX;
double limit_max = FLT_MAX;
bool limit_negative = false;
string filter_field_name;
template<class PT>
pcl::shared_ptr<PointCloud<PT>> operator()(const pcl::shared_ptr<PointCloud<PT> >& cloud)
{
pcl::shared_ptr<PointCloud<PT> > res(new PointCloud<PT>);
VoxelGrid<PT> f;
f.setInputCloud(cloud);
f.setLeafSize(leaf_x, leaf_y, leaf_z);
f.setDownsampleAllData(downsampleAllData);
f.setMinimumPointsNumberPerVoxel(min_points_per_voxel);
f.setSaveLeafLayout(save_leaf_layout);
f.setFilterLimits(limit_min, limit_max);
f.setFilterLimitsNegative(limit_negative);
f.setFilterFieldName(filter_field_name);
f.filter(*res);
return res;
}
};
struct KPclFilterVoxelGrid : KPlugBase
{
FilterVoxelGrid p;
KPclFilterVoxelGrid()
{
addProp("leaf_x").setType(PropTypeFloat).setValueAddr(&p.leaf_x);
addProp("leaf_y").setType(PropTypeFloat).setValueAddr(&p.leaf_y);
addProp("leaf_z").setType(PropTypeFloat).setValueAddr(&p.leaf_z);
addProp("downsampleAllData").setType(PropTypeBool).setValueAddr(&p.downsampleAllData);
addProp("min_points_per_voxel").setType(PropTypeInt32).setValueAddr(&p.min_points_per_voxel);
addProp("save_leaf_layout").setType(PropTypeBool).setValueAddr(&p.save_leaf_layout);
addProp("limit_min").setType(PropTypeDouble).setValueAddr(&p.limit_min);
addProp("limit_max").setType(PropTypeDouble).setValueAddr(&p.limit_max);
addProp("limit_negative").setType(PropTypeBool).setValueAddr(&p.limit_negative);
addProp("filter_field_name").setType(PropTypeString).setValueAddr(&p.filter_field_name);
}
int __exec(const KArbit& src, KArbit& dst) override
{
dst = cld_op(src, p);
return true;
}
};