Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
neighb3d.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_NEIGHB3D_HH
27 # define MLN_CORE_ALIAS_NEIGHB3D_HH
28 
33 
34 
35 # include <cmath>
36 # include <mln/core/neighb.hh>
37 # include <mln/core/alias/window3d.hh>
38 # include <mln/win/sym.hh>
39 # include <mln/convert/from_to.hh>
40 
41 
42 namespace mln
43 {
44 
49  //
51 
52 
54 
76  const neighb3d& c2_3d_sli();
77 
78 
80 
102  const neighb3d& c4_3d();
103 
105 
127  const neighb3d& c8_3d();
128 
129 
131 
153  const neighb3d& c6();
154 
156 
178  const neighb3d& c18();
179 
181 
203  const neighb3d& c26();
204 
205 
206 
207 
208  namespace convert
209  {
210 
211  namespace over_load
212  {
213 
214  template <unsigned S>
215  void from_to_(const bool (&values)[S], neighb3d& nbh);
216 
217  } // end of namespace mln::convert::over_load
218 
219  } // end of namespace mln::convert
220 
221 
222 
223 # ifndef MLN_INCLUDE_ONLY
224 
225  inline
227  {
228  static neighb3d it;
229  if (it.size() == 0)
230  {
231  window3d& win = it.hook_win_();
232  win
233  .insert(-1, 0, 0)
234  .insert(1, 0, 0);
235  }
236  return it;
237  }
238 
239 
240  inline
241  const neighb3d& c4_3d()
242  {
243  static neighb3d it;
244  if (it.size() == 0)
245  {
246  window3d& win = it.hook_win_();
247  win
248  .insert(0, 1, 0)
249  .insert(0, 0, 1);
250  win
251  .insert(win::sym(win));
252  }
253  return it;
254  }
255 
256  inline
257  const neighb3d& c8_3d()
258  {
259  static neighb3d it;
260  if (it.size() == 0)
261  {
262  static const bool vals[] = { 1, 1, 1,
263  1, 0, 1,
264  1, 1, 1 };
265  convert::from_to(vals, it);
266  }
267  return it;
268  }
269 
270  inline
271  const neighb3d& c6()
272  {
273  static neighb3d it;
274  if (it.size() == 0)
275  {
276  window3d& win = it.hook_win_();
277  win
278  .insert(1, 0, 0)
279  .insert(0, 1, 0)
280  .insert(0, 0, 1);
281  win
282  .insert(win::sym(win));
283  }
284  return it;
285  }
286 
287  inline
288  const neighb3d& c18()
289  {
290  static neighb3d it;
291  if (it.size() == 0)
292  {
293  window3d& win = it.hook_win_();
294  win
295  .insert(1, 0, 1)
296  .insert(1, 0, -1)
297  .insert(0, 1, 1)
298  .insert(0, 1, -1)
299  .insert(1, 1, 0)
300  .insert(1, -1, 0);
301  win
302  .insert(win::sym(win))
303  .insert(c6().win());
304  }
305  return it;
306  }
307 
308  inline
309  const neighb3d& c26()
310  {
311  static neighb3d it;
312  if (it.size() == 0)
313  {
314  window3d& win = it.hook_win_();
315  win
316  .insert(1, 1, 1)
317  .insert(1, 1, -1)
318  .insert(1, -1, 1)
319  .insert(1, -1, -1);
320  win
321  .insert(win::sym(win))
322  .insert(c18().win());
323  }
324  return it;
325  }
326 
327 
328  namespace convert
329  {
330 
331  namespace over_load
332  {
333 
334  template <unsigned S>
335  void
336  from_to_(const bool (&values)[S], neighb3d& nbh)
337  {
338 # ifndef NDEBUG
339  const int h = unsigned(std::pow(float(S), float(1. / 3.))) / 2;
340  mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == S);
341 # endif // ! NDEBUG
342  window3d win;
343  from_to_(values, win);
344  mln_precondition(win.is_neighbable_());
345  nbh.change_window(win);
346  }
347 
348  } // end of namespace mln::convert::over_load
349 
350  } // end of namespace mln::convert
351 
352 # endif // ! MLN_INCLUDE_ONLY
353 
354 } // end of namespace mln
355 
356 
357 #endif // ! MLN_CORE_ALIAS_NEIGHB3D_HH