00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_CORE_ALIAS_WINDOW3D_HH
00027 # define MLN_CORE_ALIAS_WINDOW3D_HH
00028 
00033 
00034 # include <cmath>
00035 # include <mln/core/window.hh>
00036 # include <mln/core/alias/dpoint3d.hh>
00037 # include <mln/convert/from_to.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00047   
00048   typedef window<mln::dpoint3d> window3d;
00049 
00052 
00073   const window3d& win_c4p_3d();
00074 
00077 
00097   const window3d& win_c8p_3d();
00098 
00099 
00100 
00101   namespace convert
00102   {
00103 
00104     namespace over_load
00105     {
00106 
00107       template <unsigned M>
00108       void from_to_(bool const (&values)[M], window3d& win);
00109 
00110     } 
00111 
00112   } 
00113 
00114 
00115 
00116 # ifndef MLN_INCLUDE_ONLY
00117 
00118   inline const window3d&
00119   win_c4p_3d()
00120   {
00121     static window3d it;
00122     if (it.size() == 0)
00123       {
00124         it
00125           .insert(0,  0, -1)
00126           .insert(0, -1,  0)
00127           .insert(0,  0,  0)
00128           .insert(0, +1,  0)
00129           .insert(0,  0, +1);
00130       }
00131     return it;
00132   }
00133 
00134   inline const window3d&
00135   win_c8p_3d()
00136   {
00137     static window3d it;
00138     if (it.size() == 0)
00139       {
00140         it
00141           .insert(0, -1, -1)
00142           .insert(0,  0, -1)
00143           .insert(0, +1, -1)
00144           .insert(0, -1,  0)
00145           .insert(0,  0,  0)
00146           .insert(0, +1,  0)
00147           .insert(0, -1, +1)
00148           .insert(0,  0, +1)
00149           .insert(0, +1, +1);
00150       }
00151     return it;
00152   }
00153 
00154   namespace convert
00155   {
00156 
00157     namespace over_load
00158     {
00159 
00160       template <unsigned M>
00161       void
00162       from_to_(bool const (&values)[M], window3d& win)
00163       {
00164         const int h = unsigned(std::pow(float(M), float(1. / 3.))) / 2;
00165         mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
00166         win.clear();
00167         unsigned i = 0;
00168         for (int sli = - h; sli <= h; ++sli)
00169           for (int row = - h; row <= h; ++row)
00170             for (int col = - h; col <= h; ++col)
00171               if (values[i++])
00172                 win.insert(sli, row, col);
00173       }
00174 
00175     } 
00176 
00177   } 
00178 
00179 # endif // ! MLN_INCLUDE_ONLY
00180 
00181 
00182 } 
00183 
00184 
00185 #endif // ! MLN_CORE_ALIAS_WINDOW3D_HH