0

My ultimate goal is to convert very efficiently a Point Cloud pcl::PointCloud<pcl::PointXYZ> to std::vector<Eigen::Vector3f>. The function getMatrixXfMap() (link) allows me to convert the Point Cloud to a Eigen::MatrixXf.

How could I convert now the Eigen::MatrixXfinto a std::vector<Eigen::Vector3f>? (or if you know a direct method to go from the pcl::PointCloud<pcl::PointXYZ> to std::vector<Eigen::Vector3f> that also works for me)

This answer is exactly the other way around

UPDATE: This is what I have so far (it works, but it's slower than iterating through all the points). I'm casting to double in this case, but any solution without casting to double also works for me:

  pcl::PointCloud<pcl::PointXYZ>::Ptr pclptr_map_;
  // Do stuff 
  Eigen::MatrixXd mat = (pclptr_map_->getMatrixXfMap()).cast<double>();
  int cols = pclptr_map_->points.size();
  std::vector<Eigen::Vector3d> v(pclptr_map_->points.size());
  Eigen::Matrix<double, 3, Eigen::Dynamic>::Map(v.data()->data(), 3, cols) = mat;

Thanks

Lab
  • 1
  • 1
  • Duplicate of: https://stackoverflow.com/questions/54682743/how-to-map-a-eigenmatrix-to-stdvectoreigenvector – ggael Feb 14 '19 at 07:03
  • Do you actually also want to covert from float to double? – chtz Feb 14 '19 at 07:13
  • No, I've just updated the question, thanks – Lab Feb 14 '19 at 14:41
  • Possible duplicate of [std::vector to Eigen::MatrixXd Eigen](https://stackoverflow.com/questions/49813340/stdvectoreigenvector3d-to-eigenmatrixxd-eigen) – chtz Feb 15 '19 at 14:38

0 Answers0