
URL: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena ChangeLog: 2008-09-17 Matthieu Garrigues <garrigues@lrde.epita.fr> Add extension::fill routine and test. * mln/extension/fill.hh: New, implementation of extension::fill. * tests/Makefile.am: Add extension test directory. * tests/core/other/Makefile.am(line_piter): Rename as... * tests/core/other/Makefile.am(box_runstart_piter): ...this * tests/extension/Makefile.am: New. To test extension namespace * tests/extension/fill.cc: New, extension::fill basic test. * tests/extension: New, extension test directory --- mln/extension/fill.hh | 119 +++++++++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 1 tests/core/other/Makefile.am | 4 - tests/extension/Makefile.am | 10 +++ tests/extension/fill.cc | 48 +++++++++++++++++ 5 files changed, 180 insertions(+), 2 deletions(-) Index: branches/cleanup-2008/milena/tests/core/other/Makefile.am =================================================================== --- branches/cleanup-2008/milena/tests/core/other/Makefile.am (revision 2286) +++ branches/cleanup-2008/milena/tests/core/other/Makefile.am (revision 2287) @@ -3,6 +3,7 @@ include $(top_srcdir)/milena/tests/tests.mk check_PROGRAMS = \ + box_runstart_piter \ category \ clock_neighb2d \ clock_test \ @@ -12,7 +13,6 @@ graph_elt_window \ line_graph_elt_neighborhood \ line_graph_elt_window \ - line_piter \ neighb \ pixel \ pixter1d \ @@ -23,6 +23,7 @@ pixter3d_more \ point_set_compatibility +box_runstart_piter_SOURCES = box_runstart_piter.cc category_SOURCES = category.cc clock_neighb2d_SOURCES = clock_neighb2d.cc clock_test_SOURCES = clock_test.cc @@ -32,7 +33,6 @@ graph_elt_window_SOURCES = graph_elt_window.cc line_graph_elt_neighborhood_SOURCES = line_graph_elt_neighborhood.cc line_graph_elt_window_SOURCES = line_graph_elt_window.cc -line_piter_SOURCES = line_piter.cc neighb_SOURCES = neighb.cc pixel_SOURCES = pixel.cc pixter1d_SOURCES = pixter1d.cc Index: branches/cleanup-2008/milena/tests/Makefile.am =================================================================== --- branches/cleanup-2008/milena/tests/Makefile.am (revision 2286) +++ branches/cleanup-2008/milena/tests/Makefile.am (revision 2287) @@ -15,6 +15,7 @@ display \ draw \ estim \ + extension \ fun \ geom \ histo \ Index: branches/cleanup-2008/milena/tests/extension/Makefile.am =================================================================== --- branches/cleanup-2008/milena/tests/extension/Makefile.am (revision 0) +++ branches/cleanup-2008/milena/tests/extension/Makefile.am (revision 2287) @@ -0,0 +1,10 @@ +## Process this file through Automake to create Makefile.in -*- Makefile -*- + +include $(top_srcdir)/milena/tests/tests.mk + +check_PROGRAMS = \ + fill + +fill_SOURCES = fill.cc + +TESTS = $(check_PROGRAMS) Index: branches/cleanup-2008/milena/tests/extension/fill.cc =================================================================== --- branches/cleanup-2008/milena/tests/extension/fill.cc (revision 0) +++ branches/cleanup-2008/milena/tests/extension/fill.cc (revision 2287) @@ -0,0 +1,48 @@ +// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE) +// +// 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/core/extension/fill.cc + * + * \brief Tests on mln::extension::fill. + */ + +#include <mln/core/image/image2d.hh> +#include <mln/extension/fill.hh> +#include <mln/value/int_u8.hh> +#include <mln/debug/println_with_border.hh> + +int main() +{ + using namespace mln; + + const unsigned border = 2; + + image2d<value::int_u8> ima(3, 3, border); + extension::fill(ima, 42); + + debug::println_with_border(ima); +} Index: branches/cleanup-2008/milena/mln/extension/fill.hh =================================================================== --- branches/cleanup-2008/milena/mln/extension/fill.hh (revision 0) +++ branches/cleanup-2008/milena/mln/extension/fill.hh (revision 2287) @@ -0,0 +1,119 @@ +// 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. + + +#ifndef MLN_CORE_EXTENSION_FILL_HH +# define MLN_CORE_EXTENSION_FILL_HH + +/*! \file mln/extension/fill.hh + * + * \brief Define function that fills domain extension. + * + */ + +# include <mln/core/concept/image.hh> +# include <mln/trait/image/props.hh> +# include <mln/border/fill.hh> +# include <mln/level/fill_with_value.hh> + +namespace mln +{ + + namespace extension + { + + /*! Fill the domain extension of image \p ima with the + * single value \p v. + * + * \param[in,out] ima The image whose domain extension is to be filled. + * \param[in] v The value to assign. + * + * \pre \p ima has to be initialized. + * + * \todo Optimize with memset if possible. + */ + template <typename I> + void fill(const Image<I>& ima, const mln_value(I)& v); + + namespace impl + { + template <typename I> + void fill_fixed_extension(const Image<I>& ima, const mln_value(I)& v); + } + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + void fill(const Image<I>& ima, const mln_value(I)& v) + { + // Case of ext_io::read_only. + if (mlc_equal(mln_trait_image_ext_io(I), + mln::trait::image::ext_io::read_only)::value == true) + return; // No-op. + + // Case of ext_domain::none. + if (mlc_equal(mln_trait_image_ext_domain(I), + mln::trait::image::ext_domain::none)::value == true) + return; // No-op. + + // Case of ext_domain::extendable. + if (mlc_equal(mln_trait_image_ext_domain(I), + mln::trait::image::ext_domain::extendable)::value == true) + return mln::border::fill(ima, v); + + + // Case of ext_domain::fixed. + if (mlc_equal(mln_trait_image_ext_domain(I), + mln::trait::image::ext_domain::fixed)::value == true) + + // Case of ext_value::single. + if (mlc_equal(mln_trait_image_ext_value(I), + mln::trait::image::ext_value::single)::value == true) + return impl::fill_fixed_extension(const_cast<I&>(exact(ima)), v); + else + return mln::level::fill_with_value(const_cast<I&>(exact(ima)), v); + + } + + namespace impl + { + template <typename I> + void fill_fixed_extension(Image<I>& ima_, const mln_value(I)& v) + { + I& ima = exact(ima_); + ima.extension() = v; + } + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::extension + +} // end of namespace mln + + +#endif // ! MLN_CORE_EXTENSION_FILL_HH