Milena (Olena)  User documentation 2.0a Id
backdiagonal2d.hh
00001 // Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and
00002 // Development 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_BACKDIAGONAL2D_HH
00028 # define MLN_CANVAS_BROWSING_BACKDIAGONAL2D_HH
00029 
00033 
00034 # include <mln/core/concept/browsing.hh>
00035 # include <mln/core/concept/image.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace canvas
00042   {
00043 
00044     namespace browsing
00045     {
00046 
00048 
00083       struct backdiagonal2d_t : public Browsing< backdiagonal2d_t >
00084       {
00085         // This default constructor is needed for compilation with gcc
00086         // 4.6.0, gcc 4.6.1 and Clang.
00087         backdiagonal2d_t();
00088 
00089         template <typename F>
00090         void operator()(F& f) const;
00091       };
00092 
00093       extern const backdiagonal2d_t backdiagonal2d;
00094 
00095 
00096 
00097 # ifndef MLN_INCLUDE_ONLY
00098 
00099 #  ifndef MLN_WO_GLOBAL_VARS
00100 
00101       const backdiagonal2d_t backdiagonal2d;
00102 
00103 #  endif // ! MLN_WO_GLOBAL_VARS
00104 
00105       inline
00106       backdiagonal2d_t::backdiagonal2d_t()
00107       {
00108       }
00109 
00110       template <typename F>
00111       inline
00112       void
00113       backdiagonal2d_t::operator()(F& f) const
00114       {
00115         trace::entering("canvas::browsing::backdiagonal2d");
00116 
00117         typedef typename F::I I;
00118         typedef mln_deduce(I, psite, delta) dpsite;
00119         typedef mln_psite(I) psite;
00120 
00121         // Directions
00122         dpsite dp_first(-1, 0);
00123         dpsite dp_second(0, 1);
00124         dpsite dp_diag(1, 1);
00125 
00126         mln_deduce(I, psite, delta) diag;
00127 
00128         psite
00129           pmin = f.input.domain().pmin(),
00130           pmax = f.input.domain().pmax();
00131 
00132         // Start at the bottom left corner.
00133         f.p[0] = pmax[0];
00134         f.p[1] = pmin[1];
00135 
00136         f.init();
00137 
00138         while (f.input.domain().has(f.p))
00139         {
00140           psite start_diag = f.p;
00141           // Browse one diag.
00142           f.init_diag();
00143           while (f.input.domain().has(f.p))
00144           {
00145             f.next();
00146             f.p = f.p + dp_diag;
00147           }
00148 
00149           // Goto next diag start.
00150           f.p = start_diag + dp_first;
00151         }
00152         f.p = f.p - dp_first;
00153 
00154         f.p = f.p + dp_second;
00155         while (f.input.domain().has(f.p))
00156         {
00157           psite start_diag = f.p;
00158 
00159           // Browse one diag.
00160           f.init_diag();
00161           while (f.input.domain().has(f.p))
00162           {
00163             f.next();
00164             f.p = f.p + dp_diag;
00165           }
00166           f.p = f.p - dp_diag;
00167 
00168           // Goto next diag start.
00169           f.p = start_diag + dp_second;
00170         }
00171 
00172         f.final();
00173         trace::exiting("canvas::browsing::backdiagonal2d");
00174       }
00175 
00176 # endif // ! MLN_INCLUDE_ONLY
00177 
00178     } // end of namespace mln::canvas::browsing
00179 
00180   } // end of namespace mln::canvas
00181 
00182 } // end of namespace mln
00183 
00184 #endif // ! MLN_CANVAS_BROWSING_BACKDIAGONAL2D_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator