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<PCL::P ointxyz>::P TR Cloud (New PCL::P OINTCLOUD<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<PCL::P ointnormal>::P tr cloud_with_normals (new PCL::P OINTCLOUD<PCL::P ointnormal>); PCL::NORMALESTIMATION<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<PCL::P ointxyz>::P tr Tree (new PCL:: Search: KDTREE<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<PCL::P ointnormal>::P tr tree2 (new PCL::SEARCH::KDTREE<PCL::P ointnormal>);
Tree2->setinputcloud (cloud_with_normals);
PCL::GREEDYPROJECTIONTRIANGULATION<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]<< ;"
\ 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; }