00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __Ransac_h__
00025 #define __Ransac_h__
00026
00027 #include "Alvar.h"
00028 #include <stdlib.h>
00029
00036 namespace alvar {
00037
00041 class ALVAR_EXPORT RansacImpl {
00042
00043 protected:
00044 void** samples;
00045 void* hypothesis;
00046 int min_params;
00047 int max_params;
00048 int sizeof_param;
00049 int sizeof_model;
00050
00051 RansacImpl(int min_params, int max_params,
00052 int sizeof_param, int sizeof_model);
00053 virtual ~RansacImpl();
00054
00055 int _estimate(void* params, int param_c,
00056 int support_limit, int max_rounds,
00057 void* model);
00058
00059 int _refine(void* params, int param_c,
00060 int support_limit, int max_rounds,
00061 void* model, char *inlier_mask = NULL);
00062
00063 virtual void _doEstimate(void** params, int param_c, void* model) {};
00064 virtual bool _doSupports(void* param, void* model) { return false; };
00065
00067 int *indices;
00068
00069 RansacImpl(int min_params, int max_params,
00070 int sizeof_model);
00071
00072 int _estimate(int param_c,
00073 int support_limit, int max_rounds,
00074 void* model);
00075
00076 int _refine(int param_c,
00077 int support_limit, int max_rounds,
00078 void* model, char *inlier_mask = NULL);
00079
00080 virtual void _doEstimate(int* params, int param_c, void* model) {};
00081 virtual bool _doSupports(int param, void* model) { return false; };
00082
00083 public:
00084
00098 int estimateRequiredRounds(float success_propability,
00099 float inlier_percentage);
00100
00101 };
00102
00170 template <typename MODEL, typename PARAMETER>
00171 class Ransac : public RansacImpl {
00172
00173 protected:
00183 virtual void doEstimate(PARAMETER** params, int param_c, MODEL* model) = 0;
00184
00196 virtual bool doSupports(PARAMETER* param, MODEL* model) = 0;
00197
00201 void _doEstimate(void** params, int param_c, void* model) {
00202 doEstimate((PARAMETER**)params, param_c, (MODEL*)model);
00203 }
00204
00208 bool _doSupports(void* param, void* model) {
00209 return doSupports((PARAMETER*)param, (MODEL*)model);
00210 }
00211
00212 public:
00225 Ransac(int min_params, int max_params)
00226 : RansacImpl(min_params, max_params, sizeof(PARAMETER), sizeof(MODEL)) {}
00227
00228 virtual ~Ransac() {}
00229
00250 int estimate(PARAMETER* params, int param_c,
00251 int support_limit, int max_rounds,
00252 MODEL* model) {
00253 return _estimate(params, param_c, support_limit, max_rounds, model);
00254 }
00255
00275 int refine(PARAMETER* params, int param_c,
00276 int support_limit, int max_rounds,
00277 MODEL* model, char *inlier_mask = NULL) {
00278 return _refine(params, param_c, support_limit, max_rounds, model, inlier_mask);
00279 }
00280
00281 };
00282
00283
00342 template <typename MODEL>
00343 class IndexRansac : public RansacImpl {
00344
00345 protected:
00355 virtual void doEstimate(int* params, int param_c, MODEL* model) = 0;
00356
00368 virtual bool doSupports(int param, MODEL* model) = 0;
00369
00373 void _doEstimate(int* params, int param_c, void* model) {
00374 doEstimate(params, param_c, (MODEL*)model);
00375 }
00376
00380 bool _doSupports(int param, void* model) {
00381 return doSupports(param, (MODEL*)model);
00382 }
00383
00384 public:
00397 IndexRansac(int min_params, int max_params)
00398 : RansacImpl(min_params, max_params, sizeof(MODEL)) {}
00399
00400 virtual ~IndexRansac() {}
00401
00421 int estimate(int param_c,
00422 int support_limit, int max_rounds,
00423 MODEL* model) {
00424 return _estimate(param_c, support_limit, max_rounds, model);
00425 }
00426
00445 int refine(int param_c,
00446 int support_limit, int max_rounds,
00447 MODEL* model, char *inlier_mask = NULL) {
00448 return _refine(param_c, support_limit, max_rounds, model, inlier_mask);
00449 }
00450
00451 };
00452
00453 }
00454
00455 #endif //__Ransac_h__