contrib/rpl/rgrl/rgrl_initializer_inv_indexing.h
Go to the documentation of this file.
00001 #ifndef rgrl_initializer_inv_indexing_h_
00002 #define rgrl_initializer_inv_indexing_h_
00003 //:
00004 // \file
00005 // \brief Generate a set of initial estimates using invariant indexing
00006 // \author Charlene Tsai
00007 // \date March 2004
00008 
00009 #include "rgrl_initializer.h"
00010 
00011 #include <vcl_vector.h>
00012 
00013 #include "rgrl_view_sptr.h"
00014 #include "rgrl_mask.h"
00015 #include "rgrl_invariant_match_sptr.h"
00016 #include "rgrl_invariant_sptr.h"
00017 
00018 //: Generate the set of initial estimates using invariant indexing.
00019 //
00020 //  The underlying data structure is rrel_kd_tree for
00021 //  k-dimensional invariant fields. The transformation model is
00022 //  determined by the invariant class. Therefore, no estimator is
00023 //  associated with the initializer.
00024 //
00025 class rgrl_initializer_inv_indexing
00026   : public rgrl_initializer
00027 {
00028  public:
00029   //: Constructor
00030   rgrl_initializer_inv_indexing( rgrl_view_sptr prior_view,
00031                                  bool should_estimate_global_region = true,
00032                                  int max_num_matches_tried = -1);
00033 
00034   rgrl_initializer_inv_indexing( rgrl_mask_sptr const&     from_image_roi,
00035                                  rgrl_mask_sptr const&     to_image_roi,
00036                                  rgrl_estimator_sptr xform_estimator = 0,
00037                                  unsigned             initial_resolution = 0,
00038                                  bool should_estimate_global_region = true,
00039                                  int max_num_matches_tried = -1);
00040 
00041   //: Destructor
00042   ~rgrl_initializer_inv_indexing() {}
00043 
00044   //: Add the set of invariants from the fixed image and the set from one moving image
00045   //
00046   //  Matches are sorted in order of decreasing distance. \a
00047   //  nn_radius has precedence over \a k_nn. If no neighbor falls in
00048   //  \a nn_radius, \a k_nn are taken.
00049   //
00050   //  \param nn_radius  nearest-neighbors in nn_radius.
00051   //  \param k   k-nearest neighbor(s)
00052   void add_data( vcl_vector<rgrl_invariant_sptr> const& fixed_set,
00053                  vcl_vector<rgrl_invariant_sptr> const& moving_set,
00054                  double nn_radius = 0,
00055                  unsigned int k_nn = 1 );
00056 
00057   //: Add a set of invariants from the fixed image and multiple sets from multiple moving images
00058   //
00059   //  Matches are sorted in order of decreasing distance. \a
00060   //  nn_radius has precedence over \a k_nn. If no neighbor falls in
00061   //  \a nn_radius, \a k_nn are taken.
00062   //
00063   //  \param nn_radius nearest-neighbors in nn_radius.
00064   //  \param k_nn k-nearest-neighbor(s)
00065   virtual void add_multiple_data( vcl_vector<rgrl_invariant_sptr> const& fixed_set,
00066                                   vcl_vector<vcl_vector<rgrl_invariant_sptr> > const& moving_sets,
00067                                   double nn_radius = 0,
00068                                   unsigned int k_nn = 1);
00069 
00070   //: Set the index of the current moving image. Default is the 0th moving-image
00071   void set_current_moving_image( unsigned int moving_image_index);
00072 
00073   //: Return the matches for the given \a moving_image_index.
00074   const vcl_vector<rgrl_invariant_match_sptr>& matches_for_moving_image( unsigned int moving_image_index);
00075 
00076   //: Get and remove the next initial estimate from the end of the list for the current moving_set
00077   bool next_initial( rgrl_view_sptr  & view,
00078                      rgrl_scale_sptr & prior_scale);
00079 
00080   //: Get and remove the next initial estimate from the end of the list for the current moving_set
00081   //  Return this match in best_match
00082   bool next_initial( rgrl_invariant_match_sptr& best_match );
00083 
00084   //: return number of initializations
00085   //  -1 stands for unknown
00086   virtual int size() const;
00087 
00088   // Defines type-related functions
00089   rgrl_type_macro( rgrl_initializer_inv_indexing, rgrl_initializer );
00090 
00091  protected:
00092   vcl_vector<vcl_vector<rgrl_invariant_match_sptr> > matches_;
00093   rgrl_view_sptr view_;
00094   bool should_estimate_global_region_;
00095   unsigned int current_moving_image_ind_;
00096   int num_matches_tried_;
00097   int max_num_matches_tried_;
00098 };
00099 
00100 #endif