cleanup-2008 2868: Update logical binary routines.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update logical binary routines. * mln/trait/op/all.hh (include): Remove duplicate. * mln/fun/vv2v/lxor.hh: New. * mln/fun/vv2v/lor.hh: New. * mln/fun/vv2v/land_not.hh: New. * mln/fun/vv2v/all.hh: Update. * mln/logical/or.hh, * mln/logical/and_not.hh, * mln/logical/and.hh: Rely on level transform. * mln/logical/or.spe.hh, * mln/logical/and_not.spe.hh: Remove; obsolete. * mln/logical/xor.hh: New. * mln/logical/all.hh: Update. * tests/logical/xor.cc: New. * tests/logical/Makefile.am: Update. mln/fun/vv2v/all.hh | 3 + mln/fun/vv2v/land_not.hh | 23 ++++++----- mln/fun/vv2v/lor.hh | 24 ++++++------ mln/fun/vv2v/lxor.hh | 26 +++++++------ mln/logical/all.hh | 1 mln/logical/and.hh | 2 - mln/logical/and_not.hh | 70 +++++++++++------------------------ mln/logical/or.hh | 68 ++++++++++------------------------ mln/logical/xor.hh | 92 ++++++++++++++++------------------------------ mln/trait/op/all.hh | 1 tests/logical/Makefile.am | 4 +- tests/logical/xor.cc | 24 ++++++------ 12 files changed, 133 insertions(+), 205 deletions(-) Index: tests/logical/Makefile.am --- tests/logical/Makefile.am (revision 2867) +++ tests/logical/Makefile.am (working copy) @@ -7,12 +7,14 @@ and \ and_not \ not \ - or + or \ + xor all_headers_SOURCES = all_headers.cc and_SOURCES = and.cc and_not_SOURCES = and_not.cc not_SOURCES = not.cc or_SOURCES = or.cc +xor_SOURCES = xor.cc TESTS = $(check_PROGRAMS) Index: tests/logical/xor.cc --- tests/logical/xor.cc (revision 2864) +++ tests/logical/xor.cc (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 @@ -25,13 +26,12 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/logical/or.cc - * - * \brief Tests on mln::logical::or. - */ +/// \file tests/logical/xor.cc +/// +/// Tests on mln::logical::xor. #include <mln/core/image/image2d.hh> -#include <mln/logical/or.hh> +#include <mln/logical/xor.hh> #include <mln/level/compare.hh> @@ -52,14 +52,14 @@ }; bool ws[3][3] = { - {1, 1, 1}, {0, 1, 0}, - {1, 1, 1} + {0, 0, 0}, + {0, 1, 0} }; - image2d<bool> ima1 (make::image(vs)); - image2d<bool> ima2 (make::image(us)); - image2d<bool> ref (make::image(ws)); + image2d<bool> ima1 = make::image(vs); + image2d<bool> ima2 = make::image(us); + image2d<bool> ref = make::image(ws); - mln_assertion (logical::or_(ima1, ima2) == ref); + mln_assertion (logical::xor_(ima1, ima2) == ref); } Property changes on: tests/logical/xor.cc ___________________________________________________________________ Added: svn:mergeinfo Index: mln/trait/op/all.hh --- mln/trait/op/all.hh (revision 2867) +++ mln/trait/op/all.hh (working copy) @@ -66,7 +66,6 @@ # include <mln/trait/op/less.hh> # include <mln/trait/op/leq.hh> -# include <mln/trait/op/lor.hh> # include <mln/trait/op/geq.hh> # include <mln/trait/op/greater.hh> Index: mln/fun/vv2v/lxor.hh --- mln/fun/vv2v/lxor.hh (revision 2864) +++ mln/fun/vv2v/lxor.hh (working copy) @@ -25,15 +25,15 @@ // 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 +#ifndef MLN_FUN_VV2V_LXOR_HH +# define MLN_FUN_VV2V_LXOR_HH -/// \file mln/fun/vv2v/land.hh +/// \file mln/fun/vv2v/lxor.hh /// -/// Functor that computes "logical and" between two values. +/// Functor that computes "logical xor" between two values. # include <mln/core/concept/function.hh> -# include <mln/trait/op/and.hh> +# include <mln/trait/op/xor.hh> namespace mln @@ -45,11 +45,11 @@ namespace vv2v { - /// Functor computing logical-and between two values. + /// Functor computing logical-xor between two values. template <typename L, typename R = L> - struct land : public Function_vv2v< land<L,R> > + struct lxor : public Function_vv2v< lxor<L,R> > { - typedef mln_trait_op_and(L, R) result; + typedef mln_trait_op_or(L, R) result; result operator()(const L& v1, const R& v2) const; }; @@ -58,10 +58,12 @@ template <typename L, typename R> inline - typename land<L,R>::result - land<L,R>::operator()(const L& v1, const R& v2) const + typename lxor<L,R>::result + lxor<L,R>::operator()(const L& v1, const R& v2) const { - return v1 && v2; + // v1 xor v2 = (v1 and (not v2)) or ((not v1) and v2) + // = (not (v1 and v2)) and (v1 or v2) + return (! (v1 && v2)) && (v1 || v2); } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +75,4 @@ } // end of namespace mln -#endif // ! MLN_FUN_VV2V_LAND_HH +#endif // ! MLN_FUN_VV2V_LXOR_HH Property changes on: mln/fun/vv2v/lxor.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/fun/vv2v/all.hh --- mln/fun/vv2v/all.hh (revision 2867) +++ mln/fun/vv2v/all.hh (working copy) @@ -51,6 +51,9 @@ # include <mln/fun/vv2v/macros.hh> # include <mln/fun/vv2v/land.hh> +# include <mln/fun/vv2v/land_not.hh> +# include <mln/fun/vv2v/lor.hh> +# include <mln/fun/vv2v/lxor.hh> # include <mln/fun/vv2v/max.hh> # include <mln/fun/vv2v/min.hh> # include <mln/fun/vv2v/vec.hh> Index: mln/fun/vv2v/lor.hh --- mln/fun/vv2v/lor.hh (revision 2864) +++ mln/fun/vv2v/lor.hh (working copy) @@ -25,15 +25,15 @@ // 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 +#ifndef MLN_FUN_VV2V_LOR_HH +# define MLN_FUN_VV2V_LOR_HH -/// \file mln/fun/vv2v/land.hh +/// \file mln/fun/vv2v/lor.hh /// -/// Functor that computes "logical and" between two values. +/// Functor that computes "logical or" between two values. # include <mln/core/concept/function.hh> -# include <mln/trait/op/and.hh> +# include <mln/trait/op/or.hh> namespace mln @@ -45,11 +45,11 @@ namespace vv2v { - /// Functor computing logical-and between two values. + /// Functor computing logical-or between two values. template <typename L, typename R = L> - struct land : public Function_vv2v< land<L,R> > + struct lor : public Function_vv2v< lor<L,R> > { - typedef mln_trait_op_and(L, R) result; + typedef mln_trait_op_or(L, R) result; result operator()(const L& v1, const R& v2) const; }; @@ -58,10 +58,10 @@ template <typename L, typename R> inline - typename land<L,R>::result - land<L,R>::operator()(const L& v1, const R& v2) const + typename lor<L,R>::result + lor<L,R>::operator()(const L& v1, const R& v2) const { - return v1 && v2; + return v1 || v2; } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +73,4 @@ } // end of namespace mln -#endif // ! MLN_FUN_VV2V_LAND_HH +#endif // ! MLN_FUN_VV2V_LOR_HH Property changes on: mln/fun/vv2v/lor.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/fun/vv2v/land_not.hh --- mln/fun/vv2v/land_not.hh (revision 2864) +++ mln/fun/vv2v/land_not.hh (working copy) @@ -25,15 +25,16 @@ // 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 +#ifndef MLN_FUN_VV2V_LAND_NOT_HH +# define MLN_FUN_VV2V_LAND_NOT_HH -/// \file mln/fun/vv2v/land.hh +/// \file mln/fun/vv2v/land_not.hh /// -/// Functor that computes "logical and" between two values. +/// Functor that computes "logical and-not" between two values. # include <mln/core/concept/function.hh> # include <mln/trait/op/and.hh> +# include <mln/trait/op/not.hh> namespace mln @@ -45,11 +46,11 @@ namespace vv2v { - /// Functor computing logical-and between two values. + /// Functor computing logical and-not between two values. template <typename L, typename R = L> - struct land : public Function_vv2v< land<L,R> > + struct land_not : public Function_vv2v< land_not<L,R> > { - typedef mln_trait_op_and(L, R) result; + typedef mln_trait_op_and(L, mln_trait_op_not(R)) result; result operator()(const L& v1, const R& v2) const; }; @@ -58,10 +59,10 @@ template <typename L, typename R> inline - typename land<L,R>::result - land<L,R>::operator()(const L& v1, const R& v2) const + typename land_not<L,R>::result + land_not<L,R>::operator()(const L& v1, const R& v2) const { - return v1 && v2; + return v1 && ! v2; } # endif // ! MLN_INCLUDE_ONLY @@ -73,4 +74,4 @@ } // end of namespace mln -#endif // ! MLN_FUN_VV2V_LAND_HH +#endif // ! MLN_FUN_VV2V_LAND_NOT_HH Property changes on: mln/fun/vv2v/land_not.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/logical/and_not.hh --- mln/logical/and_not.hh (revision 2867) +++ mln/logical/and_not.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,12 @@ #ifndef MLN_LOGICAL_AND_NOT_HH # define MLN_LOGICAL_AND_NOT_HH -/*! \file mln/logical/and_not.hh - * - * \brief Point-wise logical "and not" 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_not.hh +/// +/// Point-wise "logical and-not" between binary images. -// Specializations are in: -# include <mln/logical/and_not.spe.hh> +# include <mln/logical/includes.hh> +# include <mln/fun/vv2v/land_not.hh> namespace mln @@ -48,7 +43,7 @@ namespace logical { - /*! Point-wise logical "and not" between images \p lhs and \p rhs. + /*! Point-wise "logical and-not" between images \p lhs and \p rhs. * * \param[in] lhs First operand image. * \param[in] rhs Second operand image. @@ -57,10 +52,11 @@ * \pre \p lhs.domain == \p rhs.domain */ template <typename L, typename R> - mln_concrete(L) and_not(const Image<L>& lhs, const Image<R>& rhs); + mln_ch_fun_vv2v(land_not, L, R) + and_not(const Image<L>& lhs, const Image<R>& rhs); - /*! Point-wise in-place logical "and not" of image \p rhs in image \p lhs. + /*! Point-wise in-place "logical and-not" of image \p rhs in image \p lhs. * * \param[in,out] lhs First operand image. * \param[in] rhs Second operand image. @@ -77,42 +73,17 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - namespace generic - { - template <typename L, typename R, typename O> - inline - void and_not_(const L& lhs, const R& rhs, O& output) - { - trace::entering("logical::impl::generic::and_not_"); - - mln_piter(L) p(lhs.domain()); - for_all(p) - output(p) = lhs(p) && ! rhs(p); - - trace::exiting("logical::impl::generic::and_not_"); - } - } - - } // end of namespace mln::logical::impl - - - // Facades. - template <typename L, typename R> inline - mln_concrete(L) and_not(const Image<L>& lhs, const Image<R>& rhs) + mln_ch_fun_vv2v(land_not, L, R) + and_not(const Image<L>& lhs, const Image<R>& rhs) { trace::entering("logical::and_not"); - mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + internal::tests(lhs, rhs); - mln_concrete(L) output; - initialize(output, lhs); - impl::and_not_(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), output); + mln_fun_vv2v(land_not, L, R) f; + mln_ch_fun_vv2v(land_not, L, R) output = level::transform(lhs, rhs, f); trace::exiting("logical::and_not"); return output; @@ -124,10 +95,13 @@ { trace::entering("logical::and_not_inplace"); - mln_precondition(exact(rhs).domain() >= exact(lhs).domain()); + mlc_converts_to(mln_fun_vv2v_result(land_not, L, R), + mln_value(L))::check(); + + internal::tests(lhs, rhs); - impl::and_not_(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), exact(lhs)); + mln_fun_vv2v(land_not, L, R) f; + level::transform_inplace(lhs, rhs, f); trace::exiting("logical::and_not_inplace"); } Index: mln/logical/and.hh --- mln/logical/and.hh (revision 2867) +++ mln/logical/and.hh (working copy) @@ -32,8 +32,6 @@ /// \file mln/logical/and.hh /// /// Point-wise "logical and" between binary images. -/// -/// \todo Add static assertion and save one iterator in in-place version. # include <mln/logical/includes.hh> # include <mln/fun/vv2v/land.hh> Index: mln/logical/all.hh --- mln/logical/all.hh (revision 2867) +++ mln/logical/all.hh (working copy) @@ -55,6 +55,7 @@ # include <mln/logical/and_not.hh> # include <mln/logical/not.hh> # include <mln/logical/or.hh> +# include <mln/logical/xor.hh> #endif // ! MLN_LOGICAL_ALL_HH Index: mln/logical/xor.hh --- mln/logical/xor.hh (revision 2864) +++ mln/logical/xor.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 @@ -25,21 +26,15 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef MLN_LOGICAL_OR_HH -# define MLN_LOGICAL_OR_HH - -/*! \file mln/logical/or.hh - * - * \brief Point-wise "logical or" between binary images. - * - * \todo Add static assertion and save one iterator in in-place version. - */ - -# include <mln/core/concept/image.hh> +#ifndef MLN_LOGICAL_XOR_HH +# define MLN_LOGICAL_XOR_HH +/// \file mln/logical/xor.hh +/// +/// Point-wise "logical xor" between binary images. -// Specializations are in: -# include <mln/logical/or.spe.hh> +# include <mln/logical/includes.hh> +# include <mln/fun/vv2v/lxor.hh> namespace mln @@ -48,7 +43,7 @@ namespace logical { - /*! Point-wise "logical or" between images \p lhs and \p rhs. + /*! Point-wise "logical xor" between images \p lhs and \p rhs. * * \param[in] lhs First operand image. * \param[in] rhs Second operand image. @@ -57,79 +52,58 @@ * \pre \p lhs.domain == \p rhs.domain */ template <typename L, typename R> - mln_concrete(L) or_(const Image<L>& lhs, const Image<R>& rhs); + mln_ch_fun_vv2v(lxor, L, R) + xor_(const Image<L>& lhs, const Image<R>& rhs); - /*! Point-wise in-place "logical or" of image \p rhs in image \p lhs. + /*! Point-wise in-place "logical xor" of image \p rhs in image \p lhs. * * \param[in,out] lhs First operand image. * \param[in] rhs Second operand image. * * It performs: \n - * for all p of lhs.domain \n - * lhs(p) = lhs(p) or rhs(p) + * for all p of rhs.domain \n + * lhs(p) = lhs(p) xor rhs(p) * * \pre \p rhs.domain >= \p lhs.domain */ template <typename L, typename R> - void or_inplace(Image<L>& lhs, const Image<R>& rhs); + void xor_inplace(Image<L>& lhs, const Image<R>& rhs); # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - namespace generic - { - template <typename L, typename R, typename O> - inline - void or__(const L& lhs, const R& rhs, O& output) - { - trace::entering("logical::impl::generic::or__"); - - mln_piter(L) p(lhs.domain()); - for_all(p) - output(p) = lhs(p) || rhs(p); - - trace::exiting("logical::impl::generic::or__"); - } - } - - } // end of namespace mln::logical::impl - - - // Facades. - template <typename L, typename R> inline - mln_concrete(L) or_(const Image<L>& lhs, const Image<R>& rhs) + mln_ch_fun_vv2v(lxor, L, R) + xor_(const Image<L>& lhs, const Image<R>& rhs) { - trace::entering("logical::or_"); + trace::entering("logical::xor_"); - mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + internal::tests(lhs, rhs); - mln_concrete(L) output; - initialize(output, lhs); - impl::or__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), output); + mln_fun_vv2v(lxor, L, R) f; + mln_ch_fun_vv2v(lxor, L, R) output = level::transform(lhs, rhs, f); - trace::exiting("logical::or_"); + trace::exiting("logical::xor_"); return output; } template <typename L, typename R> inline - void or_inplace(Image<L>& lhs, const Image<R>& rhs) + void xor_inplace(Image<L>& lhs, const Image<R>& rhs) { - trace::entering("logical::or_inplace"); + trace::entering("logical::xor_inplace"); + + mlc_converts_to(mln_fun_vv2v_result(lxor, L, R), + mln_value(L))::check(); - mln_precondition(exact(rhs).domain() >= exact(lhs).domain()); + internal::tests(lhs, rhs); - impl::or__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), exact(lhs)); + mln_fun_vv2v(lxor, L, R) f; + level::transform_inplace(lhs, rhs, f); - trace::exiting("logical::or_inplace"); + trace::exiting("logical::xor_inplace"); } # endif // ! MLN_INCLUDE_ONLY @@ -139,4 +113,4 @@ } // end of namespace mln -#endif // ! MLN_LOGICAL_OR_HH +#endif // ! MLN_LOGICAL_XOR_HH Property changes on: mln/logical/xor.hh ___________________________________________________________________ Added: svn:mergeinfo Index: mln/logical/or.hh --- mln/logical/or.hh (revision 2867) +++ mln/logical/or.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,12 @@ #ifndef MLN_LOGICAL_OR_HH # define MLN_LOGICAL_OR_HH -/*! \file mln/logical/or.hh - * - * \brief Point-wise "logical or" between binary images. - * - * \todo Add static assertion and save one iterator in in-place version. - */ - -# include <mln/core/concept/image.hh> - +/// \file mln/logical/or.hh +/// +/// Point-wise "logical or" between binary images. -// Specializations are in: -# include <mln/logical/or.spe.hh> +# include <mln/logical/includes.hh> +# include <mln/fun/vv2v/lor.hh> namespace mln @@ -57,7 +52,8 @@ * \pre \p lhs.domain == \p rhs.domain */ template <typename L, typename R> - mln_concrete(L) or_(const Image<L>& lhs, const Image<R>& rhs); + mln_ch_fun_vv2v(lor, L, R) + or_(const Image<L>& lhs, const Image<R>& rhs); /*! Point-wise in-place "logical or" of image \p rhs in image \p lhs. @@ -66,7 +62,7 @@ * \param[in] rhs Second operand image. * * It performs: \n - * for all p of lhs.domain \n + * for all p of rhs.domain \n * lhs(p) = lhs(p) or rhs(p) * * \pre \p rhs.domain >= \p lhs.domain @@ -77,42 +73,17 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - namespace generic - { - template <typename L, typename R, typename O> - inline - void or__(const L& lhs, const R& rhs, O& output) - { - trace::entering("logical::impl::generic::or__"); - - mln_piter(L) p(lhs.domain()); - for_all(p) - output(p) = lhs(p) || rhs(p); - - trace::exiting("logical::impl::generic::or__"); - } - } - - } // end of namespace mln::logical::impl - - - // Facades. - template <typename L, typename R> inline - mln_concrete(L) or_(const Image<L>& lhs, const Image<R>& rhs) + mln_ch_fun_vv2v(lor, L, R) + or_(const Image<L>& lhs, const Image<R>& rhs) { trace::entering("logical::or_"); - mln_precondition(exact(rhs).domain() == exact(lhs).domain()); + internal::tests(lhs, rhs); - mln_concrete(L) output; - initialize(output, lhs); - impl::or__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), output); + mln_fun_vv2v(lor, L, R) f; + mln_ch_fun_vv2v(lor, L, R) output = level::transform(lhs, rhs, f); trace::exiting("logical::or_"); return output; @@ -124,10 +95,13 @@ { trace::entering("logical::or_inplace"); - mln_precondition(exact(rhs).domain() >= exact(lhs).domain()); + mlc_converts_to(mln_fun_vv2v_result(lor, L, R), + mln_value(L))::check(); + + internal::tests(lhs, rhs); - impl::or__(mln_trait_image_speed(L)(), exact(lhs), - mln_trait_image_speed(R)(), exact(rhs), exact(lhs)); + mln_fun_vv2v(lor, L, R) f; + level::transform_inplace(lhs, rhs, f); trace::exiting("logical::or_inplace"); }
participants (1)
-
Thierry Geraud