contrib/oxl/mvl/TripleMatchSet.h
Go to the documentation of this file.
00001 // This is oxl/mvl/TripleMatchSet.h
00002 #ifndef TripleMatchSet_h_
00003 #define TripleMatchSet_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Store integer triplets
00010 //
00011 // A TripleMatchSet contains "triplets": 3-tuples of integers (i1, i2, i3),
00012 // and methods to access and modify the set.  Access is fast only for
00013 // "forward" matches of the form i1->i2->i3, but this has proved to be
00014 // adequate for all of the triplet work so far.
00015 //
00016 // An iterator class is provided to allow iteration through all triplets
00017 // in the set.
00018 //
00019 // TripleMatchSet storage is a pair of subclass-supplied PairMatchSets.
00020 // Modifying the TripleMatchSet by adding or removing tuples will modify
00021 // the underlying PairMatchSets.
00022 //
00023 // \author
00024 //     Andrew W. Fitzgibbon, Oxford RRG, 09 Aug 96
00025 //
00026 // \verbatim
00027 //  Modifications:
00028 //   8 jun 97: PVr - removed vcl_vector<bool> instantiation (is in Templates/stl_bool.C)
00029 // \endverbatim
00030 //
00031 //-----------------------------------------------------------------------------
00032 
00033 #include <mvl/MatchSet.h>
00034 #include <mvl/PairMatchSet.h>
00035 #include <vcl_cstdlib.h> // for vcl_abort()
00036 #include <vcl_iosfwd.h>
00037 
00038 class TripleMatchSet : public MatchSet
00039 {
00040  protected:
00041   TripleMatchSet(PairMatchSet* match12, PairMatchSet* match23);
00042  public:
00043   TripleMatchSet(int i1_max, int i2_max, int i3_max);
00044   ~TripleMatchSet();
00045 
00046   void clear_matches();
00047   void clear_nontriplets();
00048   int  count() const;
00049 
00050   bool add_match(int i, int ii, int iii);
00051   bool delete_match(int i1, int i2, int i3);
00052   bool contains(int i1, int i2, int i3);
00053 
00054   bool get_1(int i1, int* i1out, int* i2out, int* i3out) const;
00055   bool get_2(int i2, int* i1out, int* i2out, int* i3out) const;
00056   bool get_3(int i3, int* i1out, int* i2out, int* i3out) const;
00057 
00058   int get_match_12(int i1) const;
00059   int get_match_23(int i2) const;
00060   int get_match_31(int i3) const;
00061   int get_match_21(int i2) const;
00062   int get_match_32(int i3) const;
00063   int get_match_13(int i1) const;
00064 
00065   int get_match_123(int i1, int i2) const;
00066 
00067   void set(PairMatchSet* match12, PairMatchSet* match23);
00068   void set_from_pairwise_matches(const PairMatchSet& matches12, const PairMatchSet& matches23);
00069 
00070   void write_ascii(vcl_ostream& s) const;
00071   bool read_ascii(vcl_istream& s);
00072 
00073   void update_feature_match_data();
00074   int  size() const;
00075   bool get_match(int at, int* i1, int* i2, int* i3) const { return get_1(at, i1, i2, i3); }
00076 
00077   // -------------------------------------------------------
00078   class iterator
00079   {
00080    public:
00081 //  iterator(bool full_only);
00082     iterator(const TripleMatchSet& ccc, bool full_only = true);
00083     iterator& operator=(const TripleMatchSet& ccc);
00084     //: Return the i1 of the pointed-to match
00085     int get_i1() const { return i1; }
00086     //: Return the i2 of the pointed-to match
00087     int get_i2() const { return i2; }
00088     //: Return the i3 of the pointed-to match
00089     int get_i3() const { return i3; }
00090     bool next();
00091     iterator& operator ++ (/*prefix*/) { next(); return *this; }
00092     bool isfull() const;
00093     operator bool () const;
00094    private:
00095     iterator operator ++ (int /*postfix*/) { vcl_abort(); return *this; }
00096 
00097    protected:
00098     const TripleMatchSet* c_;
00099     int match_index_;
00100     int i1, i2, i3;
00101     bool full_only_;
00102   };
00103   iterator begin() const { return iterator(*this, true); }
00104 
00105   // -------------------------------------------------------
00106 
00107  protected:
00108   PairMatchSet *match12_;
00109   PairMatchSet *match23_;
00110 };
00111 
00112 vcl_istream& operator >> (vcl_istream& s,  TripleMatchSet& ccc);
00113 vcl_ostream& operator << (vcl_ostream& s, const TripleMatchSet& ccc);
00114 
00115 #endif // TripleMatchSet_h_