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
42template <typename I>
43class EXPORT_3D range3d_iterator_with_boundary_flag: public std::forward_iterator_tag
44{
45public:
47 typedef typename I::reference reference;
48
50 typedef typename I::pointer pointer;
51
53 typedef typename I::value_type value_type;
54
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
138
140 pointer operator ->() const;
141
145 const C3DBounds& pos() const;
146
148 template <typename T> friend
151
156
159
160private:
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
189template <typename I>
190class EXPORT_3D range3d_iterator: public std::forward_iterator_tag
191{
192public:
194 typedef typename I::reference reference;
196 typedef typename I::pointer pointer;
197
199 typedef typename I::value_type value_type;
200
203
204
207
216 range3d_iterator(const C3DBounds& pos, const C3DBounds& size,
217 const C3DBounds& start, const C3DBounds& end, I iterator);
218
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>
258 range3d_iterator<I>& operator = (const range3d_iterator<AI>& other);
259
260
262 range3d_iterator<I>& operator ++();
264 range3d_iterator<I> operator ++(int);
265
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
291
295 const reference operator[] (int i) const;
296
297private:
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
313template <typename I>
314template <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
327template <typename I>
328template <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
340template <typename I>
343{
344 return m_iterator[i];
345}
346
351template <typename I>
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
364template <typename I>
366{
367 return !(a == b);
368}
369
370
371
372
373
374template <typename I>
375template <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
389template <typename I>
390template <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
407template <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
420template <typename I>
425
427
428namespace std
429{
430
431template <typename I>
432class iterator_traits< mia::range3d_iterator<I>>
433{
434public:
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
442template <typename I>
443class iterator_traits< mia::range3d_iterator_with_boundary_flag<I>>
444{
445public:
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
bool operator==(const range3d_iterator< I > &left, const range3d_iterator< I > &right)
bool operator!=(const range3d_iterator< I > &a, const range3d_iterator< I > &b)
bool operator==(const CAttribute &a, const CAttribute &b)
Definition attributes.hh:95
a 3D iterator that knows its position in the 3D grid, has a flag indicating whether it is on a bounda...
range3d_iterator_with_boundary_flag< I > & operator=(const range3d_iterator_with_boundary_flag< I > &other)
assignment operator
const C3DBounds & pos() const
I::value_type value_type
data value type
I::pointer pointer
data type pointer
range3d_iterator_with_boundary_flag(const C3DBounds &pos, const C3DBounds &size, const C3DBounds &start, const C3DBounds &end, I iterator)
friend class range3d_iterator_with_boundary_flag
friend iterator type because we may want to copy a iterator to a const_iterator.
I internal_iterator
data type for the real iterator in the background
range3d_iterator_with_boundary_flag(const range3d_iterator_with_boundary_flag< I > &other)
copy constructore
I::reference reference
data type reference
range3d_iterator_with_boundary_flag(const C3DBounds &pos)
a 3D iterator that knows its position in the 3D grid ans supports iterating over sub-ranges
internal_iterator get_point()
range3d_iterator_with_boundary_flag< I > with_boundary_flag() const
const reference operator[](int i) const
const C3DBounds & pos() const
I::value_type value_type
data value type
range3d_iterator(const C3DBounds &pos, const C3DBounds &size, const C3DBounds &start, const C3DBounds &end, I iterator)
range3d_iterator(const C3DBounds &pos)
I::pointer pointer
data type pointer
I internal_iterator
data type for the real iterator in the background
range3d_iterator(const range3d_iterator< I > &other)
copy constructore
friend class range3d_iterator
friend iterator type because we may want to copy a iterator to a const_iterator.
range3d_iterator< I > & operator=(const range3d_iterator< I > &other)
assignment operator
I::reference reference
data type reference
#define EXPORT_3D
Definition defines3d.hh:45
#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
F operator*(const typename TSparseSolver< F >::A_mult_x &A, const F &x)