$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
box_piter.hh
1 // Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_SITE_SET_BOX_PITER_HH
28 # define MLN_CORE_SITE_SET_BOX_PITER_HH
29 
33 
34 # include <mln/core/internal/site_set_iterator_base.hh>
35 # include <mln/core/concept/box.hh>
36 # include <mln/core/site_set/box.hh>
37 
38 
39 namespace mln
40 {
41 
49  template <typename P>
51  box_fwd_piter_<P> >
52  {
53  typedef box_fwd_piter_<P> self_;
55 
56  public:
57 
58  // Make definitions from super class available.
59  enum { dim = P::dim };
60 
63 
68  box_fwd_piter_(const mln::box<P>& b);
69 
72  bool is_valid_() const;
73 
75  void invalidate_();
76 
78  void start_();
79 
81  void next_();
83 
84  protected:
85  using super_::p_;
86  using super_::s_;
87  };
88 
89 
90 
98  template <typename P>
100  box_bkd_piter_<P> >
101  {
102  typedef box_bkd_piter_<P> self_;
104 
105  public:
106 
107  // Make definitions from super class available.
108  enum { dim = P::dim };
109 
111  box_bkd_piter_();
112 
117  box_bkd_piter_(const box<P>& b);
118 
121  bool is_valid_() const;
122 
124  void invalidate_();
125 
127  void start_();
128 
130  void next_();
132 
133  protected:
134  using super_::p_;
135  using super_::s_;
136  };
137 
138 
139 
140 
141 # ifndef MLN_INCLUDE_ONLY
142 
143 
144  // box_fwd_piter_<P>
145 
146  template <typename P>
147  inline
149  {
150  }
151 
152  template <typename P>
153  inline
155  {
156  this->change_target(b);
157  }
158 
159  template <typename P>
160  inline
161  bool
163  {
164  return p_[0] != s_->pmax()[0] + 1;
165  }
166 
167  template <typename P>
168  inline
169  void
171  {
172  p_[0] = static_cast<def::coord>(s_->pmax()[0] + 1);
173  }
174 
175  template <typename P>
176  inline
177  void
179  {
180  p_ = s_->pmin();
181  }
182 
183  template <typename P>
184  inline
185  void
187  {
188  for (int i = dim - 1; i >= 0; --i)
189  if (p_[i] != s_->pmax()[i])
190  {
191  ++p_[i];
192  break;
193  }
194  else
195  {
196  p_[i] = s_->pmin()[i];
197  if (i == 0)
198  invalidate_();
199  }
200 
201  // memo
202 
203 // for (int i = dim - 1; i >= 0; --i)
204 // if (p_[i] != s_->pmax()[i])
205 // {
206 // ++p_[i];
207 // break;
208 // }
209 // else
210 // p_[i] = s_->pmin()[i];
211 // if (p_ == s_->pmin())
212 // invalidate_();
213  }
214 
215 
216  // box_bkd_piter_<P>
217 
218  template <typename P>
219  inline
221  {
222  }
223 
224  template <typename P>
225  inline
226  box_bkd_piter_<P>::box_bkd_piter_(const box<P>& b)
227  {
228  this->change_target(b);
229  }
230 
231  template <typename P>
232  inline
233  bool
235  {
236  return p_[0] != s_->pmin()[0] - 1;
237  }
238 
239  template <typename P>
240  inline
241  void
243  {
244  p_[0] = mln_coord(P)(s_->pmin()[0] - 1);
245  }
246 
247  template <typename P>
248  inline
249  void
251  {
252  p_ = s_->pmax();
253  }
254 
255  template <typename P>
256  inline
257  void
259  {
260  for (int i = dim - 1; i >= 0; --i)
261  if (p_[i] == s_->pmin()[i])
262  p_[i] = s_->pmax()[i];
263  else
264  {
265  --p_[i];
266  break;
267  }
268  if (p_ == s_->pmax())
269  invalidate_();
270  }
271 
272 # endif // ! MLN_INCLUDE_ONLY
273 
274 } // end of namespace mln
275 
276 
277 #endif // ! MLN_CORE_SITE_SET_BOX_PITER_HH