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();
62 Eigen::VectorXf model_coefficients (
sac_model_->getModelSize ());
64 std::set<index_t> indices_subset;
66 int n_inliers_count = 0;
67 unsigned skipped_count = 0;
72 std::size_t fraction_nr_points =
pcl_lrint (
static_cast<double>(
sac_model_->getIndices ()->size ()) * fraction_nr_pretest_ / 100.0);
80 if (selection.empty ())
break;
83 if (!
sac_model_->computeModelCoefficients (selection, model_coefficients))
104 double d_cur_penalty = 0;
112 d_cur_penalty += std::min (distance,
threshold_);
115 if (d_cur_penalty < d_best_penalty)
117 d_best_penalty = d_cur_penalty;
130 double w =
static_cast<double> (n_inliers_count) /
static_cast<double>(
sac_model_->getIndices ()->size ());
131 double p_no_outliers = 1 - std::pow (w,
static_cast<double> (selection.size ()));
132 p_no_outliers = (std::max) (std::numeric_limits<double>::epsilon (), p_no_outliers);
133 p_no_outliers = (std::min) (1 - std::numeric_limits<double>::epsilon (), p_no_outliers);
134 k = std::log (1 -
probability_) / std::log (p_no_outliers);
138 if (debug_verbosity_level > 1)
139 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);
142 if (debug_verbosity_level > 0)
143 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] MSAC reached the maximum number of trials.\n");
150 if (debug_verbosity_level > 0)
151 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Unable to find a solution!\n");
158 if (
distances.size () != indices.size ())
160 PCL_ERROR (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Estimated distances (%lu) differs than the normal of indices (%lu).\n",
distances.size (), indices.size ());
167 for (std::size_t i = 0; i <
distances.size (); ++i)
169 inliers_[n_inliers_count++] = indices[i];
174 if (debug_verbosity_level > 0)
175 PCL_DEBUG (
"[pcl::RandomizedMEstimatorSampleConsensus::computeModel] Model: %lu size, %d inliers.\n",
model_.size (), n_inliers_count);