38 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_
39 #define PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_
44 template <
typename Po
intT>
bool
48 if (threshold_ == std::numeric_limits<double>::max())
50 PCL_ERROR (
"[pcl::RandomizedRandomSampleConsensus::computeModel] No threshold set!\n");
55 int n_best_inliers_count = -INT_MAX;
58 std::vector<int> selection;
59 Eigen::VectorXf model_coefficients;
60 std::set<int> indices_subset;
62 int n_inliers_count = 0;
63 unsigned skipped_count = 0;
65 const unsigned max_skip = max_iterations_ * 10;
68 size_t fraction_nr_points =
pcl_lrint (static_cast<double>(sac_model_->getIndices ()->size ()) * fraction_nr_pretest_ / 100.0);
71 while (iterations_ < k && skipped_count < max_skip)
74 sac_model_->getSamples (iterations_, selection);
76 if (selection.empty ())
break;
79 if (!sac_model_->computeModelCoefficients (selection, model_coefficients))
88 this->getRandomSamples (sac_model_->getIndices (), fraction_nr_points, indices_subset);
89 if (!sac_model_->doSamplesVerifyModel (indices_subset, model_coefficients, threshold_))
100 n_inliers_count = sac_model_->countWithinDistance (model_coefficients, threshold_);
103 if (n_inliers_count > n_best_inliers_count)
105 n_best_inliers_count = n_inliers_count;
109 model_coefficients_ = model_coefficients;
112 double w =
static_cast<double> (n_inliers_count) / static_cast<double> (sac_model_->getIndices ()->size ());
113 double p_no_outliers = 1 - pow (w, static_cast<double> (selection.size ()));
114 p_no_outliers = (std::max) (std::numeric_limits<double>::epsilon (), p_no_outliers);
115 p_no_outliers = (std::min) (1 - std::numeric_limits<double>::epsilon (), p_no_outliers);
116 k = log (1 - probability_) / log (p_no_outliers);
121 if (debug_verbosity_level > 1)
122 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);
123 if (iterations_ > max_iterations_)
125 if (debug_verbosity_level > 0)
126 PCL_DEBUG (
"[pcl::RandomizedRandomSampleConsensus::computeModel] RRANSAC reached the maximum number of trials.\n");
131 if (debug_verbosity_level > 0)
132 PCL_DEBUG (
"[pcl::RandomizedRandomSampleConsensus::computeModel] Model: %zu size, %d inliers.\n", model_.size (), n_best_inliers_count);
141 sac_model_->selectWithinDistance (model_coefficients_, threshold_, inliers_);
145 #define PCL_INSTANTIATE_RandomizedRandomSampleConsensus(T) template class PCL_EXPORTS pcl::RandomizedRandomSampleConsensus<T>;
147 #endif // PCL_SAMPLE_CONSENSUS_IMPL_RRANSAC_H_