Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2009, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id: sac_segmentation.h 1370 2011-06-19 01:06:01Z jspricke $ 00035 * 00036 */ 00037 00038 #ifndef PCL_SEGMENTATION_SAC_SEGMENTATION_H_ 00039 #define PCL_SEGMENTATION_SAC_SEGMENTATION_H_ 00040 00041 #include "pcl/pcl_base.h" 00042 #include "pcl/PointIndices.h" 00043 #include "pcl/ModelCoefficients.h" 00044 00045 // Sample Consensus methods 00046 #include "pcl/sample_consensus/sac.h" 00047 // Sample Consensus models 00048 #include "pcl/sample_consensus/sac_model.h" 00049 00050 namespace pcl 00051 { 00058 template <typename PointT> 00059 class SACSegmentation : public PCLBase<PointT> 00060 { 00061 using PCLBase<PointT>::initCompute; 00062 using PCLBase<PointT>::deinitCompute; 00063 00064 public: 00065 using PCLBase<PointT>::input_; 00066 using PCLBase<PointT>::indices_; 00067 00068 typedef pcl::PointCloud<PointT> PointCloud; 00069 typedef typename PointCloud::Ptr PointCloudPtr; 00070 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00071 00072 typedef typename SampleConsensus<PointT>::Ptr SampleConsensusPtr; 00073 typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr; 00074 00076 SACSegmentation () : model_type_ (-1), method_type_ (0), optimize_coefficients_ (true), 00077 radius_min_ (-DBL_MAX), radius_max_ (DBL_MAX), eps_angle_ (0.0), 00078 max_iterations_ (50), probability_ (0.99) 00079 { 00080 axis_.setZero (); 00081 //srand ((unsigned)time (0)); // set a random seed 00082 } 00083 00085 virtual ~SACSegmentation () { /*srv_.reset ();*/ }; 00086 00090 inline void setModelType (int model) { model_type_ = model; } 00091 00093 inline int 00094 getModelType () { return (model_type_); } 00095 00097 inline SampleConsensusPtr 00098 getMethod () { return (sac_); } 00099 00101 inline SampleConsensusModelPtr 00102 getModel () { return (model_); } 00103 00107 inline void 00108 setMethodType (int method) { method_type_ = method; } 00109 00111 inline int 00112 getMethodType () { return (method_type_); } 00113 00117 inline void 00118 setDistanceThreshold (double threshold) { threshold_ = threshold; } 00119 00121 inline double 00122 getDistanceThreshold () { return (threshold_); } 00123 00127 inline void 00128 setMaxIterations (int max_iterations) { max_iterations_ = max_iterations; } 00129 00131 inline int 00132 getMaxIterations () { return (max_iterations_); } 00133 00137 inline void 00138 setProbability (double probability) { probability_ = probability; } 00139 00141 inline double 00142 getProbability () { return (probability_); } 00143 00147 inline void 00148 setOptimizeCoefficients (bool optimize) { optimize_coefficients_ = optimize; } 00149 00151 inline bool 00152 getOptimizeCoefficients () { return (optimize_coefficients_); } 00153 00160 inline void 00161 setRadiusLimits (const double &min_radius, const double &max_radius) 00162 { 00163 radius_min_ = min_radius; 00164 radius_max_ = max_radius; 00165 } 00166 00171 inline void 00172 getRadiusLimits (double &min_radius, double &max_radius) 00173 { 00174 min_radius = radius_min_; 00175 max_radius = radius_max_; 00176 } 00177 00181 inline void 00182 setAxis (const Eigen::Vector3f &ax) { axis_ = ax; } 00183 00185 inline Eigen::Vector3f 00186 getAxis () { return (axis_); } 00187 00191 inline void 00192 setEpsAngle (double ea) { eps_angle_ = ea; } 00193 00195 inline double 00196 getEpsAngle () { return (eps_angle_); } 00197 00202 virtual void 00203 segment (PointIndices &inliers, ModelCoefficients &model_coefficients); 00204 00205 protected: 00209 virtual bool 00210 initSACModel (const int model_type); 00211 00215 virtual void 00216 initSAC (const int method_type); 00217 00219 SampleConsensusModelPtr model_; 00220 00222 SampleConsensusPtr sac_; 00223 00225 int model_type_; 00226 00228 int method_type_; 00229 00231 double threshold_; 00232 00234 bool optimize_coefficients_; 00235 00237 double radius_min_, radius_max_; 00238 00240 double eps_angle_; 00241 00243 Eigen::Vector3f axis_; 00244 00246 int max_iterations_; 00247 00249 double probability_; 00250 00252 virtual std::string 00253 getClassName () const { return ("SACSegmentation"); } 00254 }; 00255 00260 template <typename PointT, typename PointNT> 00261 class SACSegmentationFromNormals: public SACSegmentation<PointT> 00262 { 00263 using SACSegmentation<PointT>::model_; 00264 using SACSegmentation<PointT>::model_type_; 00265 using SACSegmentation<PointT>::radius_min_; 00266 using SACSegmentation<PointT>::radius_max_; 00267 using SACSegmentation<PointT>::eps_angle_; 00268 using SACSegmentation<PointT>::axis_; 00269 00270 public: 00271 using PCLBase<PointT>::input_; 00272 using PCLBase<PointT>::indices_; 00273 00274 typedef typename SACSegmentation<PointT>::PointCloud PointCloud; 00275 typedef typename PointCloud::Ptr PointCloudPtr; 00276 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00277 00278 typedef typename pcl::PointCloud<PointNT> PointCloudN; 00279 typedef typename PointCloudN::Ptr PointCloudNPtr; 00280 typedef typename PointCloudN::ConstPtr PointCloudNConstPtr; 00281 00282 typedef typename SampleConsensus<PointT>::Ptr SampleConsensusPtr; 00283 typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr; 00284 typedef typename SampleConsensusModelFromNormals<PointT, PointNT>::Ptr SampleConsensusModelFromNormalsPtr; 00285 00287 SACSegmentationFromNormals () : distance_weight_ (0.1) {}; 00288 00293 inline void 00294 setInputNormals (const PointCloudNConstPtr &normals) { normals_ = normals; } 00295 00297 inline PointCloudNConstPtr 00298 getInputNormals () { return (normals_); } 00299 00304 inline void 00305 setNormalDistanceWeight (double distance_weight) { distance_weight_ = distance_weight; } 00306 00309 inline double 00310 getNormalDistanceWeight () { return (distance_weight_); } 00311 00312 protected: 00314 PointCloudNConstPtr normals_; 00315 00319 double distance_weight_; 00320 00324 virtual bool 00325 initSACModel (const int model_type); 00326 00328 virtual std::string 00329 getClassName () const { return ("SACSegmentationFromNormals"); } 00330 }; 00331 } 00332 00333 #endif //#ifndef PCL_SEGMENTATION_SAC_SEGMENTATION_H_