目录
定义点步骤
1、定义自己的点云结构
2、注册这个点云结构
3、在程序中合理使用(可能不能用viewer显示了,可以保存相应文件)
自定义点示例
//第一步:自定义点云结构
struct MyPointType
{
float x;
float y;
float z;
float i;
float ring;
float time;
//其它的值都可以
} ;
//第二步: 注册这个点结构
POINT_CLOUD_REGISTER_POINT_STRUCT(MyPointType,
(float, x, x)
(float, y, y)
(float, z, z)
(float, i, i)
(float, ring, ring)
(float, time, time)
)
//接下来在程序中使用即可
具体使用样例
int
main(int argc, char** argv)
{
pcl::PointCloud<MyPointType> cloud;
cloud.points.resize(20000);
cloud.width = 20000;
cloud.height = 1;
for (size_t i = 0; i < cloud.points.size(); ++i)
{
//std::cout << i << std::endl;
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));
cloud.points[i].i = 1024 * (rand() / (RAND_MAX + 1.0f));
cloud.points[i].ring = 1024 * (rand() / (RAND_MAX + 1.0f));
cloud.points[i].time = 10240 * (rand() / (RAND_MAX + 1.0f));
}
pcl::io::savePCDFileASCII("test_que.pcd", cloud);
// Create the filtering object
pcl::PCLPointCloud2::Ptr cloud1(new pcl::PCLPointCloud2());
pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2());
pcl::PCDReader reader;
reader.read("test_que.pcd", *cloud1); // Remember to download the file first!
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud(cloud1);
sor.setLeafSize(50.0f, 50.0f, 50.0f);
sor.filter(*cloud_filtered);
pcl::PointCloud<MyPointType>::Ptr cloud_show(new pcl::PointCloud<MyPointType>);
pcl::fromPCLPointCloud2(*cloud_filtered, *cloud_show);
pcl::io::savePCDFile("test_que_re.pcd", *cloud_show);
}
参考链接:https://pcl.readthedocs.io/projects/tutorials/en/latest/adding_custom_ptype.html#adding-custom-ptype