52 if (
threshold_ == std::numeric_limits<double>::max())
54 PCL_ERROR (
"[pcl::LeastMedianSquares::computeModel] No threshold set!\n");
59 double d_best_penalty = std::numeric_limits<double>::max();
62 Eigen::VectorXf model_coefficients (
sac_model_->getModelSize ());
65 unsigned skipped_count = 0;
75 if (selection.empty ())
77 PCL_ERROR (
"[pcl::LeastMedianSquares::computeModel] No samples could be selected!\n");
82 if (!
sac_model_->computeModelCoefficients (selection, model_coefficients))
86 PCL_DEBUG (
"[pcl::LeastMedianSquares::computeModel] The function computeModelCoefficients failed, so continue with next iteration.\n");
105 const auto nr_valid_dists = std::distance (
distances.begin (), new_end);
108 PCL_DEBUG (
"[pcl::LeastMedianSquares::computeModel] There are %lu valid distances remaining after removing NaN values.\n", nr_valid_dists);
109 if (nr_valid_dists == 0)
118 if (d_cur_penalty < d_best_penalty)
120 d_best_penalty = d_cur_penalty;
128 if (debug_verbosity_level > 1)
130 PCL_DEBUG (
"[pcl::LeastMedianSquares::computeModel] Trial %d out of %d. Best penalty is %f.\n",
iterations_,
max_iterations_, d_best_penalty);
136 if (debug_verbosity_level > 0)
138 PCL_DEBUG (
"[pcl::LeastMedianSquares::computeModel] Unable to find a solution!\n");
154 PCL_ERROR (
"[pcl::LeastMedianSquares::computeModel] The model found failed to verify against the given constraints!\n");
160 if (
distances.size () != indices.size ())
162 PCL_ERROR (
"[pcl::LeastMedianSquares::computeModel] Estimated distances (%lu) differs than the normal of indices (%lu).\n",
distances.size (), indices.size ());
168 std::size_t n_inliers_count = 0;
169 for (std::size_t i = 0; i <
distances.size (); ++i)
173 inliers_[n_inliers_count++] = indices[i];
180 if (debug_verbosity_level > 0)
182 PCL_DEBUG (
"[pcl::LeastMedianSquares::computeModel] Model: %lu size, %lu inliers.\n",
model_.size (), n_inliers_count);
auto computeMedian(IteratorT begin, IteratorT end, Functor f) noexcept -> std::result_of_t< Functor(decltype(*begin))>
Compute the median of a list of values (fast).