00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 * $Id$ 00038 * 00039 */ 00040 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_ 00041 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_ 00042 00043 #include <pcl/registration/correspondence_rejection.h> 00044 00045 #include <pcl/sample_consensus/ransac.h> 00046 #include <pcl/sample_consensus/sac_model_registration.h> 00047 #include <pcl/common/transforms.h> 00048 00049 namespace pcl 00050 { 00051 namespace registration 00052 { 00053 /** \brief CorrespondenceRejectorSampleConsensus implements a correspondence rejection 00054 * using Random Sample Consensus to identify inliers (and reject outliers) 00055 * \author Dirk Holz 00056 * \ingroup registration 00057 */ 00058 template <typename PointT> 00059 class CorrespondenceRejectorSampleConsensus: public CorrespondenceRejector 00060 { 00061 typedef pcl::PointCloud<PointT> PointCloud; 00062 typedef typename PointCloud::Ptr PointCloudPtr; 00063 typedef typename PointCloud::ConstPtr PointCloudConstPtr; 00064 00065 public: 00066 using CorrespondenceRejector::input_correspondences_; 00067 using CorrespondenceRejector::rejection_name_; 00068 using CorrespondenceRejector::getClassName; 00069 00070 typedef boost::shared_ptr<CorrespondenceRejectorSampleConsensus> Ptr; 00071 typedef boost::shared_ptr<const CorrespondenceRejectorSampleConsensus> ConstPtr; 00072 00073 /** \brief Empty constructor. Sets the inlier threshold to 5cm (0.05m), 00074 * and the maximum number of iterations to 1000. 00075 */ 00076 CorrespondenceRejectorSampleConsensus () 00077 : inlier_threshold_ (0.05) 00078 , max_iterations_ (1000) // std::numeric_limits<int>::max () 00079 , input_ () 00080 , input_transformed_ () 00081 , target_ () 00082 , best_transformation_ () 00083 , refine_ (false) 00084 , save_inliers_ (false) 00085 { 00086 rejection_name_ = "CorrespondenceRejectorSampleConsensus"; 00087 } 00088 00089 /** \brief Empty destructor. */ 00090 virtual ~CorrespondenceRejectorSampleConsensus () {} 00091 00092 /** \brief Get a list of valid correspondences after rejection from the original set of correspondences. 00093 * \param[in] original_correspondences the set of initial correspondences given 00094 * \param[out] remaining_correspondences the resultant filtered set of remaining correspondences 00095 */ 00096 inline void 00097 getRemainingCorrespondences (const pcl::Correspondences& original_correspondences, 00098 pcl::Correspondences& remaining_correspondences); 00099 00100 /** \brief Provide a source point cloud dataset (must contain XYZ data!) 00101 * \param[in] cloud a cloud containing XYZ data 00102 */ 00103 PCL_DEPRECATED (virtual void setInputCloud (const PointCloudConstPtr &cloud), 00104 "[pcl::registration::CorrespondenceRejectorSampleConsensus::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead."); 00105 00106 /** \brief Get a pointer to the input point cloud dataset target. */ 00107 PCL_DEPRECATED (PointCloudConstPtr const getInputCloud (), "[pcl::registration::CorrespondenceRejectorSampleConsensus::getInputCloud] getInputCloud is deprecated. Please use getInputSource instead."); 00108 00109 /** \brief Provide a source point cloud dataset (must contain XYZ data!) 00110 * \param[in] cloud a cloud containing XYZ data 00111 */ 00112 virtual inline void 00113 setInputSource (const PointCloudConstPtr &cloud) 00114 { 00115 input_ = cloud; 00116 } 00117 00118 /** \brief Get a pointer to the input point cloud dataset target. */ 00119 inline PointCloudConstPtr const 00120 getInputSource () { return (input_); } 00121 00122 /** \brief Provide a target point cloud dataset (must contain XYZ data!) 00123 * \param[in] cloud a cloud containing XYZ data 00124 */ 00125 PCL_DEPRECATED (virtual void setTargetCloud (const PointCloudConstPtr &cloud), "[pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetCloud] setTargetCloud is deprecated. Please use setInputTarget instead."); 00126 00127 /** \brief Provide a target point cloud dataset (must contain XYZ data!) 00128 * \param[in] cloud a cloud containing XYZ data 00129 */ 00130 virtual inline void 00131 setInputTarget (const PointCloudConstPtr &cloud) { target_ = cloud; } 00132 00133 /** \brief Get a pointer to the input point cloud dataset target. */ 00134 inline PointCloudConstPtr const 00135 getInputTarget () { return (target_ ); } 00136 00137 /** \brief Set the maximum distance between corresponding points. 00138 * Correspondences with distances below the threshold are considered as inliers. 00139 * \param[in] threshold Distance threshold in the same dimension as source and target data sets. 00140 */ 00141 inline void 00142 setInlierThreshold (double threshold) { inlier_threshold_ = threshold; }; 00143 00144 /** \brief Get the maximum distance between corresponding points. 00145 * \return Distance threshold in the same dimension as source and target data sets. 00146 */ 00147 inline double 00148 getInlierThreshold() { return inlier_threshold_; }; 00149 00150 /** \brief Set the maximum number of iterations. 00151 * \param[in] max_iterations Maximum number if iterations to run 00152 */ 00153 PCL_DEPRECATED (void setMaxIterations (int max_iterations), "[pcl::registration::CorrespondenceRejectorSampleConsensus::setMaxIterations] setMaxIterations is deprecated. Please use setMaximumIterations instead."); 00154 00155 /** \brief Set the maximum number of iterations. 00156 * \param[in] max_iterations Maximum number if iterations to run 00157 */ 00158 inline void 00159 setMaximumIterations (int max_iterations) { max_iterations_ = std::max (max_iterations, 0); } 00160 00161 /** \brief Get the maximum number of iterations. 00162 * \return max_iterations Maximum number if iterations to run 00163 */ 00164 PCL_DEPRECATED (int getMaxIterations (), "[pcl::registration::CorrespondenceRejectorSampleConsensus::getMaxIterations] getMaxIterations is deprecated. Please use getMaximumIterations instead."); 00165 00166 /** \brief Get the maximum number of iterations. 00167 * \return max_iterations Maximum number if iterations to run 00168 */ 00169 inline int 00170 getMaximumIterations () { return (max_iterations_); } 00171 00172 /** \brief Get the best transformation after RANSAC rejection. 00173 * \return The homogeneous 4x4 transformation yielding the largest number of inliers. 00174 */ 00175 inline Eigen::Matrix4f 00176 getBestTransformation () { return best_transformation_; }; 00177 00178 /** \brief Specify whether the model should be refined internally using the variance of the inliers 00179 * \param[in] refine true if the model should be refined, false otherwise 00180 */ 00181 inline void 00182 setRefineModel (const bool refine) 00183 { 00184 refine_ = refine; 00185 } 00186 00187 /** \brief Get the internal refine parameter value as set by the user using setRefineModel */ 00188 inline bool 00189 getRefineModel () const 00190 { 00191 return (refine_); 00192 } 00193 00194 /** \brief Get the inlier indices found by the correspondence rejector. This information is only saved if setSaveInliers(true) was called in advance. 00195 * \param[out] inlier_indices Indices for the inliers 00196 */ 00197 inline void 00198 getInliersIndices (std::vector<int> &inlier_indices) { inlier_indices = inlier_indices_; } 00199 00200 /** \brief Set whether to save inliers or not 00201 * \param[in] s True to save inliers / False otherwise 00202 */ 00203 inline void 00204 setSaveInliers (bool s) { save_inliers_ = s; } 00205 00206 /** \brief Get whether the rejector is configured to save inliers */ 00207 inline bool 00208 getSaveInliers () { return save_inliers_; } 00209 00210 00211 protected: 00212 00213 /** \brief Apply the rejection algorithm. 00214 * \param[out] correspondences the set of resultant correspondences. 00215 */ 00216 inline void 00217 applyRejection (pcl::Correspondences &correspondences) 00218 { 00219 getRemainingCorrespondences (*input_correspondences_, correspondences); 00220 } 00221 00222 double inlier_threshold_; 00223 00224 int max_iterations_; 00225 00226 PointCloudConstPtr input_; 00227 PointCloudPtr input_transformed_; 00228 PointCloudConstPtr target_; 00229 00230 Eigen::Matrix4f best_transformation_; 00231 00232 bool refine_; 00233 std::vector<int> inlier_indices_; 00234 bool save_inliers_; 00235 00236 public: 00237 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00238 }; 00239 } 00240 } 00241 00242 #include <pcl/registration/impl/correspondence_rejection_sample_consensus.hpp> 00243 00244 #endif // PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
Pages generated on Wed Mar 25 00:24:55 2015