3d/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_3d_iterator_hh
22 #define mia_3d_iterator_hh
23 
24 #include <mia/3d/vector.hh>
25 
27 
28 
29 
42 template <typename I>
43 class EXPORT_3D range3d_iterator_with_boundary_flag: public std::forward_iterator_tag {
44 public:
46  typedef typename I::reference reference;
47 
49  typedef typename I::pointer pointer;
50 
52  typedef typename I::value_type value_type;
53 
55  typedef I internal_iterator;
56 
64  enum EBoundary {
65  eb_none = 0,
66  eb_xlow = 1,
67  eb_xhigh = 2,
68  eb_x = 3,
69  eb_ylow = 4,
70  eb_yhigh = 8,
71  eb_y = 0xC,
72  eb_zlow = 0x10,
73  eb_zhigh = 0x20,
74  eb_z = 0x30
75  };
76 
77 
78 
81 
91  const C3DBounds& start, const C3DBounds& end, I iterator);
92 
99 
102 
105 
107  template <typename AI>
109 
110 
118  template <typename AI>
120 
126  template <typename AI>
128 
129 
134 
136  reference operator *() const;
137 
139  pointer operator ->() const;
140 
144  const C3DBounds& pos() const;
145 
147  template <typename T> friend
150 
154  internal_iterator get_point();
155 
157  int get_boundary_flags() const;
158 
159 private:
160 
161  void increment_y();
162  void increment_z();
163 
164  C3DBounds m_pos;
165  C3DBounds m_size;
166  C3DBounds m_begin;
167  C3DBounds m_end;
168  int m_xstride;
169  int m_ystride;
170  I m_iterator;
171  int m_boundary;
172 };
173 
174 
175 
188 template <typename I>
189 class EXPORT_3D range3d_iterator: public std::forward_iterator_tag {
190 public:
192  typedef typename I::reference reference;
194  typedef typename I::pointer pointer;
195 
197  typedef typename I::value_type value_type;
198 
200  typedef I internal_iterator;
201 
202 
204  range3d_iterator();
205 
214  range3d_iterator(const C3DBounds& pos, const C3DBounds& size,
215  const C3DBounds& start, const C3DBounds& end, I iterator);
216 
222  range3d_iterator(const C3DBounds& pos);
223 
225  range3d_iterator<I>& operator = (const range3d_iterator<I>& other);
226 
228  range3d_iterator(const range3d_iterator<I>& other);
229 
231  template <typename AI>
232  friend class range3d_iterator;
233 
235  template <typename AI>
237 
238 
246  template <typename AI>
247  range3d_iterator(const range3d_iterator<AI>& other);
248 
249 
255  template <typename AI>
257 
258 
263 
265  reference operator *() const;
266 
268  pointer operator ->() const;
269 
273  const C3DBounds& pos() const;
274 
276  template <typename T> friend
277  bool operator == (const range3d_iterator<T>& left, const range3d_iterator<T>& right);
279 
283  internal_iterator get_point();
284 
288  range3d_iterator_with_boundary_flag<I> with_boundary_flag() const;
289 
293  const reference operator[] (int i) const;
294 
295 private:
296 
297  void increment_y();
298  void increment_z();
299 
300  C3DBounds m_pos;
301  C3DBounds m_size;
302  C3DBounds m_begin;
303  C3DBounds m_end;
304  int m_xstride;
305  int m_ystride;
306  I m_iterator;
307 };
308 
309 
310 
311 template <typename I>
312 template <typename AI>
314 {
315  m_pos = other.m_pos;
316  m_size = other.m_size;
317  m_begin = other.m_begin;
318  m_end = other.m_end;
319  m_iterator = other.m_iterator;
320  m_xstride = other.m_xstride;
321  m_ystride = other.m_ystride;
322  return *this;
323 }
324 
325 template <typename I>
326 template <typename AI>
328  m_pos(other.m_pos),
329  m_size(other.m_size),
330  m_begin(other.m_begin),
331  m_end(other.m_end),
332  m_xstride(other.m_xstride),
333  m_ystride(other.m_ystride),
334  m_iterator(other.m_iterator)
335 {
336 }
337 
338 template <typename I>
339 const typename range3d_iterator<I>::reference
341 {
342  return m_iterator[i];
343 }
344 
349 template <typename I>
350 bool operator == (const range3d_iterator<I>& left, const range3d_iterator<I>& right)
351 {
352  // we really want these two to the same range
353 // assert(left.m_size == right.m_size);
354 // assert(left.m_begin == right.m_begin);
355 // assert(left.m_end == right.m_end);
356 
357  return left.m_pos == right.m_pos;
358 
359 }
360 
364 template <typename I>
366 {
367  return !(a == b);
368 }
369 
370 
371 
372 
373 
374 template <typename I>
375 template <typename AI>
377 {
378  m_pos = other.m_pos;
379  m_size = other.m_size;
380  m_begin = other.m_begin;
381  m_end = other.m_end;
382  m_iterator = other.m_iterator;
383  m_xstride = other.m_xstride;
384  m_ystride = other.m_ystride;
385  m_boundary = other.m_boundary;
386  return *this;
387 }
388 
389 template <typename I>
390 template <typename AI>
392  m_pos(other.m_pos),
393  m_size(other.m_size),
394  m_begin(other.m_begin),
395  m_end(other.m_end),
396  m_xstride(other.m_xstride),
397  m_ystride(other.m_ystride),
398  m_iterator(other.m_iterator),
399  m_boundary(other.m_boundary)
400 {
401 }
402 
407 template <typename I>
409 {
410  // we really want these two to the same range
411 // assert(left.m_size == right.m_size);
412 // assert(left.m_begin == right.m_begin);
413 // assert(left.m_end == right.m_end);
414 
415  return left.m_pos == right.m_pos;
416 
417 }
418 
422 template <typename I>
424 {
425  return !(a == b);
426 }
427 
429 
430 namespace std {
431 
432 template <typename I>
433 class iterator_traits< mia::range3d_iterator<I> > {
434 public:
435  typedef typename I::difference_type difference_type;
436  typedef typename I::value_type value_type;
437  typedef typename I::pointer pointer;
438  typedef typename I::reference reference;
439  typedef forward_iterator_tag iterator_category;
440 };
441 
442 template <typename I>
443 class iterator_traits< mia::range3d_iterator_with_boundary_flag<I> > {
444 public:
445  typedef typename I::difference_type difference_type;
446  typedef typename I::value_type value_type;
447  typedef typename I::pointer pointer;
448  typedef typename I::reference reference;
449  typedef forward_iterator_tag iterator_category;
450 };
451 
452 }
453 
454 #endif
const C3DBounds & pos() const
bool operator!=(const range3d_iterator< I > &a, const range3d_iterator< I > &b)
Definition: 3d/iterator.hh:365
a 3D iterator that knows its position in the 3D grid ans supports iterating over sub-ranges ...
Definition: 3d/iterator.hh:189
range3d_iterator< I > & operator=(const range3d_iterator< I > &other)
assignment operator
a 3D iterator that knows its position in the 3D grid, has a flag indicating whether it is on a bounda...
Definition: 3d/iterator.hh:43
const reference operator[](int i) const
Definition: 3d/iterator.hh:340
I::pointer pointer
data type pointer
Definition: 3d/iterator.hh:194
I::reference reference
data type reference
Definition: 3d/iterator.hh:46
I internal_iterator
data type for the real iterator in the background
Definition: 3d/iterator.hh:55
I::value_type value_type
data value type
Definition: 3d/iterator.hh:197
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
I::value_type value_type
data value type
Definition: 3d/iterator.hh:52
range3d_iterator_with_boundary_flag< I > & operator=(const range3d_iterator_with_boundary_flag< I > &other)
assignment operator
#define EXPORT_3D
Definition: defines3d.hh:44
range3d_iterator_with_boundary_flag< I > & operator++()
prefix increment
I::reference reference
data type reference
Definition: 3d/iterator.hh:192
bool operator==(const range3d_iterator< I > &left, const range3d_iterator< I > &right)
Definition: 3d/iterator.hh:350
I::pointer pointer
data type pointer
Definition: 3d/iterator.hh:49
I internal_iterator
data type for the real iterator in the background
Definition: 3d/iterator.hh:200
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36