plane_extraction.h
Go to the documentation of this file.
00001 
00063 #ifndef __PLANE_EXTRACTION_H__
00064 #define __PLANE_EXTRACTION_H__
00065 
00066 //##################
00067 //#### includes ####
00068 
00069 // standard includes
00070 //--
00071 
00072 // ROS includes
00073 #include <pcl/point_types.h>
00074 #include <pcl/point_cloud.h>
00075 #include <pcl/segmentation/sac_segmentation.h>
00076 #include <pcl/filters/extract_indices.h>
00077 #include <pcl/filters/project_inliers.h>
00078 #include <pcl/surface/concave_hull.h>
00079 //#include <pcl/features/normal_3d_omp.h>
00080 #include <pcl/segmentation/extract_clusters.h>
00081 #include <Eigen/StdVector>
00082 
00083 // additional includes
00084 #include <pcl/common/eigen.h>
00085 #include <pcl/common/centroid.h>
00086 #include <ros/console.h>
00087 
00088 
00089 enum PlaneConstraint {NONE, HORIZONTAL, VERTICAL};
00090 
00091 //####################
00092 //#### nodelet class ####
00093 class PlaneExtraction
00094 {
00095 public:
00096   typedef pcl::PointXYZRGB Point;
00097   // Constructor
00098   PlaneExtraction();
00099 
00100   // Destructor
00101   ~PlaneExtraction()
00102   {
00104   }
00105 
00106   void
00107   extractPlanes(const pcl::PointCloud<Point>::ConstPtr& pc_in,
00108                 std::vector<pcl::PointCloud<Point>, Eigen::aligned_allocator<pcl::PointCloud<Point> > >& v_cloud_hull,
00109                 std::vector<std::vector<pcl::Vertices> >& v_hull_polygons,
00110                 std::vector<pcl::ModelCoefficients>& v_coefficients_plane);
00111 
00112   void
00113   saveHulls(pcl::PointCloud<Point>& cloud_hull,
00114             std::vector< pcl::Vertices >& hull_polygons,
00115             int plane_ctr);
00116 
00117   inline void
00118   setPlaneConstraint(PlaneConstraint constr)
00119   {
00120     plane_constraint_ = constr;
00121   }
00122 
00123   inline void
00124   setFilePath(std::string file_path)
00125   {
00126     file_path_ = file_path;
00127   }
00128 
00129   inline void
00130   setSaveToFile(bool save_to_file)
00131   {
00132     save_to_file_ = save_to_file;
00133   }
00134 
00135   inline void
00136   setClusterTolerance (double cluster_tolerance)
00137   {
00138     cluster_tolerance_ = cluster_tolerance;
00139     cluster_.setClusterTolerance (cluster_tolerance);
00140     cluster_plane_.setClusterTolerance (cluster_tolerance);
00141   }
00142 
00143   inline void
00144   setMinPlaneSize (unsigned int min_plane_size)
00145   {
00146     min_plane_size_ = min_plane_size;
00147     cluster_.setMinClusterSize (min_plane_size);
00148     cluster_plane_.setMinClusterSize (min_plane_size);
00149   }
00150 
00151   /*inline void
00152   setNormalEstimationParamRadius (double radius)
00153   {
00154     normal_estimator_.setRadiusSearch (radius);
00155   }*/
00156 
00157   inline void
00158   setSegmentationParamOptimizeCoefficients (bool optimize_coefficients)
00159   {
00160     seg_.setOptimizeCoefficients (optimize_coefficients);
00161   }
00162 
00163   inline void
00164   setSegmentationParamMethodType (int method_type)
00165   {
00166     seg_.setModelType (method_type);
00167   }
00168 
00169   /*inline void
00170   setSegmentationParamNormalDistanceWeight (double normal_distance_weight)
00171   {
00172     seg_.setNormalDistanceWeight (normal_distance_weight);
00173   }*/
00174 
00175   inline void
00176   setSegmentationParamMaxIterations (int max_iterations)
00177   {
00178     seg_.setMaxIterations (max_iterations);
00179   }
00180 
00181   inline void
00182   setSegmentationParamDistanceThreshold (double threshold)
00183   {
00184     seg_.setDistanceThreshold (threshold);
00185   }
00186 
00187   inline void
00188   setAlpha (double alpha)
00189   {
00190     alpha_ = alpha;
00191     chull_.setAlpha (alpha);
00192   }
00193 
00194   void
00195   findClosestTable(std::vector<pcl::PointCloud<Point>, Eigen::aligned_allocator<pcl::PointCloud<Point> > >& v_cloud_hull,
00196                    std::vector<pcl::ModelCoefficients>& v_coefficients_plane,
00197                    Eigen::Vector3f& robot_pose,
00198                    unsigned int& idx);
00199 
00200 
00201 protected:
00209   bool
00210   isValidPlane(const pcl::ModelCoefficients& coefficients_plane);
00211 
00219   void
00220   dumpToPCDFileAllPlanes (pcl::PointCloud<Point>::Ptr dominant_plane_ptr);
00221 
00222   int ctr_;
00223   std::string file_path_;
00224   bool save_to_file_;
00225   PlaneConstraint plane_constraint_;
00226 
00227   //clustering parameters
00228   double cluster_tolerance_;
00229   unsigned int min_plane_size_;
00230 
00231   //Normal Estimation parameters
00232   double radius_;
00233 
00234   //segmentation parameters
00235   //double normal_distance_weight_;
00236   int max_iterations_;
00237   double distance_threshold_;
00238 
00239   //convex hull parameters
00240   double alpha_;
00241 
00242   pcl::EuclideanClusterExtraction<Point> cluster_;
00243   pcl::EuclideanClusterExtraction<Point> cluster_plane_;
00244   //pcl::SACSegmentationFromNormals<Point, pcl::Normal> seg_;
00245   pcl::SACSegmentation<Point> seg_;
00246   pcl::ExtractIndices<Point> extract_;
00247   //pcl::NormalEstimation<Point, pcl::Normal> normal_estimator_;
00248   pcl::ProjectInliers<Point> proj_;
00249   pcl::ConcaveHull<Point> chull_;
00250 
00251   pcl::PointCloud<Point> extracted_planes_;
00252 
00253 public:
00254   std::vector<std::vector<int> > extracted_planes_indices_;
00255 };
00256 
00257 #endif //__PLANE_EXTRACTION_H__


cob_3d_segmentation
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:03:03