884: Update : Norme, Sanity, apply of user functors. erosion not yet usable.

Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Update : Norme, Sanity, apply of user functors. erosion not yet usable. * oln/function/min.hh: . * oln/level/apply.hh: . * oln/level/local.hh: . * oln/core/concept/functions.hh: . * oln/core/internal/max_value.hh: . * oln/morphomath/erosion.hh: . core/internal/max_value.hh | 1 function/min.hh | 39 ++++++++--------- level/apply.hh | 71 ++++++++++--------------------- level/local.hh | 102 ++++++++++++++++++++++++++++++--------------- morphomath/erosion.hh | 27 +++++++---- 5 files changed, 129 insertions(+), 111 deletions(-) Index: oln/function/min.hh --- oln/function/min.hh (revision 883) +++ oln/function/min.hh (working copy) @@ -1,5 +1,4 @@ -// Copyright (C) 2007 EPITA Research and -// Development Laboratory +// Copyright (C) 2007 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -26,32 +25,29 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_FUNCTION_MIN_HH_ -# define OLN_FUNCTION_MIN_HH_ +#ifndef _FUNCTION_MIN_HH +# define _FUNCTION_MIN_HH + +#include <oln/core/concept/functions.hh> +#include <oln/core/internal/max_value.hh> + namespace oln { - template <typename T> - struct min_ : oln::Function< min_<T> > + namespace function { - typedef T argument; - typedef void result; - min_() + template <typename T> + struct min_ : public oln::Accumulator< min_<T> > { - init(); - } + typedef T argument; + typedef T result; - void init() - { - val_ = oln_max_value(T); - } + min_() { this->init(); } - T value() const - { - return val_; - } + void init() { val_ = oln_max(T); } + result value() const { return val_; } template <typename U> void operator()(U i) const @@ -59,10 +55,13 @@ if (i < val_) val_ = static_cast<T>(i); } + private: mutable T val_; }; } -#endif /* !OLN_FUNCTION_MIN_HH_ */ +} + +#endif // ! OLN_FUNCTION_MIN_HH Index: oln/level/apply.hh --- oln/level/apply.hh (revision 883) +++ oln/level/apply.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and -// Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA +// Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -30,7 +30,9 @@ # define OLN_LEVEL_APPLY_HH # include <oln/core/concept/image.hh> - +# include <oln/core/concept/iterator.hh> +# include <oln/core/internal/f_ch_value.hh> +# include <oln/level/local.hh> namespace oln { @@ -63,63 +65,37 @@ namespace impl { - template < typename F > - struct result - { - typedef typename F::result ret; - }; - - template < typename R (*fun)(A) > - struct result - { - typedef typename R ret; - }; - - template < typename F > - struct argument - { - typedef typename F::argument ret; - }; - - template < typename R (*fun)(A) > - struct argument - { - typedef typename A ret; - }; - - - // APPLY // - //--------- + /// apply template <typename F, typename I> - oln_plain_value(I, result<typename F>::ret) - apply(const F& fun, const Image<I>& input) + oln_plain_value(I, typename F::result) + apply( F& f, const Image<I>& input) { - typedef argument<typename F>::ret A; - typedef result<typename F>::ret R; + typedef typename F::result result; + typedef typename F::argument argument; - oln_ch_value(I, R) output(input.points()); + oln_ch_value(I, result) output(input.points()); oln_piter(I) p(input.points()); for_all(p) - output(p) = fun( static_cast<A>(input(p)) ); + output(p) = f( static_cast< argument >(input(p)) ); return output; } - // APPLY_LOCAL // - //--------------- + /// apply_local template <typename F, typename I> - oln_plain_value(I, result<typename F>::ret) - apply_local(const F& fun, const Image<I>& input) + oln_plain_value(I, typename F::result) + apply_local(const Accumulator<F>& fun, + const Image_with_Nbh<I>& input) { - typedef argument<typename F>::ret A; - typedef result<typename F>::ret R; + typedef typename F::result result; + typedef typename F::argument argument; - oln_ch_value(I, R) output(input.points()); + oln_ch_value(I, argument) output(input.points()); oln_piter(I) p(input.points()); for_all(p) - output(p) = local_apply(fun, input, p); + output(p) = local(fun, input, p); return output; } @@ -173,9 +149,9 @@ template <typename F, typename I> oln_plain_value(I, typename F::result) - apply(const F& fun, const Image<I>& input) + apply(F& f, const Image<I>& input) { - return impl::apply(fun, exact(input)); + return impl::apply(f, exact(input)); } /// Apply local @@ -189,7 +165,8 @@ template <typename F, typename I> oln_plain_value(I, typename F::result) - apply_local(const F& fun, const Image<I>& input) + apply_local(const Accumulator<F>& fun, + const Image_with_Nbh<I>& input) { return impl::apply_local(fun, exact(input)); } Index: oln/level/local.hh --- oln/level/local.hh (revision 883) +++ oln/level/local.hh (working copy) @@ -1,5 +1,4 @@ -// Copyright (C) 2007 EPITA Research and -// Development Laboratory +// Copyright (C) 2007 EPITA Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -16,81 +15,118 @@ // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02111-1307, USA. // -// As a special exception, you may use this file as part of a free -// software library without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to -// produce an executable, this file does not by itself cause the -// resulting executable to be covered by the GNU General Public -// License. This exception does not however invalidate any other -// reasons why the executable file might be covered by the GNU General -// Public License. - -#ifndef OLN_LEVEL_LOCAL_HH_ -# define OLN_LEVEL_LOCAL_HH_ +// As a special exception, you may +// use this file as part of a free software library without +// restriction. Specifically, if other files instantiate templates or +// use macros or inline functions from this file, or you compile this +// file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be +// covered by the GNU General Public License. This exception does not +// however invalidate any other reasons why the executable file might +// be covered by the GNU General Public License. + +#ifndef OLN_LEVEL_LOCAL_HH +# define OLN_LEVEL_LOCAL_HH + +#include <oln/core/concept/image.hh> +#include <oln/core/concept/point.hh> +#include <oln/core/concept/functions.hh> +#include <oln/core/concept/window.hh> +#include <oln/core/concept/iterator.hh> // bizarre +#include <oln/core/equipment.hh> namespace oln { - namespace impl + namespace level { - // LOCAL APPLICATION ON NBH // - //---------------------------- + template <typename A, typename I> + typename A::result + local(const Accumulator<A>& f, + const Image_with_Nbh<I>& input, + const oln_point(I)& p); + + template <typename F, typename I, typename W> + typename F::result + local(const Accumulator<F>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win); + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { /// Local Apply on neighborhood ( nbh included in image ). - template <typename R, typename A, typename I> + template <typename A, typename I> typename A::result - local_apply(const Accumulator< A >& fun, + local(const Accumulator<A>& f, const Image_with_Nbh< I >& input, const oln_point( I )& p) { - fun.init(); + f.init(); oln_niter(I) n(p, input.points()); for_all(n) - fun(input(n)); - return fun.value(); + f(input(n)); + return f.value(); } - /// Local Apply on neighborhood ( nhb has to be given ). + /// Local Apply on neighborhood (nhb given as argument). // ...FIXME - // LOCAL APPLICATION ON WINDOW // - //------------------------------- - /// Local Apply on window ( window included in image). // ...FIXME - /// Local Apply on window ( window is given ). template <typename F, typename I, typename W> typename F::result - local_apply(const Accumulator<F>& fun, + local(const Accumulator<F>& f, const Image<I>& input, const oln_point(I)& p, const Window<W>& win) { - fun.init(); + f.init(); oln_qiter(W) q(p, win); for_all(q) - fun(input(q)); - return fun.value(); + f(input(q)); + + return f.value(); } } /// Facades. - local_apply( ) + template <typename A, typename I> + typename A::result + local(const Accumulator<A>& f, + const Image_with_Nbh<I>& input, + const oln_point( I )& p) { + return impl::local(f, input, p); + } + template <typename F, typename I, typename W> + typename F::result + local(const Accumulator<F>& f, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + return impl::local(f, input, p, win); } +#endif // ! OLN_INCLUDE_ONLY + + } } -#endif /* !OLN_LEVEL_LOCAL_HH_ */ + +#endif // ! OLN_LEVEL_LOCAL_HH Index: oln/core/concept/functions.hh Index: oln/core/internal/max_value.hh --- oln/core/internal/max_value.hh (revision 883) +++ oln/core/internal/max_value.hh (working copy) @@ -30,7 +30,6 @@ #include <cassert> #include <limits> -#include <iostream> namespace oln { Index: oln/morphomath/erosion.hh --- oln/morphomath/erosion.hh (revision 883) +++ oln/morphomath/erosion.hh (working copy) @@ -26,34 +26,41 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_MORPHOMATH_EROSION_HH_ -# define OLN_MORPHOMATH_EROSION_HH_ +#ifndef OLN_MORPHO_EROSION_HH +# define OLN_MORPHO_EROSION_HH -#include <oln/fonction/min.hh> #include <oln/level/local.hh> +#include <oln/function/min.hh> namespace oln { + + namespace morpho + { + namespace impl { /// Generic version - template <typename I, typename W> - I erosion(const Image<I>& input) + template <typename I> + I erosion(Image_with_Nbh<I>& input) { - min_<oln_value(I)> min; - return apply(min, input); + function::min_<oln_value(I)> min; + + return ::oln::level::apply_local(min, input); } } // Facade. - template <typename I, typename W> - I erosion(const Point_Wise_Accessible_Image<I>& input) + template <typename I> + I erosion(Image_with_Nbh<I>& input) { return impl::erosion(exact(input)); } + + } // end of namespace } -#endif /* !OLN_MORPHOMATH_EROSION_HH_ */ +#endif // ! OLN_MORPHO_EROSION_HH
participants (1)
-
Ugo Jardonnet