Advertisement
d10070dd

☆greedy_projection-server

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