68 int n_best_inliers_count = -INT_MAX;
71 std::vector<int> best_model;
72 std::vector<int> best_inliers, inliers;
73 std::vector<int> selection;
75 int n_inliers_count = 0;
83 if (selection.size () == 0)
break;
89 n_inliers_count = inliers.size ();
92 if (n_inliers_count > n_best_inliers_count)
94 n_best_inliers_count = n_inliers_count;
95 best_inliers = inliers;
97 best_model = selection;
101 double p_no_outliers = 1 - pow (w, (
double)selection.size ());
102 p_no_outliers = std::max (std::numeric_limits<double>::epsilon (), p_no_outliers);
103 p_no_outliers = std::min (1 - std::numeric_limits<double>::epsilon (), p_no_outliers);
109 std::cerr <<
"[RANSAC::computeModel] Trial " <<
iterations_ <<
" out of " << ceil (k) <<
": " << n_inliers_count <<
" inliers (best is: " << n_best_inliers_count <<
" so far)." << std::endl;
113 std::cerr <<
"[RANSAC::computeModel] RANSAC reached the maximum number of trials." << std::endl;
118 if (best_model.size () != 0)
121 std::cerr <<
"[RANSAC::computeModel] Model found: " << n_best_inliers_count <<
" inliers." << std::endl;
128 std::cerr <<
"[RANSAC::computeModel] Unable to find a solution!" << std::endl;
int max_iterations_
Maximum number of iterations before giving up.
double threshold_
Distance to model threshold.
virtual bool computeModelCoefficients(const std::vector< int > &samples)=0
Check whether the given index samples can form a valid model, compute the model coefficients from the...
SACModel * sac_model_
The underlying data model used (i.e. what is it that we attempt to search for).
virtual void selectWithinDistance(const std::vector< double > &model_coefficients, double threshold, std::vector< int > &inliers)=0
Select all the points which respect the given model coefficients as inliers. Pure virtual...
std::vector< int > * getIndices()
Return a pointer to the point cloud data indices.
int iterations_
Total number of internal loop iterations that we've done so far.
bool computeModel(int debug=0)
Compute the actual model and find the inliers.
RANSAC(SACModel *model)
RANSAC (RAndom SAmple Consensus) main constructor.
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual void getSamples(int &iterations, std::vector< int > &samples)=0
Get a set of random data samples and return them as point indices. Pure virtual.
double probability_
Desired probability of choosing at least one sample free from outliers.
std::vector< double > getModelCoefficients()
Return the model coefficients of the best model found so far.
void setBestModel(std::vector< int > best_model)
Set the best model. Used by SAC methods. Do not call this except if you know what you're doing...
void setBestInliers(const std::vector< int > &best_inliers)
Set the best set of inliers. Used by SAC methods. Do not call this except if you know what you're doi...