Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
dataManagerOnePointRansac.hpp
Go to the documentation of this file.
00001 
00009 #ifndef DATAMANAGERONEPOINTRANSAC_HPP_
00010 #define DATAMANAGERONEPOINTRANSAC_HPP_
00011 
00012 #include <vector>
00013 #include <list>
00014 #include "boost/shared_ptr.hpp"
00015 
00016 #include "rtslam/dataManagerAbstract.hpp"
00017 #include "rtslam/quatTools.hpp"
00018 
00019 namespace jafar {
00020   namespace rtslam {
00021 
00022     class LoggableMatchings: public kernel::Loggable
00023     {
00024      public:
00025       struct Matching
00026       {
00027         unsigned id; double u, v;
00028         Matching(unsigned id, double u, double v): id(id), u(u), v(v) {}
00029       };
00030 
00031      private:
00032       std::string filename;
00033       std::vector<Matching> matchings;
00034 
00035      public:
00036       LoggableMatchings(std::string filename): filename(filename) {}
00037       void addMatching(unsigned id, double u, double v) { matchings.push_back(Matching(id,u,v)); }
00038       virtual void log()
00039       {
00040         std::ofstream f(filename.c_str());
00041         for(std::vector<Matching>::iterator it = matchings.begin(); it != matchings.end(); ++it)
00042           f << it->id << "\t" << it->u << "\t" << it->v << std::endl;
00043         f.close();
00044       }
00045     };
00046 
00047 
00048     typedef std::vector<observation_ptr_t> ObsList;
00049     struct RansacSet {
00050         observation_ptr_t obsBasePtr;
00051         std::map<unsigned, Measurement> inlierMeasurements;
00052         ObsList inlierObs;
00053         ObsList pendingObs;
00054         size_t size() {
00055           return inlierObs.size();
00056         }
00057 
00058         void add_inlier(observation_ptr_t obsPtr)
00059         {
00060           inlierObs.push_back(obsPtr);
00061           inlierMeasurements.erase(obsPtr->id());
00062           inlierMeasurements.insert(std::make_pair(obsPtr->id(), obsPtr->measurement));
00063         }
00064 
00065     };
00066     typedef boost::shared_ptr<RansacSet> ransac_set_ptr_t;
00067     typedef std::list<ransac_set_ptr_t> RansacSetList;
00068 
00069 
00070     // TODO extend to n-point ransac ?
00076     template<class RawSpec,class SensorSpec, class FeatureSpec, class RoiSpec, class FeatureManagerSpec, class DetectorSpec, class MatcherSpec>
00077     class DataManagerOnePointRansac: public DataManagerAbstract, public SpecificChildOf<SensorSpec> {
00078 
00079       public:
00080         // Define the function linkToParentSensorSpec.
00081         ENABLE_LINK_TO_SPECIFIC_PARENT(SensorExteroAbstract, SensorSpec, SensorSpec, DataManagerAbstract);
00082         // Define the functions sensorSpec() and sensorSpecPtr().
00083         ENABLE_ACCESS_TO_SPECIFIC_PARENT(SensorSpec, sensorSpec);
00084 
00085       public: // public interface
00086         DataManagerOnePointRansac(const boost::shared_ptr<DetectorSpec> & _detector, const boost::shared_ptr<MatcherSpec> & _matcher, const boost::shared_ptr<FeatureManagerSpec> _featMan, int n_updates_total, int n_updates_ransac, int n_tries, int n_init, int n_recomp_gains, bool multi_hyps = false, kernel::LoggerTask *loggerTask = NULL):
00087           detector(_detector), matcher(_matcher), featMan(_featMan), loggerTask(loggerTask), multi_hyps_(multi_hyps)
00088         {
00089           algorithmParams.n_updates_total = n_updates_total;
00090           algorithmParams.n_updates_ransac = n_updates_ransac;
00091           algorithmParams.n_tries = n_tries;
00092           algorithmParams.n_init = n_init;
00093           algorithmParams.n_recomp_gains = n_recomp_gains;
00094           prev_average_ransac_update_time = -1.;
00095           prev_average_as_update_time = -1.;
00096           clearCounters();
00097         }
00098         virtual ~DataManagerOnePointRansac() {
00099         }
00100         void processKnown(raw_ptr_t data, double date_limit = -1.);
00101         void detectNew(raw_ptr_t data);
00102 //        void process(boost::shared_ptr<RawAbstract> data);
00103         void dump(raw_ptr_t data);
00104 
00105       protected: // main data members
00106         boost::shared_ptr<DetectorSpec> detector;
00107         boost::shared_ptr<MatcherSpec> matcher;
00108         boost::shared_ptr<FeatureManagerSpec> featMan;
00109         // the list of observations sorted by information gain
00110         typedef map<double, ObsList::iterator> ObservationListSorted;
00111         ObservationListSorted obsListSorted;
00112         // the list of visible observations to handle
00113         ObsList obsVisibleList;
00114         unsigned remainingObsCount;
00115         ObsList obsBaseList;
00116         ObsList obsFailedList;
00117         RansacSetList ransacSetList;
00118         kernel::LoggerTask *loggerTask;
00119         jblas::vec ransac_exp;
00120         bool multi_hyps_;
00121 
00122         double prev_average_ransac_update_time;
00123         double prev_average_as_update_time;
00124 
00125         struct Counters { 
00126             int visible;
00127             int measured;
00128             int matched;
00129             int updated;
00130             int created;
00131             int killed;
00132         } counters;
00133         void clearCounters() {
00134           int size = sizeof(Counters)/sizeof(int);
00135           for (int i = 0; i < size; ++i)
00136             ((int*)&counters)[i] = 0;
00137         }
00138 
00139       protected: // parameters
00140         struct alg_params_t {
00141             unsigned n_updates_total;  
00142             unsigned n_updates_ransac; 
00143             unsigned n_tries;   
00144             unsigned n_init;    
00145             unsigned n_recomp_gains; 
00146         } algorithmParams;
00147 
00148       public: // getters ans setters
00149 /*        boost::shared_ptr<FeatureManagerSpec> featureManager(void) {
00150           return featMan;
00151         }*/
00152 //        void setAlgorithmParams(int n_updates, int n_tries) {
00153 //          algorithmParams_.n_updates = n_updates;
00154 //          algorithmParams_.n_tries = n_tries;
00155 //        }
00156 //        alg_params_t algorithmParams() {
00157 //          return algorithmParams_;
00158 //        }
00159 
00160       protected: // helper functions
00161         void projectAndCollectVisibleObs();
00162         void updateVisibleObs();
00163         void getOneMatchedBaseObs(observation_ptr_t & obsBasePtr, boost::shared_ptr<RawSpec> rawData);
00164         observation_ptr_t selectOneRandomObs();
00165         vec updateMean(const observation_ptr_t & obsPtr);
00166         void projectFromMean(vec & exp, const observation_ptr_t & obsPtr, const vec & x);
00167         bool isLowInnovationInlier(const observation_ptr_t & obsPtr, const vec & exp, double lowInnTh);
00168         bool matchWithExpectedInnovation(boost::shared_ptr<RawSpec> rawData,  observation_ptr_t obsPtr, bool lowInnov = false);
00169 
00170         virtual void writeLogHeader(kernel::DataLogger& log) const;
00171         virtual void writeLogData(kernel::DataLogger& log) const;
00172     };
00173 
00174   }
00175 }
00176 
00177 
00178 #include "rtslam/dataManagerOnePointRansac.impl.hpp"
00179 
00180 #endif /* DATAMANAGERONEPOINTRANSAC_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:26 for Jafar by doxygen 1.7.6.1
LAAS-CNRS