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