$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p_centered.hh
1 // Copyright (C) 2007, 2008, 2009, 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_SITE_SET_P_CENTERED_HH
28 # define MLN_CORE_SITE_SET_P_CENTERED_HH
29 
37 
38 # include <mln/core/concept/window.hh>
39 # include <mln/core/internal/site_set_base.hh>
40 # include <mln/core/internal/site_set_iterator_base.hh>
41 
42 
43 namespace mln
44 {
45 
46  // Fwd decls.
47  template <typename W> class p_centered;
48  template <typename W> class p_centered_piter;
49 
50 
51  namespace trait
52  {
53 
54  template <typename W>
55  struct site_set_< p_centered<W> >
56  {
57  typedef trait::site_set::nsites::unknown nsites;
58  typedef trait::site_set::bbox::unknown bbox;
59  typedef trait::site_set::contents::fixed contents;
60  typedef trait::site_set::arity::unique arity;
61  };
62 
63 // template <typename W>
64 // struct set_precise_unary_< op::ord, p_centered<W> >
65 // {
66 // typedef set_precise_unary_< op::ord, p_centered<W> > ret; // Itself.
67 // bool strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const;
68 // };
69 
70  } // end of namespace mln::trait
71 
72 
76  //
77  template <typename W>
78  class p_centered : public internal::site_set_base_< mln_psite(W), p_centered<W> >,
79  private mlc_is_a(W, Window)::check_t
80  {
81  public:
82 
84  typedef mln_psite(W) psite;
85 
87  typedef mln_site(W) site;
88 
89 
91  typedef psite element;
92 
93 
96 
98  typedef p_centered_piter<W> bkd_piter; // FIXME
99 
101  typedef fwd_piter piter;
102 
103 
105  p_centered();
106 
108  p_centered(const W& win, const mln_psite(W)& c);
109 
110 
112  template <typename P>
113  bool has(const P& p) const;
114 
116  bool is_valid() const;
117 
119  std::size_t memory_size() const;
120 
122  const mln_psite(W)& center() const;
123 
125  const W& window() const;
126 
127  protected:
128 
129  W win_;
130  mln_psite(W) c_;
131  };
132 
133 
134  template <typename W>
135  class p_centered_piter : public internal::site_set_iterator_base< p_centered<W>,
136  p_centered_piter<W> >
137  {
138  typedef p_centered_piter<W> self_;
140  public:
141 
144 
147 
150  bool is_valid_() const;
151 
153  void invalidate_();
154 
156  void start_();
157 
159  void next_();
161 
162  protected:
163  using super_::p_;
164  using super_::s_;
165 
166  mln_fwd_qiter(W) q_;
167  };
168 
169 
170 
171 # ifndef MLN_INCLUDE_ONLY
172 
173  // p_centered<W>
174 
175  template <typename W>
176  inline
177  bool
179  {
180  return true; // FIXME
181  }
182 
183  template <typename W>
184  inline
186  {
187  }
188 
189  template <typename W>
190  inline
191  p_centered<W>::p_centered(const W& win, const mln_psite(W)& c)
192  : win_(win),
193  c_(c)
194  {
195  mln_precondition(is_valid());
196  }
197 
198  template <typename W>
199  template <typename P>
200  inline
201  bool
202  p_centered<W>::has(const P&) const
203  {
204  mln_precondition(is_valid());
205  return true; // FIXME
206  }
207 
208  template <typename W>
209  inline
210  std::size_t
212  {
213  return sizeof(*this);
214  }
215 
216  template <typename W>
217  inline
218  const mln_psite(W)&
219  p_centered<W>::center() const
220  {
221  return c_;
222  }
223 
224  template <typename W>
225  inline
226  const W&
227  p_centered<W>::window() const
228  {
229  return win_;
230  }
231 
232 // namespace trait
233 // {
234 
235 // template <typename W>
236 // inline
237 // bool
238 // set_precise_unary_< op::ord, p_centered<W> >::strict(const p_centered<W>& lhs, const p_centered<W>& rhs) const
239 // {
240 // // Lexicographical over "pmin then pmax".
241 // return util::ord_lexi_strict(lhs.pmin(), lhs.pmax(),
242 // rhs.pmin(), rhs.pmax());
243 // }
244 
245 // } // end of namespace mln::trait
246 
247 
248  // p_centered_piter<W>
249 
250  template <typename W>
251  inline
253  {
254  }
255 
256  template <typename W>
257  inline
258  p_centered_piter<W>::p_centered_piter(const p_centered<W>& s)
259  {
260  this->change_target(s);
261  q_.center_at(s.center());
262  q_.change_target(s.window_());
263  }
264 
265  template <typename W>
266  inline
267  bool
269  {
270  return q_.is_valid();
271  }
272 
273  template <typename W>
274  inline
275  void
277  {
278  q_.invalidate();
279  }
280 
281  template <typename W>
282  inline
283  void
285  {
286  q_.start();
287  if (is_valid_())
288  p_ = q_;
289  }
290 
291  template <typename W>
292  inline
293  void
295  {
296  q_.next();
297  if (is_valid_())
298  p_ = q_;
299  }
300 
301 # endif // ! MLN_INCLUDE_ONLY
302 
303 } // end of namespace mln
304 
305 
306 #endif // ! MLN_CORE_SITE_SET_P_CENTERED_HH