来自pcl点云入门到精通
#include <pcl/point_types.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
using namespace pcl;
//curvature 曲率
//intensity 强度
//range 视点到采样点距离
//vp_x,vp_y,vp_z:视点
PointXY A; //X,Y
PointXYZ B; //X,Y,Z
PointXYZI C; //X,Y,Z,intesity
PointXYZRGBA D; //X,Y,Z,unint_32 rga
PointXYZRGB E; //X,Y,Z,float rgb
PointXYZRGBL F; //X,Y,Z,float rgb,uint32_t label=255;
Normal a;//X,Y,Z,float/normal x,float/normal y,float/normal z,float curvature;
PointXYZRGBNormal G;//X,Y,Z,float/normal x,float/normal y,float/normal z;float curvature;float rgba;
PointXYZINormal H;//X,Y,Z,float/normal x,float/normal y,float/normal z;float curvature;float intensity;
PointWithRange I;//X,Y,Z,float range;
PointWithViewpoint O;//X,Y,Z,vp_x,vp_y,vp_z
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
pcl::PointCloud<pcl::PointXYZ> cloud;
pcl::io::loadPCDFile<pcl::PointXYZ>("/home/n1/notes/pcl/IO/test_pcd.pcd",cloud)
pcl::io::savePCDFileASCII("/home/n1/notes/pcl/IO/save_pcd.pcd",cloud1);
#include <pcl/point_types.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <iostream>
//定义数据类型
struct VelodynePointXYZIRT{
PCL_ADD_POINT4D;
PCL_ADD_INTENSITY;
uint16_t ring;
float time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
}EIGEN_ALIGN16;
//注册数据类型
POINT_CLOUD_REGISTER_POINT_STRUCT(
VelodynePointXYZIRT,
(float,x,x)
(float,y,y)
(float,z,z)
(float,intensity,intensity)
(uint16_t,ring,ring)
(float,time,time)
)
using namespace std;
using namespace pcl;
int main(int argc,char** argv){
PointCloud<VelodynePointXYZIRT> cloud;
cloud.width=100;
cloud.height=20;
cloud.resize(cloud.width*cloud.height);
for(size_t i=0;i<cloud.points.size();++i)
{
cloud.points[i].x=1024*rand()/(RAND_MAX+1.0f);
cloud.points[i].y=1024*rand()/(RAND_MAX+1.0f);
cloud.points[i].z=1024*rand()/(RAND_MAX+1.0f);
}
cout<<"size:"<<cloud.size()<<endl;
cout<<"data:";
pcl::io::savePCDFileASCII("/home/n1/notes/pcl/mypcltype/save_pcd.pcd",cloud);
for(size_t i=0;i<cloud.points.size();++i){
std::cerr<<" "<<cloud.points[i].x<<" "<<cloud.points[i].y<<" "<<cloud.points[i].z<<std::endl;
}
return 0;
}
//currentCloudMsg:sensor_msgs::PointCloud2点云数据
//laserCloudIn: pcl点云数据
pcl::moveFromROSMsg(currentCloudMsg,laserCloudIn);
//currentCloudMsg:sensor_msgs::PointCloud2点云数据
//laserCloudIn: pcl点云数据
pcl::fromROSMsg(currentCloudMsg, laserCloudout);