typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
typedef pcl::Normal PointNT;
typedef pcl::PointCloud<PointNT> PointCloudNT;
typedef pcl::PointXYZRGBNormal PointCNT;
typedef pcl::PointCloud<PointCNT> PointCloudCNT;
int main()
{
std::string fname_src = "qq0zx.pcd";
pcl::PointCloud<PointT>::Ptr cloud_src(new pcl::PointCloud<PointT>);
pcl::PointCloud<PointT>::Ptr cloud_tgt(new pcl::PointCloud<PointT>);
if (pcl::io::loadPCDFile<PointT>(fname_src, *cloud_src) == -1)
{
PCL_ERROR("Couldn't read file");
return -1;
}
pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>);
PointCloudCNT mls_points;
pcl::MovingLeastSquares<PointT, PointCNT> mls;
mls.setComputeNormals(true);
mls.setInputCloud(cloud_src);
mls.setPolynomialFit(true);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.1);
mls.setPolynomialOrder(1);
mls.process(mls_points);
// 将mls后的结果xyzrgbNormal转换成为xyzrgb
cloud_tgt->points.resize(mls_points.size());
for (size_t i = 0; i < mls_points.size(); ++i)
{
cloud_tgt->points[i].x = mls_points.points[i].x;
cloud_tgt->points[i].y = mls_points.points[i].y;
cloud_tgt->points[i].z = mls_points.points[i].z;
cloud_tgt->points[i].r = mls_points.points[i].r;
cloud_tgt->points[i].g = mls_points.points[i].g;
cloud_tgt->points[i].b = mls_points.points[i].b;
}
cloud_tgt->width = mls_points.size();
cloud_tgt->height = 1;
//pcl::io::savePCDFile("qq0p.pcd", *cloud_tgt);
pcl::io::savePCDFileASCII("qq0p.pcd", *cloud_tgt);
pcl::visualization::PCLVisualizer viewer1;
viewer1.setBackgroundColor(255, 255, 255);
viewer1.addPointCloud(cloud_src);
while (!viewer1.wasStopped())
{ //user_data++;
viewer1.spinOnce();
}
pcl::visualization::PCLVisualizer viewer2;
viewer2.setBackgroundColor(255, 255, 255);
viewer2.addPointCloud(cloud_tgt);
while (!viewer2.wasStopped())
{ //user_data++;
viewer2.spinOnce();
}
system("pause");
return (0);
}
typedef pcl::PointCloud<PointT> PointCloudT;
typedef pcl::Normal PointNT;
typedef pcl::PointCloud<PointNT> PointCloudNT;
typedef pcl::PointXYZRGBNormal PointCNT;
typedef pcl::PointCloud<PointCNT> PointCloudCNT;
int main()
{
std::string fname_src = "qq0zx.pcd";
pcl::PointCloud<PointT>::Ptr cloud_src(new pcl::PointCloud<PointT>);
pcl::PointCloud<PointT>::Ptr cloud_tgt(new pcl::PointCloud<PointT>);
if (pcl::io::loadPCDFile<PointT>(fname_src, *cloud_src) == -1)
{
PCL_ERROR("Couldn't read file");
return -1;
}
pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>);
PointCloudCNT mls_points;
pcl::MovingLeastSquares<PointT, PointCNT> mls;
mls.setComputeNormals(true);
mls.setInputCloud(cloud_src);
mls.setPolynomialFit(true);
mls.setSearchMethod(tree);
mls.setSearchRadius(0.1);
mls.setPolynomialOrder(1);
mls.process(mls_points);
// 将mls后的结果xyzrgbNormal转换成为xyzrgb
cloud_tgt->points.resize(mls_points.size());
for (size_t i = 0; i < mls_points.size(); ++i)
{
cloud_tgt->points[i].x = mls_points.points[i].x;
cloud_tgt->points[i].y = mls_points.points[i].y;
cloud_tgt->points[i].z = mls_points.points[i].z;
cloud_tgt->points[i].r = mls_points.points[i].r;
cloud_tgt->points[i].g = mls_points.points[i].g;
cloud_tgt->points[i].b = mls_points.points[i].b;
}
cloud_tgt->width = mls_points.size();
cloud_tgt->height = 1;
//pcl::io::savePCDFile("qq0p.pcd", *cloud_tgt);
pcl::io::savePCDFileASCII("qq0p.pcd", *cloud_tgt);
pcl::visualization::PCLVisualizer viewer1;
viewer1.setBackgroundColor(255, 255, 255);
viewer1.addPointCloud(cloud_src);
while (!viewer1.wasStopped())
{ //user_data++;
viewer1.spinOnce();
}
pcl::visualization::PCLVisualizer viewer2;
viewer2.setBackgroundColor(255, 255, 255);
viewer2.addPointCloud(cloud_tgt);
while (!viewer2.wasStopped())
{ //user_data++;
viewer2.spinOnce();
}
system("pause");
return (0);
}