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_SNAKE_FWD_HH
00028 # define MLN_CANVAS_BROWSING_SNAKE_FWD_HH
00029 
00033 
00034 # include <mln/core/concept/browsing.hh>
00035 # include <mln/geom/size2d.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace canvas
00042   {
00043 
00044     namespace browsing
00045     {
00046 
00048 
00084       struct snake_fwd_t : public Browsing< snake_fwd_t >
00085       {
00086         template <typename F>
00087         void operator()(F& f) const;
00088       };
00089 
00090       extern const snake_fwd_t snake_fwd;
00091 
00092 # ifndef MLN_INCLUDE_ONLY
00093 
00094 #  ifndef MLN_WO_GLOBAL_VARS
00095 
00096       const snake_fwd_t snake_fwd;
00097 
00098 #  endif // ! MLN_WO_GLOBAL_VARS
00099 
00100 
00101       template <typename F>
00102       inline
00103       void
00104       snake_fwd_t::operator()(F& f) const
00105       {
00106         
00107 
00108 
00109         trace::entering("canvas::browsing::snake_fwd");
00110         mln_precondition(f.input.is_valid());
00111         def::coord
00112           min_row = geom::min_row(f.input), max_row = geom::max_row(f.input),
00113           min_col = geom::min_col(f.input), max_col = geom::max_col(f.input);
00114 
00115         
00116         f.p = f.input.bbox().pmin();
00117         def::coord& row = f.p.row();
00118         def::coord& col = f.p.col();
00119 
00120         
00121         f.init();
00122 
00123         bool fwd = true;
00124         for (row = min_row; row <= max_row; ++row)
00125           
00126           {
00127             
00128             f.down();
00129 
00130             if (fwd)
00131               
00132               while (col < max_col)
00133                 {
00134                   ++col;
00135                   f.fwd();
00136                 }
00137             else
00138               
00139               while (col > min_col)
00140                 {
00141                   --col;
00142                   f.bkd();
00143                 }
00144 
00145             
00146             fwd = ! fwd;
00147           }
00148         trace::exiting("canvas::browsing::snake_fwd");
00149       }
00150 
00151 # endif // ! MLN_INCLUDE_ONLY
00152 
00153     } 
00154 
00155   } 
00156 
00157 } 
00158 
00159 
00160 #endif // ! MLN_CANVAS_BROWSING_SNAKE_FWD_HH