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

window2d.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_WINDOW2D_HH
00027 # define MLN_CORE_ALIAS_WINDOW2D_HH
00028 
00033 
00034 # include <mln/core/window.hh>
00035 # include <mln/core/alias/dpoint2d.hh>
00036 # include <mln/metal/math/sqrt.hh>
00037 # include <mln/convert/from_to.hxx>
00038 
00039 
00040 namespace mln
00041 {
00042 
00047   //
00048   typedef window<mln::dpoint2d> window2d;
00049 
00052 
00064   const window2d& win_c4p();
00065 
00068 
00080   const window2d& win_c8p();
00081 
00082 
00083   namespace convert
00084   {
00085 
00086     namespace over_load
00087     {
00088 
00089       template <unsigned S>
00090       void from_to_(const bool (&values)[S], window2d& win);
00091 
00092       template <unsigned R, unsigned C>
00093       void from_to_(const bool (&values)[R][C], window2d& win);
00094 
00095     } // end of namespace mln::convert::over_load
00096 
00097   } // end of namespace mln::convert
00098 
00099 
00100 
00101 # ifndef MLN_INCLUDE_ONLY
00102 
00103   inline const window2d&
00104   win_c4p()
00105   {
00106     static window2d it;
00107     if (it.size() == 0)
00108       {
00109         it
00110           .insert( 0, -1)
00111           .insert(-1,  0)
00112           .insert( 0,  0)
00113           .insert(+1,  0)
00114           .insert( 0, +1);
00115       }
00116     return it;
00117   }
00118 
00119   inline const window2d&
00120   win_c8p()
00121   {
00122     static window2d it;
00123     if (it.size() == 0)
00124       {
00125         it
00126           .insert(-1, -1)
00127           .insert( 0, -1)
00128           .insert(+1, -1)
00129           .insert(-1,  0)
00130           .insert( 0,  0)
00131           .insert(+1,  0)
00132           .insert(-1, +1)
00133           .insert( 0, +1)
00134           .insert(+1, +1);
00135       }
00136     return it;
00137   }
00138 
00139 
00140   namespace convert
00141   {
00142 
00143     namespace over_load
00144     {
00145 
00146       template <unsigned S>
00147       void
00148       from_to_(const bool (&values)[S], window2d& win)
00149       {
00150         enum { H = mlc_sqrt_int(S) / 2 };
00151         mlc_bool((2 * H + 1) * (2 * H + 1) == S)::check();
00152         win.clear();
00153         unsigned i = 0;
00154         const def::coord
00155           h  = static_cast<def::coord>(H),
00156           _h = static_cast<def::coord>(-h);
00157         for (def::coord row = _h; row <= h; ++row)
00158           for (def::coord col = _h; col <= h; ++col)
00159             if (values[i++])
00160               win.insert(row, col);
00161       }
00162 
00163       template <unsigned R, unsigned C>
00164       void
00165       from_to_(const bool (&values)[R][C], window2d& win)
00166       {
00167         mlc_bool(R % 2 == 1)::check();
00168         mlc_bool(C % 2 == 1)::check();
00169         win.clear();
00170         const def::coord
00171           drow  = static_cast<def::coord>(R / 2),
00172           _drow = static_cast<def::coord>(- drow),
00173           dcol  = static_cast<def::coord>(C / 2),
00174           _dcol = static_cast<def::coord>(- dcol);
00175         for (def::coord row = _drow; row <= drow; ++row)
00176           for (def::coord col = _dcol; col <= dcol; ++col)
00177             if (values[row + drow][col + dcol])
00178               win.insert(row, col);
00179       }
00180 
00181     } // end of namespace mln::convert::over_load
00182 
00183   } // end of namespace mln::convert
00184 
00185 # endif // ! MLN_INCLUDE_ONLY
00186 
00187 } // end of namespace mln
00188 
00189 
00190 #endif // ! MLN_CORE_ALIAS_WINDOW2D_HH

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