简体   繁体   中英

PCL How to create a Point Cloud array/vector?

I have stored 85 Point Clouds on hdd. I want to open all the clouds and save them in a vector/array.
How should I do this?

What I tested with no success:

    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;
    }
    }

In the first for loop, the PointCloudSize from both Clouuds are the same, but in the second for loop, the PointCloudSize is 0.
What I'am doing wrong?

sourceClouds.push_back(sourceCloud);

This line only copy the PointCloud::Ptr and does not copy the point cloud data.

try this:

  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;
    }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM