[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

imageiteratoradapter.hxx VIGRA

1 /************************************************************************/
2 /* */
3 /* Copyright 1998-2002 by Ullrich Koethe */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 
36 
37 #ifndef VIGRA_IMAGEITERATORADAPTER_HXX
38 #define VIGRA_IMAGEITERATORADAPTER_HXX
39 
40 #include <iterator> // iterator tags
41 
42 namespace vigra {
43 
44 /** \addtogroup ImageIteratorAdapters Image Iterator Adapters
45 
46  Iterate over rows, columns, neighborhoods, contours, and other image subsets
47 */
48 //@{
49 
50 /********************************************************/
51 /* */
52 /* ColumnIterator */
53 /* */
54 /********************************************************/
55 
56 /** \brief Iterator adapter to linearly access columns.
57 
58  This iterator may be initialized from any standard ImageIterator,
59  a MultibandImageIterator and so on.
60  It gives you STL-compatible (random access iterator) access to
61  one column of the image. If the underlying iterator is a const iterator,
62  the column iterator will also be const (i.e. doesn't allow to change
63  the values it points to).
64  The iterator gets associated with the accessor of the base iterator.
65 
66  Note that image iterators usually have a member <TT>columnIterator()</TT>
67  which returns a column iterator optimized for that particular image class.
68  ColumnIterator is only necessary if this 'native' column iterator
69  is not usable in a particular situation or is not provided.
70 
71  <b>\#include</b> <vigra/imageiteratoradapter.hxx> <br/>
72  Namespace: vigra
73 
74 */
75 template <class IMAGE_ITERATOR>
76 class ColumnIterator : private IMAGE_ITERATOR
77 {
78  public:
79  /** the iterator's value type
80  */
81  typedef typename IMAGE_ITERATOR::value_type value_type;
82 
83  /** the iterator's value type
84  */
85  typedef typename IMAGE_ITERATOR::value_type PixelType;
86 
87  /** the iterator's reference type (return type of <TT>*iter</TT>)
88  */
89  typedef typename IMAGE_ITERATOR::reference reference;
90 
91  /** the iterator's index reference type (return type of <TT>iter[n]</TT>)
92  */
93  typedef typename IMAGE_ITERATOR::index_reference index_reference;
94 
95  /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>)
96  */
97  typedef typename IMAGE_ITERATOR::pointer pointer;
98 
99  /** the iterator's difference type (argument type of <TT>iter[diff]</TT>)
100  */
101  typedef typename IMAGE_ITERATOR::difference_type::MoveY difference_type;
102 
103  /** the iterator tag (random access iterator)
104  */
105  typedef std::random_access_iterator_tag iterator_category;
106 
107  /** the type of the adapted iterator
108  */
109  typedef IMAGE_ITERATOR Adaptee;
110 
111  /** Construct from an the image iterator to be adapted.
112  */
113  ColumnIterator(IMAGE_ITERATOR const & i)
114  : IMAGE_ITERATOR(i)
115  {}
116 
117  /** Assignment.
118  */
120  {
121  IMAGE_ITERATOR::operator=(i);
122 
123  return *this;
124  }
125 
126  /** Assign a new base iterator.
127  */
128  ColumnIterator & operator=(IMAGE_ITERATOR const & i)
129  {
130  IMAGE_ITERATOR::operator=(i);
131 
132  return *this;
133  }
134 
135  /** @name Navigation */
136  //@{
137  ///
138  ColumnIterator & operator++()
139  {
140  ++(this->y);
141  return *this;
142  }
143  ///
144  ColumnIterator operator++(int)
145  {
146  ColumnIterator ret(*this);
147  (this->y)++;
148  return ret;
149  }
150 
151  ///
152  ColumnIterator & operator--()
153  {
154  --(this->y);
155  return *this;
156  }
157 
158  ///
159  ColumnIterator operator--(int)
160  {
161  ColumnIterator ret(*this);
162  (this->y)--;
163  return ret;
164  }
165 
166  ///
167  ColumnIterator & operator+=(int d)
168  {
169  this->y += d;
170  return *this;
171  }
172 
173  ///
174  ColumnIterator & operator-=(int d)
175  {
176  this->y -= d;
177  return *this;
178  }
179  //@}
180 
181  /** @name Methods */
182  //@{
183  /** Construct iterator at a distance.
184  */
186  {
187  IMAGE_ITERATOR ret(*this);
188  ret.y += d;
189  return ColumnIterator(ret);
190  }
191  /** Construct iterator at a distance.
192  */
194  {
195  IMAGE_ITERATOR ret(*this);
196  ret.y -= d;
197  return ColumnIterator(ret);
198  }
199  /** Calculate distance.
200  */
201  int operator-(ColumnIterator const & c) const
202  {
203  return this->y - c.y;
204  }
205 
206  /** Equality.
207  */
208  bool operator==(ColumnIterator const & c) const
209  {
210  return IMAGE_ITERATOR::operator==(c);
211  }
212 
213  /** Inequality.
214  */
215  bool operator!=(ColumnIterator const & c) const
216  {
217  return IMAGE_ITERATOR::operator!=(c);
218  }
219 
220  /** Smaller than.
221  */
222  bool operator<(ColumnIterator const & c) const
223  {
224  return this->y < c.y;
225  }
226 
227  /** Access current pixel.
228  */
230  {
231  return IMAGE_ITERATOR::operator*();
232  }
233 
234  /** Access pixel at distance d.
235  */
237  {
238  return IMAGE_ITERATOR::operator()(0, d);
239  }
240 
241  /** Call member function of current pixel.
242  */
244  {
245  return IMAGE_ITERATOR::operator->();
246  }
247 
248  /** Get a reference to the adapted iterator
249  */
250  Adaptee & adaptee() const { return (Adaptee &)*this; }
251 
252  //@}
253 };
254 
255 /********************************************************/
256 /* */
257 /* RowIterator */
258 /* */
259 /********************************************************/
260 
261 /** \brief Iterator adapter to linearly access row.
262 
263  This iterator may be initialized from a standard ImageIterator,
264  a MultibandImageIterator and so on.
265  It gives you STL-compatible (random access iterator) access to
266  one row of the image. If the underlying iterator is a const iterator,
267  the row iterator will also be const (i.e. doesn't allow to change
268  the values it points to).
269  The iterator gets associated with the accessor of the base iterator.
270 
271  Note that image iterators usually have a member <TT>rowIterator()</TT>
272  which returns a row iterator optimized for that particular image class.
273  RowIterator is only necessary if this 'native' row iterator
274  is not usable in a particular situation or is not provided.
275 
276  <b>\#include</b> <vigra/imageiteratoradapter.hxx> <br/>
277  Namespace: vigra
278 
279 */
280 template <class IMAGE_ITERATOR>
281 class RowIterator : private IMAGE_ITERATOR
282 {
283  public:
284  /** the iterator's value type
285  */
286  typedef typename IMAGE_ITERATOR::value_type value_type;
287 
288  /** the iterator's value type
289  */
290  typedef typename IMAGE_ITERATOR::value_type PixelType;
291 
292  /** the iterator's reference type (return type of <TT>*iter</TT>)
293  */
294  typedef typename IMAGE_ITERATOR::reference reference;
295 
296  /** the iterator's index reference type (return type of <TT>iter[n]</TT>)
297  */
298  typedef typename IMAGE_ITERATOR::index_reference index_reference;
299 
300  /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>)
301  */
302  typedef typename IMAGE_ITERATOR::pointer pointer;
303 
304  /** the iterator's difference type (argument type of <TT>iter[diff]</TT>)
305  */
306  typedef typename IMAGE_ITERATOR::difference_type::MoveY difference_type;
307 
308  /** the iterator tag (random access iterator)
309  */
310  typedef std::random_access_iterator_tag iterator_category;
311 
312  /** the type of the adapted iterator
313  */
314  typedef IMAGE_ITERATOR Adaptee;
315 
316  /** Construct from an the image iterator to be adapted.
317  */
318  RowIterator(IMAGE_ITERATOR const & i)
319  : IMAGE_ITERATOR(i)
320  {}
321 
322  /** Assignment.
323  */
325  {
326  IMAGE_ITERATOR::operator=(i);
327 
328  return *this;
329  }
330 
331  /** Assign a new base iterator.
332  */
333  RowIterator & operator=(IMAGE_ITERATOR const & i)
334  {
335  IMAGE_ITERATOR::operator=(i);
336 
337  return *this;
338  }
339 
340  /** @name Navigation */
341  //@{
342  ///
343  RowIterator & operator++()
344  {
345  ++(this->x);
346  return *this;
347  }
348  ///
349  RowIterator operator++(int)
350  {
351  RowIterator ret(*this);
352  (this->x)++;
353  return ret;
354  }
355 
356  ///
357  RowIterator & operator--()
358  {
359  --(this->x);
360  return *this;
361  }
362 
363  ///
364  RowIterator operator--(int)
365  {
366  RowIterator ret(*this);
367  (this->x)--;
368  return ret;
369  }
370 
371  ///
372  RowIterator & operator+=(int d)
373  {
374  this->x += d;
375  return *this;
376  }
377 
378  ///
379  RowIterator & operator-=(int d)
380  {
381  this->x -= d;
382  return *this;
383  }
384  //@}
385 
386  /** @name Methods */
387  //@{
388  /** Construct iterator at a distance.
389  */
390  RowIterator operator+(int d) const
391  {
392  IMAGE_ITERATOR ret(*this);
393  ret.x += d;
394  return RowIterator(ret);
395  }
396  /** Construct iterator at a distance.
397  */
398  RowIterator operator-(int d) const
399  {
400  IMAGE_ITERATOR ret(*this);
401  ret.x -= d;
402  return RowIterator(ret);
403  }
404  /** Calculate distance.
405  */
406  int operator-(RowIterator const & c) const
407  {
408  return this->x - c.x;
409  }
410 
411  /** Equality.
412  */
413  bool operator==(RowIterator const & c) const
414  {
415  return IMAGE_ITERATOR::operator==(c);
416  }
417 
418  /** Inequality.
419  */
420  bool operator!=(RowIterator const & c) const
421  {
422  return IMAGE_ITERATOR::operator!=(c);
423  }
424 
425  /** Smaller than.
426  */
427  bool operator<(RowIterator const & c) const
428  {
429  return this->x < c.x;
430  }
431 
432  /** Access current pixel.
433  */
435  {
436  return IMAGE_ITERATOR::operator*();
437  }
438 
439  /** Access pixel at distance d.
440  */
442  {
443  return IMAGE_ITERATOR::operator()(d, 0);
444  }
445 
446  /** Call member function of current pixel.
447  */
449  {
450  return IMAGE_ITERATOR::operator->();
451  }
452 
453  /** Get a reference to the adapted iterator
454  */
455  Adaptee & adaptee() const { return (Adaptee &)*this; }
456 
457  //@}
458 };
459 
460 /********************************************************/
461 /* */
462 /* LineIterator */
463 /* */
464 /********************************************************/
465 
466 /** \brief Iterator adapter to iterate along an arbitrary line on the image.
467 
468  This iterator may be initialized from a standard ImageIterator,
469  a MultibandImageIterator and so on.
470  It gives you STL-compatible (forward iterator) access to
471  an arbitrary line on the image.
472  The iterator gets associated with the accessor of the base iterator.
473 
474  <b>\#include</b> <vigra/imageiteratoradapter.hxx> <br/>
475  Namespace: vigra
476 
477 */
478 template <class IMAGE_ITERATOR>
479 class LineIterator : private IMAGE_ITERATOR
480 {
481  public:
482  /** the iterator's value type
483  */
484  typedef typename IMAGE_ITERATOR::value_type value_type;
485 
486  /** the iterator's value type
487  */
488  typedef typename IMAGE_ITERATOR::value_type PixelType;
489 
490  /** the iterator's reference type (return type of <TT>*iter</TT>)
491  */
492  typedef typename IMAGE_ITERATOR::reference reference;
493 
494  /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>)
495  */
496  typedef typename IMAGE_ITERATOR::pointer pointer;
497 
498  /** the iterator tag (forward iterator)
499  */
500  typedef std::forward_iterator_tag iterator_category;
501 
502  /** the type of the adapted iterator
503  */
504  typedef IMAGE_ITERATOR Adaptee;
505 
506  /** Construct from an the image iterator to be adapted.
507  */
508  LineIterator(IMAGE_ITERATOR const & start,
509  IMAGE_ITERATOR const & end)
510  : IMAGE_ITERATOR(start), x_(0.0), y_(0.0)
511  {
512  int dx = end.x - start.x;
513  int dy = end.y - start.y;
514  int adx = (dx < 0) ? -dx : dx;
515  int ady = (dy < 0) ? -dy : dy;
516  int dd = (adx > ady) ? adx : ady;
517  if(dd == 0) dd = 1;
518 
519  dx_ = (double)dx / dd;
520  dy_ = (double)dy / dd;
521  if(adx > ady) y_ += dy_ / 2.0;
522  else x_ += dx_ / 2.0;
523  }
524 
525  /** @name Navigation */
526  //@{
527  ///
528  LineIterator & operator++()
529  {
530  x_ += dx_;
531  if(x_ >= 1.0) {
532  x_ -= 1.0;
533  ++(this->x);
534  }
535  else if(x_ <= -1.0) {
536  x_ += 1.0;
537  --(this->x);
538  }
539  y_ += dy_;
540  if(y_ >= 1.0) {
541  y_ -= 1.0;
542  ++(this->y);
543  }
544  else if(y_ <= -1.0) {
545  y_ += 1.0;
546  --(this->y);
547  }
548  return *this;
549  }
550  ///
551  LineIterator operator++(int)
552  {
553  LineIterator ret(*this);
554  operator++();
555  return ret;
556  }
557 
558  //@}
559 
560  /** @name Methods */
561  //@{
562  /** Equality.
563  */
564  bool operator==(LineIterator const & c) const
565  {
566  return IMAGE_ITERATOR::operator==(c);
567  }
568 
569  /** Inequality.
570  */
571  bool operator!=(LineIterator const & c) const
572  {
573  return IMAGE_ITERATOR::operator!=(c);
574  }
575 
576  /** Access current pixel.
577  */
579  {
580  return IMAGE_ITERATOR::operator*();
581  }
582 
583  /** Call member function for current pixel.
584  */
586  {
587  return IMAGE_ITERATOR::operator->();
588  }
589 
590  /** Get a reference to the adapted iterator
591  */
592  Adaptee & adaptee() const { return (Adaptee &)*this; }
593 
594  //@}
595 
596  private:
597 
598  double x_, y_, dx_, dy_;
599 };
600 
601 //@}
602 
603 } // namespace vigra
604 
605 #endif // VIGRA_IMAGEITERATORADAPTER_HXX
IMAGE_ITERATOR::value_type PixelType
Definition: imageiteratoradapter.hxx:85
Adaptee & adaptee() const
Definition: imageiteratoradapter.hxx:250
LineIterator(IMAGE_ITERATOR const &start, IMAGE_ITERATOR const &end)
Definition: imageiteratoradapter.hxx:508
IMAGE_ITERATOR::index_reference index_reference
Definition: imageiteratoradapter.hxx:93
pointer operator->() const
Definition: imageiteratoradapter.hxx:243
reference operator*() const
Definition: imageiteratoradapter.hxx:229
int operator-(RowIterator const &c) const
Definition: imageiteratoradapter.hxx:406
Adaptee & adaptee() const
Definition: imageiteratoradapter.hxx:455
bool operator!=(RowIterator const &c) const
Definition: imageiteratoradapter.hxx:420
Adaptee & adaptee() const
Definition: imageiteratoradapter.hxx:592
IMAGE_ITERATOR Adaptee
Definition: imageiteratoradapter.hxx:504
RowIterator(IMAGE_ITERATOR const &i)
Definition: imageiteratoradapter.hxx:318
IMAGE_ITERATOR::pointer pointer
Definition: imageiteratoradapter.hxx:97
IMAGE_ITERATOR::value_type value_type
Definition: imageiteratoradapter.hxx:81
bool operator<(RowIterator const &c) const
Definition: imageiteratoradapter.hxx:427
reference operator*() const
Definition: imageiteratoradapter.hxx:578
Iterator adapter to linearly access row.
Definition: imageiteratoradapter.hxx:281
IMAGE_ITERATOR::value_type value_type
Definition: imageiteratoradapter.hxx:484
reference operator*() const
Definition: imageiteratoradapter.hxx:434
std::random_access_iterator_tag iterator_category
Definition: imageiteratoradapter.hxx:310
RowIterator & operator=(RowIterator const &i)
Definition: imageiteratoradapter.hxx:324
IMAGE_ITERATOR::reference reference
Definition: imageiteratoradapter.hxx:294
IMAGE_ITERATOR::difference_type::MoveY difference_type
Definition: imageiteratoradapter.hxx:101
IMAGE_ITERATOR Adaptee
Definition: imageiteratoradapter.hxx:109
RowIterator & operator=(IMAGE_ITERATOR const &i)
Definition: imageiteratoradapter.hxx:333
ColumnIterator & operator=(IMAGE_ITERATOR const &i)
Definition: imageiteratoradapter.hxx:128
pointer operator->() const
Definition: imageiteratoradapter.hxx:448
bool operator!=(LineIterator const &c) const
Definition: imageiteratoradapter.hxx:571
IMAGE_ITERATOR::value_type PixelType
Definition: imageiteratoradapter.hxx:290
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
ColumnIterator operator-(int d) const
Definition: imageiteratoradapter.hxx:193
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825
IMAGE_ITERATOR Adaptee
Definition: imageiteratoradapter.hxx:314
ColumnIterator operator+(int d) const
Definition: imageiteratoradapter.hxx:185
IMAGE_ITERATOR::pointer pointer
Definition: imageiteratoradapter.hxx:496
ColumnIterator & operator=(ColumnIterator const &i)
Definition: imageiteratoradapter.hxx:119
int operator-(ColumnIterator const &c) const
Definition: imageiteratoradapter.hxx:201
bool operator==(ColumnIterator const &c) const
Definition: imageiteratoradapter.hxx:208
bool operator==(LineIterator const &c) const
Definition: imageiteratoradapter.hxx:564
IMAGE_ITERATOR::value_type value_type
Definition: imageiteratoradapter.hxx:286
Iterator adapter to linearly access columns.
Definition: imageiteratoradapter.hxx:76
ColumnIterator(IMAGE_ITERATOR const &i)
Definition: imageiteratoradapter.hxx:113
bool operator==(RowIterator const &c) const
Definition: imageiteratoradapter.hxx:413
IMAGE_ITERATOR::pointer pointer
Definition: imageiteratoradapter.hxx:302
IMAGE_ITERATOR::difference_type::MoveY difference_type
Definition: imageiteratoradapter.hxx:306
bool operator!=(ColumnIterator const &c) const
Definition: imageiteratoradapter.hxx:215
index_reference operator[](int d) const
Definition: imageiteratoradapter.hxx:236
index_reference operator[](int d) const
Definition: imageiteratoradapter.hxx:441
IMAGE_ITERATOR::reference reference
Definition: imageiteratoradapter.hxx:492
bool operator<(ColumnIterator const &c) const
Definition: imageiteratoradapter.hxx:222
RowIterator operator-(int d) const
Definition: imageiteratoradapter.hxx:398
Iterator adapter to iterate along an arbitrary line on the image.
Definition: imageiteratoradapter.hxx:479
pointer operator->() const
Definition: imageiteratoradapter.hxx:585
IMAGE_ITERATOR::value_type PixelType
Definition: imageiteratoradapter.hxx:488
std::forward_iterator_tag iterator_category
Definition: imageiteratoradapter.hxx:500
IMAGE_ITERATOR::reference reference
Definition: imageiteratoradapter.hxx:89
std::random_access_iterator_tag iterator_category
Definition: imageiteratoradapter.hxx:105
IMAGE_ITERATOR::index_reference index_reference
Definition: imageiteratoradapter.hxx:298
RowIterator operator+(int d) const
Definition: imageiteratoradapter.hxx:390

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1 (Fri May 19 2017)