查询点的相邻点可用于估计捕获查询点周围的下层采样表面的几何形状的局部特征表示。描述表面几何形状的一个重要问题是首先在坐标系中推断其方向,即估计其法线。曲面法线是曲面的重要属性,在许多领域(如计算机图形应用程序)中大量使用,以应用生成阴影和其他视觉效果的正确光源
1,估算输入数据集中所有点的一组曲面法线。
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
//初始化点云基础类型
// 创建一个法线估算类,并将输入级传递给它
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
// 创建一个k维树,方便搜索;并将它传递给上面创建的法线估算类对象
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree);
// 输出数据集
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
// k维树以半径0.03米进行分割
ne.setRadiusSearch (0.03);
// 估算特征
ne.compute (*cloud_normals);
// cloud_normals->points.size () 应该和cloud->points.size ()一样大的规模
}
2.为输入数据集中的点子集估计一组曲面法线
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
//初始化点云基础类型
// 创建一组要使用的索引。为了简单起见,我们将使用云中前10%的点
std::vector<int> indices (floor (cloud->points.size () / 10));
for (size_t i = 0; i < indices.size (); ++i) indices[i] = i;
// / 创建一个法线估算类,并将输入数据集传递给它
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
// 传递索引
boost::shared_ptr<std::vector<int> > indicesptr (new std::vector<int> (indices));
ne.setIndices (indicesptr);
// 创建一个k维树,方便搜索;并将它传递给上面创建的法线估算类对象
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree);
// 输出数据集
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
// k维树以半径0.03米进行分割
ne.setRadiusSearch (0.03);
// 估算特征
ne.compute (*cloud_normals);
// cloud_normals->points.size () 应该和cloud->points.size ()一样大的规模
}
3.估算输入数据集中所有点的一组曲面法线,并将使用另一个数据集估计其最近邻近点。
#include <pcl/point_types.h>
#include <pcl/features/normal_3d.h>
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_downsampled (new pcl::PointCloud<pcl::PointXYZ>);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud_downsampled);
ne.setSearchSurface (cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree);
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
ne.setRadiusSearch (0.03);
ne.compute (*cloud_normals);
}