1 // This is oxl/mvl/NViewMatches.h 2 #ifndef NViewMatches_h_ 3 #define NViewMatches_h_ 4 //: 5 // \file 6 // \brief Multiple view matches with wildcards 7 // 8 // A class to hold matches over multiple views, allowing for unmatched data. 9 // With each 3d feature there is associated a multiple-view match. A 10 // multiple-view match is a vector of integers (NViewMatch) which identify 11 // 2d features in each view. 12 // 13 // If for example a 3d point X has NViewMatch "Xmatches", then 14 // Xmatches[v] = i implies that the image of X in view "v" is the corner 15 // with index "i" in view "v". 16 // 17 // \author 18 // Andrew W. Fitzgibbon, Oxford RRG, 17 May 97 19 // \verbatim 20 // Modifications: 21 // 970517 AWF Initial version. 22 // 270897 PRV Moved std::vector<NViewMatch> instantiation to Templates package 23 // 151097 AWF Added OffsetNViewMatch. 24 // 280498 David Capel made minimum match overlap user-definable, 25 // allowed merging of consistent multiple-match tracks. 26 // 280299 AWF Changed disk format to use "-1" instead of "*" for easier 27 // matlab interaction. 28 // \endverbatim 29 // 30 //----------------------------------------------------------------------------- 31 32 #include <vector> 33 #include <iostream> 34 #include <iosfwd> 35 #include <vnl/vnl_vector.h> 36 #ifdef _MSC_VER 37 # include <vcl_msvc_warnings.h> 38 #endif 39 40 struct NViewMatch : public vnl_vector<int> 41 { 42 // Constants 43 enum { nomatch = -1 }; 44 45 // Constructors 46 NViewMatch() = default; NViewMatchNViewMatch47 NViewMatch(int n): vnl_vector<int>(n, nomatch) {} 48 49 // Operations 50 bool matches(const NViewMatch& b, int min_overlap) const; 51 void incorporate(const NViewMatch& b); 52 bool is_consistent(const NViewMatch& b) const; 53 int count_observations() const; 54 }; 55 56 std::ostream& operator<<(std::ostream& s, const NViewMatch& c); 57 58 class NViewMatches : public std::vector<NViewMatch> 59 { 60 // Data Members-------------------------------------------------------------- 61 int nviews_; 62 int min_overlap_{2}; 63 64 public: 65 // Constructors/Destructors-------------------------------------------------- 66 NViewMatches(); 67 NViewMatches(std::istream& s); 68 NViewMatches(const char* filename); 69 NViewMatches(int nviews, int min_overlap = 2); 70 ~NViewMatches(); 71 72 // NViewMatches(const NViewMatches& that); - use default 73 // NViewMatches& operator=(const NViewMatches& that); - use default 74 75 // Operations---------------------------------------------------------------- nviews()76 int nviews() const { return nviews_; } 77 78 bool load(std::istream&); 79 bool load(const char* filename); 80 81 bool save(std::ostream&); 82 bool save(const char* filename); 83 84 void clear(); 85 86 int count_matches(const NViewMatch& match); 87 std::vector<int> get_matches(const NViewMatch& match); 88 int incorporate_triplet(int base_view, int c1, int c2, int c3); 89 int incorporate(const NViewMatch& matches); 90 void remove_inconsistencies(); 91 NViewMatch make_triplet_match(int base_view, int c1, int c2, int c3) const; 92 }; 93 94 class OffsetNViewMatch : public NViewMatch 95 { 96 int min_view_; 97 public: OffsetNViewMatch(int min_view,int max_view)98 OffsetNViewMatch(int min_view, int max_view): 99 NViewMatch(max_view - min_view + 1), 100 min_view_(min_view) 101 { 102 } 103 104 OffsetNViewMatch(const OffsetNViewMatch& that) = default; 105 106 OffsetNViewMatch& operator=(const OffsetNViewMatch& that) = default; 107 108 int& operator[] (int i) { return NViewMatch::operator[] (i - min_view_); } 109 }; 110 111 #endif // NViewMatches_h_ 112