Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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