Go to the documentation of this file.00001
00063
00064
00065 #ifdef PCL_MINOR_VERSION >= 6
00066
00067 #include <pcl/point_types.h>
00068 #include <pcl/io/pcd_io.h>
00069 #include <pcl/common/file_io.h>
00070 #include <pcl/search/organized.h>
00071 #include <pcl/features/integral_image_normal.h>
00072 #include <pcl/segmentation/organized_multi_plane_segmentation.h>
00073 #include <pcl/segmentation/edge_aware_plane_comparator.h>
00074
00075
00076 #include "cob_3d_mapping_common/stop_watch.h"
00077 #include "cob_3d_mapping_common/point_types.h"
00078
00079
00080 typedef pcl::PointXYZRGB PointT;
00081 typedef pcl::Normal NormalT;
00082 typedef pcl::Label LabelT;
00083
00084 class PerformanceTester
00085 {
00086 public:
00087 PerformanceTester()
00088 : n(new pcl::PointCloud<NormalT>)
00089 , l(new pcl::PointCloud<LabelT>)
00090 {
00091 ne.setNormalEstimationMethod(ne.COVARIANCE_MATRIX);
00092 ne.setMaxDepthChangeFactor(0.02f);
00093 ne.setNormalSmoothingSize(40.0f);
00094
00095 omps.setAngularThreshold(5.0f/180.0f*M_PI);
00096 omps.setMaximumCurvature(0.1);
00097 omps.setDistanceThreshold(0.02f);
00098 omps.setMinInliers(100);
00099 }
00100
00101 void
00102 computeForOneCloud(pcl::PointCloud<PointT>::ConstPtr cloud)
00103 {
00104 PrecisionStopWatch t;
00105 t.precisionStart();
00106 ne.setInputCloud(cloud);
00107 ne.compute(*n);
00108 distance_map = ne.getDistanceMap();
00109 std::cout << t.precisionStop() << " | ";
00110
00111 t.precisionStart();
00112 comparator.reset(new pcl::EdgeAwarePlaneComparator<PointT, NormalT>(distance_map));
00113 omps.setComparator(comparator);
00114 omps.setInputCloud(cloud);
00115 omps.setInputNormals(n);
00116 omps.segmentAndRefine(regions, coef, inlier_indices, l, label_indices, boundary_indices);
00117 std::cout << t.precisionStop() << std::endl;
00118
00119 coef.clear();
00120 regions.clear();
00121 inlier_indices.clear();
00122 label_indices.clear();
00123 boundary_indices.clear();
00124 l.reset(new pcl::PointCloud<LabelT>);
00125 }
00126
00127 private:
00128 pcl::PointCloud<NormalT>::Ptr n;
00129 pcl::PointCloud<pcl::Label>::Ptr l;
00130 std::vector<pcl::PlanarRegion<PointT>, Eigen::aligned_allocator<pcl::PlanarRegion<PointT> > > regions;
00131 std::vector<pcl::ModelCoefficients> coef;
00132 std::vector<pcl::PointIndices> inlier_indices;
00133 std::vector<pcl::PointIndices> label_indices;
00134 std::vector<pcl::PointIndices> boundary_indices;
00135
00136 pcl::IntegralImageNormalEstimation<PointT, NormalT> ne;
00137 float* distance_map;
00138 pcl::OrganizedMultiPlaneSegmentation<PointT, NormalT, LabelT> omps;
00139 pcl::EdgeAwarePlaneComparator<PointT, NormalT>::Ptr comparator;
00140
00141 };
00142
00143 int main (int argc, char** argv)
00144 {
00145 if (argc != 2)
00146 {
00147 std::cout << "Please provide a folder containing multiple pcd files" << std::endl;
00148 return 0;
00149 }
00150
00151 PerformanceTester pt;
00152 pcl::PCDReader r;
00153 std::vector<std::string> files;
00154 pcl::getAllPcdFilesInDirectory(argv[1], files);
00155 std::vector<pcl::PointCloud<PointT>::Ptr> clouds;
00156 for (std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it)
00157 {
00158 clouds.push_back(pcl::PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>));
00159 r.read( argv[1] + *it, *(clouds.back()) );
00160 }
00161
00162 int i = 0;
00163 while (i < 20)
00164 {
00165 std::vector<pcl::PointCloud<PointT>::Ptr>::iterator p = clouds.begin();
00166 std::cout << "Run #"<< i << std::endl;
00167 while(p != clouds.end())
00168 {
00169 pt.computeForOneCloud(*p);
00170 ++p;
00171 }
00172 ++i;
00173 }
00174
00175 return 0;
00176 }
00177
00178 #else
00179
00180 #include <iostream>
00181 int main (int argc, char** argv)
00182 {
00183 std::cout << "not supported by PCL older than 1.7" << std::endl;
00184 }
00185
00186 #endif