Go to the documentation of this file.00001 #include "rgrl_view.h"
00002
00003
00004
00005
00006
00007
00008 #include <rgrl/rgrl_estimator.h>
00009 #include <rgrl/rgrl_feature_set.h>
00010
00011 #include <vcl_cstdlib.h>
00012 #include <vcl_cassert.h>
00013
00014 rgrl_view::
00015 rgrl_view()
00016 : from_image_roi_(0),
00017 to_image_roi_(0),
00018 current_region_(0),
00019 global_region_(0),
00020 current_resolution_(0),
00021 num_updates_global_region_(0)
00022 {
00023 }
00024
00025 rgrl_view::
00026 rgrl_view( rgrl_mask_sptr const& from_image_roi,
00027 rgrl_mask_sptr const& to_image_roi,
00028 rgrl_mask_box const& region,
00029 rgrl_mask_box const& global_region,
00030 rgrl_estimator_sptr xform_estimator,
00031 rgrl_transformation_sptr xform_estimate,
00032 unsigned resolution,
00033 rgrl_transformation_sptr inverse_estimate )
00034 : from_image_roi_( from_image_roi ),
00035 to_image_roi_( to_image_roi ),
00036 current_region_( region ),
00037 global_region_( global_region ),
00038 xform_estimator_( xform_estimator ),
00039 xform_estimate_( xform_estimate ),
00040 inverse_estimate_( inverse_estimate ),
00041 current_resolution_( resolution ),
00042 num_updates_global_region_(0)
00043 {
00044 if ( !from_image_roi || !to_image_roi )
00045 {
00046 WarningMacro( "ERROR: invalid From/To image ROI.\n In the simplest case, supply an instance of rgrl_mask_box.\n" );
00047 assert( 0 ) ;
00048 }
00049 }
00050
00051
00052 rgrl_view_sptr
00053 rgrl_view::
00054 self_copy() const
00055 {
00056 return new rgrl_view( *this );
00057 }
00058
00059 bool
00060 rgrl_view::
00061 is_at_finest_resolution() const
00062 {
00063 return current_resolution_ == 0;
00064 }
00065
00066 bool
00067 rgrl_view::
00068 current_region_converged() const
00069 {
00070 return current_region_ == global_region_;
00071 }
00072
00073 bool
00074 rgrl_view::
00075 regions_converged_to(const rgrl_view& other) const
00076 {
00077
00078
00079
00080 bool current_region_changed =
00081 ( (this->current_region_.x0() - other.current_region_.x0()).inf_norm() > 1 ||
00082 (this->current_region_.x1() - other.current_region_.x1()).inf_norm() > 1);
00083
00084
00085
00086 bool current_global_region_changed =
00087 ( (this->global_region_.x0() - other.global_region_.x0()).inf_norm() > 1 ||
00088 (this->global_region_.x1() - other.global_region_.x1()).inf_norm() > 1);
00089
00090 return !current_region_changed &&
00091 !current_global_region_changed &&
00092 this->from_image_roi_ == other.from_image_roi_ &&
00093 this->to_image_roi_ == other.to_image_roi_ &&
00094 this->xform_estimator_->transformation_type() == other.xform_estimator_->transformation_type() &&
00095 this->current_resolution_ == other.current_resolution_;
00096 }
00097
00098 bool
00099 rgrl_view::is_valid() const
00100 {
00101 return xform_estimator_ && xform_estimate_;
00102 }
00103
00104 rgrl_view_sptr
00105 rgrl_view::
00106 scale_by( unsigned new_resol, double scaling ) const
00107 {
00108
00109
00110
00111
00112
00113
00114 rgrl_mask_sptr from_new_roi, to_new_roi;
00115
00116 if ( vcl_abs(scaling-1.0) <= 1e-5 )
00117 {
00118 from_new_roi = from_image_roi();
00119 to_new_roi = to_image_roi();
00120 }
00121 else
00122 {
00123
00124 from_new_roi = new rgrl_mask_box( from_image_roi()->x0()*scaling,
00125 from_image_roi()->x1()*scaling );
00126 to_new_roi = new rgrl_mask_box( to_image_roi()->x0()*scaling,
00127 to_image_roi()->x1()*scaling );
00128 }
00129
00130 rgrl_mask_box new_current_region( region().x0()*scaling,
00131 region().x1()*scaling);
00132 rgrl_mask_box new_global_region( global_region().x0()*scaling,
00133 global_region().x1()*scaling );
00134
00135
00136 rgrl_transformation_sptr new_xform_estimate;
00137 if ( xform_estimate() )
00138 new_xform_estimate = xform_estimate()->scale_by( scaling );
00139
00140
00141 rgrl_transformation_sptr new_inv_xform_estimate;
00142 if ( inverse_xform_estimate() )
00143 new_inv_xform_estimate = inverse_xform_estimate()->scale_by( scaling );
00144
00145 return new rgrl_view( from_new_roi, to_new_roi,
00146 new_current_region, new_global_region,
00147 xform_estimator(),
00148 new_xform_estimate,
00149 new_resol,
00150 new_inv_xform_estimate);
00151 }
00152
00153
00154
00155 bool
00156 rgrl_view::
00157 features_in_region( feature_vector& features, rgrl_feature_set const& fea_set ) const
00158 {
00159 fea_set.features_in_region( features, current_region_ );
00160 return true;
00161 }
00162
00163 bool
00164 rgrl_view::
00165 inside_current_region( vnl_vector<double> const& loc )
00166 {
00167 return current_region_.inside( loc );
00168 }
00169
00170 #if 0
00171 bool
00172 rgrl_view::
00173 operator==( const rgrl_view& other ) const
00174 {
00175 return this->from_image_roi_.x0() == other.from_image_roi_.x0() &&
00176 this->from_image_roi_.x1() == other.from_image_roi_.x1() &&
00177 this->to_image_roi_.x0() == other.to_image_roi_.x0() &&
00178 this->to_image_roi_.x1() == other.to_image_roi_.x1() &&
00179 this->current_region_.x0() == other.current_region_.x0() &&
00180 this->current_region_.x1() == other.current_region_.x1() &&
00181 this->global_region_.x0() == other.global_region_.x0() &&
00182 this->global_region_.x1() == other.global_region_.x1() &&
00183 this->xform_estimator_ == other.xform_estimator_ &&
00184
00185 this->current_resolution_ == other.current_resolution_;
00186 }
00187
00188 bool
00189 rgrl_view::
00190 operator!=( const rgrl_view& other ) const
00191 {
00192 return !( *this == other );
00193 }
00194 #endif // 0