cleanup-2008 2863: Make logical and use level transform.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Make logical and use level transform. * mln/level/transform.spe.hh: Layout. (transform_tests): Fix sig. (transform_fastest): New impl. (transform_dispatch): Move out of impl and augment. * mln/level/transform.hh: Call dispatch. * mln/level/transform_inplace.hh (todo): New. (transform_inplace_fastest): New impl. (transform_inplace_dispatch): New. * tests/level/transform_inplace.cc: Fix warning. * mln/fun/vv2v/min.hh: Add second parm with default. * mln/fun/vv2v/macros.hh: New. * mln/fun/vv2v/land.hh: New. * mln/fun/vv2v/all.hh: Update. * mln/logical/and.hh: Fix return type in sig. (and__): Remove. Use level transform. * mln/logical/and.spe.hh: Remove. * mln/logical/includes.hh: New. * mln/logical/all.hh: Update. mln/fun/vv2v/all.hh | 3 mln/fun/vv2v/land.hh | 76 ++++++++++++++++++ mln/fun/vv2v/macros.hh | 48 +++++++++++ mln/fun/vv2v/min.hh | 20 ++-- mln/level/transform.hh | 17 +--- mln/level/transform.spe.hh | 164 ++++++++++++++++++++++++--------------- mln/level/transform_inplace.hh | 134 +++++++++++++++++++++++++++++-- mln/logical/all.hh | 13 +-- mln/logical/and.hh | 70 +++++----------- mln/logical/includes.hh | 77 ++++++++++++++++++ tests/level/transform_inplace.cc | 2 11 files changed, 478 insertions(+), 146 deletions(-) Index: tests/level/transform_inplace.cc --- tests/level/transform_inplace.cc (revision 2862) +++ tests/level/transform_inplace.cc (working copy) @@ -45,7 +45,7 @@ using namespace mln; const unsigned size = 50; - image2d<int> ref(3, 3); + image2d<int> ref(size, size); debug::iota(ref); image2d<int> ima = clone(ref); Index: mln/level/transform.spe.hh --- mln/level/transform.spe.hh (revision 2862) +++ mln/level/transform.spe.hh (working copy) @@ -55,41 +55,42 @@ namespace level { + // Forward declarations. + namespace internal { template <typename I, typename F> - inline void transform_tests(const Image<I>& input, const Function_v2v<F>& f); template <typename I1, typename I2, typename F> - inline void transform_tests(const Image<I1>& input1, const Image<I2>& input2, - const Function_v2v<F>& f); + const Function_vv2v<F>& f); } - // Implementation - // -------------- + // Implementations. + + namespace impl { namespace generic { + // Forward declaration. + template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform(const Image<I>& input_, - const Function_v2v<F>& f_); + transform(const Image<I>& input_, const Function_v2v<F>& f_); } template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_lowq(const Image<I>& input_, - const Function_v2v<F>& f_) + transform_lowq(const Image<I>& input_, const Function_v2v<F>& f_) { trace::entering("level::impl::transform_lowq"); @@ -111,14 +112,13 @@ output(p) = lut(input(p)); trace::exiting("level::impl::transform_lowq"); - return output; } + template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_taken(const Image<I>& input_, - const Function_v2v<F>& f_) + transform_taken(const Image<I>& input_, const Function_v2v<F>& f_) { trace::entering("level::impl::transform_taken"); @@ -140,15 +140,13 @@ output(p) = lut(input(p)); trace::exiting("level::impl::transform_taken"); - return output; } template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_singleton(const Image<I>& input_, - const Function_v2v<F>& f_) + transform_singleton(const Image<I>& input_, const Function_v2v<F>& f_) { trace::entering("level::impl::transform_singleton"); @@ -163,14 +161,13 @@ fill_with_value(output, val); trace::exiting("level::impl::transform_singleton"); - return output; } + template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_fast(const Image<I>& input_, - const Function_v2v<F>& f_) + transform_fast(const Image<I>& input_, const Function_v2v<F>& f_) { trace::entering("level::impl::transform_fast"); @@ -193,16 +190,13 @@ } trace::exiting("level::impl::transform_fast"); - return output; } - template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_fast_lowq(const Image<I>& input_, - const Function_v2v<F>& f_) + transform_fast_lowq(const Image<I>& input_, const Function_v2v<F>& f_) { trace::entering("level::impl::transform_fast_lowq"); @@ -219,23 +213,48 @@ mln_pixter(const I) pi(input); mln_pixter(O) po(output); - - po.start(); - for_all(pi) - { + for_all_2(pi, po) po.val() = lut(pi.val()); - po.next(); - } trace::exiting("level::impl::transform_fast_lowq"); + return output; + } + + + template <typename I1, typename I2, typename F> + mln_ch_value(I1, mln_result(F)) + transform_fastest(const Image<I1>& input1_, const Image<I2>& input2_, + const Function_vv2v<F>& f_) + { + trace::entering("level::impl::transform_fastest"); + const I1& input1 = exact(input1_); + const I2& input2 = exact(input2_); + const F& f = exact(f_); + level::internal::transform_tests(input1, input2, f); + + typedef mln_ch_value(I1, mln_result(F)) O; + O output; + initialize(output, input1); + mln_pixter(O) po(output); + + mln_pixter(const I1) pi1(input1); + mln_pixter(const I2) pi2(input2); + for_all_3(pi1, pi2, po) + po.val() = f(pi1.val(), pi2.val()); + + trace::exiting("level::impl::transform_fastest"); return output; } - // Dispatch - // -------- + } // end of namespace mln::level::impl + + + + // Dispatch. + namespace internal { @@ -245,10 +264,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::undef, mln::trait::image::quant::any, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return impl::generic::transform(input, f); + return level::impl::generic::transform(input, f); } template <typename I, typename F> @@ -256,10 +274,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::vw_set::any, mln::trait::image::quant::any, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return impl::generic::transform(input, f); + return level::impl::generic::transform(input, f); } template <typename I, typename F> @@ -267,10 +284,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::vw_set::uni, mln::trait::image::quant::any, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return impl::transform_taken(input, f); + return level::impl::transform_taken(input, f); } @@ -279,10 +295,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::vw_set::any, mln::trait::image::quant::low, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return impl::transform_lowq(input, f); + return level::impl::transform_lowq(input, f); } @@ -292,10 +307,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::quant::any, mln::trait::image::value_access::direct, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return transform_fast(input, f); + return level::impl::transform_fast(input, f); } /// FIXME check that is right @@ -304,10 +318,9 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::quant::low, mln::trait::image::value_access::direct, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return transform_fast_lowq(input, f); + return level::impl::transform_fast_lowq(input, f); } @@ -317,8 +330,7 @@ mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::quant::any, mln::trait::image::value_access::any, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { return transform_dispatch(mln_trait_image_vw_set(I)(), mln_trait_image_quant(I)(), @@ -330,8 +342,7 @@ inline mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::value_storage::any, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { return transform_dispatch(mln_trait_image_vw_set(I)(), mln_trait_image_quant(I)(), @@ -342,18 +353,16 @@ inline mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::value_storage::singleton, - const Image<I>& input, - const Function_v2v<F>& f) + const Image<I>& input, const Function_v2v<F>& f) { - return transform_singleton(input, f); + return level::impl::transform_singleton(input, f); } template <typename I, typename F> inline mln_ch_value(I, mln_result(F)) transform_dispatch(mln::trait::image::value_storage::one_block, - const Image<I>& input_, - const Function_v2v<F>& f_) + const Image<I>& input_, const Function_v2v<F>& f_) { const I& input = exact(input_); @@ -371,20 +380,55 @@ + // Dispatch for transformation from a couple of images. + + template <typename I1, typename I2, typename F> + mln_ch_value(I1, mln_result(F)) + transform_dispatch_2(trait::image::speed::any, + trait::image::speed::any, + const Image<I1>& input1, const Image<I2>& input2, + const Function_vv2v<F>& f) + { + return level::impl::generic::transform(input1, input2, f); + } + + template <typename I1, typename I2, typename F> + mln_ch_value(I1, mln_result(F)) + transform_dispatch_2(trait::image::speed::fastest, + trait::image::speed::fastest, + const Image<I1>& input1, const Image<I2>& input2, + const Function_vv2v<F>& f) + { + return level::impl::transform_fastest(input1, input2, f); + } + + // end of Dispatch for transformation from a couple of images. + + + + // Dispatch entry points. + template <typename I, typename F> mln_ch_value(I, mln_result(F)) - transform_dispatch(const Image<I>& input, - const Function_v2v<F>& f) + transform_dispatch(const Image<I>& input, const Function_v2v<F>& f) { return transform_dispatch(mln_trait_image_value_storage(I)(), input, f); } + template <typename I1, typename I2, typename F> + mln_ch_value(I1, mln_result(F)) + transform_dispatch(const Image<I1>& input1, const Image<I2>& input2, + const Function_vv2v<F>& f) + { + return transform_dispatch_2(mln_trait_image_speed(I1)(), + mln_trait_image_speed(I2)(), + input1, input2, f); } + } // end of namespace mln::level::internal - } // end of namespace mln::level::impl } // end of namespace mln::level Index: mln/level/transform.hh --- mln/level/transform.hh (revision 2862) +++ mln/level/transform.hh (working copy) @@ -89,7 +89,6 @@ { template <typename I, typename F> - inline void transform_tests(const Image<I>& input, const Function_v2v<F>& f) { @@ -103,9 +102,7 @@ } template <typename I1, typename I2, typename F> - inline - void transform_tests(const Image<I1>& input1, - const Image<I2>& input2, + void transform_tests(const Image<I1>& input1, const Image<I2>& input2, const Function_vv2v<F>& f) { // Dynamic tests. @@ -135,7 +132,6 @@ { template <typename I, typename F> - inline mln_ch_value(I, mln_result(F)) transform(const Image<I>& input_, const Function_v2v<F>& f_) { @@ -162,7 +158,6 @@ template <typename I1, typename I2, typename F> - inline mln_ch_value(I1, mln_result(F)) transform(const Image<I1>& input1_, const Image<I2>& input2_, @@ -193,8 +188,10 @@ } // end of namespace mln::level::impl + // Facades. + template <typename I, typename F> inline mln_ch_value(I, mln_result(F)) @@ -205,17 +202,17 @@ internal::transform_tests(input, f); mln_ch_value(I, mln_result(F)) output; - output = impl::internal::transform_dispatch(exact(input), exact(f)); + output = internal::transform_dispatch(input, f); trace::exiting("level::transform"); return output; } + template <typename I1, typename I2, typename F> inline mln_ch_value(I1, mln_result(F)) - transform(const Image<I1>& input1, - const Image<I2>& input2, + transform(const Image<I1>& input1, const Image<I2>& input2, const Function_vv2v<F>& f) { trace::entering("level::transform"); @@ -223,7 +220,7 @@ internal::transform_tests(input1, input2, f); mln_ch_value(I1, mln_result(F)) output; - output = impl::generic::transform(input1, input2, f); + output = internal::transform_dispatch(input1, input2, f); trace::exiting("level::transform"); return output; Index: mln/level/transform_inplace.hh --- mln/level/transform_inplace.hh (revision 2862) +++ mln/level/transform_inplace.hh (working copy) @@ -31,6 +31,8 @@ /// \file mln/level/transform_inplace.hh /// /// Transform inplace the contents of an image through a function. +/// +/// \todo Take into account more properties; see level/transform.hh. # include <mln/core/concept/image.hh> # include <mln/core/concept/function.hh> @@ -75,6 +77,9 @@ # ifndef MLN_INCLUDE_ONLY + + // Tests. + namespace internal { @@ -116,7 +121,7 @@ mln_precondition(exact(aux).has_data()); mln_precondition(exact(aux).domain() == exact(ima).domain()); - // Avoid a warning. + // Avoid warnings. (void) ima; (void) aux; (void) f; @@ -128,13 +133,12 @@ namespace impl { + // Generic implementations. namespace generic { - // Generic implementation. template <typename I, typename F> - inline void transform_inplace(Image<I>& ima_, const Function_v2v<F>& f_) { @@ -155,10 +159,7 @@ trace::exiting("level::impl::generic::transform_inplace"); } - - // Generic implementation. template <typename I1, typename I2, typename F> - inline void transform_inplace(Image<I1>& ima_, const Image<I2>& aux_, const Function_vv2v<F>& f_) @@ -184,20 +185,131 @@ } // end of namespace mln::level::impl::generic + template <typename I, typename F> + void + transform_inplace_fastest(Image<I>& ima_, const Function_v2v<F>& f_) + { + trace::entering("level::impl::transform_inplace_fastest"); + + mlc_is(mln_trait_image_pw_io(I), + trait::image::pw_io::read_write)::check(); + + I& ima = exact(ima_); + const F& f = exact(f_); + + level::internal::transform_inplace_tests(ima, f); + + mln_pixter(I) p(ima); + for_all(p) + p.val() = f(p.val()); + + trace::exiting("level::impl::transform_inplace_fastest"); + } + + + template <typename I1, typename I2, typename F> + void + transform_inplace_fastest(Image<I1>& ima_, const Image<I2>& aux_, + const Function_vv2v<F>& f_) + { + trace::entering("level::impl::transform_inplace_fastest"); + + mlc_is(mln_trait_image_pw_io(I1), + trait::image::pw_io::read_write)::check(); + + I1& ima = exact(ima_); + const I2& aux = exact(aux_); + const F& f = exact(f_); + + level::internal::transform_inplace_tests(ima, aux, f); + + mln_pixter(I1) pi(ima); + mln_pixter(const I2) pa(aux); + for_all_2(pi, pa) + pi.val() = f(pi.val(), pa.val()); + + trace::exiting("level::impl::transform_inplace_fastest"); + } + + } // end of namespace mln::level::impl + + // Dispatch. + + namespace internal + { + + // (ima, f) version. + + template <typename I, typename F> + void + transform_inplace_dispatch(trait::image::speed::any, + Image<I>& ima, const Function_v2v<F>& f) + { + level::impl::generic::transform_inplace(ima, f); + } + + template <typename I, typename F> + void + transform_inplace_dispatch(trait::image::speed::fastest, + Image<I>& ima, const Function_v2v<F>& f) + { + level::impl::transform_inplace_fastest(ima, f); + } + + template <typename I, typename F> + void + transform_inplace_dispatch(Image<I>& ima, const Function_v2v<F>& f) + { + transform_inplace_dispatch(mln_trait_image_speed(I)(), + ima, f); + } + + // (ima, aux, f) version. + + template <typename I1, typename I2, typename F> + void + transform_inplace_dispatch(trait::image::speed::any, + trait::image::speed::any, + Image<I1>& ima, const Image<I2>& aux, const Function_vv2v<F>& f) + { + level::impl::generic::transform_inplace(ima, aux, f); + } + + template <typename I1, typename I2, typename F> + void + transform_inplace_dispatch(trait::image::speed::fastest, + trait::image::speed::fastest, + Image<I1>& ima, const Image<I2>& aux, const Function_vv2v<F>& f) + { + level::impl::transform_inplace_fastest(ima, aux, f); + } + + template <typename I1, typename I2, typename F> + void + transform_inplace_dispatch(Image<I1>& ima, const Image<I2>& aux, const Function_vv2v<F>& f) + { + transform_inplace_dispatch(mln_trait_image_speed(I1)(), + mln_trait_image_speed(I2)(), + ima, aux, f); + } + + } // end of namespace mln::level::internal + + + // Facades. template <typename I, typename F> - inline void transform_inplace(Image<I>& ima, const Function_v2v<F>& f) { trace::entering("level::transform_inplace"); - level::internal::transform_inplace_tests(ima, f); - impl::generic::transform_inplace(ima, f); + internal::transform_inplace_tests(ima, f); + internal::transform_inplace_dispatch(ima, f); trace::exiting("level::transform_inplace"); } @@ -209,8 +321,8 @@ { trace::entering("level::transform_inplace"); - level::internal::transform_inplace_tests(ima, aux, f); - impl::generic::transform_inplace(ima, aux, f); + internal::transform_inplace_tests(ima, aux, f); + internal::transform_inplace_dispatch(ima, aux, f); trace::exiting("level::transform_inplace"); } Index: mln/fun/vv2v/min.hh --- mln/fun/vv2v/min.hh (revision 2862) +++ mln/fun/vv2v/min.hh (working copy) @@ -29,7 +29,8 @@ # define MLN_FUN_VV2V_MIN_HH /// \file mln/fun/vv2v/min.hh -/// \brief computing the minimum of two values using a functor. +/// +/// Functor that computes the minimum of two values. # include <mln/core/concept/function.hh> # include <mln/math/min.hh> @@ -47,22 +48,23 @@ // FIXME: Doc. /// \brief A functor computing the minimum of two values. - template <typename V> - struct min : public Function_vv2v< min<V> > + template <typename L, typename R = L> + struct min : public Function_vv2v< min<L,R> >, + private mlc_converts_to(R,L)::check_t { - typedef V result; - V operator()(const V& v1, const V& v2) const; + typedef L result; + L operator()(const L& v1, const R& v2) const; }; # ifndef MLN_INCLUDE_ONLY - template <typename V> + template <typename L, typename R> inline - V - min<V>::operator()(const V& v1, const V& v2) const + L + min<L,R>::operator()(const L& v1, const R& v2) const { - return mln::math::min(v1, v2); + return mln::math::min(v1, L(v2)); } # endif // ! MLN_INCLUDE_ONLY Index: mln/fun/vv2v/macros.hh --- mln/fun/vv2v/macros.hh (revision 0) +++ mln/fun/vv2v/macros.hh (revision 0) @@ -0,0 +1,48 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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 MLN_FUN_VV2V_MACROS_HH +# define MLN_FUN_VV2V_MACROS_HH + +/// \file mln/fun/vv2v/macros.hh +/// +/// Define a bunch of macros related to a binary function and a couple +/// of images. + + +#define mln_fun_vv2v(F, L, R) mln::fun::vv2v::F< mln_value(L), mln_value(R) > + + +#define mln_fun_vv2v_result(F, L, R) typename mln_fun_vv2v(F, L, R)::result + + +#define mln_ch_fun_vv2v(F, L, R) \ + typename mln::trait::ch_value< L, \ + typename mln_fun_vv2v(F, L, R)::result >::ret + + +#endif // ! MLN_FUN_VV2V_MACROS_HH Index: mln/fun/vv2v/all.hh --- mln/fun/vv2v/all.hh (revision 2862) +++ mln/fun/vv2v/all.hh (working copy) @@ -48,6 +48,9 @@ } +# include <mln/fun/vv2v/macros.hh> + +# include <mln/fun/vv2v/land.hh> # include <mln/fun/vv2v/max.hh> # include <mln/fun/vv2v/min.hh> # include <mln/fun/vv2v/vec.hh> Index: mln/fun/vv2v/land.hh --- mln/fun/vv2v/land.hh (revision 0) +++ mln/fun/vv2v/land.hh (revision 0) @@ -0,0 +1,76 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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 MLN_FUN_VV2V_LAND_HH +# define MLN_FUN_VV2V_LAND_HH + +/// \file mln/fun/vv2v/land.hh +/// +/// Functor that computes "logical and" between two values. + +# include <mln/core/concept/function.hh> +# include <mln/trait/op/and.hh> + + +namespace mln +{ + + namespace fun + { + + namespace vv2v + { + + /// Functor computing logical-and between two values. + template <typename L, typename R = L> + struct land : public Function_vv2v< land<L,R> > + { + typedef mln_trait_op_and(L, R) result; + result operator()(const L& v1, const R& v2) const; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename L, typename R> + inline + typename land<L,R>::result + land<L,R>::operator()(const L& v1, const R& v2) const + { + return v1 && v2; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::vv2v + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_VV2V_LAND_HH Index: mln/logical/and.hh --- mln/logical/and.hh (revision 2862) +++ mln/logical/and.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,18 +29,14 @@ #ifndef MLN_LOGICAL_AND_HH # define MLN_LOGICAL_AND_HH -/*! \file mln/logical/and.hh - * - * \brief Point-wise "logical and" between binary images. - * - * \todo Add static assertion and save one iterator in in-place version. - */ - -# include <mln/core/concept/image.hh> - +/// \file mln/logical/and.hh +/// +/// Point-wise "logical and" between binary images. +/// +/// \todo Add static assertion and save one iterator in in-place version. -// Specializations are in: -# include <mln/logical/and.spe.hh> +# include <mln/logical/includes.hh> +# include <mln/fun/vv2v/land.hh> namespace mln @@ -57,7 +54,8 @@ * \pre \p lhs.domain == \p rhs.domain */ template <typename L, typename R> - mln_concrete(L) and_(const Image<L>& lhs, const Image<R>& rhs); + mln_ch_fun_vv2v(land, L, R) + and_(const Image<L>& lhs, const Image<R>& rhs); /*! Point-wise in-place "logical and" of image \p rhs in image \p lhs. @@ -77,44 +75,17 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - namespace generic - { - - template <typename L, typename R, typename O> - inline - void and__(const L& lhs, const R& rhs, O& output) - { - trace::entering("logical::impl::generic::and__"); - - mln_piter(L) p(lhs.domain()); - for_all(p) - output(p) = lhs(p) && rhs(p); - - trace::exiting("logical::impl::generic::and__"); - } - - } // end of namespace mln::logical::impl::generic - - } // end of namespace mln::logical::impl - - - // Facades. - template <typename L, typename R> inline - mln_concrete(L) and_(const Image<L>& lhs, const Image<R>& rhs) + mln_ch_fun_vv2v(land, L, R) + and_(const Image<L>& lhs, const Image<R>& rhs) { trace::entering("logical::and_"); - mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + internal::tests(lhs, rhs); - mln_concrete(L) output; - initialize(output, lhs); - impl::and__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), output); + mln_fun_vv2v(land, L, R) f; + mln_ch_fun_vv2v(land, L, R) output = level::transform(lhs, rhs, f); trace::exiting("logical::and_"); return output; @@ -126,10 +97,13 @@ { trace::entering("logical::and_inplace"); - mln_precondition(exact(rhs).domain() >= exact(lhs).domain()); + mlc_converts_to(mln_fun_vv2v_result(land, L, R), + mln_value(L))::check(); + + internal::tests(lhs, rhs); - impl::and__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), exact(lhs)); + mln_fun_vv2v(land, L, R) f; + level::transform_inplace(lhs, rhs, f); trace::exiting("logical::and_inplace"); } Index: mln/logical/includes.hh --- mln/logical/includes.hh (revision 0) +++ mln/logical/includes.hh (revision 0) @@ -0,0 +1,77 @@ +// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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 MLN_LOGICAL_INCLUDES_HH +# define MLN_LOGICAL_INCLUDES_HH + +/// \file mln/logical/includes.hh + + +# include <mln/core/concept/image.hh> +# include <mln/level/transform.hh> +# include <mln/level/transform_inplace.hh> +# include <mln/fun/vv2v/macros.hh> + + + +# ifndef MLN_INCLUDE_ONLY + +namespace mln +{ + + namespace logical + { + + namespace internal + { + + template <typename L, typename R> + inline + void + tests(const Image<L>& lhs_, const Image<R>& rhs_) + { + const L& lhs = exact(lhs_); + const R& rhs = exact(rhs_); + + mln_precondition(lhs.has_data()); + mln_precondition(rhs.has_data()); + mln_precondition(rhs.domain() == lhs.domain()); + + (void) lhs; + (void) rhs; + } + + } // end of namespace mln::logical::internal + + } // end of namespace mln::logical + +} // end of namespace mln + +# endif // ! MLN_INCLUDE_ONLY + + +#endif // ! MLN_LOGICAL_INCLUDES_HH Index: mln/logical/all.hh --- mln/logical/all.hh (revision 2862) +++ mln/logical/all.hh (working copy) @@ -1,4 +1,5 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -28,10 +29,9 @@ #ifndef MLN_LOGICAL_ALL_HH # define MLN_LOGICAL_ALL_HH -/*! \file mln/logical/all.hh - * - * \brief File that includes all logical operators. - */ +/// \file mln/logical/all.hh +/// +/// File that includes all logical operators. namespace mln @@ -47,11 +47,10 @@ namespace generic {} } - } - } +# include <mln/logical/includes.hh> # include <mln/logical/and.hh> # include <mln/logical/and_not.hh> # include <mln/logical/not.hh>
participants (1)
-
Thierry Geraud