$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graph_window_piter.hh
1 // Copyright (C) 2007, 2008, 2009, 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_GRAPH_WINDOW_PITER_HH
28 # define MLN_CORE_IMAGE_GRAPH_WINDOW_PITER_HH
29 
36 
37 # include <mln/core/concept/site_set.hh>
38 # include <mln/core/concept/window.hh>
39 # include <mln/core/internal/site_relative_iterator_base.hh>
40 
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  template <typename S, typename I> class p_graph_piter;
47 
48 
49  namespace internal
50  {
51 
57  template <typename C, typename P, typename E>
59  {
60  void do_start_()
61  {
62  internal::force_exact<E>(*this).iter_.start();
63  // Nothing else to do. A pointer to the window element's site
64  // set has been already stored in the constructor.
65  }
66 
67  };
68 
74  template <typename C, typename E>
75  struct impl_selector<C,C,E>
76  {
77  void do_start_()
78  {
79  E& this_ = internal::force_exact<E>(*this);
80  this_.iter_.start();
81 
82  // We need to store a pointer on the site set of the window
83  // center.
84  // We cannot do this in the constructor since the center may
85  // not be initialized.
86  // Here we suppose that if we start this iterator, the
87  // potential iterator used as center has been started just
88  // before calling this method.
89  //
90  this_.change_target_site_set(this_.center().site_set());
91  }
92 
93  };
94 
95  } // end of namespace mln::internal
96 
97 
106  template <typename S, typename W, typename I>
109  graph_window_piter<S,W,I>,
110  typename W::center_t >,
111  public internal::impl_selector<typename W::center_t, mln_psite(W),
112  graph_window_piter<S,W,I> >
113  {
115  typedef
117  typedef
118  internal::impl_selector<typename W::center_t, mln_psite(W),
120 
121 
122  public:
126  typedef mln_result(S::fun_t) P;
128  typedef typename W::center_t center_t;
130  typedef typename W::graph_element graph_element;
132 
136 
137 
138  // ---------------------------------------------------------
139  // FIXME: probably ugly to provide constructors usable for
140  // specific cases only...
141  // ---------------------------------------------------------
142 
148  //
149  template <typename Pref>
150  graph_window_piter(const Window<W>& win,
151  const Pref& p_ref);
152 
160  //
161  template <typename Pref>
162  graph_window_piter(const Window<W>& win,
163  const Site_Set<S>& target_site_set,
164  const Pref& p_ref);
166 
170  template <typename Pref>
171  void init_(const Window<W>& win, const Pref& p_ref);
172 
173  template <typename Pref>
174  void init_(const Window<W>& win,
175  const Site_Set<S>& target_site_set,
176  const Pref& p_ref);
178 
182  bool is_valid_() const;
184  void invalidate_();
185 
187  void do_next_();
188 
190  template <typename Pref>
191  void center_at_(const Pref& c);
192 
194  template <typename S2, typename I2>
195  void center_at_(const p_graph_piter<S2, I2>& c);
196 
198  mln_psite(W) compute_p_() const;
200 
202  const graph_element& element() const;
203 
208  unsigned id() const;
210 
214  void change_target_site_set(const S& s);
218  const S& target_site_set() const;
219 
220  using super_impl_::do_start_;
221 
222  friend struct internal::impl_selector<typename W::center_t, mln_psite(W),
224 
225  private:
226  I iter_;
227  const S* s_;
228  };
229 
230 
231 # ifndef MLN_INCLUDE_ONLY
232 
233 
234  template <typename S, typename W, typename I>
235  inline
237  : s_(0)
238  {
239  }
240 
241 
242  template <typename S, typename W, typename I>
243  template <typename Pref>
244  inline
246  const Pref& p_ref)
247  : s_(0)
248  {
249  // Center and neighbor sites have the same type and belong to
250  // the same site set.
251  mlc_is(center_t, mln_psite(W))::check();
252  init_(win, p_ref);
253  }
254 
255 
256  template <typename S, typename W, typename I>
257  template <typename Pref>
258  inline
260  const Site_Set<S>& target_site_set,
261  const Pref& p_ref)
262  : s_(0)
263  {
264  // Center and neighbors sites do not have the same type and do
265  // not belong to the same site set.
266  mlc_is_not(center_t, mln_psite(W))::check();
267  init_(win, target_site_set, p_ref);
268  }
269 
270  template <typename S, typename W, typename I>
271  template <typename Pref>
272  inline
273  void
274  graph_window_piter<S,W,I>::init_(const Window<W>& win,
275  const Pref& p_ref)
276  {
277  this->center_at(p_ref);
278  this->change_target(exact(win));
279 
280  mln_postcondition(!this->is_valid());
281  }
282 
283  template <typename S, typename W, typename I>
284  template <typename Pref>
285  inline
286  void
287  graph_window_piter<S,W,I>::init_(const Window<W>& win,
288  const Site_Set<S>& target_site_set,
289  const Pref& p_ref)
290  {
291  this->center_at(p_ref);
292  this->change_target(exact(win));
293  change_target_site_set(exact(target_site_set));
294  mln_postcondition(!this->is_valid());
295  }
296 
297 
298  template <typename S, typename W, typename I>
299  inline
300  bool
302  {
303  return s_ != 0 && s_->is_valid() && iter_.is_valid();
304  }
305 
306  template <typename S, typename W, typename I>
307  inline
308  void
310  {
311  iter_.invalidate();
312  }
313 
314  template <typename S, typename W, typename I>
315  inline
316  void
318  {
319  iter_.next();
320  }
321 
322  template <typename S, typename W, typename I>
323  template <typename Pref>
324  inline
325  void
327  {
328  iter_.center_at(c.p_hook_());
329  }
330 
331  template <typename S, typename W, typename I>
332  template <typename S2, typename I2>
333  inline
334  void
335  graph_window_piter<S, W, I>::center_at_(const p_graph_piter<S2, I2>& c)
336  {
337  iter_.center_at(c.hook_elt_());
338  }
339 
340  template <typename S, typename W, typename I>
341  inline
342  mln_psite(W)
343  graph_window_piter<S,W,I>::compute_p_() const
344  {
345  return mln_psite(S)(target_site_set(), iter_.id());
346  }
347 
348  template <typename S, typename W, typename I>
349  inline
350  const typename graph_window_piter<S,W,I>::graph_element&
352  {
353  return iter_;
354  }
355 
356  template <typename S, typename W, typename I>
357  inline
358  unsigned
360  {
361  return iter_.id();
362  }
363 
364  template <typename S, typename W, typename I>
365  inline
366  void
368  {
369  s_ = & s;
370  mln_assertion(s_ != 0);
371  }
372 
373  template <typename S, typename W, typename I>
374  inline
375  const S&
377  {
378  mln_precondition(s_ != 0);
379  mln_precondition(s_->is_valid());
380  return *s_;
381  }
382 
383 
384 # endif // ! MLN_INCLUDE_ONLY
385 
386 } // end of namespace mln
387 
388 #endif // ! MLN_CORE_IMAGE_GRAPH_WINDOW_PITER_HH