Go to the documentation of this file.00001 #include <boost/make_shared.hpp>
00002 #include "pcl/io/pcd_io.h"
00003
00004 #include <pcl/features/fpfh_omp.h>
00005 #include <pcl/kdtree/kdtree_flann.h>
00006 #include <pcl/features/normal_3d_omp.h>
00007 #include "pcl/filters/voxel_grid.h"
00008
00009 using namespace pcl;
00010 using namespace std;
00011 typedef KdTree<PointXYZ>::Ptr KdTreePtr;
00012
00013 int main(int argc, char** argv)
00014 {
00015
00016
00017 sensor_msgs::PointCloud2::Ptr point_cloud_data(new sensor_msgs::PointCloud2());
00018
00019 printf("Loading point cloud...\n");
00020 if (pcl::io::loadPCDFile(argv[1], *point_cloud_data) == -1)
00021 {
00022 ROS_ERROR_STREAM("Was not able to open pcd file \"" << argv[1] << "\".\n");
00023 return -1;
00024 }
00025
00026 ROS_INFO("PointCloud before filtering: %d data points (%s).",
00027 point_cloud_data->width * point_cloud_data->height,
00028 pcl::getFieldsList(*point_cloud_data).c_str());
00029
00030 printf("height %d\n", point_cloud_data->height);
00031 printf("width %d\n", point_cloud_data->width);
00032 printf("fields %d\n", point_cloud_data->fields.size());
00033 printf("endian %d\n", point_cloud_data->is_bigendian);
00034 printf("point_step %d\n", point_cloud_data->point_step);
00035 printf("row_step %d\n", point_cloud_data->row_step);
00036 printf("is_dense %d\n", point_cloud_data->is_dense);
00037
00038
00039 ROS_INFO("Downsampling..");
00040 sensor_msgs::PointCloud2::Ptr cloud_filtered(new sensor_msgs::PointCloud2());
00041 pcl::VoxelGrid<sensor_msgs::PointCloud2> sor;
00042 sor.setInputCloud(point_cloud_data);
00043 sor.setLeafSize (0.2, 0.2, 0.2);
00044 sor.filter(*cloud_filtered);
00045 ROS_INFO(" after filtering: %d points", cloud_filtered->width * cloud_filtered->height);
00046
00047 PointCloud<PointXYZ> cloud;
00048 fromROSMsg(*cloud_filtered, cloud);
00049 std::vector<int> indices;
00050 indices.resize (cloud.points.size());
00051 for (size_t i = 0; i < indices.size (); ++i) { indices[i] = i; }
00052
00053
00054 KdTreePtr tree;
00055 tree.reset(new KdTreeFLANN<PointXYZ> (false));
00056 tree->setInputCloud(cloud.makeShared());
00057
00058 PointCloud<Normal>::Ptr normals(new PointCloud<Normal>());
00059 boost::shared_ptr< vector<int> > indicesptr(new vector<int> (indices));
00060 NormalEstimation<PointXYZ, Normal> normal_estimator;
00061
00062
00063 normal_estimator.setIndices(indicesptr);
00064 normal_estimator.setSearchMethod(tree);
00065 normal_estimator.setKSearch(10);
00066
00067
00068 printf("Calculating normals...\n");
00069 normal_estimator.setInputCloud(cloud.makeShared());
00070 normal_estimator.compute(*normals);
00071
00072
00073
00074 FPFHEstimationOMP<PointXYZ, Normal, FPFHSignature33> fpfh(4);
00075
00076
00077 PointCloud<FPFHSignature33>::Ptr fpfhs (new PointCloud<FPFHSignature33>());
00078
00079
00080 fpfh.setNrSubdivisions(11, 11, 11);
00081 fpfh.setIndices(indicesptr);
00082 fpfh.setSearchMethod(tree);
00083 fpfh.setKSearch(indices.size());
00084
00085
00086 printf("Calculating fpfh...\n");
00087 fpfh.setInputNormals(normals);
00088 fpfh.setInputCloud(cloud.makeShared());
00089 fpfh.compute(*fpfhs);
00090
00091
00092 for (unsigned int i = 0; i < indicesptr->size(); i++)
00093 {
00094 printf("%d ", i);
00095 for (unsigned int j = 0; j < (11*3); j++)
00096 printf("%.2f ", fpfhs->points[i].histogram[j]);
00097
00098 printf("\n");
00099 }
00100
00101
00102
00103 return 0;
00104 }