00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00090
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
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
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
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
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 }
00223
00224 }
00225
00226 }
00227
00228 #endif // ! MLN_CANVAS_BROWSING_DIR_STRUCT_ELT_INCR_UPDATE_HH