Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #include <pcl/point_types.h>
  2. #include <pcl/point_cloud.h>
  3. #include <pcl/registration/icp.h>
  4. #include <pcl/features/normal_3d.h>
  5.  
  6. #include <pcl/search/kdtree.h>
  7. #include <pcl/search/search.h>
  8. #include <pcl/filters/filter.h>
  9.  
  10. #include <pcl/visualization/pcl_visualizer.h>
  11. #include <pcl/filters/statistical_outlier_removal.h>
  12. #include <pcl/io/pcd_io.h>
  13.  
  14. #include <pcl/registration/icp.h>
  15. #include <pcl/registration/icp_nl.h>
  16. #include <pcl/registration/transforms.h>
  17.  
  18. #include <boost/make_shared.hpp>
  19.  
  20. #include <iostream>
  21. #include <vector>
  22.  
  23.  
  24. int main(int argc, char **argv){
  25.  
  26. //load pcd files into clouds
  27. //test at first with correctly rotated clouds and then with rotated clouds
  28. pcl::PointCloud<pcl::PointXYZRGB>::Ptr sourceCloud (new pcl::PointCloud<pcl::PointXYZRGB>());
  29. pcl::PointCloud<pcl::PointXYZRGB>::Ptr targetCloud (new pcl::PointCloud<pcl::PointXYZRGB>());
  30.  
  31. int errNo1 = pcl::io::loadPCDFile("bun01.pcd", *sourceCloud);
  32. int errNo2 = pcl::io::loadPCDFile("bun02.pcd", *targetCloud);
  33.  
  34. if(errNo1){
  35. PCL_ERROR ("oops, some error occured loading file .pcd file");
  36. return (-1);
  37. }
  38.  
  39. if(errNo2){
  40. PCL_ERROR ("oops, some error occured loading .pcd file");
  41. return (-1);
  42. }
  43.  
  44.  
  45. // Create the normal estimation class, and pass the input dataset to it
  46. pcl::NormalEstimation<pcl::PointXYZRGB, pcl::Normal> ne;
  47. ne.setInputCloud(sourceCloud);
  48.  
  49. // Create an empty kdtree representation, and pass it to the normal estimation object.
  50. // Its content will be filled inside the object, based on the given input dataset (as no other search surface is given)
  51. pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZRGB> ());
  52. ne.setSearchMethod (tree);
  53.  
  54. // Output datasets
  55. pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
  56.  
  57. Eigen::Matrix4f GlobalTransform = Eigen::Matrix4f::Identity ();
  58. Eigen::Matrix4f pairTransform = Eigen::Matrix4f::Identity();
  59.  
  60. // Use all neighbors in a sphere of radius 30cm
  61. ne.setRadiusSearch (0.30);
  62. // Compute the features
  63. ne.compute (*normals);
  64.  
  65. pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> rgbSrc(sourceCloud, 125, 50, 255); //purple color
  66. pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZRGB> rgbTgt(sourceCloud, 0, 0, 255);
  67. //test with normals
  68. boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("Normal viewer"));
  69.  
  70. viewer->setBackgroundColor (0, 0, 0);
  71.  
  72. int level = 1;
  73. double scale = 0.01;
  74.  
  75. viewer->addPointCloud(sourceCloud, rgbSrc, "sample cloud");
  76. //uncomment if you want to see normals
  77. //viewer->addPointCloudNormals<pcl::PointXYZRGB, pcl::Normal>(inputCloud, normals, level, scale, "normals");
  78.  
  79. viewer->addCoordinateSystem (0.15);
  80.  
  81. /*pcl::ModelCoefficients coeffs;
  82.  
  83. coeffs.values.push_back(1.0);
  84. coeffs.values.push_back(0.0);
  85. coeffs.values.push_back(0.1);
  86. coeffs.values.push_back(1.0);
  87.  
  88. viewer->addPlane(coeffs, "plane");*/
  89.  
  90. //next register and transform on each iteration
  91. pcl::IterativeClosestPointNonLinear<pcl::PointXYZRGB, pcl::PointXYZRGB>::Ptr
  92. reg (new pcl::IterativeClosestPointNonLinear<pcl::PointXYZRGB, pcl::PointXYZRGB>());
  93.  
  94. reg->setTransformationEpsilon(1e-6);
  95. reg->setMaxCorrespondenceDistance (0.1);
  96.  
  97. while(!viewer->wasStopped()){
  98. viewer->spinOnce(10);
  99. }
  100.  
  101. /* if(kdtree->radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance)){
  102.  
  103. for (size_t i = 0; i < pointIdxRadiusSearch.size (); ++i){
  104. std::cout << " " << bunnySrc->points[ pointIdxRadiusSearch[i] ].x
  105. << " " << bunnySrc->points[ pointIdxRadiusSearch[i] ].y
  106. << " " << bunnySrc->points[ pointIdxRadiusSearch[i] ].z
  107. << " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << std::endl;
  108. }
  109. }*/
  110.  
  111. return (0);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement