Advertisement
moppa

Fast triangulation

Apr 17th, 2012
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #ifdef _DEBUG
  2. #pragma comment(lib, "pcl_common_debug.lib")
  3. #pragma comment(lib, "pcl_io_debug.lib")
  4. #pragma comment(lib, "pcl_registration_debug.lib")
  5. #pragma comment(lib, "pcl_kdtree_debug.lib")
  6. #pragma comment(lib, "pcl_surface_debug.lib")
  7. #pragma comment(lib, "pcl_search_debug.lib")
  8. #pragma comment(lib, "pcl_features_debug.lib")
  9. #else
  10. #pragma comment(lib, "pcl_common_release.lib")
  11. #pragma comment(lib, "pcl_io_release.lib")
  12. #pragma comment(lib, "pcl_registration_release.lib")
  13. #pragma comment(lib, "pcl_kdtree_release.lib")
  14. #pragma comment(lib, "pcl_surface_release.lib")
  15. #pragma comment(lib, "pcl_search_release.lib")
  16. #pragma comment(lib, "pcl_features_release.lib")
  17. #endif
  18.  
  19. #include <pcl/point_types.h>
  20. #include <pcl/io/pcd_io.h>
  21. #include <pcl/kdtree/kdtree_flann.h>
  22. #include <pcl/features/normal_3d.h>
  23. #include <pcl/surface/gp3.h>
  24. #include <pcl/io/vtk_io.h>
  25.  
  26. int
  27. main (int argc, char** argv)
  28. {
  29.   // Load input file into a PointCloud<T> with an appropriate type
  30.   pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
  31.   sensor_msgs::PointCloud2 cloud_blob;
  32.   pcl::io::loadPCDFile ("table_scene_mug_stereo_textured.pcd", cloud_blob);
  33.   pcl::fromROSMsg (cloud_blob, *cloud);
  34.   //* the data should be available in cloud
  35.   std::cout << "Laddat";
  36.  
  37.   // Normal estimation*
  38.   pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
  39.   pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
  40.   pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
  41.   tree->setInputCloud (cloud);
  42.   n.setInputCloud (cloud);
  43.   n.setSearchMethod (tree);
  44.   n.setKSearch (20);
  45.   n.compute (*normals);
  46.   //* normals should not contain the point normals + surface curvatures
  47.   std::cout << "Normaler";
  48.  
  49.   // Concatenate the XYZ and normal fields*
  50.   pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
  51.   pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
  52.   //* cloud_with_normals = cloud + normals
  53.  
  54.   // Create search tree*
  55.   pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
  56.   tree2->setInputCloud (cloud_with_normals);
  57.  
  58.   // Initialize objects
  59.   pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
  60.   pcl::PolygonMesh triangles;
  61.  
  62.   // Set the maximum distance between connected points (maximum edge length)
  63.   gp3.setSearchRadius (0.025);
  64.  
  65.   // Set typical values for the parameters
  66.   gp3.setMu (2.5);
  67.   gp3.setMaximumNearestNeighbors (100);
  68.   gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
  69.   gp3.setMinimumAngle(M_PI/18); // 10 degrees
  70.   gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
  71.   gp3.setNormalConsistency(false);
  72.  
  73.   // Get result
  74.   gp3.setInputCloud (cloud_with_normals);
  75.   gp3.setSearchMethod (tree2);
  76.   gp3.reconstruct (triangles);
  77.  
  78.   std::cout << "Rekonstruerat";
  79.  
  80.   // Additional vertex information
  81.   std::vector<int> parts = gp3.getPartIDs();
  82.   std::vector<int> states = gp3.getPointStates();
  83.  
  84.   pcl::io::saveVTKFile("mesh.vtk", triangles);
  85.   std::cout << "Sparat";
  86.   // Finish
  87.   return (0);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement