Advertisement
d10070dd

greedy_projection

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