Milena (Olena)  User documentation 2.0a Id
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         // This default constructor is needed for compilation with gcc
00085         // 4.6.0, gcc 4.6.1 and Clang.
00086         diagonal2d_t();
00087 
00088         template <typename F>
00089         void operator()(F& f) const;
00090       };
00091 
00092       extern const diagonal2d_t diagonal2d;
00093 
00094 # ifndef MLN_INCLUDE_ONLY
00095 
00096 #  ifndef MLN_WO_GLOBAL_VARS
00097 
00098       const diagonal2d_t diagonal2d;
00099 
00100 #  endif // ! MLN_WO_GLOBAL_VARS
00101 
00102       inline
00103       diagonal2d_t::diagonal2d_t()
00104       {
00105       }
00106 
00107 
00108       template <typename F>
00109       inline
00110       void
00111       diagonal2d_t::operator()(F& f) const
00112       {
00113         trace::entering("canvas::browsing::diagonal2d");
00114 
00115         typedef typename F::I I;
00116         typedef mln_deduce(I, psite, delta) dpsite;
00117         typedef mln_psite(I) psite;
00118 
00119         // Directions
00120         dpsite dp_first(1, 0);
00121         dpsite dp_second(0, 1);
00122         dpsite dp_diag(-1, 1);
00123 
00124         mln_deduce(I, psite, delta) diag;
00125 
00126         psite
00127           pmin = f.input.domain().pmin(),
00128           pmax = f.input.domain().pmax();
00129 
00130         f.p = pmin;
00131 
00132         f.init();
00133 
00134         while (f.input.domain().has(f.p))
00135         {
00136           psite start_diag = f.p;
00137           // Browse one diag.
00138           f.init_diag();
00139           while (f.input.domain().has(f.p))
00140           {
00141             f.next();
00142             f.p = f.p + dp_diag;
00143           }
00144 
00145           // Goto next diag start.
00146           f.p = start_diag + dp_first;
00147         }
00148         f.p = f.p - dp_first;
00149 
00150         f.p = f.p + dp_second;
00151         while (f.input.domain().has(f.p))
00152         {
00153           psite start_diag = f.p;
00154 
00155           // Browse one diag.
00156           f.init_diag();
00157           while (f.input.domain().has(f.p))
00158           {
00159             f.next();
00160             f.p = f.p + dp_diag;
00161           }
00162           f.p = f.p - dp_diag;
00163 
00164           // Goto next diag start.
00165           f.p = start_diag + dp_second;
00166         }
00167 
00168         f.final();
00169         trace::exiting("canvas::browsing::diagonal2d");
00170       }
00171 
00172 # endif // ! MLN_INCLUDE_ONLY
00173 
00174     } // end of namespace mln::canvas::browsing
00175 
00176   } // end of namespace mln::canvas
00177 
00178 } // end of namespace mln
00179 
00180 #endif // ! MLN_CANVAS_BROWSING_DIAGONAL2D_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator