test_geometry.cpp
Go to the documentation of this file.
00001 #include <pcl/io/pcd_io.h>
00002 #include <pcl/kdtree/kdtree_flann.h>
00003 #include <pcl/filters/passthrough.h>
00004 #include <pcl/features/normal_3d.h>
00005 #include <pcl/visualization/pcl_visualizer.h>
00006 
00007 using pcl::PointCloud;
00008 using pcl::PointXYZRGB;
00009 using pcl::Normal;
00010 using pcl::PointXYZRGBNormal;
00011 
00012 using pcl::PCDReader;
00013 using pcl::PassThrough;
00014 using pcl::NormalEstimation;
00015 using pcl::KdTreeFLANN;
00016 
00017 int 
00018   main (int argc, char **argv)
00019 {
00020   srand (time (0));
00021 
00022   PointCloud<PointXYZRGB>::Ptr cloud (new PointCloud<PointXYZRGB>);
00023 
00024   PCDReader pcd;
00025   if (pcd.read (argv[1], *cloud) == -1)
00026     return (-1);
00027 
00028   // Filter the data
00029   std::cerr << "Filtering..." << std::endl;
00030   PassThrough<PointXYZRGB> pass;
00031   pass.setInputCloud (cloud);
00032   PointCloud<PointXYZRGB>::Ptr cloud_filtered (new PointCloud<PointXYZRGB>);
00033   pass.filter (*cloud_filtered);
00034 
00035   // Estimate surface normals
00036   std::cerr << "Estimating normals..." << std::endl;
00037   NormalEstimation<PointXYZRGB, Normal> ne;
00038   ne.setInputCloud (cloud_filtered);
00039   ne.setKSearch (20);
00040   KdTreeFLANN<PointXYZRGB>::Ptr tree (new KdTreeFLANN<PointXYZRGB>);
00041   ne.setSearchMethod (tree);
00042   PointCloud<Normal> normals;
00043   ne.compute (normals);
00044 
00045   // Concatenate points and normals
00046   PointCloud<PointXYZRGBNormal> cloud_normals;
00047   pcl::concatenateFields (cloud_filtered, normals, cloud_normals);
00048 
00049   // Start the visualizer
00050   pcl::visualization::PCLVisualizer p ("test");
00051   p.setBackgroundColor (1, 1, 1);
00052   p.addCoordinateSystem (0.1);
00053 
00054   pcl::visualization::PointCloudColorHandlerRGBField<PointXYZRGBNormal> color_handler (cloud_normals);
00055   // Geometry handler demo
00056   {
00057     std::cerr << "PointCloudGeometryHandlerSurfaceNormal demo." << std::endl;
00058     pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<PointXYZRGBNormal> geometry_handler (cloud_normals);
00059     p.addPointCloud (cloud_normals, geometry_handler, "cloud_normal");
00060     p.spin ();
00061     p.removePointCloud ("cloud_normal");
00062 
00063     p.addPointCloud (cloud_normals, color_handler, geometry_handler, "cloud_normal");
00064     p.spin ();
00065     p.removePointCloud ("cloud_normal");
00066   }
00067 
00068   {
00069     std::cerr << "PointCloudGeometryHandlerXYZ demo." << std::endl;
00070     pcl::visualization::PointCloudGeometryHandlerXYZ<PointXYZRGBNormal> geometry_handler (cloud_normals);
00071     p.addPointCloud (cloud_normals, color_handler, geometry_handler, "cloud_xyz");
00072     p.spin ();
00073     p.removePointCloud ("cloud_xyz");
00074   }
00075 
00076   {
00077     std::cerr << "PointCloudGeometryHandlerXYZ demo." << std::endl;
00078     pcl::visualization::PointCloudGeometryHandlerCustom<PointXYZRGBNormal> geometry_handler (cloud_normals, "x", "y", "z");
00079     p.addPointCloud (cloud_normals, color_handler, geometry_handler, "cloud_xyz");
00080     p.spin ();
00081     p.removePointCloud ("cloud_xyz");
00082     
00083     geometry_handler = pcl::visualization::PointCloudGeometryHandlerCustom<PointXYZRGBNormal> (cloud_normals, "x", "x", "y");
00084     p.addPointCloud (cloud_normals, color_handler, geometry_handler, "cloud_xyz");
00085     p.spin ();
00086     p.removePointCloud ("cloud_xyz");
00087    }
00088   p.spin ();
00089 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:34:53