My Project
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-2017 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 EXPORT_2D range2d_iterator_with_boundary_flag: public std::forward_iterator_tag
43 {
44 public:
46  typedef typename I::reference reference;
48  typedef typename I::pointer pointer;
50  typedef I internal_iterator;
51 
52  typedef typename I::value_type value_type;
53 
61  enum EBoundary {
62  eb_none = 0,
63  eb_xlow = 1,
64  eb_xhigh = 2,
65  eb_x = 3,
66  eb_ylow = 4,
67  eb_yhigh = 8,
68  eb_y = 0xC,
69  };
70 
71 
72 
75 
85  const C2DBounds& start, const C2DBounds& end, I iterator);
86 
93 
96 
99 
101  template <typename AI>
103 
111  template <typename AI>
113 
114 
120  template <typename AI>
122 
123 
128 
131 
134 
138  const C2DBounds& pos() const;
139 
141  template <typename T> friend
144 
145  template <typename T> friend
149 
154 
156  int get_boundary_flags() const;
157 
158 private:
159 
160  void increment_y();
161  void increment_z();
162 
163  C2DBounds m_pos;
164  C2DBounds m_size;
165  C2DBounds m_begin;
166  C2DBounds m_end;
167  int m_xstride;
168  I m_iterator;
169  int m_boundary;
170 };
171 
172 
173 
174 template <typename I>
175 template <typename AI>
177 {
178  m_pos = other.m_pos;
179  m_size = other.m_size;
180  m_begin = other.m_begin;
181  m_end = other.m_end;
182  m_iterator = other.m_iterator;
183  m_xstride = other.m_xstride;
184  m_boundary = other.m_boundary;
185  return *this;
186 }
187 
188 template <typename I>
189 template <typename AI>
191  m_pos(other.m_pos),
192  m_size(other.m_size),
193  m_begin(other.m_begin),
194  m_end(other.m_end),
195  m_xstride(other.m_xstride),
196  m_iterator(other.m_iterator),
197  m_boundary(other.m_boundary)
198 {
199 }
200 
201 template <typename T>
203 {
204  return left.m_pos == right.m_pos;
205 }
206 
207 template <typename T>
209 {
210  return left.m_pos != right.m_pos;
211 }
212 
213 
214 template <typename I>
215 class EXPORT_2D range2d_iterator: public std::iterator<std::forward_iterator_tag, typename I::value_type>
216 {
217 public:
219  typedef typename I::reference reference;
221  typedef typename I::pointer pointer;
223  typedef I internal_iterator;
224 
225  typedef typename I::value_type value_type;
226 
229 
238  range2d_iterator(const C2DBounds& pos, const C2DBounds& size,
239  const C2DBounds& start, const C2DBounds& end, I iterator);
240 
247 
249  range2d_iterator<I>& operator = (const range2d_iterator<I>& other);
250 
253 
255  template <typename AI>
256  friend class range2d_iterator;
257 
265  template <typename AI>
267 
268 
274  template <typename AI>
276 
277 
282 
285 
288 
292  const C2DBounds& pos() const;
293 
295  template <typename T> friend
296  bool operator == (const range2d_iterator<T>& left, const range2d_iterator<T>& right);
298 
303 
304 
306 
310  const reference operator[] (int i) const;
311 
312 private:
313 
314  void increment_y();
315  void increment_z();
316 
317  C2DBounds m_pos;
318  C2DBounds m_size;
319  C2DBounds m_begin;
320  C2DBounds m_end;
321  int m_xstride;
322  I m_iterator;
323 };
324 
325 
326 
327 template <typename I>
328 template <typename AI>
330 {
331  m_pos = other.m_pos;
332  m_size = other.m_size;
333  m_begin = other.m_begin;
334  m_end = other.m_end;
335  m_iterator = other.m_iterator;
336  m_xstride = other.m_xstride;
337  return *this;
338 }
339 
340 template <typename I>
341 template <typename AI>
343  m_pos(other.m_pos),
344  m_size(other.m_size),
345  m_begin(other.m_begin),
346  m_end(other.m_end),
347  m_xstride(other.m_xstride),
348  m_iterator(other.m_iterator)
349 {
350 }
351 
352 
353 
354 
359 template <typename I>
360 bool operator == (const range2d_iterator<I>& left, const range2d_iterator<I>& right)
361 {
362  // we really want these two to the same range
363 // assert(left.m_size == right.m_size);
364 // assert(left.m_begin == right.m_begin);
365 // assert(left.m_end == right.m_end);
366  return left.m_pos == right.m_pos;
367 }
368 
372 template <typename I>
374 {
375  return !(a == b);
376 }
377 
378 template <typename I>
379 const typename range2d_iterator<I>::reference
381 {
382  return m_iterator[i];
383 }
384 
385 
387 
388 
389 namespace std
390 {
391 
392 template <typename I>
393 class iterator_traits< mia::range2d_iterator<I>>
394 {
395 public:
396  typedef typename I::difference_type difference_type;
397  typedef typename I::value_type value_type;
398  typedef typename I::pointer pointer;
399  typedef typename I::reference reference;
400  typedef forward_iterator_tag iterator_category;
401 };
402 
403 template <typename I>
404 class iterator_traits< mia::range2d_iterator_with_boundary_flag<I>>
405 {
406 public:
407  typedef typename I::difference_type difference_type;
408  typedef typename I::value_type value_type;
409  typedef typename I::pointer pointer;
410  typedef typename I::reference reference;
411  typedef forward_iterator_tag iterator_category;
412 };
413 
414 }
415 
416 #endif
bool operator==(const range2d_iterator_with_boundary_flag< T > &left, const range2d_iterator_with_boundary_flag< T > &right)
Definition: 2d/iterator.hh:202
bool operator!=(const range2d_iterator_with_boundary_flag< T > &left, const range2d_iterator_with_boundary_flag< T > &right)
Definition: 2d/iterator.hh:208
a 2D iterator that knows its position in the 2D grid ans supports iterating over sub-ranges
Definition: 2d/iterator.hh:43
range2d_iterator_with_boundary_flag(const C2DBounds &pos)
I internal_iterator
data type for the real iterator in the background
Definition: 2d/iterator.hh:50
I::reference reference
data type reference
Definition: 2d/iterator.hh:46
range2d_iterator_with_boundary_flag< I > & operator=(const range2d_iterator_with_boundary_flag< I > &other)
assignment operator
range2d_iterator_with_boundary_flag(const C2DBounds &pos, const C2DBounds &size, const C2DBounds &start, const C2DBounds &end, I iterator)
range2d_iterator_with_boundary_flag< I > & operator++()
prefix increment
range2d_iterator_with_boundary_flag(const range2d_iterator_with_boundary_flag< I > &other)
copy constructore
const C2DBounds & pos() const
I::pointer pointer
data type pointer
Definition: 2d/iterator.hh:48
friend class range2d_iterator_with_boundary_flag
friend iterator type because we may want to copy a iterator to a const_iterator.
Definition: 2d/iterator.hh:102
internal_iterator get_point()
I::reference reference
data type reference
Definition: 2d/iterator.hh:219
range2d_iterator< I > & operator=(const range2d_iterator< I > &other)
assignment operator
friend class range2d_iterator
friend iterator type because we may want to copy a iterator to a const_iterator.
Definition: 2d/iterator.hh:256
const C2DBounds & pos() const
const reference operator[](int i) const
Definition: 2d/iterator.hh:380
range2d_iterator(const C2DBounds &pos, const C2DBounds &size, const C2DBounds &start, const C2DBounds &end, I iterator)
range2d_iterator(const range2d_iterator< I > &other)
copy constructore
range2d_iterator(const C2DBounds &pos)
I internal_iterator
data type for the real iterator in the background
Definition: 2d/iterator.hh:223
range2d_iterator_with_boundary_flag< I > with_boundary_flag() const
range2d_iterator< I > & operator++()
prefix increment
pointer operator->() const
I::pointer pointer
data type pointer
Definition: 2d/iterator.hh:221
I::value_type value_type
Definition: 2d/iterator.hh:225
#define EXPORT_2D
Definition: defines2d.hh:37
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)