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
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
00081 ENABLE_LINK_TO_SPECIFIC_PARENT(SensorExteroAbstract, SensorSpec, SensorSpec, DataManagerAbstract);
00082
00083 ENABLE_ACCESS_TO_SPECIFIC_PARENT(SensorSpec, sensorSpec);
00084
00085 public:
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
00103 void dump(raw_ptr_t data);
00104
00105 protected:
00106 boost::shared_ptr<DetectorSpec> detector;
00107 boost::shared_ptr<MatcherSpec> matcher;
00108 boost::shared_ptr<FeatureManagerSpec> featMan;
00109
00110 typedef map<double, ObsList::iterator> ObservationListSorted;
00111 ObservationListSorted obsListSorted;
00112
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:
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:
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 protected:
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