两个点云进行数据比较,这两个点云一个是原始的,一个是追加了特征层后的点云,但是追加了特征层后会有漏点现象。
我就想利用liblas库对点云进行读取,然后因为通常数据比较大,我想利用octree树或者k-d树来进行比较。但是我不知道这个怎样通过octree进行比较来加快比较速度,我一开始的想法是遍历file1点云中的每个点,然后利用k近邻方法来遍历点云2 来找是否有匹配的点。但我发现这似乎会对点云中30W个点都使用k近邻方法,这不仅实现不了需求,也似乎是一个无底洞。
#define BOOST_TYPEOF_EMULATION
#include <iostream>
#include <chrono>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include<set>
#include <pcl/point_types.h>
#include <liblas/liblas.hpp>
#include <pcl/octree/octree.h>
int main(int argc, char** argv)
{
auto start_time = std::chrono::high_resolution_clock::now();//开始时间
int added_layer = 0;
std::cout << "请输入增加的图层是哪一层,如果输入0则全部进行比较" << std::endl;
std::cin >> added_layer;//输入这个图层
// 记录缺失的点
std::ofstream missing_file("missingPoints.txt");
if (!missing_file.is_open()) {
std::cerr << "无法打开文件:missingPoints.txt" << std::endl;
exit(1);
}
int count1, count2, countTarget = 0;//记录点的数量
// 读取第一个LAS文件
std::ifstream ifs1("file1.las", std::ios::in | std::ios::binary); // 打开第一个LAS文件
if (!ifs1) {
std::cerr << "Failed to open file1.las" << std::endl;
return 1;
}
liblas::ReaderFactory f1;
liblas::Reader reader1 = f1.CreateWithStream(ifs1); // 创建LAS读取器
const liblas::Header& header1 = reader1.GetHeader();
// 读取第二个LAS文件
std::ifstream ifs2("file2.las", std::ios::in | std::ios::binary); // 打开第二个LAS文件
if (!ifs2) {
std::cerr << "Failed to open file2.las" << std::endl;
return 1;
}
liblas::ReaderFactory f2;
liblas::Reader reader2 = f2.CreateWithStream(ifs2); // 创建LAS读取器
const liblas::Header& header2 = reader2.GetHeader();
// 创建PCL的点云对象
pcl::PointCloud<pcl::PointXYZL>::Ptr cloud1(new pcl::PointCloud<pcl::PointXYZL>);
pcl::PointCloud<pcl::PointXYZL>::Ptr cloud2(new pcl::PointCloud<pcl::PointXYZL>);
// 读取第一个LAS文件中的点云数据并将其转换为PCL的点云格式
while (reader1.ReadNextPoint()) {
liblas::Point const& p = reader1.GetPoint();
pcl::PointXYZL point;
point.x = p.GetX();
point.y = p.GetY();
point.z = p.GetZ();
point.label = (p.GetClassification().*(&liblas::Classification::GetClass))();
cloud1->push_back(point);
}
// 读取第二个LAS文件中的点云数据并将其转换为PCL的点云格式
while (reader2.ReadNextPoint()) {
liblas::Point const& p = reader2.GetPoint();
pcl::PointXYZL point;
point.x = p.GetX();
point.y = p.GetY();
point.z = p.GetZ();
point.label = (p.GetClassification().*(&liblas::Classification::GetClass))();//获取class信息
if (added_layer != 0 && point.label == added_layer) countTarget++;
cloud2->push_back(point);
}
count1 = header1.GetPointRecordsCount();
count2 = header2.GetPointRecordsCount();
std::cout << count1 << " " << count2 << std::endl;
std::cout<< "两个点云点数差为 " << count2 - count1 << " 追加的图层的点数数量为" << countTarget;
if (count1 == count2 - countTarget) {
std::cout << "点数相同,可能没有漏检的点或者多的点云";
}
else std::cout << "存在漏检多检情况"<<" 多了或少了"<<count2-count1-countTarget<<"个点"<<std::endl;
// 创建PCL的八叉树对象
pcl::octree::OctreePointCloudSearch<pcl::PointXYZL> octree1(0.01);
octree1.setInputCloud(cloud1);
octree1.addPointsFromInputCloud();
// 创建PCL的八叉树对象
pcl::octree::OctreePointCloudSearch<pcl::PointXYZL> octree2(0.01);
octree2.setInputCloud(cloud2);
-------后面能给出将这两个八叉树比较的 样例代码嘛