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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #ifndef __PLANE_EXTRACTION_H__
00056 #define __PLANE_EXTRACTION_H__
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include <pcl/point_types.h>
00066 #include <pcl/point_cloud.h>
00067 #include <pcl/segmentation/sac_segmentation.h>
00068 #include <pcl/filters/extract_indices.h>
00069 #include <pcl/filters/project_inliers.h>
00070 #include <pcl/surface/concave_hull.h>
00071
00072 #include <pcl/segmentation/extract_clusters.h>
00073 #include <Eigen/StdVector>
00074
00075
00076 #include <pcl/common/eigen.h>
00077 #include <pcl/common/centroid.h>
00078 #include <ros/console.h>
00079
00080
00081 enum PlaneConstraint {NONE, HORIZONTAL, VERTICAL};
00082
00083
00084
00085 class PlaneExtraction
00086 {
00087 public:
00088 typedef pcl::PointXYZRGB Point;
00089
00090 PlaneExtraction();
00091
00092
00093 ~PlaneExtraction()
00094 {
00096 }
00097
00098 void
00099 extractPlanes(const pcl::PointCloud<Point>::ConstPtr& pc_in,
00100 std::vector<pcl::PointCloud<Point>, Eigen::aligned_allocator<pcl::PointCloud<Point> > >& v_cloud_hull,
00101 std::vector<std::vector<pcl::Vertices> >& v_hull_polygons,
00102 std::vector<pcl::ModelCoefficients>& v_coefficients_plane);
00103
00104 void
00105 saveHulls(pcl::PointCloud<Point>& cloud_hull,
00106 std::vector< pcl::Vertices >& hull_polygons,
00107 int plane_ctr);
00108
00109 inline void
00110 setPlaneConstraint(PlaneConstraint constr)
00111 {
00112 plane_constraint_ = constr;
00113 }
00114
00115 inline void
00116 setFilePath(std::string file_path)
00117 {
00118 file_path_ = file_path;
00119 }
00120
00121 inline void
00122 setSaveToFile(bool save_to_file)
00123 {
00124 save_to_file_ = save_to_file;
00125 }
00126
00127 inline void
00128 setClusterTolerance (double cluster_tolerance)
00129 {
00130 cluster_tolerance_ = cluster_tolerance;
00131 cluster_.setClusterTolerance (cluster_tolerance);
00132 cluster_plane_.setClusterTolerance (cluster_tolerance);
00133 }
00134
00135 inline void
00136 setMinPlaneSize (unsigned int min_plane_size)
00137 {
00138 min_plane_size_ = min_plane_size;
00139 cluster_.setMinClusterSize (min_plane_size);
00140 cluster_plane_.setMinClusterSize (min_plane_size);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 inline void
00150 setSegmentationParamOptimizeCoefficients (bool optimize_coefficients)
00151 {
00152 seg_.setOptimizeCoefficients (optimize_coefficients);
00153 }
00154
00155 inline void
00156 setSegmentationParamMethodType (int method_type)
00157 {
00158 seg_.setModelType (method_type);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167 inline void
00168 setSegmentationParamMaxIterations (int max_iterations)
00169 {
00170 seg_.setMaxIterations (max_iterations);
00171 }
00172
00173 inline void
00174 setSegmentationParamDistanceThreshold (double threshold)
00175 {
00176 seg_.setDistanceThreshold (threshold);
00177 }
00178
00179 inline void
00180 setAlpha (double alpha)
00181 {
00182 alpha_ = alpha;
00183 chull_.setAlpha (alpha);
00184 }
00185
00186 void
00187 findClosestTable(std::vector<pcl::PointCloud<Point>, Eigen::aligned_allocator<pcl::PointCloud<Point> > >& v_cloud_hull,
00188 std::vector<pcl::ModelCoefficients>& v_coefficients_plane,
00189 Eigen::Vector3f& robot_pose,
00190 unsigned int& idx);
00191
00192
00193 protected:
00201 bool
00202 isValidPlane(const pcl::ModelCoefficients& coefficients_plane);
00203
00211 void
00212 dumpToPCDFileAllPlanes (pcl::PointCloud<Point>::Ptr dominant_plane_ptr);
00213
00214 int ctr_;
00215 std::string file_path_;
00216 bool save_to_file_;
00217 PlaneConstraint plane_constraint_;
00218
00219
00220 double cluster_tolerance_;
00221 unsigned int min_plane_size_;
00222
00223
00224 double radius_;
00225
00226
00227
00228 int max_iterations_;
00229 double distance_threshold_;
00230
00231
00232 double alpha_;
00233
00234 pcl::EuclideanClusterExtraction<Point> cluster_;
00235 pcl::EuclideanClusterExtraction<Point> cluster_plane_;
00236
00237 pcl::SACSegmentation<Point> seg_;
00238 pcl::ExtractIndices<Point> extract_;
00239
00240 pcl::ProjectInliers<Point> proj_;
00241 pcl::ConcaveHull<Point> chull_;
00242
00243 pcl::PointCloud<Point> extracted_planes_;
00244
00245 public:
00246 std::vector<std::vector<int> > extracted_planes_indices_;
00247 };
00248
00249 #endif //__PLANE_EXTRACTION_H__