点云法向量可视化

PCL中自带法向量估算函数,也可以使用其他方法估算法向量。下面代码展示了使用其他方法估算法向量的使用方法:

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/features/normal_3d.h>
#include <pcl/surface/gp3.h>
#include <pcl/visualization/pcl_visualizer.h>
#include<sstream>
#include<vector>
#include"IO.h"
using namespace std;

void main()
{
	IO IOExample;
	CalculateFeatures CalExample;

	char line[128];
	pcl::PointXYZ temp;
	vector<pcl::PointXYZ> PointCluster = IOExample.ReadPointXYZIntoVector("test.xyz");
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	cloud = IOExample.PointXYZ2Ptr(PointCluster);
	vector<Normal_eigenvalue> normal_vec = CalExample.normalEigenEstimate(cloud, 15);
	
	cloud->width = PointCluster.size();
	cloud->height = 1;
	cloud->resize(cloud->width*cloud->height);
	cloud->is_dense = false;
	for (int i = 0; i < PointCluster.size(); i++)
	{
		cloud->points[i] = PointCluster[i];
	}


	pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
	normals->width = PointCluster.size();
	normals->height = 1;
	normals->resize(normals->width*normals->height);
	for (int i = 0; i < normals->width; i++)
	{
		if (normal_vec[i].normal_z>0)
		{
			normals->points[i].normal_x = normal_vec[i].normal_x;
			normals->points[i].normal_y = normal_vec[i].normal_y;
			normals->points[i].normal_z = normal_vec[i].normal_z;
		}
		else
		{
			normals->points[i].normal_x = -normal_vec[i].normal_x;
			normals->points[i].normal_y = -normal_vec[i].normal_y;
			normals->points[i].normal_z = -normal_vec[i].normal_z;
		}
		

	}


	
	//* normals should not contain the point normals + surface curvatures

	//显示类
	pcl::visualization::PCLVisualizer viewer("Cloud Viewer");

	//设置背景色
	viewer.setBackgroundColor(0, 0, 0);

	//按照z值进行渲染点的颜色
	pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud, "z");

	//添加需要显示的点云数据
	viewer.addPointCloud<pcl::PointXYZ>(cloud, fildColor, "sample cloud");

	//设置点显示大小
	viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud");

	//添加需要显示的点云法向。cloud为原始点云模型,normal为法向信息,1表示需要显示法向的点云间隔,即每1个点显示一次法向,0.01表示法向长度。
	viewer.addPointCloudNormals<pcl::PointXYZ, pcl::Normal>(cloud, normals, 1, 1, "normals");

	while (!viewer.wasStopped())
	{
		viewer.spinOnce();
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

点云实验室lab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值