Ransac.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef __Ransac_h__
25 #define __Ransac_h__
26 
27 #include "Alvar.h"
28 #include <stdlib.h>
29 
36 namespace alvar {
37 
42 
43  protected:
44  void** samples;
45  void* hypothesis;
50 
51  RansacImpl(int min_params, int max_params,
52  int sizeof_param, int sizeof_model);
53  virtual ~RansacImpl();
54 
55  int _estimate(void* params, int param_c,
56  int support_limit, int max_rounds,
57  void* model);
58 
59  int _refine(void* params, int param_c,
60  int support_limit, int max_rounds,
61  void* model, char *inlier_mask = NULL);
62 
63  virtual void _doEstimate(void** params, int param_c, void* model) {};
64  virtual bool _doSupports(void* param, void* model) { return false; };
65 
67  int *indices;
68 
69  RansacImpl(int min_params, int max_params,
70  int sizeof_model);
71 
72  int _estimate(int param_c,
73  int support_limit, int max_rounds,
74  void* model);
75 
76  int _refine(int param_c,
77  int support_limit, int max_rounds,
78  void* model, char *inlier_mask = NULL);
79 
80  virtual void _doEstimate(int* params, int param_c, void* model) {};
81  virtual bool _doSupports(int param, void* model) { return false; };
82 
83  public:
84 
98  int estimateRequiredRounds(float success_propability,
99  float inlier_percentage);
100 
101 };
102 
170  template <typename MODEL, typename PARAMETER>
171  class Ransac : public RansacImpl {
172 
173  protected:
183  virtual void doEstimate(PARAMETER** params, int param_c, MODEL* model) = 0;
184 
196  virtual bool doSupports(PARAMETER* param, MODEL* model) = 0;
197 
201  void _doEstimate(void** params, int param_c, void* model) {
202  doEstimate((PARAMETER**)params, param_c, (MODEL*)model);
203  }
204 
208  bool _doSupports(void* param, void* model) {
209  return doSupports((PARAMETER*)param, (MODEL*)model);
210  }
211 
212  public:
225  Ransac(int min_params, int max_params)
226  : RansacImpl(min_params, max_params, sizeof(PARAMETER), sizeof(MODEL)) {}
227 
228  virtual ~Ransac() {}
229 
250  int estimate(PARAMETER* params, int param_c,
251  int support_limit, int max_rounds,
252  MODEL* model) {
253  return _estimate(params, param_c, support_limit, max_rounds, model);
254  }
255 
275  int refine(PARAMETER* params, int param_c,
276  int support_limit, int max_rounds,
277  MODEL* model, char *inlier_mask = NULL) {
278  return _refine(params, param_c, support_limit, max_rounds, model, inlier_mask);
279  }
280 
281  };
282 
283 
342  template <typename MODEL>
343  class IndexRansac : public RansacImpl {
344 
345  protected:
355  virtual void doEstimate(int* params, int param_c, MODEL* model) = 0;
356 
368  virtual bool doSupports(int param, MODEL* model) = 0;
369 
373  void _doEstimate(int* params, int param_c, void* model) {
374  doEstimate(params, param_c, (MODEL*)model);
375  }
376 
380  bool _doSupports(int param, void* model) {
381  return doSupports(param, (MODEL*)model);
382  }
383 
384  public:
397  IndexRansac(int min_params, int max_params)
398  : RansacImpl(min_params, max_params, sizeof(MODEL)) {}
399 
400  virtual ~IndexRansac() {}
401 
421  int estimate(int param_c,
422  int support_limit, int max_rounds,
423  MODEL* model) {
424  return _estimate(param_c, support_limit, max_rounds, model);
425  }
426 
445  int refine(int param_c,
446  int support_limit, int max_rounds,
447  MODEL* model, char *inlier_mask = NULL) {
448  return _refine(param_c, support_limit, max_rounds, model, inlier_mask);
449  }
450 
451  };
452 
453 } // namespace alvar
454 
455 #endif //__Ransac_h__
Main ALVAR namespace.
Definition: Alvar.h:174
virtual ~Ransac()
Definition: Ransac.h:228
int refine(int param_c, int support_limit, int max_rounds, MODEL *model, char *inlier_mask=NULL)
Iteratively makes the estimated model better.
Definition: Ransac.h:445
Implementation of a general RANdom SAmple Consensus algorithm with implicit parameters.
Definition: Ransac.h:343
bool param(const std::string &param_name, T &param_val, const T &default_val)
virtual bool _doSupports(int param, void *model)
Definition: Ransac.h:81
int estimate(int param_c, int support_limit, int max_rounds, MODEL *model)
Estimates a model from input data parameters.
Definition: Ransac.h:421
IndexRansac(int min_params, int max_params)
Initialize the algorithm.
Definition: Ransac.h:397
int refine(PARAMETER *params, int param_c, int support_limit, int max_rounds, MODEL *model, char *inlier_mask=NULL)
Iteratively makes the estimated model better.
Definition: Ransac.h:275
int sizeof_model
Definition: Ransac.h:49
int estimate(PARAMETER *params, int param_c, int support_limit, int max_rounds, MODEL *model)
Estimates a model from input data parameters.
Definition: Ransac.h:250
virtual void _doEstimate(void **params, int param_c, void *model)
Definition: Ransac.h:63
int sizeof_param
Definition: Ransac.h:48
void _doEstimate(int *params, int param_c, void *model)
Definition: Ransac.h:373
void ** samples
Definition: Ransac.h:44
virtual void _doEstimate(int *params, int param_c, void *model)
Definition: Ransac.h:80
#define ALVAR_EXPORT
Definition: Alvar.h:168
Implementation of a general RANdom SAmple Consensus algorithm.
Definition: Ransac.h:171
void * hypothesis
Definition: Ransac.h:45
bool _doSupports(void *param, void *model)
Definition: Ransac.h:208
Ransac(int min_params, int max_params)
Initialize the algorithm.
Definition: Ransac.h:225
virtual ~IndexRansac()
Definition: Ransac.h:400
bool _doSupports(int param, void *model)
Definition: Ransac.h:380
This file defines library export definitions, version numbers and build information.
Internal implementation of RANSAC. Please use Ransac or IndexRansac.
Definition: Ransac.h:41
int * indices
Definition: Ransac.h:64
void _doEstimate(void **params, int param_c, void *model)
Definition: Ransac.h:201


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:04