pcl曲面再構築モジュール-poisson再構築アルゴリズム例

4372 ワード

回転:http://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_ptr<:visualization::pclvisualizer>viewer(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重建算法示例_第1张图片