Triangulation greedy algorithm is a projection of the original point cloud fast triangulation algorithm, the algorithm assumes a smooth surface, a uniform density of point cloud, and smoothing the surface can not be fixed in the holes while triangulation.
method:
(1) The three-dimensional points projected onto a plane through the normal
(2) obtained by projecting the point cloud in the plane of triangulating
(3) obtaining a triangular mesh model according to the topological connection relations of three points in a plane
Uses Delaunay algorithm based on region growing space, the method by selecting a triangle as the initial sample surface, expanding the boundary surface, and finally form a complete triangular mesh plane in the triangular region of the process, according to the last projection point cloud connection relationship determining connection topology, the resulting surface model reconstruction is the triangle mesh obtained among the original three-dimensional points.
This algorithm is suitable for the sampling point cloud from the surface of a continuous smooth surface and density of the point cloud uniform case
pcl1.8.1+vs2015
#include<iostream> #include<pcl/io/pcd_io.h> #include <pcl/io/ply_io.h> #include<pcl/point_types.h> #include <pcl/kdtree/kdtree_flann.h> #include <pcl/features/normal_3d.h> #include <pcl/io/obj_io.h> #include <pcl/surface/gp3.h> #include <pcl/visualization/pcl_visualizer.h>int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>()); pcl::PCLPointCloud2 cloud_blob;* Open point cloud file// if (pcl::io::loadPCDFile("rabbit.pcd", cloud_blob) == -1) { PCL_ERROR("Couldn't read file rabbit.pcd\n"); return(-1); } pcl::fromPCLPointCloud2(cloud_blob, *cloud); //法线估计对象 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n; //存储估计的法线 pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); //定义kd树指针 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>); tree-> setInputCloud (Cloud); n.setInputCloud (Cloud); n.setSearchMethod (Tree); n.setKSearch ( 20 is ); // estimated normal storage therein n.compute (* Normals); // the Concatenate the XYZ and The fields * Normal PCL PointCloud :: <PCL PointNormal ::> :: cloud_width_normals the Ptr ( new new PCL PointCloud :: <PCL :: PointNormal> ); // link field PCL :: concatenateFields (Cloud *, * Normals, * cloud_width_normals); // definition of the search tree object PCL :: :: Search KdTree <PCL PointNormal ::> :: tree2 the Ptr ( new new PCL :: :: Search KdTree <PCL :: PointNormal> ); //Construction of the point cloud search tree tree2-> setInputCloud (cloud_width_normals); // definition of triangular objects PCL GreedyProjectionTriangulation :: <PCL :: PointNormal> GP3; // network model stores the final triangulation PCL :: PolygonMesh, triangles; // set the connection the maximum distance between the points, (i.e., the maximum side length of triangular) gp3.setSearchRadius (200.0f ); // set the various parameter values gp3.setMu (2.5f ); gp3.setMaximumNearestNeighbors ( 100 ); gp3.setMaximumSurfaceAngle (M_PI_4 ); gp3.setMinimumAngle (M_PI / 18 is ); gp3.setMaximumAngle ( 2 * M_PI /. 3 ); gp3.setNormalConsistency ( to false); // Set the search method and the input point cloud gp3.setInputCloud (cloud_width_normals); gp3.setSearchMethod (tree2); // perform reconstruction, the result is stored in triangles gp3.reconstruct (triangles); // save the trellis diagram / / PCL :: IO :: saveOBJFile ( "result.obj", triangles); STD output_dir :: String = "E: /C/cloud_mesh.ply" ; STD SAV :: String = "Mesh saved in:" ; SAV + = output_dir; PCL :: :: print_info Console (sav.c_str ()); STD :: COUT << STD :: endl; PCL :: IO :: savePLYFileBinary (output_dir.c_str (), triangles); // display the results map boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("MAP3D MESH")); ////设置背景; viewer->setBackgroundColor(0, 0, 0); //设置显示的网格 viewer->addPolygonMesh(triangles, "my"); //viewer->initCameraParameters(); while (!viewer->wasStopped()) { viewer->spin(); } std::cout << "success" << std::endl; return 0; }
operation result
Description:
More data to be processed, and therefore need to be patient wait for a while
Save the file after triangulation in E: /C/cloud_mesh.ply, opened with compareCloud