Search code examples
matrixpoint-cloud-librarycoordinate-transformationlidar

Precision getting lost when transforming the PCL pointcloud


I am using the this from PCL to transform the point cloud I have. Basically, I am only translating the cloud by some offset.

The problem is I am losing the precision after applying this transformation. More clear in the figure below.

I see that this only happens when I have large values(>6 digits) for my offset, by which the cloud is getting translated.

Below is the code which makes use of the pcl library

 Eigen::Matrix4d translationMatrix = Eigen::Matrix4d::Identity();

 //translation
 translationMatrix(0,3) = 1000000;
 translationMatrix(1,3) = 1000000;

 pcl::PointCloud<pcl::PointXYZ>::Ptr translatedCloud;
 translatedCloud.reset(new pcl::PointCloud<pcl::PointXYZ>());

 pcl::transformPointCloud(*cloud,*translatedCloud,translationMatrix);

 pcl::io::savePCDFileASCII ("translatedCloud.pcd",*translatedCloud);

original cloud

original cloud

transformed cloud

transformed cloud

I suspect the problem might be the range of the data type being used.

Any information on this would be helpful.


Solution

  • The problem was with the range of offset being used. The pcl::PointXYZ has points as the floats,so when providing such offsets out of range, it would round off the result, which was causing the loss in precision. One obvious solution to this is to normalize the range if possible. Another solution is to add a custom point type in PCL. There is a nice document about this provided by the PCL.