C++下使用Open3D进行K临近查找和半径邻域查找
#include <string>
#include <Eigen>
#include <Open3D/Open3D.h>
using namespace open3d;
using namespace std;
int main(int argc, char* argv[]) {
//读取点云
std::shared_ptr<geometry::PointCloud> cloud(new geometry::PointCloud);
open3d::io::ReadPointCloud("C:/Users/a/Desktop/2.ply", *cloud);
int k = 30;
//判断点云是否有颜色信息,如果没有颜色信息,将所有点的颜色信息置为0
if (!cloud->HasColors()) {
cloud->colors_.resize(cloud->points_.size());
for (size_t i = 0; i < cloud->points_.size(); i++) {
cloud->colors_[i].setZero();
}
}
geometry::KDTreeFlann kdtree;//创建KD树
kdtree.SetGeometry(*cloud);
std::vector<int> new_indices_vec(k);//K临近点索引
std::vector<double> new_dists_vec(k);//K临近点距离
kdtree.SearchKNN(cloud->points_[50], k, new_indices_vec,new_dists_vec);//cloud->points_[0]处的K个临近点
for (size