Milena (Olena)  User documentation 2.0a Id
chamfer.hh
00001 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_GEOM_CHAMFER_HH
00028 # define MLN_GEOM_CHAMFER_HH
00029 
00033 
00034 # include <mln/canvas/chamfer.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace geom
00041   {
00042 
00044     template <typename I, typename W>
00045     mln_ch_value(I, unsigned)
00046     chamfer(const Image<I>& input_, const W& w_win_,
00047             unsigned max = mln_max(unsigned));
00048 
00049 
00050 # ifndef MLN_INCLUDE_ONLY
00051 
00052     namespace impl
00053     {
00054 
00055       // Functors.
00056 
00057       template <typename I_, typename W_>
00058       struct chamfer_t
00059       {
00060         typedef I_ I;
00061         typedef mln_ch_value(I, unsigned) O;
00062         typedef W_ W;
00063         typedef mln_site(I_) P;
00064 
00065         // requirements from mln::canvas::chamfer:
00066 
00067         const I& input;
00068         const W& win;
00069 
00070         O output;
00071         bool status;
00072         unsigned max;
00073 
00074         void fill_output()
00075         {
00076           mln_piter(O) p(output.domain());
00077           for_all(p)
00078           {
00079             if (input(p))
00080               output(p) = 0u;
00081             else
00082               output(p) = max;
00083           }
00084         }
00085 
00086         inline
00087         void init()                            { initialize(output, exact(input));
00088                                                  fill_output();
00089                                                  // Was :
00090                                                  // data::fill((output | (input | pw::cst(true)).domain()).rw(), 0);
00091                                                  // data::fill((output | (input | pw::cst(false)).domain()).rw(), max);
00092         }
00093         inline
00094         bool handles(const P& p) const         { return input(p) == false; }
00095 
00096         // end of requirements
00097 
00098         inline
00099         chamfer_t(const I_& input, const W_& win, unsigned max)
00100           : input (input),
00101             win (win),
00102             max (max)
00103         {}
00104       };
00105 
00106     } // end of namespace mln::geom::impl
00107 
00108 
00109 
00110     // Facade.
00111 
00112     template <typename I, typename W>
00113     mln_ch_value(I, unsigned)
00114     chamfer(const Image<I>& input_, const W& w_win_,
00115             unsigned max)
00116     {
00117       trace::entering("mln::geom::chamfer");
00118       // FIXME: check that input_ is binary.
00119 
00120       const I& input = exact(input_);
00121       const W& w_win = exact(w_win_);
00122 
00123       typedef impl::chamfer_t<I, W> F;
00124 
00125       F f(input, w_win, max);
00126       canvas::chamfer<F> run(f);
00127 
00128       trace::exiting("mln::geom::chamfer");
00129       return f.output;
00130     }
00131 
00132 #endif // ! MLN_INCLUDE_ONLY
00133 
00134   } // end of namespace mln::geom
00135 
00136 }  // end of namespace mln
00137 
00138 #endif // ! MLN_GEOM_CHAMFER_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator