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 #include <mln/core/image/image2d.hh>
00027 #include <mln/canvas/browsing/snake_generic.hh>
00028 #include <mln/fun/p2v/iota.hh>
00029 #include <mln/debug/println.hh>
00030
00031
00032 template <typename I, typename F>
00033 struct assign_browsing_functor
00034 {
00035 typedef mln_site(I) S;
00036 enum { dim = S::dim };
00037
00038 typedef assign_browsing_functor<I, F> self;
00039 typedef mln_deduce(I, psite, delta) dpsite;
00040 typedef void (assign_browsing_functor<I,F>::*move_fun)();
00041
00042 I input;
00043 F f;
00044 std::vector<move_fun> moves;
00045 std::vector<dpsite> dps;
00046
00047 assign_browsing_functor(I& input, F f = F())
00048 : input(input),
00049 f(f),
00050 moves(3),
00051 dps(3)
00052 {
00053 dps[0] = dpsite(0, 1);
00054 dps[1] = dpsite(1, 0);
00055 dps[2] = dpsite(-1, 0);
00056 moves[0] = &self::fwd;
00057 moves[1] = &self::down;
00058 moves[2] = &self::up;
00059 }
00060
00061 mln_psite(I) p;
00062
00063 void init() {}
00064 void final() {}
00065 void next()
00066 {
00067 input(p) = f(p);
00068 }
00069 void fwd() { std::cout << "fwd" << std::endl; next(); }
00070 void up() { std::cout << "up" << std::endl; next(); }
00071 void down() { std::cout << "down" << std::endl; next(); }
00072 };
00073
00074 namespace mln
00075 {
00076
00077 template <typename I, typename F, typename B>
00078 void my_test(Image<I>& ima_,
00079 const Function_v2v<F>& f_,
00080 const Browsing<B>& browse_)
00081 {
00082 I& ima = exact(ima_);
00083 const F& f = exact(f_);
00084 const B& browse = exact(browse_);
00085
00086 assign_browsing_functor<I, F> fun(ima, f);
00087 browse(fun);
00088 }
00089
00090 }
00091
00092
00093 int main()
00094 {
00095 using namespace mln;
00096 image2d<unsigned> ima2(3, 3);
00097
00098 std::cout << ima2.bbox() << std::endl;
00099 my_test(ima2, fun::p2v::iota(), canvas::browsing::snake_generic);
00100 debug::println(ima2);
00101 }