contrib/oxl/mvl/mvl_multi_view_matches.h
Go to the documentation of this file.
00001 // This is oxl/mvl/mvl_multi_view_matches.h
00002 #ifndef mvl_multi_view_matches_h_
00003 #define mvl_multi_view_matches_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 //  \file
00009 // \brief Multiple view matches
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 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 //     David Capel, Oxford RRG, 16 April 2000
00022 //-----------------------------------------------------------------------------
00023 
00024 #include <vcl_functional.h>
00025 #include <vcl_vector.h>
00026 #include <vcl_iosfwd.h>
00027 #include <vcl_map.h>
00028 
00029 class mvl_multi_view_matches
00030 {
00031  public:
00032   typedef vcl_map<unsigned int, unsigned int, vcl_less<unsigned int> > Map;
00033 
00034   mvl_multi_view_matches(char const* filename);
00035   mvl_multi_view_matches(vcl_vector<int> const& views);
00036   mvl_multi_view_matches(int start, int end, int step = 1);
00037   mvl_multi_view_matches(int N);
00038 
00039   ~mvl_multi_view_matches();
00040 
00041   //: Set the view indices to which this match set will refer
00042   void set_views(vcl_vector<int> const& views);
00043   void set_views(int start, int end, int step = 1);
00044   void set_views(int N);
00045 
00046   //: Merge-in single match tracks. The view indices are \e real (i.e on-disk) indices.
00047   void add_pair(int view1, int corner1, int view2, int corner2);
00048   void add_triplet(int view1, int corner1, int view2, int corner2, int view3, int corner3);
00049   void add_track(vcl_vector<int> const& views, vcl_vector<int> const& corners);
00050 
00051   //: Merge-in a whole set of matches (possibly from a different set of views)
00052   void add_matches(mvl_multi_view_matches const& matches);
00053 
00054   int num_views() const { return views_.size(); }
00055   int num_tracks() const { return tracks_.size(); }
00056 
00057   //: Get the <frame,corner> map for track i (frame = track.first, corner = track.second)
00058   Map& get_track(int i) { return tracks_[i]; }
00059   //: Get the mapping from track frame to real view index (real_view_index = get_view_indices[track.first])
00060   vcl_vector<int>& get_view_indices () { return views_; }
00061 
00062   //: Standard I/O
00063   vcl_ostream& print(vcl_ostream&) const;
00064   vcl_istream& read(vcl_istream&);
00065   vcl_ostream& write(vcl_ostream&) const;
00066 
00067   //: Convenience
00068   void read(char const* file);
00069   void write(char const* file) const;
00070 
00071  protected:
00072   vcl_vector<int> views_;                 // maps internal frame index to real view indices
00073   Map view_to_internal_map_;              // maps real view indices to internal frame index
00074   vcl_vector<Map> tracks_;                // one map<internal_frame, corner> per track
00075   vcl_vector<Map> corner_to_track_maps_;  // one map<corner, track> per internal_frame
00076 
00077   void init();
00078   void update_maps(int track_index);      // iterate over tracks_[track_index]
00079                                           // and update the corner_to_track_maps_ to point to track_index
00080   void remove_maps(int track_index);      // iterate over tracks_[track_index] and remove the corner_to_track_maps_
00081 };
00082 
00083 inline vcl_ostream& operator<<(vcl_ostream& s, mvl_multi_view_matches const& v) { return v.print(s); }
00084 inline vcl_istream& operator>>(vcl_istream& s, mvl_multi_view_matches& v) { return v.read(s); }
00085 
00086 #endif // mvl_multi_view_matches_h_