proto-1.0 90: Add arith::min and arith::max

Index: ChangeLog from Damien Thivolle <damien@lrde.epita.fr> * tests/arith: New. * tests/arith/tests: New. * tests/arith/tests/min: New. * tests/arith/tests/max: New. * tests/arith/Makefile.am: New. * oln/basics.hh: Include oln/core/abstract/op.hh. * oln/arith: New. * oln/arith/min.hh: Compute the pointwise minimum between two images. * oln/arith/max.hh: Compute the pointwise maximum between two images. oln/arith/max.hh | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ oln/arith/min.hh | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ oln/basics.hh | 1 oln/makefile.src | 2 tests/arith/Makefile.am | 5 ++ tests/arith/tests/max | 25 +++++++++++ tests/arith/tests/min | 27 ++++++++++++ 7 files changed, 268 insertions(+) Index: tests/arith/tests/min --- tests/arith/tests/min (revision 0) +++ tests/arith/tests/min (revision 0) @@ -0,0 +1,27 @@ +#include <oln/basics2d.hh> +#include <oln/arith/min.hh> +#include <oln/level/fill.hh> +#include <oln/level/compare.hh> +#include <ntg/int.hh> + + + +bool check() +{ + oln::image2d<ntg::int_u8> ima1(10, 10); + oln::image2d<ntg::int_u8> ima2(10, 10); + + oln::level::fill(ima1, 10); + oln::level::fill(ima2, 20); + + oln::image2d<ntg::int_u8> ima; + + ima = oln::arith::min(ima1, ima2); + + if (oln::level::is_equal(ima, ima1)) + return false; + return true; +} + + + Index: tests/arith/tests/max --- tests/arith/tests/max (revision 0) +++ tests/arith/tests/max (revision 0) @@ -0,0 +1,25 @@ +#include <oln/basics2d.hh> +#include <oln/arith/max.hh> +#include <oln/level/fill.hh> +#include <oln/level/compare.hh> +#include <ntg/int.hh> + + + +bool check() +{ + oln::image2d<ntg::int_u8> ima1(10, 10); + oln::image2d<ntg::int_u8> ima2(10, 10); + + oln::level::fill(ima1, 10); + oln::level::fill(ima2, 20); + + oln::image2d<ntg::int_u8> ima; + + ima = oln::arith::max(ima1, ima2); + + if (oln::level::is_equal(ima, ima2)) + return false; + return true; +} + Index: tests/arith/Makefile.am --- tests/arith/Makefile.am (revision 0) +++ tests/arith/Makefile.am (revision 0) @@ -0,0 +1,5 @@ +include ../check/Makefile.runtests +include ../check/Makefile.check + + +check-local: check-runtests Index: oln/basics.hh --- oln/basics.hh (revision 89) +++ oln/basics.hh (working copy) @@ -58,6 +58,7 @@ # include <oln/core/abstract/point.hh> # include <oln/core/abstract/images.hh> # include <oln/core/abstract/entry.hh> +# include <oln/core/abstract/op.hh> # include <oln/core/abstract/piter.hh> # include <oln/core/abstract/witer.hh> Index: oln/makefile.src --- oln/makefile.src (revision 89) +++ oln/makefile.src (working copy) @@ -5,6 +5,8 @@ OLN_DEP = \ all.hh \ + arith/max.hh \ + arith/min.hh \ basics.hh \ basics1d.hh \ basics2d.hh \ Index: oln/arith/min.hh --- oln/arith/min.hh (revision 0) +++ oln/arith/min.hh (revision 0) @@ -0,0 +1,104 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_ARITH_MIN_HH +# define OLENA_ARITH_MIN_HH + +# include <oln/basics.hh> +# include <ntg/all.hh> + +namespace oln { + + namespace arith { + // fwd decl + namespace impl { + template <typename I> struct min_type; + } + + } + + // category + template <typename I> + struct set_category< arith::impl::min_type<I> > + { + typedef category::image ret; + }; + + // super_type + template <typename I> + struct set_super_type< arith::impl::min_type<I> > + { + typedef abstract::op<I, arith::impl::min_type<I> > ret; + }; + + namespace arith { + + namespace impl { + + template <class I> + struct min_type : abstract::op<I, min_type<I> > + { + mlc::box<const I> input1_; + mlc::box<const I> input2_; + + min_type(const abstract::non_vectorial_image<I>& input1, + const abstract::non_vectorial_image<I>& input2) : + input1_(input1.exact()), + input2_(input2.exact()) + {} + + void impl_run() + { + precondition(input1_->size() == input2_->size()); + I output(input1_->size()); + oln_type_of(I, fwd_piter) p(input1_->size()); + + for_all(p) + output[p] = ntg::min((*input1_)[p].value(), (*input2_)[p].value()); + + *this->image_ = output; + } + + }; + + } + + template <typename I> + impl::min_type<I> min(const abstract::non_vectorial_image<I>& input1, + const abstract::non_vectorial_image<I>& input2) + { + impl::min_type<I> tmp(input1, input2); + tmp.run(); + return tmp; + } + + } + +} // end of namespace oln + + +#endif // ! OLENA_ARITH_MIN_HH Index: oln/arith/max.hh --- oln/arith/max.hh (revision 0) +++ oln/arith/max.hh (revision 0) @@ -0,0 +1,104 @@ +// Copyright (C) 2005 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, 59 Temple Place - Suite 330, 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 OLENA_ARITH_MAX_HH +# define OLENA_ARITH_MAX_HH + +# include <oln/basics.hh> +# include <ntg/all.hh> + +namespace oln { + + namespace arith { + // fwd decl + namespace impl { + template <typename I> struct max_type; + } + + } + + // category + template <typename I> + struct set_category< arith::impl::max_type<I> > + { + typedef category::image ret; + }; + + // super_type + template <typename I> + struct set_super_type< arith::impl::max_type<I> > + { + typedef abstract::op<I, arith::impl::max_type<I> > ret; + }; + + namespace arith { + + namespace impl { + + template <class I> + struct max_type : abstract::op<I, max_type<I> > + { + mlc::box<const I> input1_; + mlc::box<const I> input2_; + + max_type(const abstract::non_vectorial_image<I>& input1, + const abstract::non_vectorial_image<I>& input2) : + input1_(input1.exact()), + input2_(input2.exact()) + {} + + void impl_run() + { + precondition(input1_->size() == input2_->size()); + I output(input1_->size()); + oln_type_of(I, fwd_piter) p(input1_->size()); + + for_all(p) + output[p] = ntg::max((*input1_)[p].value(), (*input2_)[p].value()); + + *this->image_ = output; + } + + }; + + } + + template <typename I> + impl::max_type<I> max(const abstract::non_vectorial_image<I>& input1, + const abstract::non_vectorial_image<I>& input2) + { + impl::max_type<I> tmp(input1, input2); + tmp.run(); + return tmp; + } + + } + +} // end of namespace oln + + +#endif // ! OLENA_ARITH_MAX_HH
participants (1)
-
Damien Thivolle