25 #ifndef __ExampleRANSAC_Plane_hh__
26 #define __ExampleRANSAC_Plane_hh__
28 #include <Base/Common/BIASpragmaStart.hh>
31 #include "MathAlgo/RANSAC.hh"
32 #include "MathAlgo/SVD.hh"
33 #include "Base/Geometry/HomgPoint3D.hh"
34 #include "Base/Geometry/HomgPlane3D.hh"
80 void Init(std::vector<HomgPoint3D>& data,
81 double inlier_distance_threshold,
83 double expected_inlier_fraction,
84 double solution_error_threshold);
93 std::vector<HomgPlane3D> &solutions);
106 bool existing_solution_flag,
107 std::vector<bool>& inlier,
109 double& evaluate_score,
110 bool& ok_to_terminate_flag);
117 virtual bool RefineSolution(std::vector<unsigned int>& which_samples,
119 std::vector<bool>& new_inliers);
146 double inlier_distance_threshold,
147 bool refine_solution,
148 double expected_inlier_fraction,
149 double solution_error_threshold)
161 std::vector<HomgPlane3D> &solutions)
169 _vData[which_samples[2]]));
171 return solutions.size();
175 bool existing_solution_flag,
176 std::vector<bool>& inlier,
178 double& evaluate_score,
179 bool& ok_to_terminate_flag)
181 bool good_flag =
true;
185 int my_accept_count = 0;
186 evaluate_score = 0.0;
198 if (my_accept_count != 0) {
199 evaluate_score /= my_accept_count;
201 evaluate_score = DBL_MAX;
206 accept_count = my_accept_count;
210 ok_to_terminate_flag =
220 std::vector<bool>& new_inliers)
224 const unsigned int nr_of_points = which_samples.size();
226 for (
unsigned int i = 0; i < nr_of_points; i++) {
227 A[i][0] =
_vData[which_samples[i]][0];
228 A[i][1] =
_vData[which_samples[i]][1];
229 A[i][2] =
_vData[which_samples[i]][2];
230 A[i][3] =
_vData[which_samples[i]][3];
234 SVD svd(A, 1e-5,
false);
237 if (svd.
Rank() < 3)
return false;
239 double norm = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
240 if (norm > 1e-5) x /= norm;
248 #include <Base/Common/BIASpragmaEnd.hh>
250 #endif // __ExampleRANSAC_double_hh__
Vector< double > GetNullvector(const int last_offset=0)
return one of the nullvectors.
void Init(std::vector< HomgPoint3D > &data, double inlier_distance_threshold, bool refine_solution, double expected_inlier_fraction, double solution_error_threshold)
Initializes RANSAC.
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
HOMGPLANE3D_TYPE DistanceSquared(const HomgPoint3D &point) const
calculates squared distance of a point from plane
Matrix< T > Transpose() const
transpose function, storing data destination matrix
double _dInlierDistanceThreshold
3D points with max distance _dInlierDistanceThreshold to plane are considered as inliers ...
Robust fitting of 3D plane to 3D point set using RANSAC.
unsigned int Rank()
returns the rank of A_
void Init(unsigned int sample_size, unsigned int max_solutions_per_sample=1, bool refine_solution=false, bool greedy=false)
class Vector4 contains a Vector of dim.
virtual bool EvaluateSolution(const HomgPlane3D &solution, bool existing_solution_flag, std::vector< bool > &inlier, int &accept_count, double &evaluate_score, bool &ok_to_terminate_flag)
The solution denoted by solution needs to be ranked.
double _dSolutionErrorThreshold
if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolu...
double _dExpectedInlierFraction
if a sample yields more than _dExpectedInlierFraction inliers and evaluate_score is lower than _dSolu...
Generic abstract base class for RANSAC (RANdom SAmple Consensus) estimators.
virtual int GetSampleSolutions(std::vector< unsigned int > &which_samples, std::vector< HomgPlane3D > &solutions)
takes sample and computes solution for this sample.
unsigned _uiDataSize
number of data elements needed to compute a solution
std::vector< HomgPoint3D > _vData
input 3D points to fit 3D plane to
virtual bool RefineSolution(std::vector< unsigned int > &which_samples, HomgPlane3D &solution, std::vector< bool > &new_inliers)
RefineSolution is only called, if the RefineSolutionFlag is set to true.
A homogeneous plane (in P^3) All points X on the plane p fulfill p ' * X = 0.