cleanup-2008 2238: Update fill_with_image and fill_with_value.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Update fill_with_image and fill_with_value. * mln/level/fill_with_image.hh (fill_with_image_tests): New. (generic): Strengthen signature and use tests. (impl): Move specialized impl into... * mln/level/fill_with_image.spe.hh: ...this new file. Update. * mln/level/fill_with_value.hh, * mln/level/fill_with_value.spe.hh: Likewise. * mln/level/fill.spe.hh: Remove; dead empty file. fill_with_image.hh | 48 ++++++------ fill_with_image.spe.hh | 84 ++++++++++++++++++++++ fill_with_value.hh | 129 +++++++--------------------------- fill_with_value.spe.hh | 185 ++++++++++++------------------------------------- 4 files changed, 183 insertions(+), 263 deletions(-) Index: mln/level/fill_with_image.hh --- mln/level/fill_with_image.hh (revision 2236) +++ mln/level/fill_with_image.hh (working copy) @@ -38,6 +38,9 @@ # include <mln/core/concept/image.hh> # include <mln/core/image/inplace.hh> +// Specializations are in: +# include <mln/level/fill_with_image.spe.hh> + namespace mln { @@ -62,6 +65,24 @@ # ifndef MLN_INCLUDE_ONLY + namespace internal + { + + template <typename I, typename J> + inline + void fill_with_image_tests(Image<I>& ima, const Image<J>& data) + { + 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(); + mln_precondition(exact(ima).has_data()); + mln_precondition(exact(data).has_data()); + mln_precondition(exact(ima).domain() <= exact(data).domain()); + } + + } // end of namespace mln::level::internal + + namespace impl { @@ -70,9 +91,10 @@ template <typename I, typename J> inline - void fill_with_image(I& ima, const J& data) + void fill_with_image(Image<I>& ima, const Image<J>& data) { trace::entering("level::impl::generic::fill_with_image"); + internal::fill_with_image_tests(ima, data); mln_piter(I) p(ima.domain()); for_all(p) @@ -83,37 +105,19 @@ } // 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_) + 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); + internal::fill_with_image_tests(ima, data); + internal::fill_with_image_dispatch(ima, data); trace::exiting("level::fill_with_image"); } Index: mln/level/fill_with_value.spe.hh --- mln/level/fill_with_value.spe.hh (revision 2236) +++ mln/level/fill_with_value.spe.hh (working copy) @@ -25,77 +25,60 @@ // reasons why the executable file might be covered by the GNU General // Public License. +#ifndef MLN_LEVEL_FILL_WITH_VALUE_SPE_HH +# define MLN_LEVEL_FILL_WITH_VALUE_SPE_HH + +/// \file mln/level/fill_with_value.spe.hh +/// Specializations for mln::level::fill_with_value. +/// +/// \todo See todos in mln/level/fill.hh + #ifndef MLN_LEVEL_FILL_WITH_VALUE_HH -# define MLN_LEVEL_FILL_WITH_VALUE_HH +# error "Forbidden inclusion of *.spe.hh" +# endif // ! 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 <cstdlib> - -# include <mln/core/concept/image.hh> -# include <mln/core/image/inplace.hh> -# include <mln/core/image/instant.hh> +# ifndef MLN_INCLUDE_ONLY + 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); - - - // Case of instant images. + namespace internal + { template <typename I, typename V> - void fill_with_value(const Image< instant_<I> >& ima, const V& val); + inline + void fill_with_value_tests(Image<I>& ima, const V& val); + } - -# ifndef MLN_INCLUDE_ONLY + // Implementations. + // ---------------- namespace impl { - template <typename I> - inline - void fill_with_value_site_wise_any(I& ima, const mln_value(I)& val) + namespace generic { - trace::entering("level::impl::fill_with_value_site_wise_any"); + template <typename I, typename V> + void fill_with_value(Image<I>& ima, const V& val); + } - mln_piter(I) p(ima.domain()); - for_all(p) - ima(p) = val; - trace::exiting("level::impl::fill_with_value_site_wise_any"); - } + // FIXME: Add specializations here... template <typename I, typename V> inline - void fill_with_value_site_wise_one_block(I& ima, const V& val) + void fill_with_value_one_block(Image<I>& ima_, const V& val) { - trace::entering("level::impl::fill_with_value_site_wise_one_block"); + trace::entering("level::impl::fill_with_value_one_block"); + + I& ima = exact(ima_); + internal::fill_with_value_tests(ima, val); // level::memset_(ima, ima.point_at_index(0), v, ima.nelements()); const unsigned n = ima.nelements(); @@ -103,126 +86,50 @@ for (unsigned i = 0; i < n; ++i) *ptr++ = val; - trace::exiting("level::impl::fill_with_value_site_wise_one_block"); + trace::exiting("level::impl::fill_with_value_one_block"); } - template <typename I, typename V> inline - void fill_with_value_cell_wise(I& ima, const V& val) + void fill_with_value_cell_wise(Image<I>& ima_, const V& val) { trace::entering("level::impl::fill_with_value_cell_wise"); - abort(); + I& ima = exact(ima_); + internal::fill_with_value_tests(ima, val); - // mln_viter(I) v(ima.values()); - // for_all(v) - // v.change_to(val); + mln_viter(I) v(ima.values()); + for_all(v) + v.change_to(val); trace::exiting("level::impl::fill_with_value_cell_wise"); } + } // end of namespace mln::level::impl - 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); - } + // Dispatch. + // --------- - template <typename I, typename V> - inline - void fill_with_value_(mln::trait::image::value_browsing::cell_wise, - I& ima, const V& val) + namespace internal { - 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) + void fill_with_value_dispatch(Image<I>& ima, const V& val) { - fill_with_value_(mln_trait_image_value_browsing(I)(), - ima, val); + impl::generic::fill_with_value(ima, val); } - } // end of namespace mln::level::impl::dispatch - - } // end of namespace mln::level::impl + } // end of namespace mln::level::internal + } // end of namespace mln::level - /// 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"); - } - - - // Un-instant. - - template <typename I, typename V> - void fill_with_value(const Image< instant_<I> >& ima, const V& val) - { - fill_with_value(exact(ima).un_instant_(), val); - } +} // end of namespace mln # endif // ! MLN_INCLUDE_ONLY - } // end of namespace mln::level -} // end of namespace mln - - -#endif // ! MLN_LEVEL_FILL_WITH_VALUE_HH +#endif // ! MLN_LEVEL_FILL_WITH_VALUE_SPE_HH Index: mln/level/fill_with_value.hh --- mln/level/fill_with_value.hh (revision 2236) +++ mln/level/fill_with_value.hh (working copy) @@ -38,6 +38,7 @@ * \todo Make memset_ work and use it when appropriate. * \todo Move specializations in a extra file. * \toto Activate fill_with_value_cell_wise. + * \todo Optimize when \p ima is large and sizeof(mln_value(I)) > 1. */ # include <cstdlib> @@ -46,6 +47,9 @@ # include <mln/core/image/inplace.hh> # include <mln/core/image/instant.hh> +// Specializations are in: +# include <mln/level/fill_with_value.spe.hh> + namespace mln { @@ -59,8 +63,6 @@ * \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); @@ -74,138 +76,61 @@ # ifndef MLN_INCLUDE_ONLY - namespace impl - { - - template <typename I> - inline - void fill_with_value_site_wise_any(I& ima, const mln_value(I)& val) + namespace internal { - 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) + void fill_with_value_tests(Image<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"); + mlc_is(mln_trait_image_value_io(I), + mln::trait::image::value_io::read_write)::check(); + mlc_converts_to(mln_exact(V), mln_value(I))::check(); + mln_precondition(exact(ima).has_data()); } + } // end of namespace mln::level::internal - 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) + namespace impl { - 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) + namespace generic { - 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) + void fill_with_value(Image<I>& ima_, const V& val) { - fill_with_value_site_wise(ima, val); - } + trace::entering("level::impl::generic::fill_with_value"); - 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); - } + I& ima = exact(ima_); + internal::fill_with_value_tests(ima, val); - // Selector w.r.t. value_browsing. + mln_value(I) v = exact(val); + mln_piter(I) p(ima.domain()); + for_all(p) + ima(p) = v; - 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); + trace::exiting("level::impl::generic::fill_with_value"); } - } // end of namespace mln::level::impl::dispatch + } // end if namespace mln::level::impl::generic } // 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()); + trace::entering("level::fill_with_value"); - impl::dispatch::fill_with_value_(exact(ima), exact(val)); + internal::fill_with_value_tests(ima, val); + internal::fill_with_value_dispatch(ima, val); - trace::exiting("level::fill"); + trace::exiting("level::fill_with_value"); } Index: mln/level/fill_with_image.spe.hh --- mln/level/fill_with_image.spe.hh (revision 0) +++ mln/level/fill_with_image.spe.hh (revision 0) @@ -0,0 +1,84 @@ +// 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_SPE_HH +# define MLN_LEVEL_FILL_WITH_IMAGE_SPE_HH + +/*! \file mln/level/fill_with_image.spe.hh + * + * \brief Specializations for mln::level::fill_with_image. + * + * \todo Add specializations then rewrite the dispatch. + */ + +# ifndef MLN_LEVEL_FILL_WITH_IMAGE_HH +# error "Forbidden inclusion of *.spe.hh" +# endif // ! MLN_LEVEL_FILL_WITH_IMAGE_HH + + + +# ifndef MLN_INCLUDE_ONLY + +namespace mln +{ + + namespace level + { + + namespace impl + { + + namespace generic + { + template <typename I, typename J> + void fill_with_image(const Image<I>& data, Image<J>& destination); + } + + // FIXME: Add specializations here... + + } // end of namespace mln::level::impl + + namespace internal + { + + template <typename I, typename J> + inline + void fill_with_image_dispatch(Image<I>& ima, const Image<J>& data) + { + impl::generic::fill_with_image(ima, data); + } + + } // end of namespace mln::level::internal + + } // end of namespace mln::level + +} // end of namespace mln + +# endif // ! MLN_INCLUDE_ONLY + + +#endif // ! MLN_LEVEL_FILL_WITH_IMAGE_HH
participants (1)
-
Thierry Geraud