1

I have been following the tutorial http://pointclouds.org/documentation/tutorials/pcl_visualizer.php#pcl-visualizer and could get a simple viewer working.

I looked up the documentation and found the function getMatrixXfMap which returns the Eigen::MatrixXf from a PointCloud.

// Get Eigen matrix
Eigen::MatrixXf M = basic_cloud_ptr->getMatrixXfMap();
cout << "(Eigen) #row :" << M.rows() << endl;
cout << "(Eigen) #col :" << M.cols() << endl;

Next I process M (basically rotations, translations and some other transforms). I how is possible to set M into the PointCloud efficiently. Or is it that I need to pushback() one point at a time?

mkuse
  • 2,250
  • 4
  • 32
  • 61
  • Just use `Eigen::Matrix4f trans;` Set the matrix as you wish. `pcl::transformPointCloud(*beforeTransCloud,*afterTransCloud,trans)` – Deepfreeze Mar 26 '15 at 15:01
  • What if my manipulation is not as simple as a linear transform? How can I retrieve the point cloud as a matrix to manipulate? – mkuse Mar 27 '15 at 04:03
  • Then indeed use push_back, or more efficiently use `cloud->resize` and then per point `cloud->points[i].x = ...` – Deepfreeze Mar 27 '15 at 12:50

1 Answers1

1

You do not need to cast your pcl cloud to an Eigen::MatrixXf, do the transformations and cast back. You can simply perform the rotation and the translation directly on your input cloud:

pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ());
// Fill the cloud
Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
// Define a translation of 2.5 meters on the x axis.
transform_2.translation() << 2.5, 0.0, 0.0;
// The same rotation matrix as before; theta radians around Z axis
transform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));
// Print the transformation
printf ("\nMethod #2: using an Affine3f\n");
std::cout << transform_2.matrix() << std::endl;
// Executing the transformation
pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud (new pcl::PointCloud<pcl::PointXYZ> ());
// You can either apply transform_1 or transform_2; they are the same
pcl::transformPointCloud (*source_cloud, *transformed_cloud, transform_2);

Taken from pcl transformation tutorial.

R.Falque
  • 904
  • 8
  • 29
Jan Hackenberg
  • 481
  • 3
  • 14