• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

neighb3d.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_CORE_ALIAS_NEIGHB3D_HH
00027 # define MLN_CORE_ALIAS_NEIGHB3D_HH
00028 
00033 
00034 
00035 # include <cmath>
00036 # include <mln/core/neighb.hh>
00037 # include <mln/core/alias/window3d.hh>
00038 # include <mln/win/sym.hh>
00039 # include <mln/convert/from_to.hh>
00040 
00041 
00042 namespace mln
00043 {
00044 
00049   //
00050   typedef neighb<window3d> neighb3d;
00051 
00053 
00075   const neighb3d& c4_3d();
00076 
00078 
00100   const neighb3d& c8_3d();
00101 
00102 
00104 
00126   const neighb3d& c6();
00127 
00129 
00151   const neighb3d& c18();
00152 
00154 
00176   const neighb3d& c26();
00177 
00178 
00179 
00180 
00181   namespace convert
00182   {
00183 
00184     namespace over_load
00185     {
00186 
00187       template <unsigned S>
00188       void from_to_(const bool (&values)[S], neighb3d& nbh);
00189 
00190     } // end of namespace mln::convert::over_load
00191 
00192   } // end of namespace mln::convert
00193 
00194 
00195 
00196 # ifndef MLN_INCLUDE_ONLY
00197 
00198   inline
00199   const neighb3d& c4_3d()
00200   {
00201     static neighb3d it;
00202     if (it.size() == 0)
00203       {
00204         window3d& win = it.hook_win_();
00205         win
00206           .insert(0, 1, 0)
00207           .insert(0, 0, 1);
00208         win
00209           .insert(win::sym(win));
00210       }
00211     return it;
00212   }
00213 
00214   inline
00215   const neighb3d& c8_3d()
00216   {
00217     static neighb3d it;
00218     if (it.size() == 0)
00219       {
00220         static const bool vals[] = { 1, 1, 1,
00221                                      1, 0, 1,
00222                                      1, 1, 1 };
00223         convert::from_to(vals, it);
00224       }
00225     return it;
00226   }
00227 
00228   inline
00229   const neighb3d& c6()
00230   {
00231     static neighb3d it;
00232     if (it.size() == 0)
00233       {
00234         window3d& win = it.hook_win_();
00235         win
00236           .insert(1, 0, 0)
00237           .insert(0, 1, 0)
00238           .insert(0, 0, 1);
00239         win
00240           .insert(win::sym(win));
00241       }
00242     return it;
00243   }
00244 
00245   inline
00246   const neighb3d& c18()
00247   {
00248     static neighb3d it;
00249     if (it.size() == 0)
00250       {
00251         window3d& win = it.hook_win_();
00252         win
00253           .insert(1,  0,  1)
00254           .insert(1,  0, -1)
00255           .insert(0,  1,  1)
00256           .insert(0,  1, -1)
00257           .insert(1,  1,  0)
00258           .insert(1, -1,  0);
00259         win
00260           .insert(win::sym(win))
00261           .insert(c6().win());
00262       }
00263     return it;
00264   }
00265 
00266   inline
00267   const neighb3d& c26()
00268   {
00269     static neighb3d it;
00270     if (it.size() == 0)
00271       {
00272         window3d& win = it.hook_win_();
00273         win
00274           .insert(1,  1,  1)
00275           .insert(1,  1, -1)
00276           .insert(1, -1,  1)
00277           .insert(1, -1, -1);
00278         win
00279           .insert(win::sym(win))
00280           .insert(c18().win());
00281       }
00282     return it;
00283   }
00284 
00285 
00286   namespace convert
00287   {
00288 
00289     namespace over_load
00290     {
00291 
00292       template <unsigned S>
00293       void
00294       from_to_(const bool (&values)[S], neighb3d& nbh)
00295       {
00296         const int h = unsigned(std::pow(float(S), float(1. / 3.))) / 2;
00297         mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == S);
00298         window3d win;
00299         from_to_(values, win);
00300         mln_precondition(win.is_neighbable_());
00301         nbh.change_window(win);
00302       }
00303 
00304     } // end of namespace mln::convert::over_load
00305 
00306   } // end of namespace mln::convert
00307 
00308 # endif // ! MLN_INCLUDE_ONLY
00309 
00310 } // end of namespace mln
00311 
00312 
00313 #endif // ! MLN_CORE_ALIAS_NEIGHB3D_HH

Generated on Thu Sep 8 2011 18:32:09 for Milena (Olena) by  doxygen 1.7.1