Ransac.h
Go to the documentation of this file.
00001 /*
00002  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
00003  *
00004  * Copyright 2007-2012 VTT Technical Research Centre of Finland
00005  *
00006  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
00007  *          <http://www.vtt.fi/multimedia/alvar.html>
00008  *
00009  * ALVAR is free software; you can redistribute it and/or modify it under the
00010  * terms of the GNU Lesser General Public License as published by the Free
00011  * Software Foundation; either version 2.1 of the License, or (at your option)
00012  * any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful, but WITHOUT
00015  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00016  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00017  * for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with ALVAR; if not, see
00021  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
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 } // namespace alvar
00454 
00455 #endif //__Ransac_h__


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Sat Dec 28 2013 16:46:15