pcl曲面重建模块-poisson重建PCL示例

转自:https://www.cnblogs.com/bozhicheng/p/5800874.html

poisson曲面重建算法
pcl-1.8测试通过

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


using namespace pcl;
using namespace std;

int
main (int argc, char** argv)
{


        /*点云读入阶段*/
        if(argc <= 2) {
                cout << "请输入点云数据文件名称,并指定输出数据文件名称" << endl;
                return 1;      

        }
        PointCloud::Ptr cloud (new PointCloud);
        if(io::loadPCDFile (argv[1], *cloud) == -1){
                cout << "数据读入失败!!" << endl;

                return 1;
        } 
        cout << "数据读入   完成" << endl;

        /*滤波阶段*/
        PointCloud::Ptr filtered(new PointCloud());
        PassThrough filter;
        filter.setInputCloud(cloud);
        filter.filter(*filtered);
        cout << "低通滤波   完成" << endl;

        // MovingLeastSquares mls;
        // mls.setInputCloud(filtered);
        // mls.setSearchRadius(0.01);
        // mls.setPolynomialFit(true);
        // mls.setPolynomialOrder(2);
        // mls.setUpsamplingMethod(MovingLeastSquares::SAMPLE_LOCAL_PLANE);
        // mls.setUpsamplingRadius(0.005);
        // mls.setUpsamplingStepSize(0.003);

        // PointCloud::Ptr cloud_smoothed (new PointCloud());
        // mls.process(*cloud_smoothed);
        // cout << "移动最小二乘平面滤波完成" << endl;

        

        /*法向计算阶段*/
        NormalEstimationOMP ne;
        ne.setNumberOfThreads(8);
        ne.setInputCloud(filtered);
        ne.setRadiusSearch(5);
        Eigen::Vector4f centroid;
        compute3DCentroid(*filtered, centroid);
        ne.setViewPoint(centroid[0], centroid[1], centroid[2]);

        PointCloud::Ptr cloud_normals (new PointCloud());
        ne.compute(*cloud_normals);
              
        for(size_t i = 0; i < cloud_normals->size(); ++i){
                cloud_normals->points[i].normal_x *= -1;
                cloud_normals->points[i].normal_y *= -1;
                cloud_normals->points[i].normal_z *= -1;
        }

            
        PointCloud::Ptr cloud_smoothed_normals(new PointCloud());
        //将点云数据的坐标和法向信息拼接
        concatenateFields(*filtered, *cloud_normals, *cloud_smoothed_normals);

        cout << "法向计算   完成" << endl;



        /*poission 重建阶段*/
        //创建poisson重建对象
        Poisson poisson;
        // poisson.setDepth(9);
        //输入poisson重建点云数据
        poisson.setInputCloud(cloud_smoothed_normals);
        //创建网格对象指针,用于存储重建结果
        PolygonMesh mesh;
        //poisson重建开始
        poisson.reconstruct(mesh);

        //将重建结果存储到硬盘,并保存为PLY格式
        io::savePLYFile(argv[2], mesh);
        cout << "曲面重建   完成" << endl;


        /*图形显示阶段*/
        cout << "开始图形显示......" << endl;
        boost::shared_ptrviewer(new pcl::visualization::PCLVisualizer("my viewer"));

        viewer->setBackgroundColor(0,0,7);
        viewer->addPolygonMesh(mesh, "my");
        viewer->addCoordinateSystem(50.0);
        viewer->initCameraParameters();

        while(!viewer->wasStopped()){

                viewer->spinOnce(100);
                boost::this_thread::sleep(boost::posix_time::microseconds(100000));
        }

        
        return (0);
}

pcl曲面重建模块-poisson重建PCL示例_第1张图片

你可能感兴趣的:(算法,c/c++,linux,人工智能)