Milena (Olena)
User documentation 2.0a Id
|
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 #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(1, 0); 00054 dps[1] = dpsite(0, 1); 00055 dps[2] = dpsite(0, -1); 00056 moves[0] = &self::down; 00057 moves[1] = &self::fwd; 00058 moves[2] = &self::bkd; 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 bkd() { std::cout << "bkd" << 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 }