Go to the documentation of this file.00001 #ifndef rgrl_match_set_h_
00002 #define rgrl_match_set_h_
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include <vcl_vector.h>
00010 #include <vcl_cstddef.h>
00011 
00012 #include <rgrl/rgrl_feature_sptr.h>
00013 #include <rgrl/rgrl_feature_set.h>
00014 #include <rgrl/rgrl_object.h>
00015 #include <rgrl/rgrl_match_set_sptr.h>
00016 
00017 #include <vcl_iosfwd.h>
00018 
00019 class rgrl_transformation;
00020 
00021 
00022 class rgrl_match_set_from;
00023 
00024 
00025 class rgrl_match_set_from_iterator;
00026 class rgrl_match_set_from_to_iterator;
00027 
00028 class rgrl_match_set_const_from_iterator;
00029 class rgrl_match_set_const_from_to_iterator;
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 class rgrl_match_set
00046   : public rgrl_object
00047 {
00048  public:
00049   typedef vcl_size_t                          size_type;
00050   typedef rgrl_match_set_from_iterator        from_iterator;
00051   typedef rgrl_match_set_const_from_iterator  const_from_iterator;
00052 
00053  public:
00054   
00055   rgrl_match_set( );
00056 
00057   
00058   rgrl_match_set( const vcl_type_info& feature_type );
00059 
00060   
00061   rgrl_match_set( const vcl_type_info& from_type,
00062                   const vcl_type_info& to_type,
00063                   const rgrl_feature_set_label& from_label = rgrl_feature_set_label(),
00064                   const rgrl_feature_set_label& to_label = rgrl_feature_set_label() );
00065 
00066   
00067   const vcl_type_info&
00068   from_type() const { return *from_type_; }
00069 
00070   
00071   const vcl_type_info&
00072   to_type() const { return *to_type_; }
00073 
00074   
00075   const rgrl_feature_set_label&
00076   from_label() const
00077   { return from_label_; }
00078 
00079   
00080   const rgrl_feature_set_label&
00081   to_label() const
00082   { return to_label_; }
00083 
00084   
00085   size_type from_size() const;
00086 
00087   const_from_iterator from_begin() const;
00088 
00089   const_from_iterator from_end() const;
00090 
00091   from_iterator from_begin();
00092 
00093   from_iterator from_end();
00094 
00095   
00096   void clear();
00097 
00098   
00099   void write( vcl_ostream& os ) const;
00100 
00101   
00102   void write_sorted( vcl_ostream& os ) const;
00103 
00104   
00105   bool read( vcl_istream& is );
00106 
00107   
00108   
00109   void add_feature_and_matches( rgrl_feature_sptr                      from_feature,
00110                                 rgrl_feature_sptr                      mapped_feature,
00111                                 vcl_vector< rgrl_feature_sptr > const& matching_to );
00112 
00113   
00114   
00115   void add_feature_matches_and_weights( rgrl_feature_sptr                      from_feature,
00116                                         rgrl_feature_sptr                      mapped_feature,
00117                                         vcl_vector< rgrl_feature_sptr > const& matching_to,
00118                                         vcl_vector< double > const&            signature_weights );
00119 
00120   
00121   
00122   void add_feature_matches_and_weights( rgrl_feature_sptr                      from_feature,
00123                                         rgrl_feature_sptr                      mapped_feature,
00124                                         vcl_vector< rgrl_feature_sptr > const& matching_to,
00125                                         vcl_vector< double > const&            sig_wgts,
00126                                         vcl_vector< double > const&            geo_wgts,
00127                                         vcl_vector< double > const&            cum_wgts );
00128 
00129   
00130   
00131   
00132   
00133   
00134   
00135   void add_feature_and_match( rgrl_feature_sptr                      from_feature,
00136                               rgrl_feature_sptr                      mapped_feature,
00137                               rgrl_feature_sptr                      matching_to,
00138                               double                                 wgt = 1.0 );
00139 
00140   
00141   
00142   
00143   
00144   
00145   void remap_from_features( rgrl_transformation const& trans );
00146 
00147   
00148   
00149   
00150   
00151   
00152   
00153   void
00154   remap_only_location( rgrl_transformation const& trans );
00155 
00156   
00157   
00158   
00159 
00160   
00161   
00162   const vcl_type_info& from_feature_type() const {return *from_type_;}
00163   const vcl_type_info& to_feature_type() const {return *to_type_;}
00164 
00165   unsigned int num_constraints_per_match() const;
00166 
00167   
00168   
00169   void reserve( unsigned i ) {
00170     from_features_.reserve( i );
00171     xformed_from_features_.reserve(i);
00172     matches_and_weights_.reserve(i);
00173   }
00174 
00175  private:
00176   
00177   class match_info
00178   {
00179    public:
00180     
00181     
00182     
00183     
00184     match_info( rgrl_feature_sptr to_feat );
00185 
00186     
00187     
00188     
00189     match_info( rgrl_feature_sptr to_feat,
00190                 double geometric_wgt,
00191                 double signature_wgt,
00192                 double cumulative_wgt = 0);
00193 
00194     
00195     
00196     match_info( rgrl_feature_sptr to_feat,
00197                 double signature_wgt );
00198 
00199     rgrl_feature_sptr to_feature;
00200     double geometric_weight;
00201     double signature_weight;
00202     double cumulative_weight;
00203   };
00204 
00205   void set_num_constraints_per_match() const;
00206 
00207  private:
00208   friend class rgrl_match_set_from_iterator;
00209   friend class rgrl_match_set_const_from_iterator;
00210   friend class rgrl_match_set_from_to_iterator;
00211   friend class rgrl_match_set_const_from_to_iterator;
00212 
00213 
00214   const vcl_type_info* from_type_;
00215   const vcl_type_info* to_type_;
00216   rgrl_feature_set_label from_label_;
00217   rgrl_feature_set_label to_label_;
00218 
00219   mutable unsigned int num_constraints_per_match_;
00220   vcl_vector< rgrl_feature_sptr > from_features_;
00221   vcl_vector< rgrl_feature_sptr > xformed_from_features_;
00222   vcl_vector< vcl_vector< match_info > > matches_and_weights_;
00223 };
00224 
00225 
00226 vcl_ostream&
00227 operator<< ( vcl_ostream& os, rgrl_match_set const& set );
00228 
00229 
00230 vcl_istream&
00231 operator>> ( vcl_istream& is, rgrl_match_set& set );
00232 
00233 class rgrl_match_set_from_iterator
00234 {
00235  private:
00236   typedef rgrl_match_set::match_info                            match_info;
00237  public:
00238   typedef rgrl_match_set_from_to_iterator                       to_iterator;
00239   typedef vcl_vector< vcl_vector< match_info > >::size_type     size_type;
00240 
00241  public:
00242   
00243   
00244   
00245   rgrl_match_set_from_iterator( );
00246 
00247   rgrl_match_set_from_iterator& operator++();
00248   rgrl_match_set_from_iterator operator+( int );
00249 
00250   bool operator==( const rgrl_match_set_from_iterator& other ) const;
00251   bool operator!=( const rgrl_match_set_from_iterator& other ) const;
00252 
00253   
00254   to_iterator begin() const;
00255 
00256   
00257   to_iterator end() const;
00258 
00259   
00260   size_type size() const;
00261 
00262   
00263   bool empty() const;
00264 
00265   
00266   rgrl_feature_sptr from_feature() const;
00267 
00268   
00269   rgrl_feature_sptr mapped_from_feature() const;
00270 
00271  private:
00272   friend class rgrl_match_set;
00273   friend class rgrl_match_set_const_from_iterator;
00274 
00275   
00276   rgrl_match_set_from_iterator( rgrl_match_set* ms,
00277                                 vcl_vector< rgrl_feature_sptr >::size_type ind );
00278 
00279   rgrl_match_set* match_set_;
00280   vcl_vector< rgrl_feature_sptr >::size_type index_;
00281 };
00282 
00283 
00284 class rgrl_match_set_const_from_iterator
00285 {
00286  private:
00287   typedef rgrl_match_set::match_info                            match_info;
00288  public:
00289   typedef rgrl_match_set_const_from_to_iterator                 to_iterator;
00290   typedef vcl_vector< vcl_vector< match_info > >::size_type     size_type;
00291 
00292  public:
00293   
00294   
00295   
00296   rgrl_match_set_const_from_iterator( );
00297 
00298   
00299   
00300   rgrl_match_set_const_from_iterator( rgrl_match_set_from_iterator const& from_iter );
00301 
00302   rgrl_match_set_const_from_iterator& operator++();
00303   rgrl_match_set_const_from_iterator operator++( int );
00304   rgrl_match_set_const_from_iterator operator+( int );
00305 
00306   bool operator==( const rgrl_match_set_const_from_iterator& other ) const;
00307   bool operator!=( const rgrl_match_set_const_from_iterator& other ) const;
00308 
00309   
00310   to_iterator begin() const;
00311 
00312   
00313   to_iterator end() const;
00314 
00315   
00316   size_type size() const;
00317 
00318   
00319   bool empty() const;
00320 
00321   
00322   rgrl_feature_sptr const& from_feature() const;
00323 
00324   
00325   rgrl_feature_sptr const& mapped_from_feature() const;
00326 
00327  private:
00328   friend class rgrl_match_set;
00329 
00330   
00331   rgrl_match_set_const_from_iterator( rgrl_match_set const* ms,
00332                                       vcl_vector< rgrl_feature_sptr >::size_type ind );
00333 
00334   rgrl_match_set const* match_set_;
00335   vcl_vector< rgrl_feature_sptr >::size_type index_;
00336 };
00337 
00338 
00339 class rgrl_match_set_from_to_iterator
00340 {
00341  public:
00342   rgrl_match_set_from_to_iterator( );
00343 
00344   
00345   
00346   
00347 
00348   
00349   rgrl_match_set_from_to_iterator& operator++();
00350   rgrl_match_set_from_to_iterator operator+(int RHS);
00351 
00352   bool operator==( const rgrl_match_set_from_to_iterator& other ) const;
00353   bool operator!=( const rgrl_match_set_from_to_iterator& other ) const;
00354 
00355   
00356   rgrl_feature_sptr to_feature() const;
00357 
00358   
00359   double geometric_weight() const;
00360 
00361   
00362   double signature_weight() const;
00363 
00364   
00365   double cumulative_weight() const;
00366 
00367   
00368   void set_geometric_weight( double geom_wgt );
00369 
00370   
00371   void set_signature_weight( double sig_wgt );
00372 
00373   
00374   void set_cumulative_weight( double cum_wgt );
00375 
00376  protected:
00377 
00378   friend class rgrl_match_set_from_iterator;
00379   friend class rgrl_match_set_const_from_to_iterator;
00380 
00381   typedef rgrl_match_set::match_info match_info;
00382   typedef vcl_vector< match_info >::iterator MatchInfoIter;
00383   
00384   rgrl_match_set_from_to_iterator( MatchInfoIter const& itr );
00385 
00386   MatchInfoIter itr_;
00387 };
00388 
00389 
00390 class rgrl_match_set_const_from_to_iterator
00391 {
00392  public:
00393   typedef rgrl_match_set_const_from_to_iterator self_type;
00394  public:
00395   rgrl_match_set_const_from_to_iterator( );
00396 
00397   
00398   
00399   
00400 
00401   
00402   
00403   rgrl_match_set_const_from_to_iterator( rgrl_match_set_from_to_iterator const& to_iter );
00404 
00405   
00406   self_type& operator++();
00407   self_type operator+(int RHS);
00408 
00409   bool operator==( const self_type& other ) const;
00410   bool operator!=( const self_type& other ) const;
00411 
00412   
00413   rgrl_feature_sptr const& to_feature() const;
00414 
00415   
00416   double geometric_weight() const;
00417 
00418   
00419   double signature_weight() const;
00420 
00421   
00422   double cumulative_weight() const;
00423 
00424  protected:
00425 
00426   friend class rgrl_match_set_const_from_iterator;
00427   typedef rgrl_match_set::match_info match_info;
00428   typedef vcl_vector< match_info >::const_iterator MatchInfoIter;
00429   
00430   rgrl_match_set_const_from_to_iterator( MatchInfoIter const& itr );
00431 
00432   MatchInfoIter itr_;
00433 };
00434 
00435 
00436 #endif // rgrl_match_set_h_