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
00036
00037
00038
00039
00040 #include <gtest/gtest.h>
00041 #include <pcl/point_cloud.h>
00042 #include <pcl/features/normal_3d.h>
00043 #include <pcl/features/cvfh.h>
00044 #include <pcl/io/pcd_io.h>
00045 #include <pcl/filters/voxel_grid.h>
00046
00047 using namespace pcl;
00048 using namespace pcl::io;
00049 using namespace std;
00050
00051 typedef search::KdTree<PointXYZ>::Ptr KdTreePtr;
00052 typedef PointCloud<PointXYZ>::Ptr CloudPtr;
00053
00054 PointCloud<PointXYZ> cloud;
00055 vector<int> indices;
00056 KdTreePtr tree;
00057
00058 CloudPtr cloud_milk;
00059 KdTreePtr tree_milk;
00060 float leaf_size_ = 0.005f;
00061
00063 TEST (PCL, CVFHEstimation)
00064 {
00065
00066 NormalEstimation<PointXYZ, Normal> n;
00067 PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
00068
00069 n.setInputCloud (cloud.makeShared ());
00070 boost::shared_ptr<vector<int> > indicesptr (new vector<int> (indices));
00071 n.setIndices (indicesptr);
00072 n.setSearchMethod (tree);
00073 n.setKSearch (10);
00074
00075 n.compute (*normals);
00076 CVFHEstimation<PointXYZ, Normal, VFHSignature308> cvfh;
00077 cvfh.setInputNormals (normals);
00078
00079
00080 PointCloud<VFHSignature308>::Ptr vfhs (new PointCloud<VFHSignature308> ());
00081
00082
00083 cvfh.setInputCloud (cloud.makeShared ());
00084 cvfh.setIndices (indicesptr);
00085 cvfh.setSearchMethod (tree);
00086
00087
00088 cvfh.compute (*vfhs);
00089 EXPECT_EQ (static_cast<int>(vfhs->points.size ()), 1);
00090 }
00091
00093 TEST (PCL, CVFHEstimationMilk)
00094 {
00095
00096
00097 NormalEstimation<PointXYZ, Normal> n;
00098 PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
00099 n.setInputCloud (cloud_milk);
00100 n.setSearchMethod (tree);
00101 n.setRadiusSearch (leaf_size_ * 4);
00102 n.compute (*normals);
00103
00104 CVFHEstimation<PointXYZ, Normal, VFHSignature308> cvfh;
00105 cvfh.setInputCloud (cloud_milk);
00106 cvfh.setInputNormals (normals);
00107 cvfh.setSearchMethod (tree_milk);
00108 cvfh.setClusterTolerance (leaf_size_ * 3);
00109 cvfh.setEPSAngleThreshold (0.13f);
00110 cvfh.setCurvatureThreshold (0.025f);
00111 cvfh.setNormalizeBins (false);
00112 cvfh.setRadiusNormals (leaf_size_ * 4);
00113
00114
00115 PointCloud<VFHSignature308>::Ptr vfhs (new PointCloud<VFHSignature308> ());
00116
00117
00118 cvfh.compute (*vfhs);
00119 EXPECT_EQ (static_cast<int>(vfhs->points.size ()), 2);
00120 }
00121
00122
00123 int
00124 main (int argc, char** argv)
00125 {
00126 if (argc < 3)
00127 {
00128 std::cerr << "No test file given. Please download `bun0.pcd` and `milk.pcd` pass its path to the test." << std::endl;
00129 return (-1);
00130 }
00131
00132 if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0)
00133 {
00134 std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00135 return (-1);
00136 }
00137
00138 CloudPtr milk_loaded(new PointCloud<PointXYZ>());
00139 if (loadPCDFile<PointXYZ> (argv[2], *milk_loaded) < 0)
00140 {
00141 std::cerr << "Failed to read test file. Please download `milk.pcd` and pass its path to the test." << std::endl;
00142 return (-1);
00143 }
00144
00145 indices.resize (cloud.points.size ());
00146 for (size_t i = 0; i < indices.size (); ++i)
00147 {
00148 indices[i] = static_cast<int>(i);
00149 }
00150
00151 tree.reset (new search::KdTree<PointXYZ> (false));
00152 tree->setInputCloud (cloud.makeShared ());
00153
00154 cloud_milk.reset(new PointCloud<PointXYZ>());
00155 CloudPtr grid;
00156 pcl::VoxelGrid < pcl::PointXYZ > grid_;
00157 grid_.setInputCloud (milk_loaded);
00158 grid_.setLeafSize (leaf_size_, leaf_size_, leaf_size_);
00159 grid_.filter (*cloud_milk);
00160
00161 tree_milk.reset (new search::KdTree<PointXYZ> (false));
00162 tree_milk->setInputCloud (cloud_milk);
00163
00164 testing::InitGoogleTest (&argc, argv);
00165 return (RUN_ALL_TESTS ());
00166 }
00167