PCL学习笔记——利用Octree找出存在于点云B中,不存在点云A中的点

resolution——八叉树分辨率,即最小体素的边长(像素单位)
getPointIndicesFromNewVoxels() —— 从前一个缓冲区中不存在的所有叶节点获取索引
switchBuffers()——交换八叉树缓存,但是先前点云对应的八叉树结构仍在内存中
// pointclouds_octree.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include
#include
#include
#include
#include

using namespace std;
using namespace cv;

int main()
{
	fstream file_name1, file_name2;
	ofstream differ;
	differ.open("differ.txt");
	file_name1.open("Result3D_end42.txt");
	file_name2.open("Result3D_end52.txt");

	pcl::PointCloud cloudA;
	pcl::PointCloud cloudB;
	
	cloudA.width = 230088;
	cloudA.height = 1;
	cloudA.is_dense = false;
	cloudA.points.resize (cloudA.width*cloudA.height);

	cloudB.width = 250025;
	cloudB.height = 1;
	cloudB.is_dense = false;  //点云密度,非密集型
	cloudB.points.resize (cloudB.width*cloudB.height);

	Vec3d dd;
	for (size_t i = 0; i < cloudA.points.size(); i++) {
		file_name1 >> dd[0];
		file_name1 >> dd[1];
		file_name1 >> dd[2];

		cloudA.points[i].x = (double)dd[0];
		cloudA.points[i].y = (double)dd[1];
		cloudA.points[i].z = (double)dd[2];
	}
	for (size_t j = 0; j < cloudB.points.size(); j++) {
		file_name2 >> dd[0];
		file_name2 >> dd[1];
		file_name2 >> dd[2];

		cloudB.points[j].x = (double)dd[0];
		cloudB.points[j].y = (double)dd[1];
		cloudB.points[j].z = (double)dd[2];
	}
	
	float resolution = 10.0f; //八叉树分辨率,即最小体素的边长
	//pcl::octree::OctreePointCloudSearch octree(resolution);  //初始化octree
	pcl::octree::OctreePointCloudChangeDetectoroctree(resolution);  //初始化空间变化检测对象
	
    //添加cloudA到八叉树中
	octree.setInputCloud(cloudA.makeShared());
	octree.addPointsFromInputCloud();
	
	octree.switchBuffers(); //交换八叉树缓存,但是coludA对应的八叉树结构仍在内存中

	//添加cloudB到八叉树中
	octree.setInputCloud(cloudB.makeShared());
	octree.addPointsFromInputCloud();

	vectornewPointIdxVector;   //存储新加入点索引的向量
	octree.getPointIndicesFromNewVoxels(newPointIdxVector);

	for (size_t i = 0; i < newPointIdxVector.size(); i++) {
		differ << cloudB.points[newPointIdxVector[i]].x << " " << cloudB.points[newPointIdxVector[i]].y << " "
			<< cloudB.points[newPointIdxVector[i]].z <<" "<< endl;
	}
	file_name1, file_name2, differ.close();
    return 0;
}

数据在Geomagic中的展示如下:

PCL学习笔记——利用Octree找出存在于点云B中,不存在点云A中的点_第1张图片
附:
银色是CloudB中的点,黑色是CloudA中的点,绿色部分是检测出来属于点云B但不属于点云A的所有点。

你可能感兴趣的:(PCL学习,PCL学习笔记,PCL,Octree)