00001
00002 #ifndef vipl_section_container_txx_
00003 #define vipl_section_container_txx_
00004
00005 #include "vipl_section_container.h"
00006 #include <vipl/filter/vipl_filter_abs.h>
00007 #include <vipl/section/vipl_section_iterator.txx>
00008 #include <vipl/section/vipl_section_descriptor.txx>
00009 #include <vcl_iostream.h>
00010
00011
00012 template < class DataType >
00013 vipl_section_container< DataType > ::vipl_section_container( vipl_section_container< DataType >* pt)
00014 : hsthe(pt),
00015 hsimgsz (2,0),
00016 hsimgstart (2,0),
00017 hssecsz (2,0),
00018 hsoverlap (2,0),
00019 hsrawdata (0),
00020 hsimgptr (0),
00021 refcount_ (1)
00022 {}
00023
00024
00025 template < class DataType >
00026 vipl_section_container< DataType > ::vipl_section_container( const vipl_section_container< DataType >* pt , int t)
00027 : hsthe(0),
00028 hsimgsz (2,0),
00029 hsimgstart (2,0),
00030 hssecsz (2,0),
00031 hsoverlap (2,0),
00032 hsrawdata (0),
00033 hsimgptr (0),
00034 refcount_ (1)
00035 {
00036 hsthe = pt->virtual_copy();
00037 }
00038
00039 template < class DataType >
00040 vipl_section_container< DataType > ::~vipl_section_container()
00041 {
00042
00043 if (hsthe && (hsthe != this)) FILTER_IMPTR_DEC_REFCOUNT(hsthe);
00044 }
00045
00046 template < class DataType >
00047 vipl_section_container< DataType > ::vipl_section_container()
00048 : hsthe(this),
00049 hsimgsz (2,0),
00050 hsimgstart (2,0),
00051 hssecsz (2,0),
00052 hsoverlap (2,0),
00053 hsrawdata (0),
00054 hsimgptr (0),
00055 refcount_ (1)
00056
00057 {}
00058
00059 template < class DataType >
00060 vipl_section_container< DataType > ::vipl_section_container(const vipl_section_container< DataType > &t)
00061 : hsthe(0),
00062 hsimgsz(t.hsimgsz),
00063 hsimgstart(t.hsimgstart),
00064 hssecsz(t.hssecsz),
00065 hsoverlap(t.hsoverlap),
00066 hsrawdata(t.hsrawdata),
00067 hsimgptr(t.hsimgptr),
00068 refcount_ (1)
00069
00070 {
00071
00072
00073
00074
00075
00076
00077 hsthe = t.hsthe->virtual_copy();
00078 }
00079
00080 template < class DataType >
00081 vipl_section_iterator< DataType > vipl_section_container< DataType > ::begin()
00082 {
00083 vipl_section_descriptor<DataType> *ptr = new vipl_section_descriptor<DataType>(0, virtual_copy());
00084 ptr->put_real_descriptor(ptr);
00085 ptr->ref_i_curr_sec_start()[0] = 0;
00086 ptr->ref_i_curr_sec_start()[1] = 0;
00087 ptr->ref_i_curr_sec_end()[0] = secsz()[0] + overlap()[0];
00088 ptr->ref_i_curr_sec_end()[1] = secsz()[1] + overlap()[1];
00089 if (ptr->ref_i_curr_sec_end()[0] > image_size(0))
00090 ptr->ref_i_curr_sec_end()[0] = image_size(0);
00091 if (ptr->ref_i_curr_sec_end()[1] > image_size(1))
00092 ptr->ref_i_curr_sec_end()[1] = image_size(1);
00093 ptr->ref_i_curr_sec_size()[0] = ptr->ref_i_curr_sec_end()[0];
00094 ptr->ref_i_curr_sec_size()[1] = ptr->ref_i_curr_sec_end()[1];
00095 vipl_section_iterator<DataType> i(ptr, virtual_copy());
00096 return i;
00097 }
00098
00099 template < class DataType >
00100 vipl_section_iterator< DataType > vipl_section_container< DataType > ::end()
00101 {
00102
00103 vipl_section_iterator<DataType> i(0, virtual_copy());
00104 return i;
00105 }
00106
00107 template < class DataType >
00108 const vipl_section_iterator< DataType > vipl_section_container< DataType > ::begin() const
00109 {
00110 vipl_section_descriptor<DataType> *ptr =
00111 new vipl_section_descriptor<DataType>(0, virtual_copy());
00112 ptr->put_real_descriptor(ptr);
00113 ptr->ref_i_curr_sec_start()[0] = 0;
00114 ptr->ref_i_curr_sec_start()[1] = 0;
00115 if (ptr->ref_i_curr_sec_end()[0] > image_size(0))
00116 ptr->ref_i_curr_sec_end()[0] = image_size(0);
00117 if (ptr->ref_i_curr_sec_end()[1] > image_size(1))
00118 ptr->ref_i_curr_sec_end()[1] = image_size(1);
00119 ptr->ref_i_curr_sec_size()[0] = ptr->ref_i_curr_sec_end()[0];
00120 ptr->ref_i_curr_sec_size()[1] = ptr->ref_i_curr_sec_end()[1];
00121 vipl_section_iterator<DataType> i(ptr, virtual_copy());
00122 return i;
00123 }
00124
00125 template < class DataType >
00126 const vipl_section_iterator< DataType > vipl_section_container< DataType > ::end() const
00127 {
00128
00129 vipl_section_iterator<DataType> i(0, virtual_copy());
00130 return i;
00131 }
00132
00133
00134 template < class DataType >
00135 bool vipl_section_container< DataType > ::operator==( const vipl_section_container< DataType >& b) const
00136 {
00137 if (this == &b) return true;
00138
00139
00140
00141 return hsimgptr == b.hsimgptr;
00142 }
00143
00144 template < class DataType >
00145 bool vipl_section_container< DataType > ::operator!=( const vipl_section_container< DataType >& b) const
00146 {
00147 return !(*this == b);
00148 }
00149
00150 template < class DataType >
00151 vipl_section_container< DataType >& vipl_section_container< DataType > ::operator=( const vipl_section_container< DataType >& b)
00152 {
00153 if (this != &b) {
00154 if (hsthe != this) FILTER_IMPTR_DEC_REFCOUNT(hsthe);
00155 hsthe = b.hsthe->virtual_copy();
00156
00157 put_imgsz(b.imgsz());
00158 put_secsz(b.secsz());
00159 }
00160 return *this;
00161 }
00162
00163 template < class DataType >
00164 int vipl_section_container< DataType > ::size() const
00165 {
00166 return ((imgsz()[0] / secsz()[0]) + ((imgsz()[0] % secsz()[0]) ? 1 : 0)) *
00167 ((imgsz()[1] / secsz()[1]) + ((imgsz()[1] % secsz()[1]) ? 1 : 0));
00168 }
00169
00170 template < class DataType >
00171 int vipl_section_container< DataType > ::max_size() const
00172 { return size(); }
00173
00174 template < class DataType >
00175 bool vipl_section_container< DataType > ::empty()
00176 { return false; }
00177
00178
00179
00180 template < class DataType >
00181 bool vipl_section_container< DataType > ::operator<( const vipl_section_container< DataType >& ) const
00182 {
00183 vcl_cerr << "Warning: called unimplemented method vipl_section_container::operator<\n";
00184 return false;
00185 }
00186
00187 template < class DataType >
00188 bool vipl_section_container< DataType > ::operator>( const vipl_section_container< DataType >& ) const
00189 {
00190 vcl_cerr << "Warning: called unimplemented method vipl_section_container::operator>\n";
00191 return false;
00192 }
00193
00194 template < class DataType >
00195 bool vipl_section_container< DataType > ::operator<=( const vipl_section_container< DataType >& ) const
00196 {
00197 vcl_cerr << "Warning: called unimplemented method vipl_section_container::operator<=\n";
00198 return false;
00199 }
00200
00201 template < class DataType >
00202 bool vipl_section_container< DataType > ::operator>=( const vipl_section_container< DataType >& ) const
00203 {
00204 vcl_cerr << "Warning: called unimplemented method vipl_section_container::operator>=\n";
00205 return false;
00206 }
00207
00208 template < class DataType >
00209 void vipl_section_container< DataType > ::swap( const vipl_section_container< DataType >& ) const
00210 {
00211 vcl_cerr << "Warning: called unimplemented method vipl_section_container::swap\n";
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221 template < class DataType >
00222 bool vipl_section_container< DataType > ::next_section(
00223 vipl_section_descriptor< DataType >& in_out)
00224 const
00225 {
00226
00227
00228
00229
00230 bool incremented_Y=0, incremented_X=0;
00231 #if 0 // commented out
00232 int xi = image_size(vipl_filter_abs::X_Axis()) - in_out.curr_sec_end(vipl_filter_abs::X_Axis());
00233 int yi = image_size(vipl_filter_abs::Y_Axis()) - in_out.curr_sec_end(vipl_filter_abs::Y_Axis());
00234 if (xi > section_size(vipl_filter_abs::X_Axis())) xi = section_size(vipl_filter_abs::X_Axis());
00235 if (yi > section_size(vipl_filter_abs::Y_Axis())) yi = section_size(vipl_filter_abs::Y_Axis());
00236
00237
00238
00239
00240 if (xi > 0) {
00241 incremented_X = 1;
00242 in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()] += xi;
00243 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()] += xi;
00244 in_out.ref_i_curr_sec_size()[vipl_filter_abs::X_Axis()] = xi;
00245 }
00246 else if (yi > 0) {
00247 incremented_Y = 1;
00248
00249 in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()] = 0;
00250 in_out.ref_i_curr_sec_start()[vipl_filter_abs::Y_Axis()] += yi;
00251 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()] = xi;
00252 in_out.ref_i_curr_sec_end()[vipl_filter_abs::Y_Axis()] += yi;
00253 in_out.ref_i_curr_sec_size()[vipl_filter_abs::X_Axis()] = xi;
00254 in_out.ref_i_curr_sec_size()[vipl_filter_abs::Y_Axis()] = yi;
00255 }
00256 #endif
00257
00258
00259 int xi = image_size(vipl_filter_abs::X_Axis())
00260 - in_out.curr_sec_end(vipl_filter_abs::X_Axis());
00261 int yi = image_size(vipl_filter_abs::Y_Axis())
00262 - in_out.curr_sec_end(vipl_filter_abs::Y_Axis());
00263 if (xi > section_size(vipl_filter_abs::X_Axis()))
00264 xi = section_size(vipl_filter_abs::X_Axis());
00265 if (yi > section_size(vipl_filter_abs::Y_Axis()))
00266 yi = section_size(vipl_filter_abs::Y_Axis());
00267
00268
00269
00270
00271 if (xi > 0) {
00272 incremented_X = 1;
00273
00274 if (in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()] > 0){
00275 in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()]
00276 += section_size(vipl_filter_abs::X_Axis());
00277 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00278 += section_size(vipl_filter_abs::X_Axis());
00279 }
00280 else {
00281
00282 in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()]
00283 += section_size(vipl_filter_abs::X_Axis())
00284 - overlap()[vipl_filter_abs::X_Axis()];
00285 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00286 = in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()]
00287 + section_size(vipl_filter_abs::X_Axis())
00288 + 2*overlap()[vipl_filter_abs::X_Axis()];
00289 }
00290 if (in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00291 > image_size(vipl_filter_abs::X_Axis()))
00292 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()] =
00293 image_size(vipl_filter_abs::X_Axis());
00294 in_out.ref_i_curr_sec_size()[vipl_filter_abs::X_Axis()] =
00295 in_out.i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00296 - in_out.i_curr_sec_start()[vipl_filter_abs::X_Axis()];
00297 }
00298 else if (yi > 0) {
00299 incremented_Y = 1;
00300
00301 in_out.ref_i_curr_sec_start()[vipl_filter_abs::X_Axis()] = 0;
00302 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00303 = section_size(vipl_filter_abs::X_Axis())
00304 + overlap()[vipl_filter_abs::X_Axis()];
00305
00306 if (in_out.ref_i_curr_sec_start()[vipl_filter_abs::Y_Axis()] > 0 ){
00307 in_out.ref_i_curr_sec_start()[vipl_filter_abs::Y_Axis()] +=
00308 section_size(vipl_filter_abs::Y_Axis());
00309 in_out.ref_i_curr_sec_end()[vipl_filter_abs::Y_Axis()] +=
00310 section_size(vipl_filter_abs::Y_Axis());
00311 }
00312 else {
00313 in_out.ref_i_curr_sec_start()[vipl_filter_abs::Y_Axis()] =
00314 section_size(vipl_filter_abs::Y_Axis())
00315 - overlap()[vipl_filter_abs::Y_Axis()];
00316 in_out.ref_i_curr_sec_end()[vipl_filter_abs::Y_Axis()] =
00317 in_out.ref_i_curr_sec_start()[vipl_filter_abs::Y_Axis()]
00318 + section_size(vipl_filter_abs::Y_Axis())
00319 + 2*overlap()[vipl_filter_abs::Y_Axis()];
00320 }
00321 in_out.ref_i_curr_sec_size()[vipl_filter_abs::X_Axis()] =
00322 in_out.i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00323 - in_out.i_curr_sec_start()[vipl_filter_abs::X_Axis()];
00324 in_out.ref_i_curr_sec_size()[vipl_filter_abs::Y_Axis()] =
00325 in_out.i_curr_sec_end()[vipl_filter_abs::Y_Axis()]
00326 - in_out.i_curr_sec_start()[vipl_filter_abs::Y_Axis()];
00327 if (in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00328 > image_size(vipl_filter_abs::X_Axis()))
00329 in_out.ref_i_curr_sec_end()[vipl_filter_abs::X_Axis()]
00330 = image_size(vipl_filter_abs::X_Axis());
00331 if (in_out.ref_i_curr_sec_end()[vipl_filter_abs::Y_Axis()]
00332 > image_size(vipl_filter_abs::Y_Axis()))
00333 in_out.ref_i_curr_sec_end()[vipl_filter_abs::Y_Axis()] =
00334 image_size(vipl_filter_abs::Y_Axis());
00335 }
00336 if (in_out.real_container() == the()) {
00337 vcl_cout << "next_section() for 0x" << (void *)&in_out << vcl_endl;
00338 }
00339 return incremented_Y | incremented_X;
00340 }
00341
00342
00343
00344
00345
00346
00347 template < class DataType >
00348 int vipl_section_container< DataType > ::image_start(int ) const
00349 {
00350 return 0;
00351 }
00352
00353
00354
00355
00356
00357 template < class DataType >
00358 int vipl_section_container< DataType > ::image_size( int axis) const
00359 {
00360 return imgsz()[axis];
00361 }
00362
00363
00364
00365
00366
00367 template < class DataType >
00368 int vipl_section_container< DataType > ::image_end( int axis) const
00369 {
00370 return imgsz()[axis] +
00371 imgstart()[axis];
00372 }
00373
00374
00375
00376
00377
00378
00379
00380 template < class DataType >
00381 int vipl_section_container< DataType > ::section_size( int axis) const
00382 {
00383 return secsz()[axis];
00384 }
00385
00386
00387
00388
00389 template < class DataType >
00390 bool vipl_section_container< DataType > ::is_pointer_safe() const
00391 {
00392 return false;
00393 }
00394
00395
00396
00397 template < class DataType >
00398 vipl_section_container< DataType >* vipl_section_container< DataType > ::virtual_copy() const
00399 {
00400 vipl_section_container< DataType >*rtn = new vipl_section_container<DataType> (0);
00401 rtn->put_the(rtn);
00402 rtn->put_imgsz(imgsz());
00403 rtn->put_secsz(secsz());
00404 rtn->put_imgptr(imgptr());
00405 rtn->put_overlap(overlap());
00406 return rtn;
00407 }
00408
00409 #endif // vipl_section_container_txx_