
max and min value for any type can be obtain with std lib yet. Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Update and add : apply, local canvas. * tests/core/Makefile.am: . * oln/function: New. * oln/function/min.hh: New. * oln/level/apply.hh: . * oln/level/local.hh: New. * oln/core/concept/image.hh: . * oln/core/concept/functions.hh: . * oln/core/internal/max_value.hh: New. * oln/morphomath: New. * oln/morphomath/dilatation.hh: New. * oln/morphomath/erosion.hh: New. oln/core/concept/functions.hh | 10 ++++ oln/core/internal/max_value.hh | 42 +++++++++++++++++ oln/function/min.hh | 68 +++++++++++++++++++++++++++++ oln/level/apply.hh | 87 ++++++++++++++++++++++++++++++++++--- oln/level/local.hh | 96 +++++++++++++++++++++++++++++++++++++++++ oln/morphomath/dilatation.hh | 29 ++++++++++++ oln/morphomath/erosion.hh | 59 +++++++++++++++++++++++++ tests/core/Makefile.am | 1 8 files changed, 384 insertions(+), 8 deletions(-) Index: tests/core/Makefile.am --- tests/core/Makefile.am (revision 874) +++ tests/core/Makefile.am (working copy) @@ -37,7 +37,6 @@ neighb2d_SOURCES = neighb2d.cc npoints_SOURCES = npoints.cc window2d_SOURCES = window2d.cc -neighb2d_SOURCES = neighb2d.cc # Methods. at_SOURCES = at.cc Index: oln/function/min.hh --- oln/function/min.hh (revision 0) +++ oln/function/min.hh (revision 0) @@ -0,0 +1,68 @@ +// 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// 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_FUNCTION_MIN_HH_ +# define OLN_FUNCTION_MIN_HH_ + +namespace oln +{ + + template <typename T> + struct min_ : oln::Function< min_<T> > + { + typedef T argument; + typedef void result; + + min_() + { + init(); + } + + void init() + { + val_ = oln_max_value(T); + } + + T value() const + { + return val_; + } + + template <typename U> + void operator()(U i) const + { + if (i < val_) + val_ = static_cast<T>(i); + } + private: + mutable T val_; + }; + +} + +#endif /* !OLN_FUNCTION_MIN_HH_ */ Index: oln/level/apply.hh --- oln/level/apply.hh (revision 874) +++ oln/level/apply.hh (working copy) @@ -63,16 +63,63 @@ namespace impl { - /// Generic version. + template < typename F > + struct result + { + typedef typename F::result ret; + }; - template <typename R, typename A, typename I> - oln_plain_value(I, R) - apply(R (*fun)(A), const Image<I>& input) + 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 // + //--------- + + template <typename F, typename I> + oln_plain_value(I, result<typename F>::ret) + apply(const F& fun, const Image<I>& input) + { + typedef argument<typename F>::ret A; + typedef result<typename F>::ret R; + + oln_ch_value(I, R) output(input.points()); + oln_piter(I) p(input.points()); + for_all(p) + output(p) = fun( static_cast<A>(input(p)) ); + return output; + } + + + // 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, R) output(input.points()); + typedef argument<typename F>::ret A; + typedef result<typename F>::ret R; + + oln_ch_value(I, R) output(input.points()); oln_piter(I) p(input.points()); for_all(p) - output(p) = fun(input(p)); + output(p) = local_apply(fun, input, p); return output; } @@ -112,8 +159,11 @@ } // end of namespace oln::level::impl + /// Facades. + //---------------------------- + + /// Apply. - /// Facade. template <typename R, typename A, typename I> oln_plain_value(I, R) apply(R (*fun)(A), const Image<I>& input) @@ -121,6 +171,29 @@ return impl::apply(fun, exact(input)); } + template <typename F, typename I> + oln_plain_value(I, typename F::result) + apply(const F& fun, const Image<I>& input) + { + return impl::apply(fun, exact(input)); + } + + /// Apply local + + template <typename R, typename A, typename I> + oln_plain_value(I, R) + apply_local(R (*fun)(A), const Image<I>& input) + { + return impl::apply_local(fun, exact(input)); + } + + template <typename F, typename I> + oln_plain_value(I, typename F::result) + apply_local(const F& fun, const Image<I>& input) + { + return impl::apply_local(fun, exact(input)); + } + // /// Facade. // template <typename I, typename F> // oln_plain_value(I, typename F::result_value) Index: oln/level/local.hh --- oln/level/local.hh (revision 0) +++ oln/level/local.hh (revision 0) @@ -0,0 +1,96 @@ +// 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// 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_ + +namespace oln +{ + + namespace impl + { + + // LOCAL APPLICATION ON NBH // + //---------------------------- + + /// Local Apply on neighborhood ( nbh included in image ). + + template <typename R, typename A, typename I> + typename A::result + local_apply(const Accumulator< A >& fun, + const Image_with_Nbh< I >& input, + const oln_point( I )& p) + { + fun.init(); + oln_niter(I) n(p, input.points()); + for_all(n) + fun(input(n)); + return fun.value(); + } + + + /// Local Apply on neighborhood ( nhb has to be given ). + + // ...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, + const Image<I>& input, + const oln_point(I)& p, + const Window<W>& win) + { + fun.init(); + oln_qiter(W) q(p, win); + for_all(q) + fun(input(q)); + return fun.value(); + } + + } + + /// Facades. + + local_apply( ) + { + + } + +} +#endif /* !OLN_LEVEL_LOCAL_HH_ */ Index: oln/core/concept/image.hh Index: oln/core/concept/functions.hh --- oln/core/concept/functions.hh (revision 874) +++ oln/core/concept/functions.hh (working copy) @@ -73,6 +73,16 @@ }; + // Neighborhood -> Value. + + template <typename Exact> + struct Accumulator : public Function<Exact> + { + protected: + Accumulator(); + }; + + /* // Value1 -> Value2 *and* Value2 -> Value1. Index: oln/core/internal/max_value.hh --- oln/core/internal/max_value.hh (revision 0) +++ oln/core/internal/max_value.hh (revision 0) @@ -0,0 +1,42 @@ +// 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// 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_CORE_INTERNAL_MAX_VALUE_HH_ +# define OLN_CORE_INTERNAL_MAX_VALUE_HH_ + +#include <cassert> +#include <limits> +#include <iostream> + +namespace oln +{ + +#define oln_max(T) std::numeric_limits< T >::max() + +} + +#endif /* !OLN_CORE_INTERNAL_MAX_VALUE_HH_ */ Index: oln/morphomath/dilatation.hh --- oln/morphomath/dilatation.hh (revision 0) +++ oln/morphomath/dilatation.hh (revision 0) @@ -0,0 +1,29 @@ +#ifndef OLN_MORPHOMATH_DILATATION_HH_ +# define OLN_MORPHOMATH_DILATATION_HH_ + +// Facade. + +namespace impl +{ + + /// Generic version + + template <typename I, typename W> + I dilatation(const Image<I>& input) + { + max_<oln_value(I)> max; + return apply(max, input); + } + +} + + +/// Facade. + +template <typename I, typename W> +I erosion(const Image<I>& input) +{ + return impl::dilatation(exact(input)); +} + +#endif /* !OLN_MORPHOMATH_DILATATION_HH_ */ Index: oln/morphomath/erosion.hh --- oln/morphomath/erosion.hh (revision 0) +++ oln/morphomath/erosion.hh (revision 0) @@ -0,0 +1,59 @@ +// 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 +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// 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_MORPHOMATH_EROSION_HH_ +# define OLN_MORPHOMATH_EROSION_HH_ + +#include <oln/fonction/min.hh> +#include <oln/level/local.hh> + +namespace oln +{ + namespace impl + { + + /// Generic version + + template <typename I, typename W> + I erosion(const Image<I>& input) + { + min_<oln_value(I)> min; + return apply(min, input); + } + } + + // Facade. + + template <typename I, typename W> + I erosion(const Point_Wise_Accessible_Image<I>& input) + { + return impl::erosion(exact(input)); + } +} + +#endif /* !OLN_MORPHOMATH_EROSION_HH_ */