Creating a PCL point cloud using a container of Eigen Vector3d
Asked Answered
F

2

6

I am trying to generate a PCL point cloud. All my points are in the following container type:

std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> >

I would like to create a pointer to a PCL point cloud:

pcl::PointCloud<pcl::PointXYZ>::Ptr pc 

What would be the most efficient way to create this point cloud?

Feudalize answered 15/6, 2013 at 23:55 Comment(0)
C
5

Since PCL seems to use a float[4] to store the points, when you specify pcl:PointXYZ, you will have to copy each element individually (not tested):

pc->points.resize( v.size() );
for(size_t i=0; i<v.size(); ++i)
    pc->points[i].getVector3fMap() = v[i].cast<float>();

if you used a vector4d instead and ensured that the last coefficient of each element is 0, you could do a memcpy or even a swap (with a bit of trickery).

Centipede answered 17/6, 2013 at 12:36 Comment(2)
So you mean, if I had std::vector<Eigen::Vector3f,Eigen::aligned_allocator<Eigen::Vector3f> > instead, could I simply call pc->points = container ?Feudalize
ah... missed that your original question used a double. You need a cast here (updated answer). And no, using Vector3f still wouldn't have the right memory layout. Vector4f would, but even then you needed some tricks to assign the container directly.Centipede
C
0

Point Cloud:

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

Vector:

std::vector<pcl::PointCloud<pcl::PointXYZ>, Eigen::aligned_allocator<pcl::PointXYZ> > vectorOfPointCloud;

Push-back to add point clouds into a vector:

vectorOfPointCloud.push_back(*cloud);
Casas answered 19/2, 2015 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.