$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
core/alias/neighb2d.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_ALIAS_NEIGHB2D_HH
28 # define MLN_CORE_ALIAS_NEIGHB2D_HH
29 
36 
37 # include <cmath>
38 # include <mln/core/alias/window2d.hh>
39 # include <mln/core/neighb.hh>
40 # include <mln/convert/from_to.hh>
41 # include <mln/make/double_neighb2d.hh>
42 # include <mln/fun/p2b/chess.hh>
43 
44 
45 namespace mln
46 {
47 
108 
109  typedef neighb<window2d> neighb2d;
111 
112 }
113 
114 
115 namespace mln
116 {
117 
119 
133  const neighb2d& c4();
134 
135 
137 
151  const neighb2d& c8();
152 
153 
155 
168  const neighb2d& c2_row();
169 
170 
172 
186  const neighb2d& c2_col();
187 
188 
207  neighb< win::multiple<window2d, mln::fun::p2b::chess> > c6_2d();
208 
209 
211  template <unsigned S>
212  void from_to_(const bool (&values)[S], neighb2d& nbh);
213 
215  template <unsigned R, unsigned C>
216  void from_to_(bool const (&values)[R][C], neighb2d& nbh);
217 
218 
219 
220 # ifndef MLN_INCLUDE_ONLY
221 
222  inline
223  const neighb2d& c4()
224  {
225  static neighb2d it;
226  if (it.size() == 0)
227  {
228  static const bool vals[] = { 0, 1, 0,
229  1, 0, 1,
230  0, 1, 0 };
231  convert::from_to(vals, it);
232  }
233  return it;
234  }
235 
236  inline
237  const neighb2d& c8()
238  {
239  static neighb2d it;
240  if (it.size() == 0)
241  {
242  static const bool vals[] = { 1, 1, 1,
243  1, 0, 1,
244  1, 1, 1 };
245  convert::from_to(vals, it);
246  }
247  return it;
248  }
249 
250  inline
251  const neighb2d& c2_row()
252  {
253  static neighb2d it;
254  if (it.size() == 0)
255  {
256  static const bool vals[] = { 0, 0, 0,
257  1, 0, 1,
258  0, 0, 0 };
259  convert::from_to(vals, it);
260  }
261  return it;
262  }
263 
264  inline
265  const neighb2d& c2_col()
266  {
267  static neighb2d it;
268  if (it.size() == 0)
269  {
270  static const bool vals[] = { 0, 1, 0,
271  0, 0, 0,
272  0, 1, 0 };
273  convert::from_to(vals, it);
274  }
275  return it;
276  }
277 
278 
279  inline
280  neighb< win::multiple<window2d, mln::fun::p2b::chess> >
281  c6_2d()
282  {
283  bool vert[] = { 1, 1, 0,
284  1, 0, 1,
285  0, 1, 1 };
286 
287  bool hori[] = { 0, 1, 1,
288  1, 0, 1,
289  1, 1, 0 };
290 
291  return make::double_neighb2d(fun::p2b::chess(),
292  vert,
293  hori);
294  }
295 
296 
297  template <unsigned S>
298  void
299  from_to_(const bool (&values)[S], neighb2d& nbh)
300  {
301  enum { h = mlc_sqrt_int(S) / 2 };
302  mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check();
303  window2d& win = nbh.hook_win_();
304  convert::from_to(values, win);
305  mln_postcondition(win.is_neighbable_());
306  }
307 
308  template <unsigned R, unsigned C>
309  void
310  from_to_(bool const (&values)[R][C], neighb2d& nbh)
311  {
312  mlc_bool(R % 2 == 1)::check();
313  mlc_bool(C % 2 == 1)::check();
314  window2d& win = nbh.hook_win_();
315  convert::from_to(values, win);
316  mln_postcondition(win.is_neighbable_());
317  }
318 
319 
320 # endif // ! MLN_INCLUDE_ONLY
321 
322 } // end of namespace mln
323 
324 
325 
326 #endif // ! MLN_CORE_ALIAS_NEIGHB2D_HH