$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
complex_window_piter.hh
1 // Copyright (C) 2008, 2009, 2010, 2011, 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_IMAGE_COMPLEX_WINDOW_PITER_HH
28 # define MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH
29 
32 
33 # include <mln/core/concept/window.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_window_fwd_piter<I, G, W>. |
50  `------------------------------------*/
51 
56  template <typename I, typename G, typename W>
59  complex_window_fwd_piter<I, G, W> >
60  {
63 
64  public:
66  typedef mln_psite(W) psite;
68  typedef typename W::complex_fwd_iter iter_type;
69 
70  public:
74  template <typename Pref>
75  complex_window_fwd_piter(const Window<W>& win, const Pref& p_ref);
77 
80  template <typename Pref>
81  void init_(const Window<W>& win, const Pref& p_ref);
82 
86  bool is_valid_() const;
88  void invalidate_();
89 
91  void do_start_();
93  void do_next_();
94 
96  template <typename Pref>
97  void center_at_(const Pref& c);
98 
100  psite compute_p_() const;
103 
106  const iter_type& iter() const;
107  iter_type& iter();
109 
110  private:
112  iter_type iter_;
113  };
114 
115 
117  template <typename I, typename G, typename W>
118  std::ostream&
119  operator<<(std::ostream& ostr,
120  const complex_window_fwd_piter<I, G, W>& p);
121 
122 
123  /*------------------------------------.
124  | complex_window_bkd_piter<I, G, W>. |
125  `------------------------------------*/
126 
131  template <typename I, typename G, typename W>
133  : public internal::site_relative_iterator_base< W,
134  complex_window_bkd_piter<I, G, W> >
135  {
138 
139  public:
141  typedef mln_psite(W) psite;
143  typedef typename W::complex_bkd_iter iter_type;
144 
145  public:
149  template <typename Pref>
150  complex_window_bkd_piter(const Window<W>& win, const Pref& p_ref);
152 
155  template <typename Pref>
156  void init_(const Window<W>& win, const Pref& p_ref);
157 
161  bool is_valid_() const;
163  void invalidate_();
164 
166  void do_start_();
168  void do_next_();
169 
171  template <typename Pref>
172  void center_at_(const Pref& c);
173 
175  psite compute_p_() const;
178 
181  const iter_type& iter() const;
182  iter_type& iter();
184 
185  private:
187  iter_type iter_;
188  };
189 
190 
192  template <typename I, typename G, typename W>
193  std::ostream&
194  operator<<(std::ostream& ostr,
195  const complex_window_bkd_piter<I, G, W>& p);
196 
197 
198 
199 # ifndef MLN_INCLUDE_ONLY
200 
201  /*------------------------------------.
202  | complex_window_fwd_piter<I, G, W>. |
203  `------------------------------------*/
204 
205  template <typename I, typename G, typename W>
206  inline
208  {
209  }
210 
211  template <typename I, typename G, typename W>
212  template <typename Pref>
213  inline
215  const Pref& p_ref)
216  {
217  init_(win, p_ref);
218  }
219 
220  template <typename I, typename G, typename W>
221  template <typename Pref>
222  inline
223  void
224  complex_window_fwd_piter<I, G, W>::init_(const Window<W>& win,
225  const Pref& p_ref)
226  {
227  this->change_target(exact(win));
228  this->center_at(p_ref);
229  mln_postcondition(!this->is_valid());
230  }
231 
232 
233  template <typename I, typename G, typename W>
234  inline
235  bool
237  {
238  return iter_.is_valid();
239  }
240 
241  template <typename I, typename G, typename W>
242  inline
243  void
245  {
246  iter_.invalidate();
247  }
248 
249  template <typename I, typename G, typename W>
250  inline
251  void
253  {
254  iter_.start();
255  }
256 
257  template <typename I, typename G, typename W>
258  inline
259  void
261  {
262  iter_.next();
263  }
264 
265  template <typename I, typename G, typename W>
266  template <typename Pref>
267  inline
268  void
270  {
271  iter_.center_at(this->center().face());
272  }
273 
274  template <typename I, typename G, typename W>
275  inline
276  mln_psite(W)
277  complex_window_fwd_piter<I, G, W>::compute_p_() const
278  {
279  return psite(this->center().site_set(), iter_);
280  }
281 
282  template <typename I, typename G, typename W>
283  inline
284  const typename W::complex_fwd_iter&
286  {
287  return iter_;
288  }
289 
290  template <typename I, typename G, typename W>
291  inline
292  typename W::complex_fwd_iter&
294  {
295  return iter_;
296  }
297 
298 
299  template <typename I, typename G, typename W>
300  inline
301  std::ostream&
302  operator<<(std::ostream& ostr,
303  const complex_window_fwd_piter<I, G, W>& p)
304  {
305  return ostr << p.unproxy_();
306  }
307 
308 
309  /*------------------------------------.
310  | complex_window_bkd_piter<I, G, W>. |
311  `------------------------------------*/
312 
313  template <typename I, typename G, typename W>
314  inline
315  complex_window_bkd_piter<I, G, W>::complex_window_bkd_piter()
316  {
317  }
318 
319  template <typename I, typename G, typename W>
320  template <typename Pref>
321  inline
322  complex_window_bkd_piter<I, G, W>::complex_window_bkd_piter(const Window<W>& win,
323  const Pref& p_ref)
324  {
325  init_(win, p_ref);
326  }
327 
328  template <typename I, typename G, typename W>
329  template <typename Pref>
330  inline
331  void
332  complex_window_bkd_piter<I, G, W>::init_(const Window<W>& win,
333  const Pref& p_ref)
334  {
335  this->change_target(exact(win));
336  this->center_at(p_ref);
337  mln_postcondition(!this->is_valid());
338  }
339 
340 
341  template <typename I, typename G, typename W>
342  inline
343  bool
345  {
346  return iter_.is_valid();
347  }
348 
349  template <typename I, typename G, typename W>
350  inline
351  void
353  {
354  iter_.invalidate();
355  }
356 
357  template <typename I, typename G, typename W>
358  inline
359  void
361  {
362  iter_.start();
363  }
364 
365  template <typename I, typename G, typename W>
366  inline
367  void
369  {
370  iter_.next();
371  }
372 
373  template <typename I, typename G, typename W>
374  template <typename Pref>
375  inline
376  void
378  {
379  // FIXME: Argument C is not used here... Is this normal?
380  (void) c;
381  iter_.center_at(this->center().face());
382  }
383 
384  template <typename I, typename G, typename W>
385  inline
386  mln_psite(W)
387  complex_window_bkd_piter<I, G, W>::compute_p_() const
388  {
389  return psite(this->center().site_set(), iter_);
390  }
391 
392  template <typename I, typename G, typename W>
393  inline
394  const typename W::complex_bkd_iter&
396  {
397  return iter_;
398  }
399 
400  template <typename I, typename G, typename W>
401  inline
402  typename W::complex_bkd_iter&
404  {
405  return iter_;
406  }
407 
408 
409  template <typename I, typename G, typename W>
410  inline
411  std::ostream&
412  operator<<(std::ostream& ostr,
413  const complex_window_bkd_piter<I, G, W>& p)
414  {
415  return ostr << p.unproxy_();
416  }
417 
418 # endif // ! MLN_INCLUDE_ONLY
419 
420 } // end of namespace mln
421 
422 #endif // ! MLN_CORE_IMAGE_COMPLEX_WINDOW_PITER_HH