Advertisement
hasegawa

☆greedy_projection-server

Feb 6th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.95 KB | None | 0 0
  1. 1.#include <pcl/point_types.h>
  2.  
  3.  
  4. 2.#include <pcl/io/pcd_io.h>
  5.  
  6.  
  7. 3.#include <pcl/kdtree/kdtree_flann.h>
  8.  
  9.  
  10. 4.#include <pcl/features/normal_3d.h>
  11.  
  12.  
  13. 5.#include <pcl/surface/gp3.h>
  14.  
  15.  
  16. 6.#include <pcl/io/vtk_io.h>
  17.  
  18.  
  19. 7.
  20.  
  21.  
  22. 8.int
  23.  
  24.  
  25. 9.main (int argc, char** argv)
  26.  
  27.  
  28. 10.{
  29.  
  30.  
  31. 11.  int search;
  32.  
  33.  
  34. 12.  float radius;
  35.  
  36.  
  37. 13.  float mu;
  38.  
  39.  
  40. 14.  int neighbors;
  41.  
  42.  
  43. 15.  search=atoi(argv[3]);
  44.  
  45.  
  46. 16.  radius=atof(argv[4]);
  47.  
  48.  
  49. 17.  mu=atof(argv[5]);
  50.  
  51.  
  52. 18.  neighbors=atoi(argv[6]);
  53.  
  54.  
  55. 19.  // Load input file into a PointCloud<T> with an appropriate type
  56.  
  57.  
  58. 20.  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  59.  
  60.  
  61. 21.  pcl::PCLPointCloud2 cloud_blob;
  62.  
  63.  
  64. 22.  pcl::io::loadPCDFile (argv[1], cloud_blob);
  65.  
  66.  
  67. 23.  pcl::fromPCLPointCloud2 (cloud_blob, *cloud);
  68.  
  69.  
  70. 24.  //* the data should be available in cloud
  71.  
  72.  
  73. 25.
  74.  
  75.  
  76. 26.  // Normal estimation*
  77.  
  78.  
  79. 27.  pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
  80.  
  81.  
  82. 28.  pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
  83.  
  84.  
  85. 29.  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
  86.  
  87.  
  88. 30.  tree->setInputCloud (cloud);
  89.  
  90.  
  91. 31.  n.setInputCloud (cloud);
  92.  
  93.  
  94. 32.  n.setSearchMethod (tree);
  95.  
  96.  
  97. 33.  n.setKSearch (search);
  98.  
  99.  
  100. 34.  n.compute (*normals);
  101.  
  102.  
  103. 35.  //* normals should not contain the point normals + surface curvatures
  104.  
  105.  
  106. 36.
  107.  
  108.  
  109. 37.  // Concatenate the XYZ and normal fields*
  110.  
  111.  
  112. 38.  pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
  113.  
  114.  
  115. 39.  pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
  116.  
  117.  
  118. 40.  //* cloud_with_normals = cloud + normals
  119.  
  120.  
  121. 41.
  122.  
  123.  
  124. 42.  // Create search tree*
  125.  
  126.  
  127. 43.  pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
  128.  
  129.  
  130. 44.  tree2->setInputCloud (cloud_with_normals);
  131.  
  132.  
  133. 45.
  134.  
  135.  
  136. 46.  // Initialize objects
  137.  
  138.  
  139. 47.  pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
  140.  
  141.  
  142. 48.  pcl::PolygonMesh triangles;
  143.  
  144.  
  145. 49.
  146.  
  147.  
  148. 50.  // Set the maximum distance between connected points (maximum edge length)
  149.  
  150.  
  151. 51.  gp3.setSearchRadius (radius);
  152.  
  153.  
  154. 52.
  155.  
  156.  
  157. 53.  // Set typical values for the parameters
  158.  
  159.  
  160. 54.  gp3.setMu (mu);
  161.  
  162.  
  163. 55.  gp3.setMaximumNearestNeighbors (neighbors);
  164.  
  165.  
  166. 56.  gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
  167.  
  168.  
  169. 57.  gp3.setMinimumAngle(M_PI/18); // 10 degrees
  170.  
  171.  
  172. 58.  gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
  173.  
  174.  
  175. 59.  gp3.setNormalConsistency(false);
  176.  
  177.  
  178. 60.
  179.  
  180.  
  181. 61.  // Get result
  182.  
  183.  
  184. 62.  gp3.setInputCloud (cloud_with_normals);
  185.  
  186.  
  187. 63.  gp3.setSearchMethod (tree2);
  188.  
  189.  
  190. 64.  gp3.reconstruct (triangles);
  191.  
  192.  
  193. 65.
  194.  
  195.  
  196. 66.    pcl::io::saveVTKFile (argv[2], triangles);
  197.  
  198.  
  199. 67.
  200.  
  201.  
  202. 68.  // Additional vertex information
  203.  
  204.  
  205. 69.  std::vector<int> parts = gp3.getPartIDs();
  206.  
  207.  
  208. 70.  std::vector<int> states = gp3.getPointStates();
  209.  
  210.  
  211. 71.    
  212.  
  213.  
  214. 72.
  215.  
  216.  
  217. 73.  // Finish
  218.  
  219.  
  220. 74.  return (0);
  221.  
  222.  
  223. 75.}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement