欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Pcl:Normal的定义结构及输出

程序员文章站 2022-07-13 21:28:30
...

1. pcl::Normal在pcl官网中的定义
 /*brief A point structure representing normal coordinates and the surface curvature estimate. (SSE friendly)ingroup common*/

struct Normal : public _Normal
{
    inline Normal (const _Normal &p)
    {
     normal_x = p.normal_x; 
     normal_y = p.normal_y; 
     normal_z = p.normal_z;
     data_n[3] = 0.0f;
     curvature = p.curvature;
    }

    inline Normal ()
    {
     normal_x = normal_y = normal_z = data_n[3] = 0.0f;
     curvature = 0;
    }

    inline Normal (float n_x, float n_y, float n_z)
    {
     normal_x = n_x; normal_y = n_y; normal_z = n_z;
     curvature = 0;
     data_n[3] = 0.0f;
    }

    friend std::ostream& operator << (std::ostream& os, const Normal& p);
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

2. 官网 tutorial中的资料
union{
float data_n[4]
float normal[3];
struct
{
float normal_x;
float normal_y;
float normal_z;
};
};
union{
struct{
float curvature;
};
float data_c[4];
};

看出,pcl::Normals normal的四个值表示(normal_x, normal_y, normal_z, curvature);

3. 表示pcl::Normal的几种方式:
 

pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>); 
std::cout<<normals->points[100]<<std::endl;
std::cout<<"["<<normals->points[100].normal_x<<" "
              <<normals->points[100].normal_y<<" "
              <<normals->points[100].normal_z<<" "
              <<normals->points[100].curvature<<"]"<<endl;
std::cout<<"["<<normals->points[100].normal[0]<<" "
              <<normals->points[100].normal[1]<<" "
              <<normals->points[100].normal[2]<<" "
              <<normals->points[100].curvature<<"]"<<endl;
//此种显示方式不带曲率,只有XYZ
std::cout<<"["<<normals->points[100].data_n[0]<<" "
              <<normals->points[100].data_n[1]<<" "
              <<normals->points[100].data_n[2]<<" "
              <<normals->points[100].curvature<<"]"<<endl;

带曲率的输出方式:

//计算法线
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
//建立kdtree来进行近邻点集搜索
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(nepcl::search::KdTree<pcl::PointXYZ>);
n.setInputCloud(cloud);
n.setSearchMethod(tree);
//点云法向计算时,需要所搜的近邻点大小
n.setKSearch(3);
//开始进行法向计算
n.compute(*normals);
cout << "point normal size = " << normals->points.size() << endl;
        

cout << "point normal" << normals->points[i] << endl;
cout << " k point normal " << normals->points[pointIdxNKNSearch[m]]<< endl;

结果如下:(这是法向量用坐标X,Y,Z表示的结果,最后一个应该是曲率???)

Pcl:Normal的定义结构及输出 Pcl:Normal的定义结构及输出

相关标签: PCL