My Project
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 {
45 public:
47  typedef typename I::reference reference;
48 
50  typedef typename I::pointer pointer;
51 
53  typedef typename I::value_type value_type;
54 
56  typedef I internal_iterator;
57 
65  enum EBoundary {
66  eb_none = 0,
67  eb_xlow = 1,
68  eb_xhigh = 2,
69  eb_x = 3,
70  eb_ylow = 4,
71  eb_yhigh = 8,
72  eb_y = 0xC,
73  eb_zlow = 0x10,
74  eb_zhigh = 0x20,
75  eb_z = 0x30
76  };
77 
78 
79 
82 
92  const C3DBounds& start, const C3DBounds& end, I iterator);
93 
100 
103 
106 
108  template <typename AI>
110 
111 
119  template <typename AI>
121 
127  template <typename AI>
129 
130 
135 
137  reference operator *() const;
138 
140  pointer operator ->() const;
141 
145  const C3DBounds& pos() const;
146 
148  template <typename T> friend
151 
156 
158  int get_boundary_flags() const;
159 
160 private:
161 
162  void increment_y();
163  void increment_z();
164 
165  C3DBounds m_pos;
166  C3DBounds m_size;
167  C3DBounds m_begin;
168  C3DBounds m_end;
169  int m_xstride;
170  int m_ystride;
171  I m_iterator;
172  int m_boundary;
173 };
174 
175 
176 
189 template <typename I>
190 class EXPORT_3D range3d_iterator: public std::forward_iterator_tag
191 {
192 public:
194  typedef typename I::reference reference;
196  typedef typename I::pointer pointer;
197 
199  typedef typename I::value_type value_type;
200 
202  typedef I internal_iterator;
203 
204 
207 
216  range3d_iterator(const C3DBounds& pos, const C3DBounds& size,
217  const C3DBounds& start, const C3DBounds& end, I iterator);
218 
224  range3d_iterator(const C3DBounds& pos);
225 
227  range3d_iterator<I>& operator = (const range3d_iterator<I>& other);
228 
231 
233  template <typename AI>
234  friend class range3d_iterator;
235 
237  template <typename AI>
239 
240 
248  template <typename AI>
250 
251 
257  template <typename AI>
259 
260 
265 
267  reference operator *() const;
268 
270  pointer operator ->() const;
271 
275  const C3DBounds& pos() const;
276 
278  template <typename T> friend
279  bool operator == (const range3d_iterator<T>& left, const range3d_iterator<T>& right);
281 
286 
290  range3d_iterator_with_boundary_flag<I> with_boundary_flag() const;
291 
295  const reference operator[] (int i) const;
296 
297 private:
298 
299  void increment_y();
300  void increment_z();
301 
302  C3DBounds m_pos;
303  C3DBounds m_size;
304  C3DBounds m_begin;
305  C3DBounds m_end;
306  int m_xstride;
307  int m_ystride;
308  I m_iterator;
309 };
310 
311 
312 
313 template <typename I>
314 template <typename AI>
316 {
317  m_pos = other.m_pos;
318  m_size = other.m_size;
319  m_begin = other.m_begin;
320  m_end = other.m_end;
321  m_iterator = other.m_iterator;
322  m_xstride = other.m_xstride;
323  m_ystride = other.m_ystride;
324  return *this;
325 }
326 
327 template <typename I>
328 template <typename AI>
330  m_pos(other.m_pos),
331  m_size(other.m_size),
332  m_begin(other.m_begin),
333  m_end(other.m_end),
334  m_xstride(other.m_xstride),
335  m_ystride(other.m_ystride),
336  m_iterator(other.m_iterator)
337 {
338 }
339 
340 template <typename I>
341 const typename range3d_iterator<I>::reference
343 {
344  return m_iterator[i];
345 }
346 
351 template <typename I>
352 bool operator == (const range3d_iterator<I>& left, const range3d_iterator<I>& right)
353 {
354  // we really want these two to the same range
355 // assert(left.m_size == right.m_size);
356 // assert(left.m_begin == right.m_begin);
357 // assert(left.m_end == right.m_end);
358  return left.m_pos == right.m_pos;
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  return left.m_pos == right.m_pos;
415 }
416 
420 template <typename I>
422 {
423  return !(a == b);
424 }
425 
427 
428 namespace std
429 {
430 
431 template <typename I>
432 class iterator_traits< mia::range3d_iterator<I>>
433 {
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 {
445 public:
446  typedef typename I::difference_type difference_type;
447  typedef typename I::value_type value_type;
448  typedef typename I::pointer pointer;
449  typedef typename I::reference reference;
450  typedef forward_iterator_tag iterator_category;
451 };
452 
453 }
454 
455 #endif
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::reference
I::reference reference
Definition: 3d/iterator.hh:449
std::iterator_traits< mia::range3d_iterator< I > >::reference
I::reference reference
Definition: 3d/iterator.hh:438
range3d_iterator
a 3D iterator that knows its position in the 3D grid ans supports iterating over sub-ranges
Definition: 3d/iterator.hh:190
range3d_iterator_with_boundary_flag::reference
I::reference reference
data type reference
Definition: 3d/iterator.hh:47
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::pointer
I::pointer pointer
Definition: 3d/iterator.hh:448
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::iterator_category
forward_iterator_tag iterator_category
Definition: 3d/iterator.hh:450
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::value_type
I::value_type value_type
Definition: 3d/iterator.hh:447
range3d_iterator_with_boundary_flag::get_point
internal_iterator get_point()
operator!=
bool operator!=(const range3d_iterator< I > &a, const range3d_iterator< I > &b)
Definition: 3d/iterator.hh:365
std::iterator_traits< mia::range3d_iterator< I > >::pointer
I::pointer pointer
Definition: 3d/iterator.hh:437
range3d_iterator::operator[]
const reference operator[](int i) const
Definition: 3d/iterator.hh:342
range3d_iterator::operator=
range3d_iterator< I > & operator=(const range3d_iterator< I > &other)
assignment operator
std::iterator_traits< mia::range3d_iterator< I > >::difference_type
I::difference_type difference_type
Definition: 3d/iterator.hh:435
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
range3d_iterator_with_boundary_flag::pos
const C3DBounds & pos() const
range3d_iterator_with_boundary_flag::operator++
range3d_iterator_with_boundary_flag< I > & operator++()
prefix increment
range3d_iterator::pointer
I::pointer pointer
data type pointer
Definition: 3d/iterator.hh:196
std::iterator_traits< mia::range3d_iterator< I > >::value_type
I::value_type value_type
Definition: 3d/iterator.hh:436
range3d_iterator_with_boundary_flag::pointer
I::pointer pointer
data type pointer
Definition: 3d/iterator.hh:50
range3d_iterator::value_type
I::value_type value_type
data value type
Definition: 3d/iterator.hh:199
range3d_iterator::reference
I::reference reference
data type reference
Definition: 3d/iterator.hh:194
range3d_iterator_with_boundary_flag::get_boundary_flags
int get_boundary_flags() const
EXPORT_3D
#define EXPORT_3D
Definition: defines3d.hh:45
range3d_iterator_with_boundary_flag
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
range3d_iterator_with_boundary_flag::internal_iterator
I internal_iterator
data type for the real iterator in the background
Definition: 3d/iterator.hh:56
std::iterator_traits< mia::range3d_iterator_with_boundary_flag< I > >::difference_type
I::difference_type difference_type
Definition: 3d/iterator.hh:446
operator==
bool operator==(const range3d_iterator< I > &left, const range3d_iterator< I > &right)
Definition: 3d/iterator.hh:352
range3d_iterator::internal_iterator
I internal_iterator
data type for the real iterator in the background
Definition: 3d/iterator.hh:202
range3d_iterator_with_boundary_flag::operator=
range3d_iterator_with_boundary_flag< I > & operator=(const range3d_iterator_with_boundary_flag< I > &other)
assignment operator
std
Definition: gsl_iterator.hh:323
range3d_iterator_with_boundary_flag::range3d_iterator_with_boundary_flag
range3d_iterator_with_boundary_flag()
mia
Definition: convergence_measure.hh:30
std::iterator_traits< mia::range3d_iterator< I > >::iterator_category
forward_iterator_tag iterator_category
Definition: 3d/iterator.hh:439
T3DVector< unsigned int >
range3d_iterator_with_boundary_flag::value_type
I::value_type value_type
data value type
Definition: 3d/iterator.hh:53
range3d_iterator_with_boundary_flag::EBoundary
EBoundary
Definition: 3d/iterator.hh:65
gsl::operator*
Matrix EXPORT_GSL operator*(const Matrix &lhs, const Matrix &rhs)
vector.hh
range3d_iterator_with_boundary_flag::operator->
pointer operator->() const
range3d_iterator::range3d_iterator
range3d_iterator()