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 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_
00039 #define PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_
00040
00041 #include "pcl/sample_consensus/rransac.h"
00042
00044 template <typename PointT> bool
00045 pcl::RandomizedRandomSampleConsensus<PointT>::computeModel (int debug_verbosity_level)
00046 {
00047
00048 if (threshold_ == DBL_MAX)
00049 {
00050 ROS_ERROR ("[pcl::RandomizedRandomSampleConsensus::computeModel] No threshold set!");
00051 return (false);
00052 }
00053
00054 iterations_ = 0;
00055 int n_best_inliers_count = -INT_MAX;
00056 double k = 1.0;
00057
00058 std::vector<int> best_model;
00059 std::vector<int> best_inliers, inliers;
00060 std::vector<int> selection;
00061 Eigen::VectorXf model_coefficients;
00062 std::set<int> indices_subset;
00063
00064 int n_inliers_count = 0;
00065
00066
00067 size_t fraction_nr_points = lrint (sac_model_->getIndices ()->size () * fraction_nr_pretest_ / 100.0);
00068
00069
00070 while (iterations_ < k)
00071 {
00072
00073 sac_model_->getSamples (iterations_, selection);
00074
00075 if (selection.empty ()) break;
00076
00077
00078 if (!sac_model_->computeModelCoefficients (selection, model_coefficients))
00079 {
00080
00081 continue;
00082 }
00083
00084
00085
00086 getRandomSamples (sac_model_->getIndices (), fraction_nr_points, indices_subset);
00087 if (!sac_model_->doSamplesVerifyModel (indices_subset, model_coefficients, threshold_))
00088 {
00089
00090 if (k > 1.0)
00091 {
00092 ++iterations_;
00093 continue;
00094 }
00095 }
00096
00097
00098 sac_model_->selectWithinDistance (model_coefficients, threshold_, inliers);
00099
00100
00101
00102 n_inliers_count = inliers.size ();
00103
00104
00105 if (n_inliers_count > n_best_inliers_count)
00106 {
00107 n_best_inliers_count = n_inliers_count;
00108
00109
00110 inliers_ = inliers;
00111 model_ = selection;
00112 model_coefficients_ = model_coefficients;
00113
00114
00115 double w = (double)((double)n_inliers_count / (double)sac_model_->getIndices ()->size ());
00116 double p_no_outliers = 1 - pow (w, (double)selection.size ());
00117 p_no_outliers = (std::max) (std::numeric_limits<double>::epsilon (), p_no_outliers);
00118 p_no_outliers = (std::min) (1 - std::numeric_limits<double>::epsilon (), p_no_outliers);
00119 k = log (1 - probability_) / log (p_no_outliers);
00120 }
00121
00122 ++iterations_;
00123
00124 if (debug_verbosity_level > 1)
00125 ROS_DEBUG ("[pcl::RandomizedRandomSampleConsensus::computeModel] Trial %d out of %d: %d inliers (best is: %d so far).", iterations_, (int)ceil (k), n_inliers_count, n_best_inliers_count);
00126 if (iterations_ > max_iterations_)
00127 {
00128 if (debug_verbosity_level > 0)
00129 ROS_DEBUG ("[pcl::RandomizedRandomSampleConsensus::computeModel] RRANSAC reached the maximum number of trials.");
00130 break;
00131 }
00132 }
00133
00134 if (debug_verbosity_level > 0)
00135 ROS_DEBUG ("[pcl::RandomizedRandomSampleConsensus::computeModel] Model: %zu size, %d inliers.", model_.size (), n_best_inliers_count);
00136
00137 if (model_.empty ())
00138 return (false);
00139 return (true);
00140 }
00141
00142 #define PCL_INSTANTIATE_RandomizedRandomSampleConsensus(T) template class pcl::RandomizedRandomSampleConsensus<T>;
00143
00144 #endif // PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_
00145