Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <ros/ros.h>
00036 #include <pointcloud_registration/spin_image_estimation/spin_image_estimation.h>
00037 #include <pointcloud_registration/pointcloud_registration_point_types.h>
00038 #include <pcl/io/pcd_io.h>
00039 #include "pcl/kdtree/kdtree_flann.h"
00040 #include <pcl/features/normal_3d_omp.h>
00041
00042 #include "fstream"
00043
00044 #define PCD_FILE "29_July_full_room_no_downsample.pcd"
00045 #define MAX_NN 300
00046 #define RADIUS 0.1
00047 #define SUB_DIVISIONS 10
00048 #define MAX_VALUE_PPM 20
00049
00050 int main()
00051 {
00052 sensor_msgs::PointCloud2 cloud_blob;
00053 pcl::PointCloud<pcl::PointXYZ> cloud;
00054 pcl::SpinImageEstimation<pcl::PointXYZ, pcl::PointNormal, pcl::SpinImageLocal> s;
00055 pcl::PointCloud<pcl::SpinImageLocal> sil;
00056 std::vector<int> indices;
00057
00058 int sil_indices_array[] = {277816, 205251, 198723, 221146, 271903};
00059 std::vector<int> sil_indices (sil_indices_array, sil_indices_array + sizeof(sil_indices_array) / sizeof(int) );
00060 if (pcl::io::loadPCDFile (PCD_FILE, cloud_blob) == -1)
00061 {
00062 ROS_ERROR ("Couldn't read pcd file.");
00063 return (-1);
00064 }
00065 ROS_INFO ("Loaded %d data points from pcd files", (int)(cloud_blob.width * cloud_blob.height));
00066
00067
00068 pcl::fromROSMsg(cloud_blob, cloud);
00069
00070
00071 pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree;
00072 tree = boost::make_shared<pcl::KdTreeFLANN<pcl::PointXYZ> > ();
00073 tree->setInputCloud (boost::make_shared<pcl::PointCloud<pcl::PointXYZ> > (cloud));
00074
00075
00076 indices.resize(cloud.points.size());
00077 for(size_t i = 0; i < cloud.points.size(); i++)
00078 {
00079 indices[i] = i;
00080 }
00081
00082 pcl::NormalEstimation<pcl::PointXYZ, pcl::PointNormal> n;
00083 pcl::PointCloud<pcl::PointNormal> normals;
00084
00085 n.setInputCloud (boost::make_shared <const pcl::PointCloud<pcl::PointXYZ> > (cloud));
00086 n.setIndices (boost::make_shared <std::vector<int> > (indices));
00087 n.setSearchMethod (tree);
00088 n.setKSearch (30);
00089
00090 n.compute (normals);
00091 ROS_INFO("Normals computed.");
00092
00093
00094
00095 s.setInputNormals(boost::make_shared< pcl::PointCloud<pcl::PointNormal> > (normals));
00096 s.setInputCloud(boost::make_shared< pcl::PointCloud<pcl::PointXYZ> > (cloud));
00097 s.setIndices(boost::make_shared< std::vector<int> > (sil_indices));
00098 s.setSearchMethod(tree);
00099 s.setKSearch(MAX_NN);
00100 s.setNrSubdivisions(SUB_DIVISIONS);
00101 s.setRadius(RADIUS);
00102 s.compute(sil);
00103
00104 ROS_INFO("Spin Image Estimation Complete.");
00105
00106
00107 std::ofstream ppm_file;
00108
00109
00110 for(size_t idx = 0 ; idx < sil_indices.size(); idx++)
00111 {
00112 std::stringstream ss;
00113 ss <<PCD_FILE<<"_"<<sil_indices[idx]<<".ppm";
00114 ppm_file.open((ss.str()).c_str());
00115 ppm_file << "P3"<<std::endl;
00116 ppm_file << "#Point: "<<sil_indices[idx]<<std::endl;
00117 ppm_file << SUB_DIVISIONS*10<<" " <<SUB_DIVISIONS*10<<std::endl;
00118 ppm_file << MAX_VALUE_PPM << std::endl;
00119
00120 for(int row = 0; row < SUB_DIVISIONS; row ++)
00121 {
00122 for(int j = 0; j < 10; j++)
00123 {
00124 for(int col = 0; col < SUB_DIVISIONS; col ++)
00125 {
00126 int i = row*SUB_DIVISIONS + col;
00127 if( sil.points[idx].histogram[i] > MAX_VALUE_PPM)
00128 {
00129 ROS_WARN("Spin Image feature value larger than user defined max value");
00130 sil.points[idx].histogram[i] = MAX_VALUE_PPM;
00131 }
00132 for(int k =0; k < 10; k++)
00133 {
00134 ppm_file<<sil.points[idx].histogram[i] <<" ";
00135 ppm_file<<sil.points[idx].histogram[i] <<" ";
00136 ppm_file<<sil.points[idx].histogram[i] <<" ";
00137 ppm_file<<" ";
00138 }
00139 }
00140
00141 ppm_file << std::endl;
00142 }
00143 }
00144 ppm_file.close();
00145 }
00146 return 0;
00147 }