点云智能指针格式和非指针格式的转换
pcl::PointCloud<PointT>::Ptr cloud_ptr(new pcl::PointCloud<PointT>);
pcl::PointCloud<PointT> cloud;
cloud = *cloud_ptr;
cloud_ptr = boost::make_shared<pcl::PointCloud<PointT>>(cloud);
全部代码:
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>//pcd 读写类相关的头文件。
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>//PCL中支持的点类型头文件。using std::cout;int user_data;// 创建一个点云
pcl::PointCloud<pcl::PointXYZ> createFirstCloud()
{pcl::PointCloud<pcl::PointXYZ> cloud;cloud.width = 10000;cloud.height = 1;cloud.is_dense = false;cloud.points.resize(cloud.width * cloud.height);// 创建一个在0-1024 之间的正方体点云for (size_t i = 0; i < cloud.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));}return cloud;
}
int main()
{pcl::PointCloud<pcl::PointXYZ> cloud=createFirstCloud();pcl::PointCloud<pcl::PointXYZ> ::Ptr cloud_ptr(new pcl::PointCloud<pcl::PointXYZ>);*cloud_ptr = cloud;boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("show my pountcloud "));viewer->setBackgroundColor(0, 0, 0);viewer->addPointCloud<pcl::PointXYZ>(cloud_ptr, "sample cloud");// 显示while (!viewer->wasStopped()){viewer->spinOnce(100);}return 0;
}