0
votes

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]);
2

2 Answers

0
votes

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.

0
votes
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]));
}