sample_consensus_prerejective.h
Go to the documentation of this file.
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  *  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 
00041 #ifndef PCL_REGISTRATION_SAMPLE_CONSENSUS_PREREJECTIVE_H_
00042 #define PCL_REGISTRATION_SAMPLE_CONSENSUS_PREREJECTIVE_H_
00043 
00044 #include <pcl/registration/registration.h>
00045 #include <pcl/registration/transformation_estimation_svd.h>
00046 #include <pcl/registration/transformation_validation.h>
00047 #include <pcl/registration/correspondence_rejection_poly.h>
00048 
00049 namespace pcl
00050 {
00076   template <typename PointSource, typename PointTarget, typename FeatureT>
00077   class SampleConsensusPrerejective : public Registration<PointSource, PointTarget>
00078   {
00079     public:
00080       typedef typename Registration<PointSource, PointTarget>::Matrix4 Matrix4;
00081       
00082       using Registration<PointSource, PointTarget>::reg_name_;
00083       using Registration<PointSource, PointTarget>::getClassName;
00084       using Registration<PointSource, PointTarget>::input_;
00085       using Registration<PointSource, PointTarget>::target_;
00086       using Registration<PointSource, PointTarget>::tree_;
00087       using Registration<PointSource, PointTarget>::max_iterations_;
00088       using Registration<PointSource, PointTarget>::corr_dist_threshold_;
00089       using Registration<PointSource, PointTarget>::transformation_;
00090       using Registration<PointSource, PointTarget>::final_transformation_;
00091       using Registration<PointSource, PointTarget>::transformation_estimation_;
00092       using Registration<PointSource, PointTarget>::getFitnessScore;
00093       using Registration<PointSource, PointTarget>::converged_;
00094 
00095       typedef typename Registration<PointSource, PointTarget>::PointCloudSource PointCloudSource;
00096       typedef typename PointCloudSource::Ptr PointCloudSourcePtr;
00097       typedef typename PointCloudSource::ConstPtr PointCloudSourceConstPtr;
00098 
00099       typedef typename Registration<PointSource, PointTarget>::PointCloudTarget PointCloudTarget;
00100 
00101       typedef PointIndices::Ptr PointIndicesPtr;
00102       typedef PointIndices::ConstPtr PointIndicesConstPtr;
00103 
00104       typedef pcl::PointCloud<FeatureT> FeatureCloud;
00105       typedef typename FeatureCloud::Ptr FeatureCloudPtr;
00106       typedef typename FeatureCloud::ConstPtr FeatureCloudConstPtr;
00107 
00108       typedef boost::shared_ptr<SampleConsensusPrerejective<PointSource, PointTarget, FeatureT> > Ptr;
00109       typedef boost::shared_ptr<const SampleConsensusPrerejective<PointSource, PointTarget, FeatureT> > ConstPtr;
00110 
00111       typedef typename KdTreeFLANN<FeatureT>::Ptr FeatureKdTreePtr;
00112       
00113       typedef pcl::registration::CorrespondenceRejectorPoly<PointSource, PointTarget> CorrespondenceRejectorPoly;
00114       typedef typename CorrespondenceRejectorPoly::Ptr CorrespondenceRejectorPolyPtr;
00115       typedef typename CorrespondenceRejectorPoly::ConstPtr CorrespondenceRejectorPolyConstPtr;
00116       
00118       SampleConsensusPrerejective ()
00119         : input_features_ ()
00120         , target_features_ ()
00121         , nr_samples_(3)
00122         , k_correspondences_ (2)
00123         , feature_tree_ (new pcl::KdTreeFLANN<FeatureT>)
00124         , correspondence_rejector_poly_ (new CorrespondenceRejectorPoly)
00125         , inlier_fraction_ (0.0f)
00126       {
00127         reg_name_ = "SampleConsensusPrerejective";
00128         correspondence_rejector_poly_->setSimilarityThreshold (0.6f);
00129         max_iterations_ = 5000;
00130         transformation_estimation_.reset (new pcl::registration::TransformationEstimationSVD<PointSource, PointTarget>);
00131       };
00132       
00134       virtual ~SampleConsensusPrerejective ()
00135       {
00136       }
00137 
00141       void 
00142       setSourceFeatures (const FeatureCloudConstPtr &features);
00143 
00145       inline const FeatureCloudConstPtr
00146       getSourceFeatures () const
00147       { 
00148         return (input_features_);
00149       }
00150 
00154       void 
00155       setTargetFeatures (const FeatureCloudConstPtr &features);
00156 
00158       inline const FeatureCloudConstPtr 
00159       getTargetFeatures () const
00160       {
00161         return (target_features_);
00162       }
00163 
00167       inline void 
00168       setNumberOfSamples (int nr_samples)
00169       {
00170         nr_samples_ = nr_samples;
00171       }
00172 
00174       inline int 
00175       getNumberOfSamples () const
00176       {
00177         return (nr_samples_);
00178       }
00179 
00184       inline void
00185       setCorrespondenceRandomness (int k)
00186       {
00187         k_correspondences_ = k;
00188       }
00189 
00191       inline int
00192       getCorrespondenceRandomness () const
00193       {
00194         return (k_correspondences_);
00195       }
00196       
00201       inline void
00202       setSimilarityThreshold (float similarity_threshold)
00203       {
00204         correspondence_rejector_poly_->setSimilarityThreshold (similarity_threshold);
00205       }
00206       
00210       inline float
00211       getSimilarityThreshold () const
00212       {
00213         return correspondence_rejector_poly_->getSimilarityThreshold ();
00214       }
00215       
00219       inline void
00220       setInlierFraction (float inlier_fraction)
00221       {
00222         inlier_fraction_ = inlier_fraction;
00223       }
00224       
00228       inline float
00229       getInlierFraction () const
00230       {
00231         return inlier_fraction_;
00232       }
00233       
00237       inline const std::vector<int>&
00238       getInliers () const
00239       {
00240         return inliers_;
00241       }
00242 
00243     protected:
00247       inline int 
00248       getRandomIndex (int n) const
00249       {
00250         return (static_cast<int> (n * (rand () / (RAND_MAX + 1.0))));
00251       };
00252       
00259       void 
00260       selectSamples (const PointCloudSource &cloud, int nr_samples, 
00261                      std::vector<int> &sample_indices);
00262 
00270       void 
00271       findSimilarFeatures (const FeatureCloud &input_features, const std::vector<int> &sample_indices, 
00272                            std::vector<int> &corresponding_indices);
00273 
00277       void 
00278       computeTransformation (PointCloudSource &output, const Eigen::Matrix4f& guess);
00279 
00288       void 
00289       getFitness (std::vector<int>& inliers, float& fitness_score);
00290 
00292       FeatureCloudConstPtr input_features_;
00293 
00295       FeatureCloudConstPtr target_features_;  
00296 
00298       int nr_samples_;
00299 
00301       int k_correspondences_;
00302      
00304       FeatureKdTreePtr feature_tree_;
00305       
00307       CorrespondenceRejectorPolyPtr correspondence_rejector_poly_;
00308       
00310       float inlier_fraction_;
00311       
00313       std::vector<int> inliers_;
00314   };
00315 }
00316 
00317 #include <pcl/registration/impl/sample_consensus_prerejective.hpp>
00318 
00319 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:32:38