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-2013 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 
41 template <typename I>
42 class range3d_iterator: public std::forward_iterator_tag {
43 public:
45  typedef typename I::reference reference;
47  typedef typename I::pointer pointer;
49  typedef I internal_iterator;
50 
58  enum EBoundary {
59  eb_none = 0,
60  eb_xlow = 1,
61  eb_xhigh = 2,
62  eb_x = 3,
63  eb_ylow = 4,
64  eb_yhigh = 8,
65  eb_y = 0xC,
66  eb_zlow = 0x10,
67  eb_zhigh = 0x20,
68  eb_z = 0x30
69  };
70 
71 
72 
75 
84  range3d_iterator(const C3DBounds& pos, const C3DBounds& size,
85  const C3DBounds& start, const C3DBounds& end, I iterator);
86 
93 
96 
99 
101  template <typename AI>
102  friend class range3d_iterator;
103 
111  template <typename AI>
112  range3d_iterator(const range3d_iterator<AI>& other);
113 
114 
120  template <typename AI>
122 
123 
128 
130  reference operator *() const;
131 
133  pointer operator ->() const;
134 
138  const C3DBounds& pos() const;
139 
141  template <typename T> friend
142  bool operator == (const range3d_iterator<T>& left, const range3d_iterator<T>& right);
144 
149 
151  int get_boundary_flags() const;
152 
153 private:
154 
155  void increment_y();
156  void increment_z();
157 
158  C3DBounds m_pos;
159  C3DBounds m_size;
160  C3DBounds m_begin;
161  C3DBounds m_end;
162  int m_xstride;
163  int m_ystride;
164  I m_iterator;
165  int m_boundary;
166 };
167 
168 
169 
170 template <typename I>
171 template <typename AI>
173 {
174  m_pos = other.m_pos;
175  m_size = other.m_size;
176  m_begin = other.m_begin;
177  m_end = other.m_end;
178  m_iterator = other.m_iterator;
179  m_xstride = other.m_xstride;
180  m_ystride = other.m_ystride;
181  m_boundary = other.m_boundary;
182  return *this;
183 }
184 
185 template <typename I>
186 template <typename AI>
188  m_pos(other.m_pos),
189  m_size(other.m_size),
190  m_begin(other.m_begin),
191  m_end(other.m_end),
192  m_xstride(other.m_xstride),
193  m_ystride(other.m_ystride),
194  m_iterator(other.m_iterator),
195  m_boundary(other.m_boundary)
196 {
197 }
198 
199 
204 template <typename I>
205 bool operator == (const range3d_iterator<I>& left, const range3d_iterator<I>& right)
206 {
207  // we really want these two to the same range
208 // assert(left.m_size == right.m_size);
209 // assert(left.m_begin == right.m_begin);
210 // assert(left.m_end == right.m_end);
211 
212  return left.m_pos == right.m_pos;
213 
214 }
215 
219 template <typename I>
221 {
222  return !(a == b);
223 }
224 
226 
227 #endif