Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <pcl/point_types.h>
- #include <pcl/io/pcd_io.h>
- #include <pcl/kdtree/kdtree_flann.h>
- #include <pcl/features/normal_3d.h>
- #include <pcl/surface/gp3.h>
- int
- main (int argc, char** argv)
- {
- int setKS;
- float setSR;
- float setM;
- int setMNN;
- setk=atoi(argv[3]);
- setS=atof(argv[4]);
- setM=atof(argv[5]);
- setMN=atoi(argv[6]);
- // Load input file into a PointCloud<T> with an appropriate type
- pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
- pcl::PCLPointCloud2 cloud_blob;
- pcl::io::loadPCDFile (argv[1], cloud_blob);
- pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
- //* the data should be available in cloud
- // Normal estimation*
- pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
- pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
- pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
- tree->setInputCloud (cloud);
- n.setInputCloud (cloud);
- n.setSearchMethod (tree);
- n.setKSearch (argv[3]);
- n.compute (*normals);
- //* normals should not contain the point normals + surface curvatures
- // Concatenate the XYZ and normal fields*
- pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
- pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
- //* cloud_with_normals = cloud + normals
- // Create search tree*
- pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
- tree2->setInputCloud (cloud_with_normals);
- // Initialize objects
- pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
- pcl::PolygonMesh triangles;
- // Set the maximum distance between connected points (maximum edge length)
- gp3.setSearchRadius (argv[4]);
- // Set typical values for the parameters
- gp3.setMu (argv[5]);
- gp3.setMaximumNearestNeighbors (argv[6]);
- gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
- gp3.setMinimumAngle(M_PI/18); // 10 degrees
- gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
- gp3.setNormalConsistency(false);
- // Get result
- gp3.setInputCloud (cloud_with_normals);
- gp3.setSearchMethod (tree2);
- gp3.reconstruct (triangles);
- pcl::io::saveVTKFile (argv[2], triangles)
- // Additional vertex information
- std::vector<int> parts = gp3.getPartIDs();
- std::vector<int> states = gp3.getPointStates();
- // Finish
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement