d10070dd

greedy_projection-1.6.0

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