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

dir_struct_elt_incr_update.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_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH
00027 # define MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH
00028 
00032 
00033 # include <mln/core/concept/browsing.hh>
00034 # include <mln/core/concept/image.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace canvas
00041   {
00042 
00043     namespace browsing
00044     {
00045 
00047 
00086       struct dir_struct_elt_incr_update_t : public Browsing< dir_struct_elt_incr_update_t >
00087       {
00088         template <typename F>
00089         void operator()(F& f) const;
00090       };
00091 
00092       extern const dir_struct_elt_incr_update_t dir_struct_elt_incr_update;
00093 
00094 # ifndef MLN_INCLUDE_ONLY
00095 
00096       const dir_struct_elt_incr_update_t dir_struct_elt_incr_update;
00097 
00098       template <typename F>
00099       inline
00100       void
00101       dir_struct_elt_incr_update_t::operator()(F& f) const
00102       {
00103         trace::entering("canvas::browsing::dir_struct_elt_incr_update");
00104         mln_precondition(f.dir < f.dim);
00105         typedef typename F::I I;
00106 
00107         const mln_psite(I)
00108           pmin = f.input.domain().pmin(),
00109           pmax = f.input.domain().pmax();
00110 
00111         typedef mln_deduce(I, site, coord) C;
00112         const C
00113           pmin_dir = pmin[f.dir],
00114           pmax_dir = pmax[f.dir],
00115           pmin_dir_plus_half_length  = static_cast<C>(pmin_dir + f.length / 2),
00116           pmax_dir_minus_half_length = static_cast<C>(pmax_dir - f.length / 2);
00117 
00118         mln_psite(I) pt, pu;
00119 
00120         def::coord&
00121           ct = pt[f.dir],
00122           cu = pu[f.dir],
00123           p_dir = f.p[f.dir];
00124 
00125         f.p = pmin;
00126 
00127         f.init();
00128 
00129         do
00130         {
00131           pt = f.p;
00132           pu = f.p;
00133 
00134           f.init_line();
00135 
00136           // initialization (before first point of the line)
00137           std::cout << "init" << std::endl;
00138           for (ct = pmin_dir; ct < pmin_dir_plus_half_length; ++ ct)
00139             if (f.input.has(pt))
00140               {
00141                 std::cout << '+' << pt << ' ';
00142                 f.add_point(pt);
00143               }
00144 
00145           // left columns (just take new points)
00146           std::cout << "left" << std::endl;
00147           for (p_dir = pmin_dir; p_dir <= pmin_dir_plus_half_length; ++p_dir, ++ct)
00148           {
00149             if (f.input.has(pt))
00150               {
00151                 std::cout << '+' << pt << ' ';
00152                 f.add_point(pt);
00153               }
00154             f.next();
00155           }
00156 
00157           // middle columns (both take and untake)
00158           std::cout << "middle" << std::endl;
00159           cu = pmin_dir;
00160           for (; p_dir <= pmax_dir_minus_half_length; ++cu, ++p_dir, ++ct)
00161           {
00162             if (f.input.has(pt))
00163               {
00164                 std::cout << '+' << pt << ' ';
00165                 f.add_point(pt);
00166               }
00167             if (f.input.has(pu))
00168               {
00169                 std::cout << '-' << pu << ' ';
00170                 f.remove_point(pu);
00171               }
00172             f.next();
00173           }
00174 
00175           // right columns (now just untake old points)
00176           std::cout << "right" << std::endl;
00177           for (; p_dir <= pmax_dir; ++cu, ++p_dir)
00178           {
00179             if (f.input.has(pu))
00180               {
00181                 std::cout << '-' << pu << ' ';
00182                 f.remove_point(pu);
00183               }
00184             f.next();
00185           }
00186 
00187           p_dir = pmin_dir;
00188 
00189           for (int c = F::dim - 1; c >= 0; --c)
00190           {
00191             if (c == int(f.dir))
00192               continue;
00193             if (f.p[c] != pmax[c])
00194             {
00195               ++f.p[c];
00196               break;
00197             }
00198             f.p[c] = pmin[c];
00199           }
00200         } while (f.p != pmin);
00201 
00202         f.final();
00203         trace::exiting("canvas::browsing::dir_struct_elt_incr_update");
00204       }
00205 
00206 # endif // ! MLN_INCLUDE_ONLY
00207 
00208     } // end of namespace mln::canvas::browsing
00209 
00210   } // end of namespace mln::canvas
00211 
00212 } // end of namespace mln
00213 
00214 #endif // ! MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH

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