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

diagonal2d.hh

00001 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CANVAS_BROWSING_DIAGONAL2D_HH
00028 # define MLN_CANVAS_BROWSING_DIAGONAL2D_HH
00029 
00033 
00034 # include <mln/core/concept/browsing.hh>
00035 # include <mln/core/concept/image.hh>
00036 
00037 namespace mln
00038 {
00039 
00040   namespace canvas
00041   {
00042 
00043     namespace browsing
00044     {
00045 
00047 
00082       struct diagonal2d_t : public Browsing< diagonal2d_t >
00083       {
00084         template <typename F>
00085         void operator()(F& f) const;
00086       };
00087 
00088       extern const diagonal2d_t diagonal2d;
00089 
00090 # ifndef MLN_INCLUDE_ONLY
00091 
00092 #  ifndef MLN_WO_GLOBAL_VARS
00093 
00094       const diagonal2d_t diagonal2d;
00095 
00096 #  endif // ! MLN_WO_GLOBAL_VARS
00097 
00098 
00099       template <typename F>
00100       inline
00101       void
00102       diagonal2d_t::operator()(F& f) const
00103       {
00104         trace::entering("canvas::browsing::diagonal2d");
00105 
00106         typedef typename F::I I;
00107         typedef mln_deduce(I, psite, delta) dpsite;
00108         typedef mln_psite(I) psite;
00109 
00110         // Directions
00111         dpsite dp_first(1, 0);
00112         dpsite dp_second(0, 1);
00113         dpsite dp_diag(-1, 1);
00114 
00115         mln_deduce(I, psite, delta) diag;
00116 
00117         psite
00118           pmin = f.input.domain().pmin(),
00119           pmax = f.input.domain().pmax();
00120 
00121         f.p = pmin;
00122 
00123         f.init();
00124 
00125         while (f.input.domain().has(f.p))
00126         {
00127           psite start_diag = f.p;
00128           // Browse one diag.
00129           f.init_diag();
00130           while (f.input.domain().has(f.p))
00131           {
00132             f.next();
00133             f.p = f.p + dp_diag;
00134           }
00135 
00136           // Goto next diag start.
00137           f.p = start_diag + dp_first;
00138         }
00139         f.p = f.p - dp_first;
00140 
00141         f.p = f.p + dp_second;
00142         while (f.input.domain().has(f.p))
00143         {
00144           psite start_diag = f.p;
00145 
00146           // Browse one diag.
00147           f.init_diag();
00148           while (f.input.domain().has(f.p))
00149           {
00150             f.next();
00151             f.p = f.p + dp_diag;
00152           }
00153           f.p = f.p - dp_diag;
00154 
00155           // Goto next diag start.
00156           f.p = start_diag + dp_second;
00157         }
00158 
00159         f.final();
00160         trace::exiting("canvas::browsing::diagonal2d");
00161       }
00162 
00163 # endif // ! MLN_INCLUDE_ONLY
00164 
00165     } // end of namespace mln::canvas::browsing
00166 
00167   } // end of namespace mln::canvas
00168 
00169 } // end of namespace mln
00170 
00171 #endif // ! MLN_CANVAS_BROWSING_DIAGONAL2D_HH

Generated on Tue Oct 4 2011 15:23:41 for Milena (Olena) by  doxygen 1.7.1