[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/imageiteratoradapter.hxx | ![]() |
---|
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 1998-2002 by Ullrich Koethe */ 00004 /* Cognitive Systems Group, University of Hamburg, Germany */ 00005 /* */ 00006 /* This file is part of the VIGRA computer vision library. */ 00007 /* ( Version 1.2.0, Aug 07 2003 ) */ 00008 /* You may use, modify, and distribute this software according */ 00009 /* to the terms stated in the LICENSE file included in */ 00010 /* the VIGRA distribution. */ 00011 /* */ 00012 /* The VIGRA Website is */ 00013 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00014 /* Please direct questions, bug reports, and contributions to */ 00015 /* koethe@informatik.uni-hamburg.de */ 00016 /* */ 00017 /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ 00018 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 00019 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* */ 00021 /************************************************************************/ 00022 00023 00024 #ifndef VIGRA_IMAGEITERATORADAPTER_HXX 00025 #define VIGRA_IMAGEITERATORADAPTER_HXX 00026 00027 #include <iterator> // iterator tags 00028 00029 namespace vigra { 00030 00031 /** \addtogroup ImageIteratorAdapters Image Iterator Adapters 00032 00033 Iterate over rows, columns, neighborhoods, contours, and other image subsets 00034 */ 00035 //@{ 00036 00037 /********************************************************/ 00038 /* */ 00039 /* ColumnIterator */ 00040 /* */ 00041 /********************************************************/ 00042 00043 /** \brief Iterator adapter to linearly access colums. 00044 00045 This iterator may be initialized from any standard ImageIterator, 00046 a MultibandImageIterator and so on. 00047 It gives you STL-compatible (random access iterator) access to 00048 one column of the image. If the underlying iterator is a const iterator, 00049 the column iterator will also be const (i.e. doesn't allow to change 00050 the values it points to). 00051 The iterator gets associated with the accessor of the base iterator. 00052 00053 Note that image iterators usually have a member <TT>columnIterator()</TT> 00054 which returns a column iterator optimized for that particular image class. 00055 ColumnIterator is only necessary if this 'native' column iterator 00056 is not usable in a particular situation or is not provided. 00057 00058 <b>\#include</b> "<a href="imageiteratoradapter_8hxx-source.html">vigra/imageiteratoradapter.hxx</a>" 00059 00060 Namespace: vigra 00061 00062 */ 00063 template <class IMAGE_ITERATOR> 00064 class ColumnIterator : private IMAGE_ITERATOR 00065 { 00066 public: 00067 /** the iterator's value type 00068 */ 00069 typedef typename IMAGE_ITERATOR::value_type value_type; 00070 00071 /** the iterator's value type 00072 */ 00073 typedef typename IMAGE_ITERATOR::value_type PixelType; 00074 00075 /** the iterator's reference type (return type of <TT>*iter</TT>) 00076 */ 00077 typedef typename IMAGE_ITERATOR::reference reference; 00078 00079 /** the iterator's index reference type (return type of <TT>iter[n]</TT>) 00080 */ 00081 typedef typename IMAGE_ITERATOR::index_reference index_reference; 00082 00083 /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>) 00084 */ 00085 typedef typename IMAGE_ITERATOR::pointer pointer; 00086 00087 /** the iterator's difference type (argument type of <TT>iter[diff]</TT>) 00088 */ 00089 typedef typename IMAGE_ITERATOR::difference_type::MoveY difference_type; 00090 00091 /** the iterator tag (random access iterator) 00092 */ 00093 typedef std::random_access_iterator_tag iterator_category; 00094 00095 /** the type of the adapted iterator 00096 */ 00097 typedef IMAGE_ITERATOR Adaptee; 00098 00099 /** Construct from an the image iterator to be adapted. 00100 */ 00101 ColumnIterator(IMAGE_ITERATOR const & i) 00102 : IMAGE_ITERATOR(i) 00103 {} 00104 00105 /** Assignment. 00106 */ 00107 ColumnIterator & operator=(ColumnIterator const & i) 00108 { 00109 IMAGE_ITERATOR::operator=(i); 00110 00111 return *this; 00112 } 00113 00114 /** Assign a new base iterator. 00115 */ 00116 ColumnIterator & operator=(IMAGE_ITERATOR const & i) 00117 { 00118 IMAGE_ITERATOR::operator=(i); 00119 00120 return *this; 00121 } 00122 00123 /** @name Navigation */ 00124 //@{ 00125 /// 00126 ColumnIterator & operator++() 00127 { 00128 ++(this->y); 00129 return *this; 00130 } 00131 /// 00132 ColumnIterator operator++(int) 00133 { 00134 ColumnIterator ret(*this); 00135 (this->y)++; 00136 return ret; 00137 } 00138 00139 /// 00140 ColumnIterator & operator--() 00141 { 00142 --(this->y); 00143 return *this; 00144 } 00145 00146 /// 00147 ColumnIterator operator--(int) 00148 { 00149 ColumnIterator ret(*this); 00150 (this->y)--; 00151 return ret; 00152 } 00153 00154 /// 00155 ColumnIterator & operator+=(int d) 00156 { 00157 this->y += d; 00158 return *this; 00159 } 00160 00161 /// 00162 ColumnIterator & operator-=(int d) 00163 { 00164 this->y -= d; 00165 return *this; 00166 } 00167 //@} 00168 00169 /** @name Methods */ 00170 //@{ 00171 /** Construct iterator at a distance. 00172 */ 00173 ColumnIterator operator+(int d) const 00174 { 00175 IMAGE_ITERATOR ret(*this); 00176 ret.y += d; 00177 return ColumnIterator(ret); 00178 } 00179 /** Construct iterator at a distance. 00180 */ 00181 ColumnIterator operator-(int d) const 00182 { 00183 IMAGE_ITERATOR ret(*this); 00184 ret.y -= d; 00185 return ColumnIterator(ret); 00186 } 00187 /** Calculate distance. 00188 */ 00189 int operator-(ColumnIterator const & c) const 00190 { 00191 return this->y - c.y; 00192 } 00193 00194 /** Equality. 00195 */ 00196 bool operator==(ColumnIterator const & c) const 00197 { 00198 return IMAGE_ITERATOR::operator==(c); 00199 } 00200 00201 /** Inequality. 00202 */ 00203 bool operator!=(ColumnIterator const & c) const 00204 { 00205 return IMAGE_ITERATOR::operator!=(c); 00206 } 00207 00208 /** Smaller than. 00209 */ 00210 bool operator<(ColumnIterator const & c) const 00211 { 00212 return this->y < c.y; 00213 } 00214 00215 /** Access current pixel. 00216 */ 00217 reference operator*() const 00218 { 00219 return IMAGE_ITERATOR::operator*(); 00220 } 00221 00222 /** Access pixel at distance d. 00223 */ 00224 index_reference operator[](int d) const 00225 { 00226 return IMAGE_ITERATOR::operator()(0, d); 00227 } 00228 00229 /** Call member function of current pixel. 00230 */ 00231 pointer operator->() const 00232 { 00233 return IMAGE_ITERATOR::operator->(); 00234 } 00235 00236 /** Get a reference to the adapted iterator 00237 */ 00238 Adaptee & adaptee() const { return (Adaptee &)*this; } 00239 00240 //@} 00241 }; 00242 00243 /********************************************************/ 00244 /* */ 00245 /* RowIterator */ 00246 /* */ 00247 /********************************************************/ 00248 00249 /** \brief Iterator adapter to linearly access row. 00250 00251 This iterator may be initialized from a standard ImageIterator, 00252 a MultibandImageIterator and so on. 00253 It gives you STL-compatible (random access iterator) access to 00254 one row of the image. If the underlying iterator is a const iterator, 00255 the row iterator will also be const (i.e. doesn't allow to change 00256 the values it points to). 00257 The iterator gets associated with the accessor of the base iterator. 00258 00259 Note that image iterators usually have a member <TT>rowIterator()</TT> 00260 which returns a row iterator optimized for that particular image class. 00261 RowIterator is only necessary if this 'native' row iterator 00262 is not usable in a particular situation or is not provided. 00263 00264 <b>\#include</b> "<a href="imageiteratoradapter_8hxx-source.html">vigra/imageiteratoradapter.hxx</a>" 00265 00266 Namespace: vigra 00267 00268 */ 00269 template <class IMAGE_ITERATOR> 00270 class RowIterator : private IMAGE_ITERATOR 00271 { 00272 public: 00273 /** the iterator's value type 00274 */ 00275 typedef typename IMAGE_ITERATOR::value_type value_type; 00276 00277 /** the iterator's value type 00278 */ 00279 typedef typename IMAGE_ITERATOR::value_type PixelType; 00280 00281 /** the iterator's reference type (return type of <TT>*iter</TT>) 00282 */ 00283 typedef typename IMAGE_ITERATOR::reference reference; 00284 00285 /** the iterator's index reference type (return type of <TT>iter[n]</TT>) 00286 */ 00287 typedef typename IMAGE_ITERATOR::index_reference index_reference; 00288 00289 /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>) 00290 */ 00291 typedef typename IMAGE_ITERATOR::pointer pointer; 00292 00293 /** the iterator's difference type (argument type of <TT>iter[diff]</TT>) 00294 */ 00295 typedef typename IMAGE_ITERATOR::difference_type::MoveY difference_type; 00296 00297 /** the iterator tag (random access iterator) 00298 */ 00299 typedef std::random_access_iterator_tag iterator_category; 00300 00301 /** the type of the adapted iterator 00302 */ 00303 typedef IMAGE_ITERATOR Adaptee; 00304 00305 /** Construct from an the image iterator to be adapted. 00306 */ 00307 RowIterator(IMAGE_ITERATOR const & i) 00308 : IMAGE_ITERATOR(i) 00309 {} 00310 00311 /** Assignment. 00312 */ 00313 RowIterator & operator=(RowIterator const & i) 00314 { 00315 IMAGE_ITERATOR::operator=(i); 00316 00317 return *this; 00318 } 00319 00320 /** Assign a new base iterator. 00321 */ 00322 RowIterator & operator=(IMAGE_ITERATOR const & i) 00323 { 00324 IMAGE_ITERATOR::operator=(i); 00325 00326 return *this; 00327 } 00328 00329 /** @name Navigation */ 00330 //@{ 00331 /// 00332 RowIterator & operator++() 00333 { 00334 ++(this->x); 00335 return *this; 00336 } 00337 /// 00338 RowIterator operator++(int) 00339 { 00340 RowIterator ret(*this); 00341 (this->x)++; 00342 return ret; 00343 } 00344 00345 /// 00346 RowIterator & operator--() 00347 { 00348 --(this->x); 00349 return *this; 00350 } 00351 00352 /// 00353 RowIterator operator--(int) 00354 { 00355 RowIterator ret(*this); 00356 (this->x)--; 00357 return ret; 00358 } 00359 00360 /// 00361 RowIterator & operator+=(int d) 00362 { 00363 this->x += d; 00364 return *this; 00365 } 00366 00367 /// 00368 RowIterator & operator-=(int d) 00369 { 00370 this->x -= d; 00371 return *this; 00372 } 00373 //@} 00374 00375 /** @name Methods */ 00376 //@{ 00377 /** Construct iterator at a distance. 00378 */ 00379 RowIterator operator+(int d) const 00380 { 00381 IMAGE_ITERATOR ret(*this); 00382 ret.x += d; 00383 return RowIterator(ret); 00384 } 00385 /** Construct iterator at a distance. 00386 */ 00387 RowIterator operator-(int d) const 00388 { 00389 IMAGE_ITERATOR ret(*this); 00390 ret.x -= d; 00391 return RowIterator(ret); 00392 } 00393 /** Calculate distance. 00394 */ 00395 int operator-(RowIterator const & c) const 00396 { 00397 return this->x - c.x; 00398 } 00399 00400 /** Equality. 00401 */ 00402 bool operator==(RowIterator const & c) const 00403 { 00404 return IMAGE_ITERATOR::operator==(c); 00405 } 00406 00407 /** Inequality. 00408 */ 00409 bool operator!=(RowIterator const & c) const 00410 { 00411 return IMAGE_ITERATOR::operator!=(c); 00412 } 00413 00414 /** Smaller than. 00415 */ 00416 bool operator<(RowIterator const & c) const 00417 { 00418 return this->x < c.x; 00419 } 00420 00421 /** Access current pixel. 00422 */ 00423 reference operator*() const 00424 { 00425 return IMAGE_ITERATOR::operator*(); 00426 } 00427 00428 /** Access pixel at distance d. 00429 */ 00430 index_reference operator[](int d) const 00431 { 00432 return IMAGE_ITERATOR::operator()(d, 0); 00433 } 00434 00435 /** Call member function of current pixel. 00436 */ 00437 pointer operator->() const 00438 { 00439 return IMAGE_ITERATOR::operator->(); 00440 } 00441 00442 /** Get a reference to the adapted iterator 00443 */ 00444 Adaptee & adaptee() const { return (Adaptee &)*this; } 00445 00446 //@} 00447 }; 00448 00449 /********************************************************/ 00450 /* */ 00451 /* LineIterator */ 00452 /* */ 00453 /********************************************************/ 00454 00455 /** \brief Iterator adapter to iterate along an arbitrary line on the image. 00456 00457 This iterator may be initialized from a standard ImageIterator, 00458 a MultibandImageIterator and so on. 00459 It gives you STL-compatible (forward iterator) access to 00460 an arbitraty line on the image. 00461 The iterator gets associated with the accessor of the base iterator. 00462 00463 <b>\#include</b> "<a href="imageiteratoradapter_8hxx-source.html">vigra/imageiteratoradapter.hxx</a>" 00464 00465 Namespace: vigra 00466 00467 */ 00468 template <class IMAGE_ITERATOR> 00469 class LineIterator : private IMAGE_ITERATOR 00470 { 00471 public: 00472 /** the iterator's value type 00473 */ 00474 typedef typename IMAGE_ITERATOR::value_type value_type; 00475 00476 /** the iterator's value type 00477 */ 00478 typedef typename IMAGE_ITERATOR::value_type PixelType; 00479 00480 /** the iterator's reference type (return type of <TT>*iter</TT>) 00481 */ 00482 typedef typename IMAGE_ITERATOR::reference reference; 00483 00484 /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>) 00485 */ 00486 typedef typename IMAGE_ITERATOR::pointer pointer; 00487 00488 /** the iterator tag (forward iterator) 00489 */ 00490 typedef std::forward_iterator_tag iterator_category; 00491 00492 /** the type of the adapted iterator 00493 */ 00494 typedef IMAGE_ITERATOR Adaptee; 00495 00496 /** Construct from an the image iterator to be adapted. 00497 */ 00498 LineIterator(IMAGE_ITERATOR const & start, 00499 IMAGE_ITERATOR const & end) 00500 : IMAGE_ITERATOR(start), x_(0.0), y_(0.0) 00501 { 00502 int dx = end.x - start.x; 00503 int dy = end.y - start.y; 00504 int adx = (dx < 0) ? -dx : dx; 00505 int ady = (dy < 0) ? -dy : dy; 00506 int dd = (adx > ady) ? adx : ady; 00507 if(dd == 0) dd = 1; 00508 00509 dx_ = (double)dx / dd; 00510 dy_ = (double)dy / dd; 00511 if(adx > ady) y_ += dy_ / 2.0; 00512 else x_ += dx_ / 2.0; 00513 } 00514 00515 /** @name Navigation */ 00516 //@{ 00517 /// 00518 LineIterator & operator++() 00519 { 00520 x_ += dx_; 00521 if(x_ >= 1.0) { 00522 x_ -= 1.0; 00523 ++(this->x); 00524 } 00525 else if(x_ <= -1.0) { 00526 x_ += 1.0; 00527 --(this->x); 00528 } 00529 y_ += dy_; 00530 if(y_ >= 1.0) { 00531 y_ -= 1.0; 00532 ++(this->y); 00533 } 00534 else if(y_ <= -1.0) { 00535 y_ += 1.0; 00536 --(this->y); 00537 } 00538 return *this; 00539 } 00540 /// 00541 LineIterator operator++(int) 00542 { 00543 LineIterator ret(*this); 00544 operator++(); 00545 return ret; 00546 } 00547 00548 //@} 00549 00550 /** @name Methods */ 00551 //@{ 00552 /** Equality. 00553 */ 00554 bool operator==(LineIterator const & c) const 00555 { 00556 return IMAGE_ITERATOR::operator==(c); 00557 } 00558 00559 /** Inequality. 00560 */ 00561 bool operator!=(LineIterator const & c) const 00562 { 00563 return IMAGE_ITERATOR::operator!=(c); 00564 } 00565 00566 /** Access current pixel. 00567 */ 00568 reference operator*() const 00569 { 00570 return IMAGE_ITERATOR::operator*(); 00571 } 00572 00573 /** Call member function for current pixel. 00574 */ 00575 pointer operator->() const 00576 { 00577 return IMAGE_ITERATOR::operator->(); 00578 } 00579 00580 /** Get a reference to the adapted iterator 00581 */ 00582 Adaptee & adaptee() const { return (Adaptee &)*this; } 00583 00584 //@} 00585 00586 private: 00587 00588 double x_, y_, dx_, dy_; 00589 }; 00590 00591 //@} 00592 00593 } // namespace vigra 00594 00595 #endif // VIGRA_IMAGEITERATORADAPTER_HXX
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|