简体   繁体   中英

from std::vector of 3 into a pcl::PointCloud<PointXYZ>::Ptr?

I have a point cloud of obstacles, because I used vectors of vector in my binary tree, I'd like to insert the values in std::vector of 3 elements into a pcl::PointCloud::Ptr object to do clustering.

std::vector<std::vector<float> > points;
typename pcl::PointCloud<PointXYZ>::Ptr cluster(new pcl::PointCloud<PointT>);
// next line is not possible, but how do I insert the component of vector<float> into the x,y,z of  struct PointXYZ
cluster->push_back(points[idx]);

Most likely something like

  for (int j=0; j<points.size(); ++j) {
    std::vector<float> &vec = points[j];   
    for (int i=0;i<vec.size();i+=3)
          cluster->push_back(PointXYZ(vec[i], vec[i+1], vec[i+2]));
  }

I am assuming every 3 value in the inner std::vector<float> is a point.

for (int i=0; i<points.size(); ++i) {
    if (points[i].size() != 3)
        continue;
    cluster->push_back(pcl::PointXYZ(points[i][0], points[i][1], points[i][2]));
}

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