$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
complex_neighborhood_piter.hh
1 // Copyright (C) 2008, 2009, 2012, 2013 EPITA Research and Development
2 // 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_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
28 # define MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
29 
32 
33 # include <mln/core/concept/neighborhood.hh>
34 # include <mln/core/internal/site_relative_iterator_base.hh>
35 
36 // FIXME: These might be factor-able, both between fwd/bkd and nbh/win.
37 
38 /* FIXME: Do we really want to inherit from
39  internal::site_relative_iterator_base? It might duplicate things,
40  since most of the implementation of this iterator is delegated to
41  the underlying complex iter. Think about introducing base class
42  replacement. */
43 
44 
45 namespace mln
46 {
47 
48  /*------------------------------------------.
49  | complex_neighborhood_fwd_piter<I, G, N>. |
50  `------------------------------------------*/
51 
56  template <typename I, typename G, typename N>
59  complex_neighborhood_fwd_piter<I, G, N> >
60  {
63 
64  public:
66  typedef mln_psite(N) psite;
68  typedef typename N::complex_fwd_iter iter_type;
69 
70  public:
74  template <typename Pref>
75  complex_neighborhood_fwd_piter(const Neighborhood<N>& nbh,
76  const Pref& p_ref);
78 
81  template <typename Pref>
82  void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
83 
87  bool is_valid_() const;
89  void invalidate_();
90 
92  void do_start_();
94  void do_next_();
95 
97  template <typename Pref>
98  void center_at_(const Pref& c);
99 
101  psite compute_p_() const;
104 
107  const iter_type& iter() const;
108  iter_type& iter();
110 
111  private:
113  iter_type iter_;
114  };
115 
116 
118  template <typename I, typename G, typename N>
119  std::ostream&
120  operator<<(std::ostream& ostr,
121  const complex_neighborhood_fwd_piter<I, G, N>& p);
122 
123 
124  /*------------------------------------------.
125  | complex_neighborhood_bkd_piter<I, G, N>. |
126  `------------------------------------------*/
127 
132  template <typename I, typename G, typename N>
134  : public internal::site_relative_iterator_base< N,
136  {
139 
140  public:
142  typedef mln_psite(N) psite;
144  typedef typename N::complex_bkd_iter iter_type;
145 
146  public:
150  template <typename Pref>
151  complex_neighborhood_bkd_piter(const Neighborhood<N>& nbh,
152  const Pref& p_ref);
154 
157  template <typename Pref>
158  void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
159 
163  bool is_valid_() const;
165  void invalidate_();
166 
168  void do_start_();
170  void do_next_();
171 
173  template <typename Pref>
174  void center_at_(const Pref& c);
175 
177  psite compute_p_() const;
180 
183  const iter_type& iter() const;
184  iter_type& iter();
186 
187  private:
189  iter_type iter_;
190  };
191 
192 
194  template <typename I, typename G, typename N>
195  std::ostream&
196  operator<<(std::ostream& ostr,
197  const complex_neighborhood_bkd_piter<I, G, N>& p);
198 
199 
200 
201 # ifndef MLN_INCLUDE_ONLY
202 
203  /*------------------------------------------.
204  | complex_neighborhood_fwd_piter<I, G, N>. |
205  `------------------------------------------*/
206 
207  template <typename I, typename G, typename N>
208  inline
210  {
211  }
212 
213  template <typename I, typename G, typename N>
214  template <typename Pref>
215  inline
217  const Pref& p_ref)
218  {
219  init_(nbh, p_ref);
220  }
221 
222  template <typename I, typename G, typename N>
223  template <typename Pref>
224  inline
225  void
226  complex_neighborhood_fwd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
227  const Pref& p_ref)
228  {
229  this->change_target(exact(nbh));
230  this->center_at(p_ref);
231  mln_postcondition(!this->is_valid());
232  }
233 
234  template <typename I, typename G, typename N>
235  inline
236  bool
238  {
239  return iter_.is_valid();
240  }
241 
242  template <typename I, typename G, typename N>
243  inline
244  void
246  {
247  iter_.invalidate();
248  }
249 
250  template <typename I, typename G, typename N>
251  inline
252  void
254  {
255  iter_.start();
256  }
257 
258  template <typename I, typename G, typename N>
259  inline
260  void
262  {
263  iter_.next();
264  }
265 
266  template <typename I, typename G, typename N>
267  template <typename Pref>
268  inline
269  void
271  {
272  iter_.center_at(this->center().face());
273  }
274 
275  template <typename I, typename G, typename N>
276  inline
277  mln_psite(N)
278  complex_neighborhood_fwd_piter<I, G, N>::compute_p_() const
279  {
280  return psite(this->center().site_set(), iter_);
281  }
282 
283  template <typename I, typename G, typename N>
284  inline
285  const typename N::complex_fwd_iter&
287  {
288  return iter_;
289  }
290 
291  template <typename I, typename G, typename N>
292  inline
293  typename N::complex_fwd_iter&
295  {
296  return iter_;
297  }
298 
299 
300  template <typename I, typename G, typename N>
301  inline
302  std::ostream&
303  operator<<(std::ostream& ostr,
304  const complex_neighborhood_fwd_piter<I, G, N>& p)
305  {
306  return ostr << p.unproxy_();
307  }
308 
309 
310  /*------------------------------------------.
311  | complex_neighborhood_bkd_piter<I, G, N>. |
312  `------------------------------------------*/
313 
314  template <typename I, typename G, typename N>
315  inline
316  complex_neighborhood_bkd_piter<I, G, N>::complex_neighborhood_bkd_piter()
317  {
318  }
319 
320  template <typename I, typename G, typename N>
321  template <typename Pref>
322  inline
323  complex_neighborhood_bkd_piter<I, G, N>::complex_neighborhood_bkd_piter(const Neighborhood<N>& nbh,
324  const Pref& p_ref)
325  {
326  init_(nbh, p_ref);
327  }
328 
329  template <typename I, typename G, typename N>
330  template <typename Pref>
331  inline
332  void
333  complex_neighborhood_bkd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
334  const Pref& p_ref)
335  {
336  this->change_target(exact(nbh));
337  this->center_at(p_ref);
338  mln_postcondition(!this->is_valid());
339  }
340 
341  template <typename I, typename G, typename N>
342  inline
343  bool
345  {
346  return iter_.is_valid();
347  }
348 
349  template <typename I, typename G, typename N>
350  inline
351  void
353  {
354  iter_.invalidate();
355  }
356 
357  template <typename I, typename G, typename N>
358  inline
359  void
361  {
362  iter_.start();
363  }
364 
365  template <typename I, typename G, typename N>
366  inline
367  void
369  {
370  iter_.next();
371  }
372 
373  template <typename I, typename G, typename N>
374  template <typename Pref>
375  inline
376  void
378  {
379  iter_.center_at(this->center().face());
380  }
381 
382  template <typename I, typename G, typename N>
383  inline
384  mln_psite(N)
385  complex_neighborhood_bkd_piter<I, G, N>::compute_p_() const
386  {
387  return psite(this->center().site_set(), iter_);
388  }
389 
390  template <typename I, typename G, typename N>
391  inline
392  const typename N::complex_bkd_iter&
394  {
395  return iter_;
396  }
397 
398  template <typename I, typename G, typename N>
399  inline
400  typename N::complex_bkd_iter&
402  {
403  return iter_;
404  }
405 
406 
407  template <typename I, typename G, typename N>
408  inline
409  std::ostream&
410  operator<<(std::ostream& ostr,
411  const complex_neighborhood_bkd_piter<I, G, N>& p)
412  {
413  return ostr << p.unproxy_();
414  }
415 
416 # endif // ! MLN_INCLUDE_ONLY
417 
418 } // end of namespace mln
419 
420 #endif // ! MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH