PCL表面重建

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

using namespace pcl;
using namespace std;

int main()
{
    PointCloud::Ptr cloud(new PointCloud);
    if (io::loadPCDFile("test.pcd",*cloud)==1)return 0;
    cout << io::loadPCDFile("test.pcd", *cloud) << endl;
    NormalEstimation n;
    PointCloud::Ptr normals(new PointCloud);
    search::KdTree::Ptr tree(new  search::KdTree);
    tree->setInputCloud(cloud);
    n.setInputCloud(cloud);
    n.setSearchMethod(tree);
    n.setKSearch(20);
    n.compute(*normals);

    PointCloud::Ptr cloud_with_normals(new PointCloud);
    concatenateFields(*cloud, *normals,*cloud_with_normals);

    search::KdTree::Ptr tree2(new search::KdTree);
    tree2->setInputCloud(cloud_with_normals);

    GreedyProjectionTriangulation gp3;
    PolygonMesh triangles;

    gp3.setSearchRadius(1.5f);
    gp3.setMu(2.5f);
    gp3.setMaximumNearestNeighbors(100);
    gp3.setMaximumSurfaceAngle(M_PI / 4);
    gp3.setMinimumAngle(M_PI / 18);
    gp3.setMaximumAngle(2 * M_PI / 3);
    gp3.setNormalConsistency(false);

    gp3.setInputCloud(cloud_with_normals);
    gp3.setSearchMethod(tree2);

    gp3.reconstruct(triangles);

    io::savePLYFile("result.pcd", triangles);

    boost::shared_ptrviewer(new visualization::PCLVisualizer);
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addPolygonMesh(triangles, "my");
    viewer->addCoordinateSystem(1, 0);
    viewer->initCameraParameters();

    while (!viewer->wasStopped())
    {
        viewer->spinOnce(100);
        boost::this_thread::sleep(boost::posix_time::microseconds(100000));
    }
    system("pause");
    return 0;
}

你可能感兴趣的:(PCL表面重建)