plane_extraction.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_vision
00012  * ROS package name: cob_env_model
00013  * Description:
00014  *
00015  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00016  *
00017  * Author: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00018  * Supervised by: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de
00019  *
00020  * Date of creation: 08/2011
00021  * ToDo:
00022  *
00023  *
00024  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00025  *
00026  * Redistribution and use in source and binary forms, with or without
00027  * modification, are permitted provided that the following conditions are met:
00028  *
00029  *     * Redistributions of source code must retain the above copyright
00030  *       notice, this list of conditions and the following disclaimer.
00031  *     * Redistributions in binary form must reproduce the above copyright
00032  *       notice, this list of conditions and the following disclaimer in the
00033  *       documentation and/or other materials provided with the distribution.
00034  *     * Neither the name of the Fraunhofer Institute for Manufacturing
00035  *       Engineering and Automation (IPA) nor the names of its
00036  *       contributors may be used to endorse or promote products derived from
00037  *       this software without specific prior written permission.
00038  *
00039  * This program is free software: you can redistribute it and/or modify
00040  * it under the terms of the GNU Lesser General Public License LGPL as
00041  * published by the Free Software Foundation, either version 3 of the
00042  * License, or (at your option) any later version.
00043  *
00044  * This program is distributed in the hope that it will be useful,
00045  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00046  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00047  * GNU Lesser General Public License LGPL for more details.
00048  *
00049  * You should have received a copy of the GNU Lesser General Public
00050  * License LGPL along with this program.
00051  * If not, see <http://www.gnu.org/licenses/>.
00052  *
00053  ****************************************************************/
00054 
00055 #ifndef __PLANE_EXTRACTION_H__
00056 #define __PLANE_EXTRACTION_H__
00057 
00058 //##################
00059 //#### includes ####
00060 
00061 // standard includes
00062 //--
00063 
00064 // ROS includes
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 //#include <pcl/features/normal_3d_omp.h>
00072 #include <pcl/segmentation/extract_clusters.h>
00073 #include <Eigen/StdVector>
00074 
00075 // additional includes
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 //#### nodelet class ####
00085 class PlaneExtraction
00086 {
00087 public:
00088   typedef pcl::PointXYZRGB Point;
00089   // Constructor
00090   PlaneExtraction();
00091 
00092   // Destructor
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   /*inline void
00144   setNormalEstimationParamRadius (double radius)
00145   {
00146     normal_estimator_.setRadiusSearch (radius);
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   /*inline void
00162   setSegmentationParamNormalDistanceWeight (double normal_distance_weight)
00163   {
00164     seg_.setNormalDistanceWeight (normal_distance_weight);
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   //clustering parameters
00220   double cluster_tolerance_;
00221   unsigned int min_plane_size_;
00222 
00223   //Normal Estimation parameters
00224   double radius_;
00225 
00226   //segmentation parameters
00227   //double normal_distance_weight_;
00228   int max_iterations_;
00229   double distance_threshold_;
00230 
00231   //convex hull parameters
00232   double alpha_;
00233 
00234   pcl::EuclideanClusterExtraction<Point> cluster_;
00235   pcl::EuclideanClusterExtraction<Point> cluster_plane_;
00236   //pcl::SACSegmentationFromNormals<Point, pcl::Normal> seg_;
00237   pcl::SACSegmentation<Point> seg_;
00238   pcl::ExtractIndices<Point> extract_;
00239   //pcl::NormalEstimation<Point, pcl::Normal> normal_estimator_;
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__


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