|
Point Cloud Library (PCL)
1.5.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2012, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: sac_segmentation.h 4702 2012-02-23 09:39:33Z gedikli $ 00037 * 00038 */ 00039 00040 #ifndef PCL_SEGMENTATION_SAC_SEGMENTATION_H_ 00041 #define PCL_SEGMENTATION_SAC_SEGMENTATION_H_ 00042 00043 #include "pcl/pcl_base.h" 00044 #include "pcl/PointIndices.h" 00045 #include "pcl/ModelCoefficients.h" 00046 00047 // Sample Consensus methods 00048 #include "pcl/sample_consensus/method_types.h" 00049 #include "pcl/sample_consensus/sac.h" 00050 // Sample Consensus models 00051 #include "pcl/sample_consensus/model_types.h" 00052 #include "pcl/sample_consensus/sac_model.h" 00053 00054 namespace pcl 00055 { 00062 template <typename PointT> 00063 class SACSegmentation : public PCLBase<PointT> 00064 { 00065 using PCLBase<PointT>::initCompute; 00066 using PCLBase<PointT>::deinitCompute; 00067 00068 public: 00069 using PCLBase<PointT>::input_; 00070 using PCLBase<PointT>::indices_; 00071 00072 typedef pcl::PointCloud<PointT> PointCloud; 00073 typedef typename PointCloud::Ptr PointCloudPtr; 00074 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00075 00076 typedef typename SampleConsensus<PointT>::Ptr SampleConsensusPtr; 00077 typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr; 00078 00080 SACSegmentation () : model_type_ (-1), method_type_ (0), optimize_coefficients_ (true), 00081 radius_min_ (-DBL_MAX), radius_max_ (DBL_MAX), eps_angle_ (0.0), 00082 max_iterations_ (50), probability_ (0.99) 00083 { 00084 axis_.setZero (); 00085 //srand ((unsigned)time (0)); // set a random seed 00086 } 00087 00089 virtual ~SACSegmentation () { /*srv_.reset ();*/ }; 00090 00094 inline void 00095 setModelType (int model) { model_type_ = model; } 00096 00098 inline int 00099 getModelType () const { return (model_type_); } 00100 00102 inline SampleConsensusPtr 00103 getMethod () const { return (sac_); } 00104 00106 inline SampleConsensusModelPtr 00107 getModel () const { return (model_); } 00108 00112 inline void 00113 setMethodType (int method) { method_type_ = method; } 00114 00116 inline int 00117 getMethodType () const { return (method_type_); } 00118 00122 inline void 00123 setDistanceThreshold (double threshold) { threshold_ = threshold; } 00124 00126 inline double 00127 getDistanceThreshold () const { return (threshold_); } 00128 00132 inline void 00133 setMaxIterations (int max_iterations) { max_iterations_ = max_iterations; } 00134 00136 inline int 00137 getMaxIterations () const { return (max_iterations_); } 00138 00142 inline void 00143 setProbability (double probability) { probability_ = probability; } 00144 00146 inline double 00147 getProbability () const { return (probability_); } 00148 00152 inline void 00153 setOptimizeCoefficients (bool optimize) { optimize_coefficients_ = optimize; } 00154 00156 inline bool 00157 getOptimizeCoefficients () const { return (optimize_coefficients_); } 00158 00164 inline void 00165 setRadiusLimits (const double &min_radius, const double &max_radius) 00166 { 00167 radius_min_ = min_radius; 00168 radius_max_ = max_radius; 00169 } 00170 00175 inline void 00176 getRadiusLimits (double &min_radius, double &max_radius) 00177 { 00178 min_radius = radius_min_; 00179 max_radius = radius_max_; 00180 } 00181 00185 inline void 00186 setAxis (const Eigen::Vector3f &ax) { axis_ = ax; } 00187 00189 inline Eigen::Vector3f 00190 getAxis () const { return (axis_); } 00191 00195 inline void 00196 setEpsAngle (double ea) { eps_angle_ = ea; } 00197 00199 inline double 00200 getEpsAngle () const { return (eps_angle_); } 00201 00206 virtual void 00207 segment (PointIndices &inliers, ModelCoefficients &model_coefficients); 00208 00209 protected: 00213 virtual bool 00214 initSACModel (const int model_type); 00215 00219 virtual void 00220 initSAC (const int method_type); 00221 00223 SampleConsensusModelPtr model_; 00224 00226 SampleConsensusPtr sac_; 00227 00229 int model_type_; 00230 00232 int method_type_; 00233 00235 double threshold_; 00236 00238 bool optimize_coefficients_; 00239 00241 double radius_min_, radius_max_; 00242 00244 double eps_angle_; 00245 00247 Eigen::Vector3f axis_; 00248 00250 int max_iterations_; 00251 00253 double probability_; 00254 00256 virtual std::string 00257 getClassName () const { return ("SACSegmentation"); } 00258 }; 00259 00264 template <typename PointT, typename PointNT> 00265 class SACSegmentationFromNormals: public SACSegmentation<PointT> 00266 { 00267 using SACSegmentation<PointT>::model_; 00268 using SACSegmentation<PointT>::model_type_; 00269 using SACSegmentation<PointT>::radius_min_; 00270 using SACSegmentation<PointT>::radius_max_; 00271 using SACSegmentation<PointT>::eps_angle_; 00272 using SACSegmentation<PointT>::axis_; 00273 00274 public: 00275 using PCLBase<PointT>::input_; 00276 using PCLBase<PointT>::indices_; 00277 00278 typedef typename SACSegmentation<PointT>::PointCloud PointCloud; 00279 typedef typename PointCloud::Ptr PointCloudPtr; 00280 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00281 00282 typedef typename pcl::PointCloud<PointNT> PointCloudN; 00283 typedef typename PointCloudN::Ptr PointCloudNPtr; 00284 typedef typename PointCloudN::ConstPtr PointCloudNConstPtr; 00285 00286 typedef typename SampleConsensus<PointT>::Ptr SampleConsensusPtr; 00287 typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr; 00288 typedef typename SampleConsensusModelFromNormals<PointT, PointNT>::Ptr SampleConsensusModelFromNormalsPtr; 00289 00291 SACSegmentationFromNormals () : distance_weight_ (0.1) {}; 00292 00297 inline void 00298 setInputNormals (const PointCloudNConstPtr &normals) { normals_ = normals; } 00299 00301 inline PointCloudNConstPtr 00302 getInputNormals () const { return (normals_); } 00303 00308 inline void 00309 setNormalDistanceWeight (double distance_weight) { distance_weight_ = distance_weight; } 00310 00313 inline double 00314 getNormalDistanceWeight () const { return (distance_weight_); } 00315 00319 inline void 00320 setDistanceFromOrigin (const double d) { distance_from_origin_ = d; } 00321 00323 inline double 00324 getDistanceFromOrigin () const { return (distance_from_origin_); } 00325 00326 protected: 00328 PointCloudNConstPtr normals_; 00329 00333 double distance_weight_; 00334 00336 double distance_from_origin_; 00337 00341 virtual bool 00342 initSACModel (const int model_type); 00343 00345 virtual std::string 00346 getClassName () const { return ("SACSegmentationFromNormals"); } 00347 }; 00348 } 00349 00350 #endif //#ifndef PCL_SEGMENTATION_SAC_SEGMENTATION_H_
1.8.0