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-2016 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 
290 
291 private:
292 
293  void increment_y();
294  void increment_z();
295 
296  C3DBounds m_pos;
297  C3DBounds m_size;
298  C3DBounds m_begin;
299  C3DBounds m_end;
300  int m_xstride;
301  int m_ystride;
302  I m_iterator;
303 };
304 
305 
306 
307 template <typename I>
308 template <typename AI>
310 {
311  m_pos = other.m_pos;
312  m_size = other.m_size;
313  m_begin = other.m_begin;
314  m_end = other.m_end;
315  m_iterator = other.m_iterator;
316  m_xstride = other.m_xstride;
317  m_ystride = other.m_ystride;
318  return *this;
319 }
320 
321 template <typename I>
322 template <typename AI>
324  m_pos(other.m_pos),
325  m_size(other.m_size),
326  m_begin(other.m_begin),
327  m_end(other.m_end),
328  m_xstride(other.m_xstride),
329  m_ystride(other.m_ystride),
330  m_iterator(other.m_iterator)
331 {
332 }
333 
334 
339 template <typename I>
340 bool operator == (const range3d_iterator<I>& left, const range3d_iterator<I>& right)
341 {
342  // we really want these two to the same range
343 // assert(left.m_size == right.m_size);
344 // assert(left.m_begin == right.m_begin);
345 // assert(left.m_end == right.m_end);
346 
347  return left.m_pos == right.m_pos;
348 
349 }
350 
354 template <typename I>
356 {
357  return !(a == b);
358 }
359 
360 
361 
362 
363 
364 template <typename I>
365 template <typename AI>
367 {
368  m_pos = other.m_pos;
369  m_size = other.m_size;
370  m_begin = other.m_begin;
371  m_end = other.m_end;
372  m_iterator = other.m_iterator;
373  m_xstride = other.m_xstride;
374  m_ystride = other.m_ystride;
375  m_boundary = other.m_boundary;
376  return *this;
377 }
378 
379 template <typename I>
380 template <typename AI>
382  m_pos(other.m_pos),
383  m_size(other.m_size),
384  m_begin(other.m_begin),
385  m_end(other.m_end),
386  m_xstride(other.m_xstride),
387  m_ystride(other.m_ystride),
388  m_iterator(other.m_iterator),
389  m_boundary(other.m_boundary)
390 {
391 }
392 
397 template <typename I>
399 {
400  // we really want these two to the same range
401 // assert(left.m_size == right.m_size);
402 // assert(left.m_begin == right.m_begin);
403 // assert(left.m_end == right.m_end);
404 
405  return left.m_pos == right.m_pos;
406 
407 }
408 
412 template <typename I>
414 {
415  return !(a == b);
416 }
417 
419 
420 namespace std {
421 
422 template <typename I>
423 class iterator_traits< mia::range3d_iterator<I> > {
424 public:
425  typedef typename I::difference_type difference_type;
426  typedef typename I::value_type value_type;
427  typedef typename I::pointer pointer;
428  typedef typename I::reference reference;
429  typedef forward_iterator_tag iterator_category;
430 };
431 
432 template <typename I>
433 class iterator_traits< mia::range3d_iterator_with_boundary_flag<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 }
443 
444 #endif
const C3DBounds & pos() const
bool operator!=(const range3d_iterator< I > &a, const range3d_iterator< I > &b)
Definition: 3d/iterator.hh:355
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
Definition: fastica.hh:28
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
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:340
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