Advertisement
d10070dd

greedy_projection-edit

Nov 8th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <pcl/point_types.h>
  2. #include <pcl/io/pcd_io.h>
  3. #include <pcl/kdtree/kdtree_flann.h>
  4. #include <pcl/features/normal_3d.h>
  5. #include <pcl/surface/gp3.h>
  6.  
  7. int
  8. main (int argc, char** argv)
  9. {
  10.   int setKS;
  11.   float setSR;
  12.   float setM;
  13.   int setMNN;
  14.   setk=atoi(argv[3]);
  15.   setS=atof(argv[4]);
  16.   setM=atof(argv[5]);
  17.   setMN=atoi(argv[6]);
  18.   // Load input file into a PointCloud<T> with an appropriate type
  19.   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  20.   pcl::PCLPointCloud2 cloud_blob;
  21.   pcl::io::loadPCDFile (argv[1], cloud_blob);
  22.   pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
  23.   //* the data should be available in cloud
  24.  
  25.   // Normal estimation*
  26.   pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
  27.   pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
  28.   pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
  29.   tree->setInputCloud (cloud);
  30.   n.setInputCloud (cloud);
  31.   n.setSearchMethod (tree);
  32.   n.setKSearch (argv[3]);
  33.   n.compute (*normals);
  34.   //* normals should not contain the point normals + surface curvatures
  35.  
  36.   // Concatenate the XYZ and normal fields*
  37.   pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
  38.   pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
  39.   //* cloud_with_normals = cloud + normals
  40.  
  41.   // Create search tree*
  42.   pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
  43.   tree2->setInputCloud (cloud_with_normals);
  44.  
  45.   // Initialize objects
  46.   pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
  47.   pcl::PolygonMesh triangles;
  48.  
  49.   // Set the maximum distance between connected points (maximum edge length)
  50.   gp3.setSearchRadius (argv[4]);
  51.  
  52.   // Set typical values for the parameters
  53.   gp3.setMu (argv[5]);
  54.   gp3.setMaximumNearestNeighbors (argv[6]);
  55.   gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
  56.   gp3.setMinimumAngle(M_PI/18); // 10 degrees
  57.   gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
  58.   gp3.setNormalConsistency(false);
  59.  
  60.   // Get result
  61.   gp3.setInputCloud (cloud_with_normals);
  62.   gp3.setSearchMethod (tree2);
  63.   gp3.reconstruct (triangles);
  64.  
  65.   pcl::io::saveVTKFile (argv[2], triangles)
  66.  
  67.   // Additional vertex information
  68.   std::vector<int> parts = gp3.getPartIDs();
  69.   std::vector<int> states = gp3.getPointStates();
  70.  
  71.   // Finish
  72.   return (0);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement