$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
graph_window_if_piter.hh
1 // Copyright (C) 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_GRAPH_WINDOW_IF_PITER_HH
28 # define MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH
29 
33 
34 # include <mln/core/concept/window.hh>
35 # include <mln/core/internal/is_masked_impl_selector.hh>
36 # include <mln/core/internal/site_relative_iterator_base.hh>
37 
38 
39 namespace mln
40 {
41 
42  // Forward declaration.
43  template <typename S, typename I> class p_graph_piter;
44 
45 
46 
50  template <typename S, typename W, typename I>
53  graph_window_if_piter<S,W,I> >,
55  typename W::mask_t::domain_t,
56  graph_window_if_piter<S,W,I> >
57  {
60 
61  public:
64  typedef mln_result(S::fun_t) P;
66 
70  template <typename Pref>
71  graph_window_if_piter(const Window<W>& win,
72  const Pref& p_ref);
74 
77  template <typename Pref>
78  void init_(const Window<W>& win, const Pref& p_ref);
79 
83  bool is_valid_() const;
85  void invalidate_();
86 
88  void do_start_();
90  void do_next_();
91 
93  template <typename Pref>
94  void center_at_(const Pref& c);
95 
97  template <typename I2>
98  void center_at_(const p_graph_piter<S, I2>& c);
99 
101  mln_psite(W) compute_p_() const;
103 
105  const mln_graph_element(S)& element() const;
106 
111  unsigned id() const;
113 
114  private:
115  I iter_;
116 
117  protected:
119  using super_::s_;
120  };
121 
122 
123 
124 # ifndef MLN_INCLUDE_ONLY
125 
126  template <typename S, typename W, typename I>
127  inline
129  {
130  }
131 
132  template <typename S, typename W, typename I>
133  template <typename Pref>
134  inline
136  const Pref& p_ref)
137  {
138  init_(win, p_ref);
139  }
140 
141  template <typename S, typename W, typename I>
142  template <typename Pref>
143  inline
144  void
145  graph_window_if_piter<S,W,I>::init_(const Window<W>& win,
146  const Pref& p_ref)
147  {
148  this->center_at(p_ref);
149  this->change_target(exact(win));
150 
151  mln_postcondition(!this->is_valid());
152  }
153 
154  template <typename S, typename W, typename I>
155  inline
156  bool
158  {
159  return iter_.is_valid();
160  }
161 
162  template <typename S, typename W, typename I>
163  inline
164  void
166  {
167  iter_.invalidate();
168  }
169 
170  template <typename S, typename W, typename I>
171  inline
172  void
174  {
175  iter_.start();
176  while (iter_.is_valid() && this->is_masked(this->c_->element(), iter_))
177  iter_.next();
178  }
179 
180  template <typename S, typename W, typename I>
181  inline
182  void
184  {
185  iter_.next();
186  while (iter_.is_valid() && this->is_masked(this->c_->element(), iter_))
187  iter_.next();
188  }
189 
190  template <typename S, typename W, typename I>
191  template <typename Pref>
192  inline
193  void
195  {
196  iter_.center_at(c.p_hook_());
197  }
198 
199  template <typename S, typename W, typename I>
200  template <typename I2>
201  inline
202  void
203  graph_window_if_piter<S,W,I>::center_at_(const p_graph_piter<S, I2>& c)
204  {
205  iter_.center_at(c.hook_elt_());
206  }
207 
208  template <typename S, typename W, typename I>
209  inline
210  mln_psite(W)
211  graph_window_if_piter<S,W,I>::compute_p_() const
212  {
213  return mln_psite(S)(this->center().site_set(), iter_.id());
214  }
215 
216  template <typename S, typename W, typename I>
217  inline
218  const mln_graph_element(S)&
220  {
221  return iter_;
222  }
223 
224  template <typename S, typename W, typename I>
225  inline
226  unsigned
228  {
229  return iter_.id();
230  }
231 
232 
233 # endif // ! MLN_INCLUDE_ONLY
234 
235 } // end of namespace mln
236 
237 #endif // ! MLN_CORE_IMAGE_GRAPH_WINDOW_IF_PITER_HH