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 #ifndef MLN_CANVAS_CHAMFER_HH
00027 # define MLN_CANVAS_CHAMFER_HH
00028 
00034 # include <mln/core/internal/image_morpher.hh>
00035 # include <mln/win/sym.hh>
00036 
00037 namespace mln
00038 {
00039   namespace canvas
00040   {
00041 
00046     template <typename F>
00047     struct chamfer
00048     {
00049       typedef typename F::I I;
00050       typedef typename F::W W;
00051       typedef mln_psite(I) point;
00052 
00053       F& f;
00054 
00055       chamfer(F& f);
00056 
00057       void run();
00058     };
00059 
00060 # ifndef MLN_INCLUDE_ONLY
00061 
00062     template<typename F>
00063     inline
00064     chamfer<F>::chamfer(F& f)
00065       : f(f)
00066     {
00067       run();
00068     }
00069 
00070     template<typename F>
00071     inline
00072     void
00073     chamfer<F>::run()
00074     {
00075 
00077       {
00078         f.init();
00079       }
00080 
00082       {
00083         mln_fwd_piter(I) p(f.input.domain());
00084         mln_qiter(W) q(f.win, p);
00085 
00086         for_all(p) if (f.handles (p))
00087           for_all(q) if (f.input.domain().has(q))
00088             if (f.output(q) != f.max
00089                 && f.output(q) + q.w() < f.output(p))
00090               f.output(p) = f.output(q) + q.w();
00091       }
00092 
00094       {
00095         W w_win_b = win::sym(f.win);
00096 
00097         mln_bkd_piter(I) p(f.input.domain());
00098         mln_qiter(W) q(w_win_b, p);
00099 
00100         for_all(p) if (f.handles (p))
00101           for_all(q) if (f.input.domain().has(q))
00102             if (f.output(q) != f.max
00103                 && f.output(q) + q.w() < f.output(p))
00104               f.output(p) = f.output(q) + q.w();
00105         f.status = true;
00106       }
00107     }
00108 
00109 # endif // ! MLN_INCLUDE_ONLY
00110 
00111   } 
00112 
00113 } 
00114 
00115 #endif // ! MLN_CANVAS_CHAMFER_HH