00001
00002
00003 #ifndef SAMS_MATCHER_HPP
00004 #define SAMS_MATCHER_HPP
00005
00006 #include "jafarConfig.h"
00007
00008 #include <functional>
00009 #include <algorithm>
00010 #include <vector>
00011 #include "sams/frame.hpp"
00012 #include "sams/model.hpp"
00013
00014 namespace jafar {
00015 namespace sams {
00016
00017 class Match {
00018 public:
00019 ViewPartLink * modelRef;
00020 Feature * frameRef;
00021 bool valid;
00022 Match(ViewPartLink * mref_=0, Feature * fref_=0, double valid_=false) :
00023 modelRef(mref_), frameRef(fref_), valid(valid_) {};
00024
00025 bool operator== (Match const & mi_) const {
00026 return ( modelRef == mi_.modelRef );
00027 };
00028
00029 inline static std::vector<Match> extractByView(std::vector<Match> const & m_, int id_) {
00030 std::vector<Match> m4v;
00031 for(std::vector<Match>::const_iterator it=m_.begin(); it!=m_.end(); it++) {
00032 if ( it->modelRef->view()->id() == id_)
00033 m4v.push_back(*it);
00034 }
00035 return m4v;
00036 };
00037
00038 inline static ViewPartLink * getMatch(std::vector<Match> const & m_, Feature * const fref_) {
00039 checkFeature cf(fref_);
00040 std::vector<Match>::const_iterator found = std::find_if(m_.begin(),m_.end(),cf);
00041 return ( found == m_.end() ? NULL : ( found->valid == true ? found->modelRef : NULL ) );
00042 };
00043
00044 private:
00045 struct checkFeature :
00046 std::unary_function<Match& , bool> {
00047 Feature * f;
00048 checkFeature(Feature * f_) : f(f_) {};
00049 bool operator() (Match const & y_) const {
00050 return ( f == y_.frameRef );
00051 };
00052 };
00053 };
00054
00055
00060 class Matcher {
00061 public:
00062 virtual ~Matcher() {};
00064 virtual int operator() (jafar::sams::Model const & md_,
00065 jafar::sams::Frame const & f_,
00066 std::vector<Match> & mt_) const = 0;
00067 };
00068
00073 class SNNMatcher : public jafar::sams::Matcher {
00074 public:
00075 virtual ~SNNMatcher () {};
00077 virtual int operator() (jafar::sams::Model const & md_,
00078 jafar::sams::Frame const & f_,
00079 std::vector<Match> & mt_) const ;
00080
00081 };
00082
00083
00084 #ifdef HAVE_BOOST_SANDBOX
00085 #ifdef HAVE_LAPACK
00086
00087
00092 class SVDMatcher : public jafar::sams::Matcher {
00093 public:
00094 virtual ~SVDMatcher () {};
00095
00096 virtual int operator() (const jafar::sams::Model& md_,
00097 const jafar::sams::Frame& f_,
00098 std::vector<Match> & mt_) const;
00099
00100 };
00101
00102 #endif // HAVE_LAPACK
00103 #endif // HAVE_BOOST_SANDBOX
00104
00105 }
00106 }
00107
00108 #endif // SAMS_MATCHING_HPP