PCL如何创建点云array/vector?
PCL How to create a Point Cloud array/vector?
我在硬盘上存储了 85 个点云。我想把所有的云都打开保存在一个vector/array.
我应该怎么做?
我没有成功测试的内容:
define _CRT_SECURE_NO_WARNINGS
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/common/transforms.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/radius_outlier_removal.h>
#include <Eigen/Geometry>
#include <iostream>
#include <string>
using namespace pcl;
using namespace std;
int main(int argc, char** argv)
{
//Create Point Clouds
PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;
//save PointClouds to array
for (int i = 1; i < (argc - 1); i++)
{
if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
{
return -1;
}
cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
sourceClouds.push_back(sourceCloud);
cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
sourceCloud->clear();
}
for (int i = 0; i < sourceClouds.size() - 1; i++)
{
cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
}
}
在第一个for循环中,两个Clouuds的PointCloudSize相同,但在第二个for循环中,PointCloudSize为0。
我做错了什么?
sourceClouds.push_back(sourceCloud);
此行只复制PointCloud::Ptr,不复制点云数据
试试这个:
int main(int argc, char** argv)
{
//Create Point Clouds
//PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;
//save PointClouds to array
for (int i = 1; i < (argc - 1); i++)
{
PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
{
return -1;
}
cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
sourceClouds.push_back(sourceCloud);
cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
// sourceCloud->clear();
}
for (int i = 0; i < sourceClouds.size() - 1; i++)
{
cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
}
}
我在硬盘上存储了 85 个点云。我想把所有的云都打开保存在一个vector/array.
我应该怎么做?
我没有成功测试的内容:
define _CRT_SECURE_NO_WARNINGS
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/common/transforms.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/radius_outlier_removal.h>
#include <Eigen/Geometry>
#include <iostream>
#include <string>
using namespace pcl;
using namespace std;
int main(int argc, char** argv)
{
//Create Point Clouds
PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;
//save PointClouds to array
for (int i = 1; i < (argc - 1); i++)
{
if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
{
return -1;
}
cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
sourceClouds.push_back(sourceCloud);
cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
sourceCloud->clear();
}
for (int i = 0; i < sourceClouds.size() - 1; i++)
{
cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
}
}
在第一个for循环中,两个Clouuds的PointCloudSize相同,但在第二个for循环中,PointCloudSize为0。
我做错了什么?
sourceClouds.push_back(sourceCloud);
此行只复制PointCloud::Ptr,不复制点云数据
试试这个:
int main(int argc, char** argv)
{
//Create Point Clouds
//PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
vector < PointCloud<PointXYZ>::Ptr, Eigen::aligned_allocator <PointCloud <PointXYZ>::Ptr > > sourceClouds;
//save PointClouds to array
for (int i = 1; i < (argc - 1); i++)
{
PointCloud<PointXYZ>::Ptr sourceCloud(new PointCloud<PointXYZ>);
if (io::loadPCDFile<PointXYZ>(argv[i], *sourceCloud) != 0)
{
return -1;
}
cout << "Loaded file " << argv[i] << " (" << sourceCloud->size() << " points)" << endl;
sourceClouds.push_back(sourceCloud);
cout << "Point Cloud " << i-1 << "has got " << sourceClouds[i-1]->size() << " Points" << endl;
// sourceCloud->clear();
}
for (int i = 0; i < sourceClouds.size() - 1; i++)
{
cout << "Point Cloud " << i << "has got " << sourceClouds[i]->size() << " Points" << endl;
}
}