2d/iterator.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_2d_iterator_hh
22 #define mia_2d_iterator_hh
23 
24 #include <mia/2d/vector.hh>
25 
27 
41 template <typename I>
42 class range2d_iterator: public std::forward_iterator_tag {
43 public:
45  typedef typename I::reference reference;
47  typedef typename I::pointer pointer;
49  typedef I internal_iterator;
50 
58  enum EBoundary {
59  eb_none = 0,
60  eb_xlow = 1,
61  eb_xhigh = 2,
62  eb_x = 3,
63  eb_ylow = 4,
64  eb_yhigh = 8,
65  eb_y = 0xC,
66  };
67 
68 
69 
72 
81  range2d_iterator(const C2DBounds& pos, const C2DBounds& size,
82  const C2DBounds& start, const C2DBounds& end, I iterator);
83 
90 
93 
96 
98  template <typename AI>
99  friend class range2d_iterator;
100 
108  template <typename AI>
109  range2d_iterator(const range2d_iterator<AI>& other);
110 
111 
117  template <typename AI>
119 
120 
125 
127  reference operator *() const;
128 
130  pointer operator ->() const;
131 
135  const C2DBounds& pos() const;
136 
138  template <typename T> friend
139  bool operator == (const range2d_iterator<T>& left, const range2d_iterator<T>& right);
141 
146 
148  int get_boundary_flags() const;
149 
150 private:
151 
152  void increment_y();
153  void increment_z();
154 
155  C2DBounds m_pos;
156  C2DBounds m_size;
157  C2DBounds m_begin;
158  C2DBounds m_end;
159  int m_xstride;
160  I m_iterator;
161  int m_boundary;
162 };
163 
164 
165 
166 template <typename I>
167 template <typename AI>
169 {
170  m_pos = other.m_pos;
171  m_size = other.m_size;
172  m_begin = other.m_begin;
173  m_end = other.m_end;
174  m_iterator = other.m_iterator;
175  m_xstride = other.m_xstride;
176  m_boundary = other.m_boundary;
177  return *this;
178 }
179 
180 template <typename I>
181 template <typename AI>
183  m_pos(other.m_pos),
184  m_size(other.m_size),
185  m_begin(other.m_begin),
186  m_end(other.m_end),
187  m_xstride(other.m_xstride),
188  m_iterator(other.m_iterator),
189  m_boundary(other.m_boundary)
190 {
191 }
192 
193 
198 template <typename I>
199 bool operator == (const range2d_iterator<I>& left, const range2d_iterator<I>& right)
200 {
201  // we really want these two to the same range
202 // assert(left.m_size == right.m_size);
203 // assert(left.m_begin == right.m_begin);
204 // assert(left.m_end == right.m_end);
205 
206  return left.m_pos == right.m_pos;
207 
208 }
209 
213 template <typename I>
215 {
216  return !(a == b);
217 }
218 
220 
221 #endif