My Project
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 
29 #include <stdlib.h>
30 
37 namespace alvar {
38 
42 class ALVAR_EXPORT RansacImpl
43 {
44 protected:
45  void **samples;
46  void * hypothesis;
47  int min_params;
48  int max_params;
49  int sizeof_param;
50  int sizeof_model;
51 
52  RansacImpl(int min_params, int max_params, int sizeof_param, int sizeof_model);
53  virtual ~RansacImpl();
54 
55  int _estimate(void *params, int param_c, int support_limit, int max_rounds, void *model);
56 
57  int _refine(void *params,
58  int param_c,
59  int support_limit,
60  int max_rounds,
61  void *model,
62  char *inlier_mask = NULL);
63 
64  virtual void _doEstimate(void **params, int param_c, void *model){};
65  virtual bool
66  _doSupports(void *param, void *model)
67  {
68  return false;
69  };
70 
72  int *indices;
73 
74  RansacImpl(int min_params, int max_params, int sizeof_model);
75 
76  int _estimate(int param_c, int support_limit, int max_rounds, void *model);
77 
78  int
79  _refine(int param_c, int support_limit, int max_rounds, void *model, char *inlier_mask = NULL);
80 
81  virtual void _doEstimate(int *params, int param_c, void *model){};
82  virtual bool
83  _doSupports(int param, void *model)
84  {
85  return false;
86  };
87 
88 public:
102  int estimateRequiredRounds(float success_propability, float inlier_percentage);
103 };
104 
172 template <typename MODEL, typename PARAMETER>
173 class Ransac : public RansacImpl
174 {
175 protected:
185  virtual void doEstimate(PARAMETER **params, int param_c, MODEL *model) = 0;
186 
198  virtual bool doSupports(PARAMETER *param, MODEL *model) = 0;
199 
203  void
204  _doEstimate(void **params, int param_c, void *model)
205  {
206  doEstimate((PARAMETER **)params, param_c, (MODEL *)model);
207  }
208 
212  bool
213  _doSupports(void *param, void *model)
214  {
215  return doSupports((PARAMETER *)param, (MODEL *)model);
216  }
217 
218 public:
231  Ransac(int min_params, int max_params)
232  : RansacImpl(min_params, max_params, sizeof(PARAMETER), sizeof(MODEL))
233  {
234  }
235 
236  virtual ~Ransac()
237  {
238  }
239 
260  int
261  estimate(PARAMETER *params, int param_c, int support_limit, int max_rounds, MODEL *model)
262  {
263  return _estimate(params, param_c, support_limit, max_rounds, model);
264  }
265 
285  int
286  refine(PARAMETER *params,
287  int param_c,
288  int support_limit,
289  int max_rounds,
290  MODEL * model,
291  char * inlier_mask = NULL)
292  {
293  return _refine(params, param_c, support_limit, max_rounds, model, inlier_mask);
294  }
295 };
296 
355 template <typename MODEL>
356 class IndexRansac : public RansacImpl
357 {
358 protected:
368  virtual void doEstimate(int *params, int param_c, MODEL *model) = 0;
369 
381  virtual bool doSupports(int param, MODEL *model) = 0;
382 
386  void
387  _doEstimate(int *params, int param_c, void *model)
388  {
389  doEstimate(params, param_c, (MODEL *)model);
390  }
391 
395  bool
396  _doSupports(int param, void *model)
397  {
398  return doSupports(param, (MODEL *)model);
399  }
400 
401 public:
414  IndexRansac(int min_params, int max_params) : RansacImpl(min_params, max_params, sizeof(MODEL))
415  {
416  }
417 
418  virtual ~IndexRansac()
419  {
420  }
421 
441  int
442  estimate(int param_c, int support_limit, int max_rounds, MODEL *model)
443  {
444  return _estimate(param_c, support_limit, max_rounds, model);
445  }
446 
465  int
466  refine(int param_c, int support_limit, int max_rounds, MODEL *model, char *inlier_mask = NULL)
467  {
468  return _refine(param_c, support_limit, max_rounds, model, inlier_mask);
469  }
470 };
471 
472 } // namespace alvar
473 
474 #endif //__Ransac_h__
This file defines library export definitions, version numbers and build information.
Implementation of a general RANdom SAmple Consensus algorithm with implicit parameters.
Definition: Ransac.h:357
IndexRansac(int min_params, int max_params)
Initialize the algorithm.
Definition: Ransac.h:414
virtual bool doSupports(int param, MODEL *model)=0
Computes how well a parameters supports a model.
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:466
void _doEstimate(int *params, int param_c, void *model)
Definition: Ransac.h:387
virtual void doEstimate(int *params, int param_c, MODEL *model)=0
Creates a model estimate from a set of parameters.
int estimate(int param_c, int support_limit, int max_rounds, MODEL *model)
Estimates a model from input data parameters.
Definition: Ransac.h:442
bool _doSupports(int param, void *model)
Definition: Ransac.h:396
Implementation of a general RANdom SAmple Consensus algorithm.
Definition: Ransac.h:174
void _doEstimate(void **params, int param_c, void *model)
Definition: Ransac.h:204
virtual void doEstimate(PARAMETER **params, int param_c, MODEL *model)=0
Creates a model estimate from a set of parameters.
bool _doSupports(void *param, void *model)
Definition: Ransac.h:213
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:286
Ransac(int min_params, int max_params)
Initialize the algorithm.
Definition: Ransac.h:231
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:261
virtual bool doSupports(PARAMETER *param, MODEL *model)=0
Computes how well a parameters supports a model.
Internal implementation of RANSAC. Please use Ransac or IndexRansac.
Definition: Ransac.h:43
int * indices
Definition: Ransac.h:69
int estimateRequiredRounds(float success_propability, float inlier_percentage)
How many rounds are needed for the Ransac to work.
Main ALVAR namespace.
Definition: Alvar.h:174