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