PCL Point Cloud meshing

Source: Internet
Author: User
PCL Point Cloud meshing
#include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/kdtree/kdtree_flann.h> # Include <pcl/features/normal_3d_omp.h> #include <pcl/features/normal_3d.h> #include <pcl/surface/ gp3.h> #include <pcl/visualization/pcl_visualizer.h> #include <boost/thread/thread.hpp> #include <   
    fstream> void Main () {PCL::P OINTCLOUD&LT;PCL::P ointxyz>::P TR Cloud (New PCL::P OINTCLOUD&LT;PCL::P ointxyz>);  if (Pcl::io::loadpcdfile ("C:\\USERS\\WANGYANG\\DESKTOP\\LXD-PART.PCD", *cloud) = =-1) {Pcl_error ("Could  
            Not read PCD file!\n ");
    Return  
    } PCL::P OINTCLOUD&LT;PCL::P ointnormal>::P tr cloud_with_normals (new PCL::P OINTCLOUD&LT;PCL::P ointnormal>); PCL::NORMALESTIMATION&LT;PCL::P ointxyz, pcl::normal> n;//Normal Estimation object PCL::P ointcloud<pcl::normal>::P tr normals (New PCL::P ointcloud<pcl::normal>);//Store estimated normal PCL::SEARCH::KDTREE&LT;PCL::P ointxyz>::P tr Tree (new PCL:: Search: KDTREE&LT;PCL::P ointxyz>); 
    Tree->setinputcloud (Cloud);  
    N.setinputcloud (Cloud); 
    N.setsearchmethod (tree);
    N.setksearch (20);
    N.compute (*normals);
    Pcl::concatenatefields (*cloud, *normals, *cloud_with_normals);
    PCL::SEARCH::KDTREE&LT;PCL::P ointnormal>::P tr tree2 (new PCL::SEARCH::KDTREE&LT;PCL::P ointnormal>);
    Tree2->setinputcloud (cloud_with_normals);
    PCL::GREEDYPROJECTIONTRIANGULATION&LT;PCL::P ointnormal> GP3; PCL::P Olygonmesh Mesh; The grid model that stores the final triangulation Gp3.setsearchradius (2);//This parameter needs to be changed GP3.SETMU (2.5);//Set the sample point to search its neighboring points at the farthest distance of 2.5 gp3.setmaximumnearestn
    Eighbors (100);//The number of neighbors to set the sample point search is Gp3.setmaximumsurfaceangle (M_PI/3);//Set a point normal direction deviation from the sample point normal direction of the maximum angle of 45 degrees
    Gp3.setminimumangle (m_pi/180);//The triangular angle is 10 degrees Gp3.setmaximumangle (2*M_PI/3) when the triangles are set. Gp3.setnormalconsistency (false);//Set this parameter to ensure that the normals are oriented toward a consistent gp3.setinputcloud (cloud_with_normals);//Set the input point cloud to a directed point cloud Gp3.setsearc Hmethod (tree2);//Set the search method to Tree2 gp3.reconstruct (MeSH);//reconstruction extraction of triangular std::vector<int> parts = Gp3.getpartids ();
    std::vector<int> status = Gp3.getpointstates ();
    FStream FS;

    Fs.open ("PartsID.txt", ios::out); 
    if (!FS) {return;

    } fs<< "Number of Point clouds:" <<parts.size () << "\ n"; for (int i = 0; i < parts.size (); i++) {if (parts[i]! = 0) {fs<<parts[i]<&lt ;" 

        \ n "; }} boost::shared_ptr<pcl::visualization::P clvisualizer> Viewer (new pcl::visualization::P Clvisualizer ("3
    Dviewer "));
    Viewer->setbackgroundcolor (0, 0, 0);
    Viewer->addpolygonmesh (Mesh, "W");
    Viewer->initcameraparameters ();
        while (!viewer->wasstopped ()) {viewer->spinonce (100);
    Boost::this_thread::sleep (boost::p osix_time::microseconds (50000));
} return; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.