Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
complex_neighborhood_piter.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
27 # define MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH
28 
31 
32 # include <mln/core/concept/neighborhood.hh>
33 # include <mln/core/internal/site_relative_iterator_base.hh>
34 
35 // FIXME: These might be factor-able, both between fwd/bkd and nbh/win.
36 
37 /* FIXME: Do we really want to inherit from
38  internal::site_relative_iterator_base? It might duplicate things,
39  since most of the implementation of this iterator is delegated to
40  the underlying complex iter. Think about introducing base class
41  replacement. */
42 
43 
44 namespace mln
45 {
46 
47  /*------------------------------------------.
48  | complex_neighborhood_fwd_piter<I, G, N>. |
49  `------------------------------------------*/
50 
52  template <typename I, typename G, typename N>
54  : public internal::site_relative_iterator_base< N,
55  complex_neighborhood_fwd_piter<I, G, N> >
56  {
58  typedef internal::site_relative_iterator_base< N, self_ > super_;
59 
60  public:
62  typedef mln_psite(N) psite;
64  typedef typename N::complex_fwd_iter iter_type;
65 
66  public:
70  template <typename Pref>
71  complex_neighborhood_fwd_piter(const Neighborhood<N>& nbh,
72  const Pref& p_ref);
74 
76  template <typename Pref>
77  void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
78 
82  bool is_valid_() const;
84  void invalidate_();
85 
87  void do_start_();
89  void do_next_();
90 
92  template <typename Pref>
93  void center_at_(const Pref& c);
94 
96  psite compute_p_() const;
98 
101  const iter_type& iter() const;
102  iter_type& iter();
104 
105  private:
107  iter_type iter_;
108  };
109 
110 
112  template <typename I, typename G, typename N>
113  std::ostream&
114  operator<<(std::ostream& ostr,
115  const complex_neighborhood_fwd_piter<I, G, N>& p);
116 
117 
118  /*------------------------------------------.
119  | complex_neighborhood_bkd_piter<I, G, N>. |
120  `------------------------------------------*/
121 
123  template <typename I, typename G, typename N>
125  : public internal::site_relative_iterator_base< N,
127  {
129  typedef internal::site_relative_iterator_base< N, self_ > super_;
130 
131  public:
133  typedef mln_psite(N) psite;
135  typedef typename N::complex_bkd_iter iter_type;
136 
137  public:
141  template <typename Pref>
142  complex_neighborhood_bkd_piter(const Neighborhood<N>& nbh,
143  const Pref& p_ref);
145 
147  template <typename Pref>
148  void init_(const Neighborhood<N>& nbh, const Pref& p_ref);
149 
153  bool is_valid_() const;
155  void invalidate_();
156 
158  void do_start_();
160  void do_next_();
161 
163  template <typename Pref>
164  void center_at_(const Pref& c);
165 
167  psite compute_p_() const;
169 
172  const iter_type& iter() const;
173  iter_type& iter();
175 
176  private:
178  iter_type iter_;
179  };
180 
181 
183  template <typename I, typename G, typename N>
184  std::ostream&
185  operator<<(std::ostream& ostr,
186  const complex_neighborhood_bkd_piter<I, G, N>& p);
187 
188 
189 
190 # ifndef MLN_INCLUDE_ONLY
191 
192  /*------------------------------------------.
193  | complex_neighborhood_fwd_piter<I, G, N>. |
194  `------------------------------------------*/
195 
196  template <typename I, typename G, typename N>
197  inline
199  {
200  }
201 
202  template <typename I, typename G, typename N>
203  template <typename Pref>
204  inline
206  const Pref& p_ref)
207  {
208  init_(nbh, p_ref);
209  }
210 
211  template <typename I, typename G, typename N>
212  template <typename Pref>
213  inline
214  void
215  complex_neighborhood_fwd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
216  const Pref& p_ref)
217  {
218  this->change_target(exact(nbh));
219  this->center_at(p_ref);
220  mln_postcondition(!this->is_valid());
221  }
222 
223  template <typename I, typename G, typename N>
224  inline
225  bool
226  complex_neighborhood_fwd_piter<I, G, N>::is_valid_() const
227  {
228  return iter_.is_valid();
229  }
230 
231  template <typename I, typename G, typename N>
232  inline
233  void
234  complex_neighborhood_fwd_piter<I, G, N>::invalidate_()
235  {
236  iter_.invalidate();
237  }
238 
239  template <typename I, typename G, typename N>
240  inline
241  void
242  complex_neighborhood_fwd_piter<I, G, N>::do_start_()
243  {
244  iter_.start();
245  }
246 
247  template <typename I, typename G, typename N>
248  inline
249  void
250  complex_neighborhood_fwd_piter<I, G, N>::do_next_()
251  {
252  iter_.next();
253  }
254 
255  template <typename I, typename G, typename N>
256  template <typename Pref>
257  inline
258  void
259  complex_neighborhood_fwd_piter<I, G, N>::center_at_(const Pref&)
260  {
261  iter_.center_at(this->center().face());
262  }
263 
264  template <typename I, typename G, typename N>
265  inline
266  mln_psite(N)
267  complex_neighborhood_fwd_piter<I, G, N>::compute_p_() const
268  {
269  return psite(this->center().site_set(), iter_);
270  }
271 
272  template <typename I, typename G, typename N>
273  inline
274  const typename N::complex_fwd_iter&
276  {
277  return iter_;
278  }
279 
280  template <typename I, typename G, typename N>
281  inline
282  typename N::complex_fwd_iter&
284  {
285  return iter_;
286  }
287 
288 
289  template <typename I, typename G, typename N>
290  inline
291  std::ostream&
292  operator<<(std::ostream& ostr,
294  {
295  return ostr << p.unproxy_();
296  }
297 
298 
299  /*------------------------------------------.
300  | complex_neighborhood_bkd_piter<I, G, N>. |
301  `------------------------------------------*/
302 
303  template <typename I, typename G, typename N>
304  inline
306  {
307  }
308 
309  template <typename I, typename G, typename N>
310  template <typename Pref>
311  inline
313  const Pref& p_ref)
314  {
315  init_(nbh, p_ref);
316  }
317 
318  template <typename I, typename G, typename N>
319  template <typename Pref>
320  inline
321  void
322  complex_neighborhood_bkd_piter<I, G, N>::init_(const Neighborhood<N>& nbh,
323  const Pref& p_ref)
324  {
325  this->change_target(exact(nbh));
326  this->center_at(p_ref);
327  mln_postcondition(!this->is_valid());
328  }
329 
330  template <typename I, typename G, typename N>
331  inline
332  bool
333  complex_neighborhood_bkd_piter<I, G, N>::is_valid_() const
334  {
335  return iter_.is_valid();
336  }
337 
338  template <typename I, typename G, typename N>
339  inline
340  void
341  complex_neighborhood_bkd_piter<I, G, N>::invalidate_()
342  {
343  iter_.invalidate();
344  }
345 
346  template <typename I, typename G, typename N>
347  inline
348  void
349  complex_neighborhood_bkd_piter<I, G, N>::do_start_()
350  {
351  iter_.start();
352  }
353 
354  template <typename I, typename G, typename N>
355  inline
356  void
357  complex_neighborhood_bkd_piter<I, G, N>::do_next_()
358  {
359  iter_.next();
360  }
361 
362  template <typename I, typename G, typename N>
363  template <typename Pref>
364  inline
365  void
366  complex_neighborhood_bkd_piter<I, G, N>::center_at_(const Pref&)
367  {
368  iter_.center_at(this->center().face());
369  }
370 
371  template <typename I, typename G, typename N>
372  inline
373  mln_psite(N)
374  complex_neighborhood_bkd_piter<I, G, N>::compute_p_() const
375  {
376  return psite(this->center().site_set(), iter_);
377  }
378 
379  template <typename I, typename G, typename N>
380  inline
381  const typename N::complex_bkd_iter&
383  {
384  return iter_;
385  }
386 
387  template <typename I, typename G, typename N>
388  inline
389  typename N::complex_bkd_iter&
391  {
392  return iter_;
393  }
394 
395 
396  template <typename I, typename G, typename N>
397  inline
398  std::ostream&
399  operator<<(std::ostream& ostr,
401  {
402  return ostr << p.unproxy_();
403  }
404 
405 # endif // ! MLN_INCLUDE_ONLY
406 
407 } // end of namespace mln
408 
409 #endif // ! MLN_CORE_IMAGE_COMPLEX_NEIGHBORHOOD_PITER_HH