Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
core/alias/neighb2d.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_ALIAS_NEIGHB2D_HH
27 # define MLN_CORE_ALIAS_NEIGHB2D_HH
28 
35 
36 # include <cmath>
37 # include <mln/core/alias/window2d.hh>
38 # include <mln/core/neighb.hh>
39 # include <mln/convert/from_to.hh>
40 # include <mln/make/double_neighb2d.hh>
41 # include <mln/fun/p2b/chess.hh>
42 
43 
44 namespace mln
45 {
46 
52 
53 }
54 
55 
56 namespace mln
57 {
58 
60 
72  const neighb2d& c4();
73 
74 
76 
88  const neighb2d& c8();
89 
90 
92 
103  const neighb2d& c2_row();
104 
105 
107 
119  const neighb2d& c2_col();
120 
121 
122  // FIXME: Documentation
123  neighb< win::multiple<window2d, mln::fun::p2b::chess> > c6_2d();
124 
125 
126 
127  namespace convert
128  {
129 
130  namespace over_load
131  {
132 
133  template <unsigned S>
134  void from_to_(const bool (&values)[S], neighb2d& nbh);
135 
136  template <unsigned R, unsigned C>
137  void from_to_(bool const (&values)[R][C], neighb2d& nbh);
138 
139  } // end of namespace mln::convert::over_load
140 
141  } // end of namespace mln::convert
142 
143 
144 
145 # ifndef MLN_INCLUDE_ONLY
146 
147  inline
148  const neighb2d& c4()
149  {
150  static neighb2d it;
151  if (it.size() == 0)
152  {
153  static const bool vals[] = { 0, 1, 0,
154  1, 0, 1,
155  0, 1, 0 };
156  convert::from_to(vals, it);
157  }
158  return it;
159  }
160 
161  inline
162  const neighb2d& c8()
163  {
164  static neighb2d it;
165  if (it.size() == 0)
166  {
167  static const bool vals[] = { 1, 1, 1,
168  1, 0, 1,
169  1, 1, 1 };
170  convert::from_to(vals, it);
171  }
172  return it;
173  }
174 
175  inline
176  const neighb2d& c2_row()
177  {
178  static neighb2d it;
179  if (it.size() == 0)
180  {
181  static const bool vals[] = { 0, 0, 0,
182  1, 0, 1,
183  0, 0, 0 };
184  convert::from_to(vals, it);
185  }
186  return it;
187  }
188 
189  inline
190  const neighb2d& c2_col()
191  {
192  static neighb2d it;
193  if (it.size() == 0)
194  {
195  static const bool vals[] = { 0, 1, 0,
196  0, 0, 0,
197  0, 1, 0 };
198  convert::from_to(vals, it);
199  }
200  return it;
201  }
202 
203 
204  inline
205  neighb< win::multiple<window2d, mln::fun::p2b::chess> >
206  c6_2d()
207  {
208  bool vert[] = { 1, 1, 0,
209  1, 0, 1,
210  0, 1, 1 };
211 
212  bool hori[] = { 0, 1, 1,
213  1, 0, 1,
214  1, 1, 0 };
215 
216  return make::double_neighb2d(fun::p2b::chess(),
217  vert,
218  hori);
219  }
220 
221 
222  namespace convert
223  {
224 
225  namespace over_load
226  {
227 
228  template <unsigned S>
229  void
230  from_to_(const bool (&values)[S], neighb2d& nbh)
231  {
232  enum { h = mlc_sqrt_int(S) / 2 };
233  mlc_bool((2 * h + 1) * (2 * h + 1) == S)::check();
234  window2d& win = nbh.hook_win_();
235  convert::from_to(values, win);
236  mln_postcondition(win.is_neighbable_());
237  }
238 
239  template <unsigned R, unsigned C>
240  void
241  from_to_(bool const (&values)[R][C], neighb2d& nbh)
242  {
243  mlc_bool(R % 2 == 1)::check();
244  mlc_bool(C % 2 == 1)::check();
245  window2d& win = nbh.hook_win_();
246  convert::from_to(values, win);
247  mln_postcondition(win.is_neighbable_());
248  }
249 
250  } // end of namespace mln::convert::over_load
251 
252  } // end of namespace mln::convert
253 
254 # endif // ! MLN_INCLUDE_ONLY
255 
256 } // end of namespace mln
257 
258 
259 
260 #endif // ! MLN_CORE_ALIAS_NEIGHB2D_HH