$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
neighb3d.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_NEIGHB3D_HH
28 # define MLN_CORE_ALIAS_NEIGHB3D_HH
29 
34 
35 
36 # include <cmath>
37 # include <mln/core/neighb.hh>
38 # include <mln/core/alias/window3d.hh>
39 # include <mln/win/sym.hh>
40 # include <mln/convert/from_to.hh>
41 
42 
43 namespace mln
44 {
45 
115 
116  typedef neighb<window3d> neighb3d;
118 
119 
121 
144  const neighb3d& c2_3d_sli();
145 
146 
148 
171  const neighb3d& c4_3d();
172 
174 
197  const neighb3d& c8_3d();
198 
199 
201 
224  const neighb3d& c6();
225 
227 
250  const neighb3d& c18();
251 
253 
276  const neighb3d& c26();
277 
278 
280  template <unsigned S>
281  void from_to_(const bool (&values)[S], neighb3d& nbh);
282 
283 
284 # ifndef MLN_INCLUDE_ONLY
285 
286  inline
287  const neighb3d& c2_3d_sli()
288  {
289  static neighb3d it;
290  if (it.size() == 0)
291  {
292  window3d& win = it.hook_win_();
293  win
294  .insert(-1, 0, 0)
295  .insert(1, 0, 0);
296  }
297  return it;
298  }
299 
300 
301  inline
302  const neighb3d& c4_3d()
303  {
304  static neighb3d it;
305  if (it.size() == 0)
306  {
307  window3d& win = it.hook_win_();
308  win
309  .insert(0, 1, 0)
310  .insert(0, 0, 1);
311  win
312  .insert(win::sym(win));
313  }
314  return it;
315  }
316 
317  inline
318  const neighb3d& c8_3d()
319  {
320  static neighb3d it;
321  if (it.size() == 0)
322  {
323  window3d& win = it.hook_win_();
324  win
325  .insert(0, 0, 0)
326  .insert(0, 0, 1)
327  .insert(0, 0, 2)
328  .insert(0, 1, 2)
329  .insert(0, 2, 2)
330  .insert(0, 2, 1)
331  .insert(0, 2, 0)
332  .insert(0, 1, 0);
333  }
334  return it;
335  }
336 
337  inline
338  const neighb3d& c6()
339  {
340  static neighb3d it;
341  if (it.size() == 0)
342  {
343  window3d& win = it.hook_win_();
344  win
345  .insert(1, 0, 0)
346  .insert(0, 1, 0)
347  .insert(0, 0, 1);
348  win
349  .insert(win::sym(win));
350  }
351  return it;
352  }
353 
354  inline
355  const neighb3d& c18()
356  {
357  static neighb3d it;
358  if (it.size() == 0)
359  {
360  window3d& win = it.hook_win_();
361  win
362  .insert(1, 0, 1)
363  .insert(1, 0, -1)
364  .insert(0, 1, 1)
365  .insert(0, 1, -1)
366  .insert(1, 1, 0)
367  .insert(1, -1, 0);
368  win
369  .insert(win::sym(win))
370  .insert(c6().win());
371  }
372  return it;
373  }
374 
375  inline
376  const neighb3d& c26()
377  {
378  static neighb3d it;
379  if (it.size() == 0)
380  {
381  window3d& win = it.hook_win_();
382  win
383  .insert(1, 1, 1)
384  .insert(1, 1, -1)
385  .insert(1, -1, 1)
386  .insert(1, -1, -1);
387  win
388  .insert(win::sym(win))
389  .insert(c18().win());
390  }
391  return it;
392  }
393 
394 
395  template <unsigned S>
396  void
397  from_to_(const bool (&values)[S], neighb3d& nbh)
398  {
399 # ifndef NDEBUG
400  const int h = unsigned(std::pow(float(S), float(1. / 3.))) / 2;
401  mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == S);
402 # endif // ! NDEBUG
403  window3d win;
404  from_to_(values, win);
405  mln_precondition(win.is_neighbable_());
406  nbh.change_window(win);
407  }
408 
409 # endif // ! MLN_INCLUDE_ONLY
410 
411 } // end of namespace mln
412 
413 
414 #endif // ! MLN_CORE_ALIAS_NEIGHB3D_HH