本文主要是介绍concatenate clouds,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
写在这儿方面以后查找阅览----------------------------
代码来自PCL点云库那本书---------------------------
#include "stdafx.h"
#include <iostream>#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
//连接两个点云的字段或者数据形成新的点云
int
main(int argc,char** argv)
{
if(argc!=2)
{
std::cerr<<"please specify command line arg '-f' or '-p'"<<std::endl;
exit(0);
}
pcl::PointCloud<pcl::PointXYZ> cloud_a,cloud_b,cloud_c;
pcl::PointCloud<pcl::Normal> n_cloud_b;
pcl::PointCloud<pcl::PointNormal> p_n_cloud_c;
// 创建点云
cloud_a.width=5;
cloud_a.height=cloud_b.height=n_cloud_b.height=1;
cloud_a.points.resize(cloud_a.width*cloud_a.height);
if(strcmp(argv[1],"-p")==0)
{
cloud_b.width=3;
cloud_b.points.resize(cloud_b.width*cloud_b.height);
}
else{
n_cloud_b.width=5;
n_cloud_b.points.resize(n_cloud_b.width*n_cloud_b.height);
}
for(size_t i=0;i<cloud_a.points.size();++i)
{
cloud_a.points[i].x=1024*rand()/(RAND_MAX+1.0f);
cloud_a.points[i].y=1024*rand()/(RAND_MAX+1.0f);
cloud_a.points[i].z=1024*rand()/(RAND_MAX+1.0f);
}
if(strcmp(argv[1],"-p")==0)
for(size_t i=0;i<cloud_b.points.size();++i)
{
cloud_b.points[i].x=1024*rand()/(RAND_MAX+1.0f);
cloud_b.points[i].y=1024*rand()/(RAND_MAX+1.0f);
cloud_b.points[i].z=1024*rand()/(RAND_MAX+1.0f);
}
else
for(size_t i=0;i<n_cloud_b.points.size();++i)
{
n_cloud_b.points[i].normal[0]=1024*rand()/(RAND_MAX+1.0f);
n_cloud_b.points[i].normal[1]=1024*rand()/(RAND_MAX+1.0f);
n_cloud_b.points[i].normal[2]=1024*rand()/(RAND_MAX+1.0f);
}
std::cerr<<"Cloud A: "<<std::endl;
for(size_t i=0;i<cloud_a.points.size();++i)
std::cerr<<" "<<cloud_a.points[i].x<<" "<<cloud_a.points[i].y<<" "<<cloud_a.points[i].z<<std::endl;
std::cerr<<"Cloud B: "<<std::endl;
if(strcmp(argv[1],"-p")==0)
for(size_t i=0;i<cloud_b.points.size();++i)
std::cerr<<" "<<cloud_b.points[i].x<<" "<<cloud_b.points[i].y<<" "<<cloud_b.points[i].z<<std::endl;
else
for(size_t i=0;i<n_cloud_b.points.size();++i)
std::cerr<<" "<<n_cloud_b.points[i].normal[0]<<" "<<n_cloud_b.points[i].normal[1]<<" "<<n_cloud_b.points[i].normal[2]<<std::endl;
//拷贝点云数据
if(strcmp(argv[1],"-p")==0)
{
cloud_c=cloud_a;
cloud_c+=cloud_b;
//creates cloud_c by concatenating the points of cloud_a and cloud_b together.
std::cerr<<"Cloud C: "<<std::endl;
for(size_t i=0;i<cloud_c.points.size();++i)std::cerr<<" "<<cloud_c.points[i].x<<" "<<cloud_c.points[i].y<<" "<<cloud_c.points[i].z<<" "<<std::endl;
}
else
{
pcl::concatenateFields(cloud_a,n_cloud_b,p_n_cloud_c);
std::cerr<<"Cloud C: "<<std::endl;
for(size_t i=0;i<p_n_cloud_c.points.size();++i)std::cerr<<" "<<
p_n_cloud_c.points[i].x<<" "<<p_n_cloud_c.points[i].y<<" "<<p_n_cloud_c.points[i].z<<" "<<
p_n_cloud_c.points[i].normal[0]<<" "<<p_n_cloud_c.points[i].normal[1]<<" "<<p_n_cloud_c.points[i].normal[2]<<std::endl;
}
//is used to show the content of cloud_c or p_n_cloud_c to the screen depending on if we concatenated the points or fields of the PointClouds.
system("pause");
return(0);
}
注释了一些重要的代码,主要有一个问题是弹出来的exe窗口闪退,看不到cloud_a,...b,.....c的点云数据,不知道是什么原因,另外不知道这句话是什么意思:
if(argc!=2)
{
std::cerr<<"please specify command line arg '-f' or '-p'"<<std::endl;
exit(0);
}难道是要用户输入-f或者-p吗,如果是,exe窗口为什么会闪退,这句话的作用是什么呢?有待解答。
这篇关于concatenate clouds的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!