contrib/rpl/rgrl/rgrl_view.h
Go to the documentation of this file.
00001 #ifndef rgrl_view_h_
00002 #define rgrl_view_h_
00003 //:
00004 // \file
00005 // \brief  Represent a "view" of the registration problem.
00006 // \author Chuck Stewart
00007 // \date 12 Nov 2002
00008 // \verbatim
00009 // Modifications
00010 //   June.2005 - Gehua Yang - change image ROI from rgrl_mask_box to rgrl_mask_sptr
00011 //   Oct. 2006 - Gehua Yang - add a virtual function to scale the view by a scalar ratio
00012 // \endverbatim
00013 
00014 
00015 #include <rgrl/rgrl_transformation_sptr.h>
00016 #include <rgrl/rgrl_estimator_sptr.h>
00017 #include <rgrl/rgrl_mask.h>
00018 #include <rgrl/rgrl_mask_sptr.h>
00019 
00020 #include <rgrl/rgrl_view_sptr.h>
00021 #include <rgrl/rgrl_feature_sptr.h>
00022 #include <rgrl/rgrl_fwd.h>
00023 #include <vcl_stlfwd.h>
00024 
00025 //: Represents a "view" of the registration problem.
00026 //
00027 // A view captures the current region, the current transformation (and
00028 // estimator), and the current resolution.
00029 //
00030 class rgrl_view
00031   : public rgrl_object
00032 {
00033  public:
00034   
00035   typedef vcl_vector< rgrl_feature_sptr > feature_vector;
00036   
00037   //: ctor
00038   rgrl_view();
00039   
00040   //:  Build a view for registration estimation problem.
00041   rgrl_view( rgrl_mask_sptr      const& from_image_roi,
00042              rgrl_mask_sptr      const& to_image_roi,
00043              rgrl_mask_box       const& region,
00044              rgrl_mask_box       const& global_region,
00045              rgrl_estimator_sptr        xform_estimator,
00046              rgrl_transformation_sptr   xform_estimate,
00047              unsigned                   resolution = 0,
00048              rgrl_transformation_sptr   inverse_estimate = 0 );
00049 
00050   // default copy and assignment are good.
00051 
00052   //: return a self copy
00053   virtual
00054   rgrl_view_sptr
00055   self_copy() const;
00056   
00057   //:  Access "from" image region of interest
00058   rgrl_mask_sptr const& from_image_roi() const
00059   { return from_image_roi_; }
00060 
00061   //: set "from" image region of interest
00062   void set_from_image_roi(rgrl_mask_sptr const& roi)
00063   { from_image_roi_ = roi; }
00064     
00065   //:  Access "to" image region of interest
00066   rgrl_mask_sptr const& to_image_roi() const
00067   { return to_image_roi_; }
00068 
00069   //: set "to" image region of interest
00070   void set_to_image_roi(rgrl_mask_sptr const& roi)
00071   { to_image_roi_ = roi; }
00072 
00073   //:  Access current transformation region in "from" image coords
00074   rgrl_mask_box const& region() const
00075   { return current_region_; }
00076   
00077   //: set current region in "from" image coords
00078   void set_region( rgrl_mask_box const& box )
00079   { current_region_ = box; }
00080 
00081   //:  Access the approximated overlap region in "from" image coords
00082   rgrl_mask_box const& global_region() const
00083   { return global_region_; }
00084 
00085   //: set the approximated overlap region in "from" image coords
00086   void set_global_region( rgrl_mask_box const& global_region )
00087   { global_region_ = global_region; }
00088   
00089   //:  Access current transform estimator
00090   rgrl_estimator_sptr xform_estimator() const
00091   { return xform_estimator_; }
00092   
00093   //: set current transform estimator
00094   void set_xform_estimator( rgrl_estimator_sptr const& est)
00095   { xform_estimator_ = est; }
00096 
00097   //:  Access current transform estimate
00098   rgrl_transformation_sptr xform_estimate() const
00099   { return xform_estimate_; }
00100   
00101   //: set current transform estimate
00102   void set_xform_estimate( rgrl_transformation_sptr const& xform )
00103   { xform_estimate_ = xform; }
00104 
00105   //:  Access current REVERSE transform estimate
00106   rgrl_transformation_sptr inverse_xform_estimate() const
00107   { return inverse_estimate_; }
00108   
00109   //:  Set REVERSE transform estimate
00110   void set_inverse_xform_estimate(rgrl_transformation_sptr const& inverse)
00111   { inverse_estimate_ = inverse; }
00112 
00113   //:  Access the current resolution at which registration is working
00114   unsigned resolution() const
00115   { return current_resolution_; }
00116   
00117   //:  Set current resolution
00118   void set_resolution( unsigned res )
00119   { current_resolution_ = res; }
00120 
00121   //:  Return true if the current resolution is the finest level
00122   bool is_at_finest_resolution() const;
00123 
00124   //: get number of updates on global region
00125   int num_updates_global_region() const
00126   { return num_updates_global_region_; }
00127   
00128   //: set number of updates on global region
00129   //  shall be done inside view generator
00130   void set_num_updates_global_region(int num)
00131   { num_updates_global_region_ = num; }
00132 
00133   //: extract features within current region
00134   //  feature vector will be cleared before the operation
00135   virtual
00136   bool
00137   features_in_region( feature_vector& features, rgrl_feature_set const& fea_set ) const;
00138   
00139   //:  Return true if the current_region_ reached the global_region_
00140   virtual 
00141   bool current_region_converged() const;
00142 
00143   //:  Return true if all components except the xform_estimate_ are the same
00144   //
00145   virtual
00146   bool regions_converged_to(const rgrl_view& other) const;
00147 
00148   //:  Return true if both xform_estimator_ and xform_estimate_ are not null
00149   virtual
00150   bool is_valid() const;
00151 
00152   //: scale a view by a ratio
00153   virtual
00154   rgrl_view_sptr scale_by( unsigned new_resol, double scaling ) const;
00155 
00156   virtual
00157   bool
00158   inside_current_region( vnl_vector<double> const& loc );
00159   
00160 #if 0
00161   //: True iff all the components are equal.
00162   bool operator==( const rgrl_view& other ) const;
00163 
00164   //: True iff some of the components are not equal.
00165   bool operator!=( const rgrl_view& other ) const;
00166 #endif
00167 
00168   // Defines type-related functions
00169   rgrl_type_macro( rgrl_view, rgrl_object );
00170 
00171  protected:
00172   rgrl_mask_sptr                  from_image_roi_;
00173   rgrl_mask_sptr                  to_image_roi_;
00174 
00175   rgrl_mask_box                   current_region_;
00176   rgrl_mask_box                   global_region_; //The estimated overlap region
00177                                                   //of from_image_roi_ with
00178                                                   //to_image_roi_
00179 
00180   rgrl_estimator_sptr        xform_estimator_;
00181   rgrl_transformation_sptr   xform_estimate_;
00182   rgrl_transformation_sptr   inverse_estimate_;
00183   
00184   unsigned                   current_resolution_;
00185   int                        num_updates_global_region_;
00186 };
00187 
00188 
00189 #endif // rgrl_view_h_