00001 // This is oxl/mvl/PairMatchSet.h 00002 #ifndef PairMatchSet_h_ 00003 #define PairMatchSet_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Set of pairs of integers 00010 // 00011 // A PairMatchSet stores tuples of integers (i1, i2), stored as 00012 // an array of matches indexed by i1. Access characteristics are 00013 // therefore: 00014 // 00015 // Indexing on i1 ("forward matches") is O(1) 00016 // 00017 // Indexing on i2 ("backward matches") is O(n) 00018 // 00019 // The first index must be unique (see PairMatchMulti to allow 00020 // multiple i2's for a single i1). In general the i1's ought also 00021 // to be small, less than 1000, say. 00022 // 00023 // A class PairMatchSet::iterator is provided to allow traversal of 00024 // the complete list of matches. 00025 // 00026 // \author 00027 // Andrew W. Fitzgibbon, Oxford RRG, 09 Aug 96 00028 // 00029 //----------------------------------------------------------------------------- 00030 00031 #include <vcl_iosfwd.h> 00032 #include <vcl_vector.h> 00033 #include <mvl/MatchSet.h> 00034 00035 class PairMatchSet : public MatchSet 00036 { 00037 // Data Members-------------------------------------------------------------- 00038 vcl_vector<int> matches_; 00039 unsigned int match_count_; 00040 public: 00041 // Constants----------------------------------------------------------------- 00042 enum { use_existing = true }; 00043 public: 00044 // Constructors/Destructors-------------------------------------------------- 00045 00046 PairMatchSet(unsigned size = 0); 00047 PairMatchSet(const PairMatchSet& that); 00048 PairMatchSet& operator=(const PairMatchSet& that); 00049 00050 virtual ~PairMatchSet(); 00051 00052 // Data Control-------------------------------------------------------------- 00053 void set_size(unsigned size); 00054 bool add_match(int i1, int i2); 00055 int get_match_12(int i1) const; 00056 int get_match_21(int i2) const; 00057 void clear_match_1(int i1); 00058 void set_identity(); 00059 00060 // Operations---------------------------------------------------------------- 00061 unsigned int count() const { return match_count_; } 00062 00063 void update_feature_match_data(); 00064 void clear(); 00065 00066 void update(const vcl_vector<bool>& inliers); 00067 00068 int size() const; 00069 00070 // Computations-------------------------------------------------------------- 00071 int compute_match_count(); 00072 00073 // Data Access--------------------------------------------------------------- 00074 00075 // ******* ITERATOR 00076 class iterator 00077 { 00078 VCL_SAFE_BOOL_DEFINE; 00079 const PairMatchSet* c_; 00080 int match_index_; 00081 int i1, i2; 00082 bool full_only_; 00083 public: 00084 iterator(bool full_only = true); 00085 iterator(const PairMatchSet& ccc, bool full_only = true); 00086 iterator& operator=(const PairMatchSet& ccc); 00087 int get_i1() const { return i1; } 00088 int get_i2() const { return i2; } 00089 bool next(); 00090 iterator& operator ++ (/*prefix*/) { next(); return *this; } 00091 bool isfull() const; 00092 //: Return true if the iterator has not yet enumerated all matches. 00093 operator safe_bool() const { return match_index_ < c_->size() ? VCL_SAFE_BOOL_TRUE : 0; } 00094 //: Return false if the iterator has not yet enumerated all matches. 00095 bool operator!() const { return match_index_ < c_->size() ? false : true; } 00096 private: 00097 iterator operator++ (int /*postfix*/);// { abort(); return *this; } 00098 }; 00099 // ******* END ITERATOR 00100 00101 // Input/Output-------------------------------------------------------------- 00102 void print_brief(vcl_ostream& s) const; 00103 void print_brief() const; 00104 void write_ascii(vcl_ostream& s) const; 00105 bool read_ascii(vcl_istream& s); 00106 00107 friend vcl_ostream& operator<<(vcl_ostream& s, const PairMatchSet& cc); 00108 friend vcl_istream& operator>>(vcl_istream& s, PairMatchSet& cc); 00109 00110 bool get_match(int at, int* i1, int* i2) const; 00111 }; 00112 00113 #endif // PairMatchSet_h_