// 无序点云数据集的空间变换检测
//
#include "stdafx.h"
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <iostream>
#include <vector>
#include <ctime>
int
main (int argc, char*argv)
{
srand((unsigned int) time(NULL));
//八叉树分辨率,即体素的大小
float resolution = 32.0f;
pcl::octree::OctreePointCloudChangeDetector<pcl::PointXYZ> octree(resolution);
pcl::PointCloud<pcl::PointXYZ> ::Ptr cloudA( new pcl::PointCloud<pcl::PointXYZ>);
//构建点云数据 cloudA
cloudA->width = 128;
cloudA->height = 1;
cloudA->points.resize(cloudA->width * cloudA->height);
for(size_t i = 0; i<cloudA->points.size();++i)
{
cloudA->points[i].x = 64.0f * rand() / (RAND_MAX + 1.0f);
cloudA->points[i].y = 64.0f * rand() / (RAND_MAX + 1.0f);
cloudA->points[i].z = 64.0f * rand() / (RAND_MAX + 1.0f);
}
//添加点云到八叉树,建立八叉树
octree.setInputCloud(cloudA);
octree.addPointsFromInputCloud();
//交换八叉树缓存,
octree.switchBuffers();
//创建点云B
pcl::PointCloud<pcl::PointXYZ> ::Ptr cloudB (new pcl::PointCloud<pcl::PointXYZ>);
cloudB->width = 128;
cloudB->height = 1;
cloudB->resize(cloudB->width * cloudB->height);
for( size_t i = 0; i <cloudB->points.size();++i)
{
cloudB->points[i].x =64.0f* rand () / (RAND_MAX +1.0f);
cloudB->points[i].y =64.0f* rand () / (RAND_MAX +1.0f);
cloudB->points[i].z =64.0f* rand () / (RAND_MAX +1.0f);
}
//添加点云到八叉树
octree.setInputCloud(cloudB);
octree.addPointsFromInputCloud();
std::vector<int > newPointIdxVector;
//获取前一cloudA对应的八叉树在cloudB对应的八叉树中没有的体素
octree.getPointIndicesFromNewVoxels(newPointIdxVector);
//打印输出点
std::cout<<"Output from getPointIndicesFromNewVoxels:"<<std::endl;
for(size_t i = 0;i<newPointIdxVector.size();++i)
{
std::cout<<i<<"# Index:"<< newPointIdxVector[i]<<" Point:"
<<cloudB->points[newPointIdxVector[i]].x<< " "
<<cloudB->points[newPointIdxVector[i]].y<< " "
<<cloudB->points[newPointIdxVector[i]].z<< std::endl;
}
system("pause");
}
reference:朱德海. 点云库PCL学习教程[M]. 北京航空航天大学出版社, 2012.