51 if (
threshold_ == std::numeric_limits<double>::max())
53 PCL_ERROR (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] No threshold set!\n");
58 double d_best_penalty = std::numeric_limits<double>::max();
61 const double log_probability = std::log (1.0 -
probability_);
62 const double one_over_indices = 1.0 /
static_cast<double> (
sac_model_->getIndices ()->size ());
65 Eigen::VectorXf model_coefficients (
sac_model_->getModelSize ());
67 std::set<index_t> indices_subset;
69 int n_inliers_count = 0;
70 unsigned skipped_count = 0;
75 const std::size_t fraction_nr_points = (fraction_nr_pretest_ < 0.0 ? nr_samples_pretest_ :
pcl_lrint (
static_cast<double>(
sac_model_->getIndices ()->size ()) * fraction_nr_pretest_ / 100.0));
76 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Using %lu points for RMSAC pre-test.\n", fraction_nr_points);
84 if (selection.empty ())
break;
87 if (!
sac_model_->computeModelCoefficients (selection, model_coefficients))
108 double d_cur_penalty = 0;
119 d_cur_penalty += std::min (distance,
threshold_);
122 if (d_cur_penalty < d_best_penalty)
124 d_best_penalty = d_cur_penalty;
137 const double w =
static_cast<double> (n_inliers_count) * one_over_indices;
138 double p_outliers = 1.0 - std::pow (w,
static_cast<double> (selection.size ()));
139 p_outliers = (std::max) (std::numeric_limits<double>::epsilon (), p_outliers);
140 p_outliers = (std::min) (1.0 - std::numeric_limits<double>::epsilon (), p_outliers);
141 k = log_probability / std::log (p_outliers);
145 if (debug_verbosity_level > 1)
146 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Trial %d out of %d. Best penalty is %f.\n",
iterations_,
static_cast<int> (std::ceil (k)), d_best_penalty);
149 if (debug_verbosity_level > 0)
150 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] MSAC reached the maximum number of trials.\n");
157 if (debug_verbosity_level > 0)
158 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Unable to find a solution!\n");
165 if (
distances.size () != indices.size ())
167 PCL_ERROR (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Estimated distances (%lu) differs than the normal of indices (%lu).\n",
distances.size (), indices.size ());
174 for (std::size_t i = 0; i <
distances.size (); ++i)
176 inliers_[n_inliers_count++] = indices[i];
181 if (debug_verbosity_level > 0)
182 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Model: %lu size, %d inliers.\n",
model_.size (), n_inliers_count);