contrib/oxl/mvl/NViewMatches.h
Go to the documentation of this file.
00001 // This is oxl/mvl/NViewMatches.h
00002 #ifndef NViewMatches_h_
00003 #define NViewMatches_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Multiple view matches with wildcards
00010 //
00011 //    A class to hold matches over multiple views, allowing for unmatched data.
00012 //    With each 3d feature there is associated a multiple-view match. A
00013 //    multiple-view match is a vector of integers (NViewMatch) which identify
00014 //    2d features in each view.
00015 //
00016 //    If for example a 3d point X has NViewMatch "Xmatches", then
00017 //    Xmatches[v] = i implies that the image of X in view "v" is the corner
00018 //    with index "i" in view "v".
00019 //
00020 // \author
00021 //     Andrew W. Fitzgibbon, Oxford RRG, 17 May 97
00022 // \verbatim
00023 // Modifications:
00024 //     970517 AWF Initial version.
00025 //     270897 PRV Moved vcl_vector<NViewMatch> instantiation to Templates package
00026 //     151097 AWF Added OffsetNViewMatch.
00027 //     280498 David Capel made minimum match overlap user-definable,
00028 //            allowed merging of consistent multiple-match tracks.
00029 //     280299 AWF Changed disk format to use "-1" instead of "*" for easier
00030 //            matlab interaction.
00031 // \endverbatim
00032 //
00033 //-----------------------------------------------------------------------------
00034 
00035 #include <vnl/vnl_vector.h>
00036 #include <vcl_vector.h>
00037 #include <vcl_iosfwd.h>
00038 
00039 struct NViewMatch : public vnl_vector<int>
00040 {
00041   // Constants
00042   enum { nomatch = -1 };
00043 
00044   // Constructors
00045   NViewMatch() {}
00046   NViewMatch(int n): vnl_vector<int>(n, nomatch) {}
00047 
00048   // Operations
00049   bool matches(const NViewMatch& b, int min_overlap) const;
00050   void incorporate(const NViewMatch& b);
00051   bool is_consistent(const NViewMatch& b) const;
00052   int count_observations() const;
00053 };
00054 
00055 vcl_ostream& operator<<(vcl_ostream& s, const NViewMatch& c);
00056 
00057 class NViewMatches : public vcl_vector<NViewMatch>
00058 {
00059   // Data Members--------------------------------------------------------------
00060   int nviews_;
00061   int min_overlap_;
00062 
00063  public:
00064   // Constructors/Destructors--------------------------------------------------
00065   NViewMatches();
00066   NViewMatches(vcl_istream& s);
00067   NViewMatches(const char* filename);
00068   NViewMatches(int nviews, int min_overlap = 2);
00069   ~NViewMatches();
00070 
00071   // NViewMatches(const NViewMatches& that); - use default
00072   // NViewMatches& operator=(const NViewMatches& that); - use default
00073 
00074   // Operations----------------------------------------------------------------
00075   int nviews() const { return nviews_; }
00076 
00077   bool load(vcl_istream&);
00078   bool load(const char* filename);
00079 
00080   bool save(vcl_ostream&);
00081   bool save(const char* filename);
00082 
00083   void clear();
00084 
00085   int count_matches(const NViewMatch& match);
00086   vcl_vector<int> get_matches(const NViewMatch& match);
00087   int incorporate_triplet(int base_view, int c1, int c2, int c3);
00088   int incorporate(const NViewMatch& matches);
00089   void remove_inconsistencies();
00090   NViewMatch make_triplet_match(int base_view, int c1, int c2, int c3);
00091 };
00092 
00093 class OffsetNViewMatch : public NViewMatch
00094 {
00095   int min_view_;
00096  public:
00097   OffsetNViewMatch(int min_view, int max_view):
00098     NViewMatch(max_view - min_view + 1),
00099     min_view_(min_view)
00100   {
00101   }
00102 
00103   OffsetNViewMatch(const OffsetNViewMatch& that):
00104     NViewMatch(that),
00105     min_view_(that.min_view_)
00106   {
00107   }
00108 
00109   OffsetNViewMatch& operator=(const OffsetNViewMatch& that)
00110   {
00111     NViewMatch::operator=(that);
00112     min_view_ = that.min_view_;
00113     return *this;
00114   }
00115 
00116   int& operator[] (int i) { return NViewMatch::operator[] (i - min_view_); }
00117 };
00118 
00119 #endif // NViewMatches_h_