using PointType = pcl::PointCloud<pcl::PointXYZ>;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
PointType::Ptr cloud_in(new PointType);
cloud_in->width = 5;
cloud_in->height = 1;
cloud_in->is_dense = false;
cloud_in->points.resize(cloud_in->width * cloud_in->height);
for (size_t t = 0; t < cloud_in->points.size(); ++t)
{
cloud_in->points[t].x = 1024 * rand() / (RAND_MAX + 1.0f);
cloud_in->points[t].y = 1024 * rand() / (RAND_MAX + 1.0f);
cloud_in->points[t].z = 1024 * rand() / (RAND_MAX + 1.0f);
}
PointType::Ptr cloud_out(new PointType);
*cloud_out = *cloud_in;
//实现一个简单的点云刚体变换,以构造目标点云
for (size_t i = 0; i < cloud_in->points.size(); ++i)
cloud_out->points[i].x = cloud_in->points[i].x + 0.7f;
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
icp.setInputCloud(cloud_in); //cloud_in设置为点云的源点
icp.setInputTarget(cloud_out); //cloud_out设置为与cloud_in对应的匹配目标
PointType Final; //存储经过配准变换点云后的点云
icp.align(Final); //打印配准相关输入信息
std::cout << "has converged:" << icp.hasConverged() << endl << \
" score: " << icp.getFitnessScore() << std::endl;
std::cout << icp.getFinalTransformation() << std::endl;
return a.exec();
}