Re: [Olena-patches] milena r1523: Subdirectory level ready for rereading (except median)

Guillaume Duhamel wrote:
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog: 2007-11-23 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr>
Subdirectory display ready for rereading (except median).
Level review. * mln/level/abs.hh, * mln/level/all.hh, * mln/level/memcpy_.hh, * mln/level/memset_.hh, * mln/level/paste.hh, * mln/level/paste.spe.hh, * mln/level/saturate.hh, * mln/level/sort_points.hh, * mln/level/take.hh: Review doc, add precondition and check typo.
Add metal::is_not_const. * mln/metal/is_not_const.hh: New file for handling check in memcpy and memset in level. * mln/metal/all.hh: Add is_not_const header.
Add tests. * tests/all.cc: New tests, which include all headers all.hh.
--- mln/level/abs.hh | 4 + mln/level/all.hh | 9 +++- mln/level/memcpy_.hh | 59 +++++++++++++++++++++++------ mln/level/memset_.hh | 57 +++++++++++++++++++++------- mln/level/paste.hh | 3 - mln/level/paste.spe.hh | 2 mln/level/saturate.hh | 14 ++++++ mln/level/sort_points.hh | 12 +++++ mln/level/take.hh | 2 mln/metal/all.hh | 1 mln/metal/is_not_const.hh | 68 +++++++++++++++++++++++++++++++++ tests/all.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 292 insertions(+), 32 deletions(-)
Index: trunk/milena/tests/all.cc =================================================================== --- trunk/milena/tests/all.cc (revision 0) +++ trunk/milena/tests/all.cc (revision 1523) @@ -0,0 +1,93 @@ +// 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/all.cc + * + * \brief Tests with all headers. (check norris tests) + */ + + +#include <mln/test/all.hh> +#include <mln/convert/all.hh> +#include <mln/estim/all.hh> +#include <mln/debug/all.hh> +#include <mln/histo/all.hh> +#include <mln/pw/all.hh> +#include <mln/geom/all.hh> +#include <mln/core/trait/all.hh> +#include <mln/fun/i2v/all.hh> +#include <mln/fun/p2b/all.hh> +#include <mln/fun/p2v/all.hh> +#include <mln/fun/v2v/all.hh> +#include <mln/fun/x2x/all.hh> +#include <mln/fun/all.hh> +#include <mln/math/all.hh> +#include <mln/set/all.hh> +#include <mln/draw/all.hh> +#include <mln/metal/math/all.hh> +#include <mln/metal/all.hh> +#include <mln/morpho/all.hh> +#include <mln/io/pfm/all.hh> +#include <mln/io/pgm/all.hh> +#include <mln/io/fits/all.hh> +#include <mln/io/ppm/all.hh> +#include <mln/io/pbm/all.hh> +#include <mln/io/pnm/all.hh> +#include <mln/io/all.hh> +#include <mln/level/naive/all.hh> +#include <mln/level/approx/all.hh> +#include <mln/level/all.hh> +#include <mln/arith/all.hh> +#include <mln/linear/all.hh> +#include <mln/logical/all.hh> +#include <mln/canvas/morpho/all.hh> +#include <mln/canvas/browsing/all.hh> +#include <mln/canvas/all.hh> +#include <mln/accu/all.hh> +#include <mln/norm/all.hh> +#include <mln/value/internal/all.hh> +#include <mln/value/all.hh> +#include <mln/value/concept/all.hh> +#include <mln/value/builtin/all.hh> +#include <mln/make/all.hh> +#include <mln/border/all.hh> +#include <mln/labeling/all.hh> +#include <mln/util/all.hh> +#include <mln/trait/all.hh> +#include <mln/trait/value/all.hh> +#include <mln/trait/op/all.hh> +#include <mln/tag/all.hh> +#include <mln/trace/all.hh> +#include <mln/literal/all.hh> +#include <mln/display/all.hh> +#include <mln/win/all.hh> + + +int main () +{ + +} Index: trunk/milena/mln/metal/is_not_const.hh =================================================================== --- trunk/milena/mln/metal/is_not_const.hh (revision 0) +++ trunk/milena/mln/metal/is_not_const.hh (revision 1523) @@ -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 MLN_METAL_IS_NOT_CONST_HH +# define MLN_METAL_IS_NOT_CONST_HH + +/*! + * \file mln/metal/is_not_const.hh + * + * \brief FIXME. + */ + +# include <mln/metal/bool.hh> + + +# define mlc_is_not_const(T) mln::metal::is_not_const< T > + + +namespace mln +{ + + namespace metal + { + + template <typename T> + struct is_not_const : true_ + {}; + + template <typename T> + struct is_not_const< const T > : false_ + {}; + + template <typename T> + struct is_not_const< const T& > : false_ + {}; + + // FIXME: What about "T*const" and "const T*"? + + } // end of namespace mln::metal + +} // end of namespace mln + + +#endif // ! MLN_METAL_IS_NOT_CONST_HH Index: trunk/milena/mln/metal/all.hh =================================================================== --- trunk/milena/mln/metal/all.hh (revision 1522) +++ trunk/milena/mln/metal/all.hh (revision 1523) @@ -63,6 +63,7 @@ # include <mln/metal/const.hh> # include <mln/metal/unconst.hh> # include <mln/metal/is_const.hh> +# include <mln/metal/is_not_const.hh>
# include <mln/metal/unptr.hh> # include <mln/metal/unref.hh> Index: trunk/milena/mln/level/sort_points.hh =================================================================== --- trunk/milena/mln/level/sort_points.hh (revision 1522) +++ trunk/milena/mln/level/sort_points.hh (revision 1523) @@ -49,7 +49,7 @@ {
/*! Sort points the image \p input through a function \p f to set - * the \p output image. + * the \p output image in increasing way. * * \param[in] input The input image. * @@ -58,6 +58,16 @@ template <typename I> p_array<mln_point(I)> sort_points_increasing(const Image<I>& input);
+ /*! Sort points the image \p input through a function \p f to set + * the \p output image in decreasing way. + * + * \param[in] input The input image. + * + * \pre \p input.has_data + */ + template <typename I> + p_array<mln_point(I)> sort_points_decreasing(const Image<I>& input); +
# ifndef MLN_INCLUDE_ONLY
Index: trunk/milena/mln/level/take.hh =================================================================== --- trunk/milena/mln/level/take.hh (revision 1522) +++ trunk/milena/mln/level/take.hh (revision 1523) @@ -53,6 +53,8 @@ * This routine runs: \n * for all p of \p input, \p a.take( \p input(p) ) \n * + * \pre \p input has to be initialized. + * * \warning This routine does not perform a.init(). */ template <typename A, typename I> Index: trunk/milena/mln/level/saturate.hh =================================================================== --- trunk/milena/mln/level/saturate.hh (revision 1522) +++ trunk/milena/mln/level/saturate.hh (revision 1523) @@ -53,6 +53,9 @@ * The saturation is based on the min and max values of the output * value type. This assumes that the range of values in the input * image is larger than the one of the output image. + * + * \pre \p input and \p output have to own the same domain. + * */ template <typename I, typename O> void saturate(const Image<I>& input, Image<O>& output); @@ -64,6 +67,9 @@ * \param[in] min The minimum output value. * \param[in] max The maximum output value. * \param[out] output The output image. + * + * \pre \p input and \p output have to own the same domain. + * */ template <typename I, typename O> void saturate(const Image<I>& input, @@ -75,7 +81,10 @@ * * \param[in,out] input The input image. * \param[in] min The minimum output value. - * \param[in] max The maximum output value. + * \param[in] max The maximum output value + * + * \pre \p input has to be initialized. + * */ template <typename I> void saturate_inplace(Image<I>& input, @@ -90,6 +99,7 @@ trace::entering("level::saturate");
mln_precondition(exact(input).domain() == exact(output).domain()); + fun::v2v::saturate<mln_value(O)> f; level::transform(input, f, output);
@@ -104,6 +114,7 @@ trace::entering("level::saturate");
mln_precondition(exact(input).domain() == exact(output).domain()); + fun::v2v::saturate<mln_value(O)> f(min, max); level::transform(input, f, output);
@@ -117,6 +128,7 @@ trace::entering("level::saturate_inplace");
mln_precondition(exact(input).has_data()); + fun::v2v::saturate<mln_value(I)> f(min, max); level::apply(input, f);
Index: trunk/milena/mln/level/memcpy_.hh =================================================================== --- trunk/milena/mln/level/memcpy_.hh (revision 1522) +++ trunk/milena/mln/level/memcpy_.hh (revision 1523) @@ -37,7 +37,7 @@
# include <mln/core/concept/image.hh> # include <mln/core/pixel.hh> - +# include <mln/metal/is_not_const.hh>
namespace mln { @@ -52,7 +52,13 @@ * \param[in] src The source pixel (to get values). * \param[in] n The number of pixels to copy. * - * \pre FIXME: ! + * \pre \p src has to be initialized. + * \pre \p dest has to be initialized. + * \pre \p src and dest image values have to own the same sizeof. + * \pre \p dest pixel has to be on \p dest image domain. + * \pre \p src pixel has to be on \p src image domain. + * \pre \p dest + \p n has to be on \p dest image domain. + * \pre \p src + \p n has to be on \p src image domain. */ template <typename Pd, typename Ps> void memcpy_(Generalized_Pixel<Pd>& dest, const Generalized_Pixel<Ps>& src, @@ -61,20 +67,16 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl + { + template <typename Pd, typename Ps> - void memcpy_(Generalized_Pixel<Pd>& dest_, const Generalized_Pixel<Ps>& src_, - std::size_t n) + void memcpy__(Pd& dest, const Ps& src, std::size_t n) { + trace::entering("level::impl::memcpy__"); + typedef mln_image(Pd) Id; - // FIXME: metal::is_not_const<Id>::check(); typedef mln_image(Ps) Is; - Pd& dest = internal::force_exact<Pd>(dest_); - Ps& src = internal::force_exact<Ps>(src_); - - mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is))); - mln_precondition(dest.ima().has_data()); - mln_precondition(src.ima().has_data()); - // FIXME: Add precondition about n.
if (n == 0) { @@ -100,6 +102,39 @@ for (std::size_t i = 0; i < n; ++i) *p_d++ = *p_s++; } + + trace::exiting("level::impl::memcpy__"); + } + + } + + template <typename Pd, typename Ps> + void memcpy_(Generalized_Pixel<Pd>& dest_, const Generalized_Pixel<Ps>& src_, + std::size_t n) + { + trace::entering("level::memcpy_"); + + typedef mln_image(Pd) Id; + metal::is_not_const<Id>::check(); + typedef mln_image(Ps) Is; + Pd& dest = internal::force_exact<Pd>(dest_); + Ps& src = internal::force_exact<Ps>(src_); + + mln_precondition(sizeof(mln_value(Id)) == sizeof(mln_value(Is))); + mln_precondition(dest.ima().has_data()); + mln_precondition(src.ima().has_data()); + + mln_precondition(& dest.val() >= & dest.ima()[0]); + mln_precondition(& dest.val() < & dest.ima()[0] + dest.ima().ncells()); + mln_precondition(& dest.val() + n <= & dest.ima()[0] + dest.ima().ncells()); + + mln_precondition(& src.val() >= & src.ima()[0]); + mln_precondition(& src.val() < & src.ima()[0] + src.ima().ncells()); + mln_precondition(& src.val() + n <= & src.ima()[0] + src.ima().ncells()); + + impl::memcpy__(dest, src, n); + + trace::exiting("level::memcpy_"); }
# endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/level/memset_.hh =================================================================== --- trunk/milena/mln/level/memset_.hh (revision 1522) +++ trunk/milena/mln/level/memset_.hh (revision 1523) @@ -35,7 +35,7 @@
# include <mln/core/concept/image.hh> # include <mln/core/pixel.hh> - +# include <mln/metal/is_not_const.hh>
namespace mln { @@ -49,7 +49,9 @@ * \param[in] v The value to set pixels with. * \param[in] n The number of pixels to set. * - * \pre FIXME: ! + * \pre \p pix image has to be initialized. + * \pre \p pix has to be on \p pix image domain. + * \pre \p pix + \p n has to be on \p pix image domain. */ template <typename P> void memset_(Generalized_Pixel<P>& pix, @@ -63,7 +65,9 @@ * \param[in] v The value to set to points. * \param[in] n The number of points to set. * - * \pre \p input has to be initialized. FIXME: More. + * \pre \p input image has to be initialized. + * \pre \p input has to own \p p. + * \pre \p p + \p n is <= \p input size. */ template <typename I> void memset_(I& input, const mln_point(I)& p, @@ -72,19 +76,15 @@
# ifndef MLN_INCLUDE_ONLY
- template <typename P> - void memset_(Generalized_Pixel<P>& pix_, - const mln_value(P)& v, std::size_t n) + namespace impl { - typedef mln_image(P) I; - // FIXME: metal::is_not_const<I>::check();
- P& pix = internal::force_exact<P>(pix_); - mln_precondition(pix.ima().has_data()); - mln_precondition(& pix.val() >= & pix.ima()[0]); - mln_precondition(& pix.val() < & pix.ima()[0] + pix.ima().ncells()); - mln_precondition(& pix.val() + n <= & pix.ima()[0] + pix.ima().ncells()); + template <typename P> + void memset__(P& pix, const mln_value(P)& v, std::size_t n) + { + trace::entering("level::impl::memset_");
+ typedef mln_image(P) I; if (n == 0) { return; // no-op @@ -108,12 +108,39 @@ for (std::size_t i = 0; i < n; ++i) *ptr++ = v; } + + trace::exiting("level::impl::memset_"); + } + + } // end of namespace mln::level::impl + + + template <typename P> + void memset_(Generalized_Pixel<P>& pix_, + const mln_value(P)& v, std::size_t n) + { + trace::entering("level::memset_"); + + typedef mln_image(P) I; + metal::is_not_const<I>::check(); + + P& pix = internal::force_exact<P>(pix_); + mln_precondition(pix.ima().has_data()); + mln_precondition(& pix.val() >= & pix.ima()[0]); + mln_precondition(& pix.val() < & pix.ima()[0] + pix.ima().ncells()); + mln_precondition(& pix.val() + n <= & pix.ima()[0] + pix.ima().ncells()); + + impl::memset__(pix, v, n); + + trace::exiting("level::memset_"); }
template <typename I> void memset_(I& input, const mln_point(I)& p, const mln_value(I)& v, std::size_t n) { + trace::entering("level::memset_"); + mlc_is(mln_trait_image_speed(I), trait::image::speed::fastest)::check();
mln_precondition(input.has_data()); @@ -121,7 +148,9 @@ mln_precondition(input.offset_at(p) + n <= input.ncells());
pixel<I> pix(input, p); - memset_(pix, v, n); + impl::memset__(pix, v, n); + + trace::exiting("level::memset_"); }
# endif // ! MLN_INCLUDE_ONLY Index: trunk/milena/mln/level/paste.spe.hh =================================================================== --- trunk/milena/mln/level/paste.spe.hh (revision 1522) +++ trunk/milena/mln/level/paste.spe.hh (revision 1523) @@ -48,14 +48,12 @@ namespace impl {
- namespace generic { template <typename I, typename J> void paste_(const I& data, J& destination); }
- template <typename I, typename J> void paste_lines_(const I& data, J& destination) { Index: trunk/milena/mln/level/abs.hh =================================================================== --- trunk/milena/mln/level/abs.hh (revision 1522) +++ trunk/milena/mln/level/abs.hh (revision 1523) @@ -69,8 +69,10 @@ void abs(const Image<I>& input, Image<O>& output) { trace::entering("level::abs"); + mln_precondition(exact(input).domain() == exact(output).domain()); level::transform(input, fun::v2v::abs<mln_value(I)>(), output); + trace::exiting("level::abs"); }
@@ -78,8 +80,10 @@ void abs_inplace(Image<I>& input) { trace::entering("level::abs_inplace"); + mln_precondition(exact(input).has_data()); level::apply(input, fun::v2v::abs<mln_value(I)>()); + trace::exiting("level::abs_inplace"); }
Index: trunk/milena/mln/level/all.hh =================================================================== --- trunk/milena/mln/level/all.hh (revision 1522) +++ trunk/milena/mln/level/all.hh (revision 1523) @@ -40,8 +40,15 @@ /// Namespace of image processing routines related to pixel levels. namespace level { + /// Implementation namespace of level namespace. - namespace impl {} + namespace impl { + + /// Generic implementation namespace of level namespace. + namespace generic {} + + } + }
} Index: trunk/milena/mln/level/paste.hh =================================================================== --- trunk/milena/mln/level/paste.hh (revision 1522) +++ trunk/milena/mln/level/paste.hh (revision 1523) @@ -99,9 +99,10 @@ template <typename I, typename J> void paste(const Image<I>& data_, Image<J>& destination_) { + trace::entering("level::paste"); + const I& data = exact(data_); J& destination = exact(destination_); - trace::entering("level::paste");
mlc_is(mln_trait_image_io(J), trait::image::io::write)::check(); mlc_converts_to(mln_value(I), mln_value(J))::check();
Fix title.
participants (1)
-
Guillaume Duhamel