Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009, 2011 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_DIR_STRUCT_ELT_INCR_UPDATE_HH 00028 # define MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_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 00087 struct dir_struct_elt_incr_update_t : public Browsing< dir_struct_elt_incr_update_t > 00088 { 00089 // This default constructor is needed for compilation with gcc 00090 // 4.6.0, gcc 4.6.1 and Clang. 00091 dir_struct_elt_incr_update_t(); 00092 00093 template <typename F> 00094 void operator()(F& f) const; 00095 }; 00096 00097 extern const dir_struct_elt_incr_update_t dir_struct_elt_incr_update; 00098 00099 # ifndef MLN_INCLUDE_ONLY 00100 00101 # ifndef MLN_WO_GLOBAL_VARS 00102 00103 const dir_struct_elt_incr_update_t dir_struct_elt_incr_update; 00104 00105 # endif // ! MLN_WO_GLOBAL_VARS 00106 00107 inline 00108 dir_struct_elt_incr_update_t::dir_struct_elt_incr_update_t() 00109 { 00110 } 00111 00112 template <typename F> 00113 inline 00114 void 00115 dir_struct_elt_incr_update_t::operator()(F& f) const 00116 { 00117 trace::entering("canvas::browsing::dir_struct_elt_incr_update"); 00118 mln_precondition(f.dir < f.dim); 00119 typedef typename F::I I; 00120 00121 const mln_psite(I) 00122 pmin = f.input.domain().pmin(), 00123 pmax = f.input.domain().pmax(); 00124 00125 typedef mln_deduce(I, site, coord) C; 00126 const C 00127 pmin_dir = pmin[f.dir], 00128 pmax_dir = pmax[f.dir], 00129 pmin_dir_plus_half_length = static_cast<C>(pmin_dir + f.length / 2), 00130 pmax_dir_minus_half_length = static_cast<C>(pmax_dir - f.length / 2); 00131 00132 mln_psite(I) pt, pu; 00133 00134 def::coord& 00135 ct = pt[f.dir], 00136 cu = pu[f.dir], 00137 p_dir = f.p[f.dir]; 00138 00139 f.p = pmin; 00140 00141 f.init(); 00142 00143 do 00144 { 00145 pt = f.p; 00146 pu = f.p; 00147 00148 f.init_line(); 00149 00150 // initialization (before first point of the line) 00151 std::cout << "init" << std::endl; 00152 for (ct = pmin_dir; ct < pmin_dir_plus_half_length; ++ ct) 00153 if (f.input.has(pt)) 00154 { 00155 std::cout << '+' << pt << ' '; 00156 f.add_point(pt); 00157 } 00158 00159 // left columns (just take new points) 00160 std::cout << "left" << std::endl; 00161 for (p_dir = pmin_dir; p_dir <= pmin_dir_plus_half_length; ++p_dir, ++ct) 00162 { 00163 if (f.input.has(pt)) 00164 { 00165 std::cout << '+' << pt << ' '; 00166 f.add_point(pt); 00167 } 00168 f.next(); 00169 } 00170 00171 // middle columns (both take and untake) 00172 std::cout << "middle" << std::endl; 00173 cu = pmin_dir; 00174 for (; p_dir <= pmax_dir_minus_half_length; ++cu, ++p_dir, ++ct) 00175 { 00176 if (f.input.has(pt)) 00177 { 00178 std::cout << '+' << pt << ' '; 00179 f.add_point(pt); 00180 } 00181 if (f.input.has(pu)) 00182 { 00183 std::cout << '-' << pu << ' '; 00184 f.remove_point(pu); 00185 } 00186 f.next(); 00187 } 00188 00189 // right columns (now just untake old points) 00190 std::cout << "right" << std::endl; 00191 for (; p_dir <= pmax_dir; ++cu, ++p_dir) 00192 { 00193 if (f.input.has(pu)) 00194 { 00195 std::cout << '-' << pu << ' '; 00196 f.remove_point(pu); 00197 } 00198 f.next(); 00199 } 00200 00201 p_dir = pmin_dir; 00202 00203 for (int c = F::dim - 1; c >= 0; --c) 00204 { 00205 if (c == int(f.dir)) 00206 continue; 00207 if (f.p[c] != pmax[c]) 00208 { 00209 ++f.p[c]; 00210 break; 00211 } 00212 f.p[c] = pmin[c]; 00213 } 00214 } while (f.p != pmin); 00215 00216 f.final(); 00217 trace::exiting("canvas::browsing::dir_struct_elt_incr_update"); 00218 } 00219 00220 # endif // ! MLN_INCLUDE_ONLY 00221 00222 } // end of namespace mln::canvas::browsing 00223 00224 } // end of namespace mln::canvas 00225 00226 } // end of namespace mln 00227 00228 #endif // ! MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH