
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add norm functors. * mln/fun/v2v/norm.hh: New. Provide norm functors. * mln/fun/all.hh: Fix namespace description. * tests/fun/v2v/norm.cc: New. * tests/fun/v2v/Makefile.am (check_PROGRAMS): New. Add norm. (norm_SOURCES): New. (TESTS): New. * tests/fun/Makefile.am (SUBDIRS): Add v2v. mln/fun/all.hh | 2 mln/fun/v2v/norm.hh | 125 ++++++++++++++++++++++++++++++++++++++++++++++ tests/fun/Makefile.am | 2 tests/fun/v2v/Makefile.am | 6 ++ tests/fun/v2v/norm.cc | 69 +++++++++++++++++++++++++ 5 files changed, 202 insertions(+), 2 deletions(-) Index: mln/fun/v2v/norm.hh --- mln/fun/v2v/norm.hh (revision 0) +++ mln/fun/v2v/norm.hh (revision 0) @@ -0,0 +1,125 @@ +// 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 MLN_FUN_V2V_NORM_HH +# define MLN_FUN_V2V_NORM_HH + +/*! \file mln/fun/v2v/norm.hh + * + * \brief Norm functors. + * + * \see mln/norm/. + */ + +# include <mln/core/concept/function.hh> +# include <mln/trait/value_.hh> + +# include <mln/norm/all.hh> + + +namespace mln +{ + + namespace fun + { + + namespace v2v + { + + /*! \brief L1-norm. + * + * \c V is the type of input values; \c R is the result type. + * + * \see mln::norm::l1. + */ + template <typename V, typename R> + struct l1_norm : public Function_v2v< l1_norm<V, R> > + { + typedef R result; + R operator()(const V& v) const; + }; + + /*! \brief L2-norm. + * + * \c V is the type of input values; \c R is the result type. + * + * \see mln::norm::l2. + */ + template <typename V, typename R> + struct l2_norm : public Function_v2v< l2_norm<V, R> > + { + typedef R result; + R operator()(const V& v) const; + }; + + /*! \brief L-infty norm. + * + * \c V is the type of input values; \c R is the result type. + * + * \see mln::norm::linfty. + */ + template <typename V, typename R> + struct linfty_norm : public Function_v2v< linfty_norm<V, R> > + { + typedef R result; + R operator()(const V& v) const; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename V, typename R> + R + l1_norm<V, R>::operator()(const V& v) const + { + return mln::norm::l1 (v); + } + + template <typename V, typename R> + R + l2_norm<V, R>::operator()(const V& v) const + { + return mln::norm::l2 (v); + } + + template <typename V, typename R> + R + linfty_norm<V, R>::operator()(const V& v) const + { + return mln::norm::linfty (v); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::fun::v2v + + } // end of namespace mln::fun + +} // end of namespace mln + + +#endif // ! MLN_FUN_V2V_NORM_HH Index: mln/fun/all.hh --- mln/fun/all.hh (revision 1550) +++ mln/fun/all.hh (working copy) @@ -37,7 +37,7 @@ namespace mln { - /// Namespace of image processing routines related to pixel funs. + /// Namespace of image processing routines related to functions. namespace fun { Index: tests/fun/v2v/norm.cc --- tests/fun/v2v/norm.cc (revision 0) +++ tests/fun/v2v/norm.cc (revision 0) @@ -0,0 +1,69 @@ +// 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. + +/*! \file tests/norm/l1.hh + * + * \brief Test the norm functors. + */ + +#include <mln/metal/vec.hh> +#include <mln/fun/v2v/norm.hh> + +#include <tests/norm/common.hh> + + +int main() +{ + typedef mln::metal::vec<3, int> vec_t; + + // L1-norm. + { + vec_t t, u; + t.set (1, -2, 3); + u.set (5, 1, 0); + mln::fun::v2v::l1_norm<vec_t, float> l1; + test::check_norm(l1, t, u); + } + + // L2-norm. + { + vec_t t, u; + t.set (2, -2, 3); + u.set (4, 1, 0); + mln::fun::v2v::l2_norm<vec_t, float> l2; + test::check_norm(l2, t, u); + } + + // L-infinity-norm. + { + vec_t t, u; + t.set (2, -2, 4); + u.set (4, 1, 0); + mln::fun::v2v::linfty_norm<vec_t, int> linfty; + test::check_norm(linfty, t, u); + } +} Index: tests/fun/v2v/Makefile.am --- tests/fun/v2v/Makefile.am (revision 1550) +++ tests/fun/v2v/Makefile.am (working copy) @@ -1,3 +1,9 @@ ## Process this file through Automake to create Makefile.in -*- Makefile -*- include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = norm + +norm_SOURCES = norm.cc + +TESTS = $(check_PROGRAMS) Index: tests/fun/Makefile.am --- tests/fun/Makefile.am (revision 1550) +++ tests/fun/Makefile.am (working copy) @@ -2,4 +2,4 @@ include $(top_srcdir)/milena/tests/tests.mk -SUBDIRS = x2x +SUBDIRS = v2v x2x