
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Start cleaning up level::fill. * tests/level/fill_with_value.cc: New. * tests/level/Makefile.am: Update. * mln/level/fill_with_image.hh: New. * mln/level/fill.hh (generic): Remove. (fill): Use fill_with_value and fill_with_image. * mln/level/fill.spe.hh: Deactivate obsolete contents. * mln/level/fill_with_value.hh: New. mln/level/fill.hh | 70 +++---------- mln/level/fill.spe.hh | 33 ------ mln/level/fill_with_image.hh | 128 ++++++++++++++++++++++++ mln/level/fill_with_value.hh | 211 +++++++++++++++++++++++++++++++++++++++++ tests/level/Makefile.am | 2 tests/level/fill_with_value.cc | 48 +++++++++ 6 files changed, 406 insertions(+), 86 deletions(-) Index: tests/level/fill_with_value.cc --- tests/level/fill_with_value.cc (revision 0) +++ tests/level/fill_with_value.cc (revision 0) @@ -0,0 +1,48 @@ +// Copyright (C) 2007, 2008 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/level/fill_with_value.cc + * + * \brief Tests on mln::level::fill_with_value + */ + +#include <mln/core/image2d.hh> +#include <mln/level/fill_with_value.hh> + + +int main() +{ + using namespace mln; + + const unsigned size = 100; + + image2d<unsigned char> ima(size, size); + level::fill_with_value(ima, 51); + box2d::piter p(ima.domain()); + for_all(p) + mln_assertion(ima(p) == 51); +} Index: tests/level/Makefile.am --- tests/level/Makefile.am (revision 2087) +++ tests/level/Makefile.am (working copy) @@ -12,6 +12,7 @@ compare \ compute \ fill \ + fill_with_value \ median \ median_dir \ median_fast \ @@ -34,6 +35,7 @@ compare_SOURCES = compare.cc compute_SOURCES = compute.cc fill_SOURCES = fill.cc +fill_with_value_SOURCES = fill_with_value.cc median_SOURCES = median.cc median_dir_SOURCES = median_dir.cc median_fast_SOURCES = median_fast.cc Index: mln/level/fill_with_image.hh --- mln/level/fill_with_image.hh (revision 0) +++ mln/level/fill_with_image.hh (revision 0) @@ -0,0 +1,128 @@ +// Copyright (C) 2008 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_LEVEL_FILL_WITH_IMAGE_HH +# define MLN_LEVEL_FILL_WITH_IMAGE_HH + +/*! \file mln/level/fill_with_image.hh + * + * \brief Fill an image with the values from another image. + * + * \todo Specialize with line_piter... + */ + +# include <mln/core/concept/image.hh> +# include <mln/core/inplace.hh> + + +namespace mln +{ + + namespace level + { + + /*! Fill the image \p ima with the values of the image \p data. + * + * \param[in,out] ima The image to be filled. + * \param[in] data The image. + * + * \warning The definition domain of \p ima has to be included in + * the one of \p data. + * + * \pre \p ima.domain <= \p data.domain. + */ + template <typename I, typename J> + void fill_with_image(Image<I>& ima, const Image<J>& data); + + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + namespace generic + { + + template <typename I, typename J> + inline + void fill_with_image(I& ima, const J& data) + { + trace::entering("level::impl::generic::fill_with_image"); + + mln_piter(I) p(ima.domain()); + for_all(p) + ima(p) = data(p); + + trace::exiting("level::impl::generic::fill_with_image"); + } + + } // end if namespace mln::level::impl::generic + + + // Selector. + + template <typename I, typename J> + inline + void fill_with_image_(I& ima, const J& data) + { + generic::fill_with_image(ima, data); + } + + } // end of namespace mln::level::impl + + + + /// Facade. + + template <typename I, typename J> + inline + void fill_with_image(Image<I>& ima_, const Image<J>& data_) + { + trace::entering("level::fill_with_image"); + + mlc_is(mln_trait_image_value_io(I), + mln::trait::image::value_io::read_write)::check(); + mlc_converts_to(mln_value(J), mln_value(I))::check(); + + I& ima = exact(ima_); + const J& data = exact(data_); + mln_precondition(ima.domain() <= data.domain()); + + impl::fill_with_image_(ima, data); + + trace::exiting("level::fill_with_image"); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::level + +} // end of namespace mln + + +#endif // ! MLN_LEVEL_FILL_WITH_IMAGE_HH Index: mln/level/fill.hh --- mln/level/fill.hh (revision 2087) +++ mln/level/fill.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -35,16 +35,14 @@ * \todo Re-organize this file contents + Overload for fastest images. */ -# include <cstring> - -# include <mln/core/concept/image.hh> # include <mln/core/concept/function.hh> -# include <mln/core/inplace.hh> -# include <mln/level/memset_.hh> +# include <mln/level/fill_with_value.hh> +# include <mln/level/fill_with_image.hh> // Specializations are in: -# include <mln/level/fill.spe.hh> +// # include <mln/level/fill.spe.hh> + namespace mln { @@ -55,7 +53,7 @@ /*! Fill the whole image \p ima with the single value \p v. * * \param[in,out] ima The image to be filled. - * \param[in] v The value to assign to all pixels. + * \param[in] v The value to assign to all sites. * * \pre \p ima has to be initialized. * @@ -132,44 +130,27 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - namespace generic - { + // With: value + template <typename I> inline - void fill_with_value(I& ima, const mln_value(I)& value) + void fill(Image<I>& ima, const mln_value(I)& value) { - trace::entering("level::impl::generic::fill_with_value"); - - mln_piter(I) p(ima.domain()); - for_all(p) - ima(p) = value; - - trace::exiting("level::impl::generic::fill_with_value"); + trace::entering("level::fill"); + fill_with_value(ima, value); + trace::exiting("level::fill"); } - } // end if namespace mln::level::impl::generic - - } // end of namespace mln::level::impl - + // with: Image<J> - // with: value - - template <typename I> + template <typename I, typename J> inline - void fill(Image<I>& ima, const mln_value(I)& value) + void fill(Image<I>& ima, const Image<J>& data) { trace::entering("level::fill"); - - mlc_is(mln_trait_image_value_io(I), - trait::image::value_io::read_write)::check(); // FIXME: Only the upcoming general facade!!! - mln_precondition(exact(ima).has_data()); - impl::fill_with_value(mln_trait_image_speed(I)(), exact(ima), - value); - + fill_with_image(ima, data); trace::exiting("level::fill"); } @@ -233,25 +214,6 @@ } - // with: Image<J> - - template <typename I, typename J> - inline - void fill(Image<I>& ima_, const Image<J>& data_) - { - trace::entering("level::fill"); - - I& ima = exact(ima_); - const J& data = exact(data_); - mln_precondition(ima.domain() <= data.domain()); - - mln_piter(I) p(ima.domain()); - for_all(p) - ima(p) = data(p); - - trace::exiting("level::fill"); - } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::level Index: mln/level/fill.spe.hh --- mln/level/fill.spe.hh (revision 2087) +++ mln/level/fill.spe.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -43,7 +43,6 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/function.hh> # include <mln/core/inplace.hh> -# include <mln/level/memset_.hh> # ifndef MLN_INCLUDE_ONLY @@ -57,36 +56,6 @@ namespace impl { - namespace generic - { - template <typename I> - void fill_with_value(I& ima, const mln_value(I)& value); - } - - - // Disjunction. - - - template <typename I> - inline - void fill_with_value(trait::image::speed::any, I& ima, - const mln_value(I)& value) - { - generic::fill_with_value(ima, value); - } - - template <typename I> - inline - void fill_with_value(trait::image::speed::fastest, I& ima, - const mln_value(I)& value) - { - trace::entering("level::impl::fill_with_value"); - - level::memset_(ima, ima.point_at_offset(0), value, ima.ncells()); - - trace::exiting("level::impl::fill_with_value"); - } - } // end of namespace mln::level::impl Index: mln/level/fill_with_value.hh --- mln/level/fill_with_value.hh (revision 0) +++ mln/level/fill_with_value.hh (revision 0) @@ -0,0 +1,211 @@ +// Copyright (C) 2008 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_LEVEL_FILL_WITH_VALUE_HH +# define MLN_LEVEL_FILL_WITH_VALUE_HH + +/*! \file mln/level/fill_with_value.hh + * + * \brief Fill an image with a value, that is, set all pixel values to + * the given value. + * + * \todo Overload for fastest images. + * \todo Handle all value_storage properties (piecewise, etc.) + * \todo Make memset_ work and use it when appropriate. + * \todo Move specializations in a extra file. + * \toto Activate fill_with_value_cell_wise. + */ + +# include <mln/core/concept/image.hh> +# include <mln/core/inplace.hh> + + +namespace mln +{ + + namespace level + { + + /*! Fill the whole image \p ima with the single value \p v. + * + * \param[in,out] ima The image to be filled. + * \param[in] val The value to assign to all sites. + * + * \pre \p ima has to be initialized. + * + * \todo Optimize when \p ima is large and sizeof(mln_value(I)) > 1. + */ + template <typename I, typename V> + void fill_with_value(Image<I>& ima, const V& val); + + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename I> + inline + void fill_with_value_site_wise_any(I& ima, const mln_value(I)& val) + { + trace::entering("level::impl::fill_with_value_site_wise_any"); + + mln_piter(I) p(ima.domain()); + for_all(p) + ima(p) = val; + + trace::exiting("level::impl::fill_with_value_site_wise_any"); + } + + + template <typename I, typename V> + inline + void fill_with_value_site_wise_one_block(I& ima, const V& val) + { + trace::entering("level::impl::fill_with_value_site_wise_one_block"); + + // level::memset_(ima, ima.point_at_index(0), v, ima.nelements()); + const unsigned n = ima.nelements(); + mln_value(I)* ptr = ima.buffer(); + for (unsigned i = 0; i < n; ++i) + *ptr++ = val; + + trace::exiting("level::impl::fill_with_value_site_wise_one_block"); + } + + + template <typename I, typename V> + inline + void fill_with_value_cell_wise(I& ima, const V& val) + { + trace::entering("level::impl::fill_with_value_cell_wise"); + + abort(); +// mln_viter(I) v(ima.values()); +// for_all(v) +// v.change_to(val); + + trace::exiting("level::impl::fill_with_value_cell_wise"); + } + + + namespace dispatch + { + + // Cases for "value_browsing == site_wise_only" w.r.t. value_storage. + + template <typename I, typename V> + inline + void fill_with_value_site_wise_(mln::trait::image::value_storage::any, + I& ima, const V& val) + { + fill_with_value_site_wise_any(ima, val); + } + + template <typename I, typename V> + inline + void fill_with_value_site_wise_(mln::trait::image::value_storage::one_block, + I& ima, const V& val) + { + fill_with_value_site_wise_one_block(ima, val); + } + + // Case site_wise -> selector w.r.t. value_storage. + + template <typename I, typename V> + inline + void fill_with_value_site_wise(I& ima, const V& val) + { + fill_with_value_site_wise_(mln_trait_image_value_storage(I)(), + ima, val); + } + + + // Cases w.r.t. value_browsing. + + template <typename I, typename V> + inline + void fill_with_value_(mln::trait::image::value_browsing::site_wise_only, + I& ima, const V& val) + { + fill_with_value_site_wise(ima, val); + } + + template <typename I, typename V> + inline + void fill_with_value_(mln::trait::image::value_browsing::cell_wise, + I& ima, const V& val) + { + fill_with_value_cell_wise(ima, val); + } + + // Selector w.r.t. value_browsing. + + template <typename I, typename V> + inline + void fill_with_value_(I& ima, const V& val) + { + fill_with_value_(mln_trait_image_value_browsing(I)(), + ima, val); + } + + } // end of namespace mln::level::impl::dispatch + + } // end of namespace mln::level::impl + + + + /// Facade. + + template <typename I, typename V> + inline + void fill_with_value(Image<I>& ima, const V& val) + { + trace::entering("level::fill"); + + mlc_is(mln_trait_image_value_io(I), + mln::trait::image::value_io::read_write)::check(); + mlc_converts_to(V, mln_value(I))::check(); + + mln_precondition(exact(ima).has_data()); + + impl::dispatch::fill_with_value_(exact(ima), exact(val)); + + trace::exiting("level::fill"); + } + + + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::level + +} // end of namespace mln + + +#endif // ! MLN_LEVEL_FILL_WITH_VALUE_HH