Reputation: 1307
My question is related to Creating a PCL point cloud using a container of Eigen Vector3d but I am using a Eigen::MatrixXd
instead of Eigen::Vector3d
. getMatrixXfMap()
is not a part of the member function and so cannot be used instead of getVector3fMap()
. How can the types be converted in this case?
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// resize to number of points
cloud->points.resize(Pts.rows());
/*DOES NOT WORK */
for(int i=0;i<Pts.rows();i++)
cloud->points[i].getMatrixXfMap() = Pts[i].cast<float>();
Upvotes: 0
Views: 2892
Reputation: 185
This is what I did. My source_cloud
is a Nx3 Matrix constaining XYZ points in float32 format.
typedef pcl::PointCloud<pcl::PointXYZRGBA> PointCloudRGBA;
Eigen::MatrixXf convertToPointCloud(const Eigen::MatrixXf source_cloud){
PointCloudRGBA::Ptr cloud(new PointCloudRGBA);
cloud->points.resize(source_cloud.rows());
for(int i=0; i<source_cloud.rows(); i++){
cloud->points[i].getVector3fMap() = Eigen::Vector3d(source_cloud(i, 0), source_cloud(i, 1), source_cloud(i, 2)).cast<float>();
}
}
Upvotes: 0
Reputation: 1243
It may not be very sexy, but why not just create each point in your for loop? No need for the resize in that case.
pcl::PointXYZ temp;
temp.x = Pts[i][0];
temp.y = Pts[i][1];
temp.z = Pts[i][2];
cloud.push_back(temp);
Upvotes: 1