olena-2.0-126-g1f73c20 Add immerse_with_border.

* mln/world/k1/immerse_with_inner_border.hh, * mln/world/k2/immerse_with_inner_border.hh, * mln/world/kn/immerse_with_inner_border.hh, * mln/world/kn/internal/domain_from_k0.hh, * mln/world/kn/internal/fill_primary_2_faces_from_input.hh, * tests/world/k1/immerse_with_inner_border.cc, * tests/world/k2/immerse_with_inner_border.cc, * tests/world/kn/immerse_with_inner_border.cc: New. * mln/world/kn/immerse.hh, * mln/world/kn/internal/immerse_point.hh: Rely on immerse_with_inner_border. * tests/world/k1/Makefile.am, * tests/world/k2/Makefile.am, * tests/world/kn/Makefile.am: Update targets. * tests/world/k2/immerse.cc, * tests/world/kn/immerse.cc: Fix tests. --- milena/ChangeLog | 24 +++ milena/mln/world/k1/immerse_with_inner_border.hh | 168 ++++++++++++++++++ milena/mln/world/k2/immerse_with_inner_border.hh | 172 +++++++++++++++++++ milena/mln/world/kn/immerse.hh | 42 +---- milena/mln/world/kn/immerse_with_inner_border.hh | 179 ++++++++++++++++++++ milena/mln/world/kn/internal/domain_from_k0.hh | 103 +++++++++++ .../kn/internal/fill_primary_2_faces_from_input.hh | 118 +++++++++++++ milena/mln/world/kn/internal/immerse_point.hh | 37 ++++- milena/tests/world/k1/Makefile.am | 2 + milena/tests/world/k1/immerse_with_inner_border.cc | 93 ++++++++++ milena/tests/world/k2/Makefile.am | 2 + milena/tests/world/k2/immerse.cc | 18 +- milena/tests/world/k2/immerse_with_inner_border.cc | 92 ++++++++++ milena/tests/world/kn/Makefile.am | 2 + milena/tests/world/kn/immerse.cc | 57 +++---- milena/tests/world/kn/immerse_with_inner_border.cc | 136 +++++++++++++++ 16 files changed, 1166 insertions(+), 79 deletions(-) create mode 100644 milena/mln/world/k1/immerse_with_inner_border.hh create mode 100644 milena/mln/world/k2/immerse_with_inner_border.hh create mode 100644 milena/mln/world/kn/immerse_with_inner_border.hh create mode 100644 milena/mln/world/kn/internal/domain_from_k0.hh create mode 100644 milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh create mode 100644 milena/tests/world/k1/immerse_with_inner_border.cc create mode 100644 milena/tests/world/k2/immerse_with_inner_border.cc create mode 100644 milena/tests/world/kn/immerse_with_inner_border.cc diff --git a/milena/ChangeLog b/milena/ChangeLog index e939e2c..af00618 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,29 @@ 2012-10-23 Guillaume Lazzara <z@lrde.epita.fr> + Add immerse_with_border. + + * mln/world/k1/immerse_with_inner_border.hh, + * mln/world/k2/immerse_with_inner_border.hh, + * mln/world/kn/immerse_with_inner_border.hh, + * mln/world/kn/internal/domain_from_k0.hh, + * mln/world/kn/internal/fill_primary_2_faces_from_input.hh, + * tests/world/k1/immerse_with_inner_border.cc, + * tests/world/k2/immerse_with_inner_border.cc, + * tests/world/kn/immerse_with_inner_border.cc: New. + + * mln/world/kn/immerse.hh, + * mln/world/kn/internal/immerse_point.hh: Rely on + immerse_with_inner_border. + + * tests/world/k1/Makefile.am, + * tests/world/k2/Makefile.am, + * tests/world/kn/Makefile.am: Update targets. + + * tests/world/k2/immerse.cc, + * tests/world/kn/immerse.cc: Fix tests. + +2012-10-23 Guillaume Lazzara <z@lrde.epita.fr> + * mln/value/intsub.hh: Add operator=(literal::zero). 2012-10-23 Guillaume Lazzara <z@lrde.epita.fr> diff --git a/milena/mln/world/k1/immerse_with_inner_border.hh b/milena/mln/world/k1/immerse_with_inner_border.hh new file mode 100644 index 0000000..7cfeb00 --- /dev/null +++ b/milena/mln/world/k1/immerse_with_inner_border.hh @@ -0,0 +1,168 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_WORLD_K1_IMMERSE_WITH_INNER_BORDER_HH +# define MLN_WORLD_K1_IMMERSE_WITH_INNER_BORDER_HH + +/// \file +/// +/// \brief Immerse a 2D image into K1 with additional border pixels. + +# include <mln/core/concept/image.hh> +# include <mln/world/kn/immerse_with_inner_border.hh> + + + +namespace mln +{ + + namespace world + { + + namespace k1 + { + /*! \brief Immerse a 2D image into K1 with additional border + /// pixels. + + \param[in] ima A 2D image. + \param[in] n Set in which space K\p n to immerse \p ima. + \param[in] new_value_type An instance of the output value type. + \param[in] inner_border_thickness Define the inner border size. + + By default, the output image is not initialized except the + primary 2-faces. + + \verbatim + 0 1 + + 0 X Y + \endverbatim + + immersion with inner_border_thickness = 1 --> + + \verbatim + 0 2 4 6 + + - + - + - + - + + 0 | b | b | b | b | + + - + - + - + - + + 2 | b | X | Y | b | + + - + - + - + - + + 4 | b | b | b | b | + + - + - + - + - + + \endverbatim + */ + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + unsigned inner_border_thickness); + + /// \overload + /// This overload initializes the output image with \p + /// default_value. + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness); + + /// \overload + /// The output image has the same type as \p ima. + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned inner_border_thickness); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k1::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + mln_ch_value(I,V) + output = world::kn::immerse_with_inner_border(ima, + 1, + new_value_type, + inner_border_thickness); + + trace::exiting("mln::world::k1::immerse_with_inner_border"); + return output; + } + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k1::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + mln_ch_value(I,V) + output = world::kn::immerse_with_inner_border(ima, + 1, + new_value_type, + default_value, + inner_border_thickness); + + trace::exiting("mln::world::k1::immerse_with_inner_border"); + return output; + } + + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k1::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + typedef mln_value(I) V; + mln_concrete(I) + output = immerse_with_inner_border(ima, 1, V(), + inner_border_thickness); + + trace::exiting("mln::world::k1::immerse_with_inner_border"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::world::k1 + + } // end of namespace mln::world + +} // end of namespace mln + + +#endif // ! MLN_WORLD_K1_IMMERSE_WITH_INNER_BORDER_HH diff --git a/milena/mln/world/k2/immerse_with_inner_border.hh b/milena/mln/world/k2/immerse_with_inner_border.hh new file mode 100644 index 0000000..46c3675 --- /dev/null +++ b/milena/mln/world/k2/immerse_with_inner_border.hh @@ -0,0 +1,172 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_WORLD_K2_IMMERSE_WITH_INNER_BORDER_HH +# define MLN_WORLD_K2_IMMERSE_WITH_INNER_BORDER_HH + +/// \file +/// +/// \brief Immerse a 2D image into K2 with additional border pixels. + +# include <mln/core/concept/image.hh> +# include <mln/world/kn/immerse_with_inner_border.hh> + + + +namespace mln +{ + + namespace world + { + + namespace k2 + { + /*! \brief Immerse a 2D image into K2 with additional border + /// pixels. + + \param[in] ima A 2D image. + \param[in] n Set in which space K\p n to immerse \p ima. + \param[in] new_value_type An instance of the output value type. + \param[in] inner_border_thickness Define the inner border size. + + By default, the output image is not initialized except the + primary 2-faces. + + \verbatim + 0 1 + + 0 X Y + \endverbatim + + immersion with inner_border_thickness = 1 --> + + \verbatim + 0 4 8 12 + + - + - + - + - + - + - + - + + 0 | b | | b | | b | | b | + + - + - + - + - + - + - + - + + | | | | | | | | + + - + - + - + - + - + - + - + + 4 | b | | X | | Y | | b | + + - + - + - + - + - + - + - + + | | | | | | | | + + - + - + - + - + - + - + - + + 8 | b | | b | | b | | b | + + - + - + - + - + - + - + - + + \endverbatim + */ + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + unsigned inner_border_thickness); + + /// \overload + /// This overload initializes the output image with \p + /// default_value. + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness); + + /// \overload + /// The output image has the same type as \p ima. + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned inner_border_thickness); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k2::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + mln_ch_value(I,V) + output = world::kn::immerse_with_inner_border(ima, + 2, + new_value_type, + inner_border_thickness); + + trace::exiting("mln::world::k2::immerse_with_inner_border"); + return output; + } + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k2::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + mln_ch_value(I,V) + output = world::kn::immerse_with_inner_border(ima, + 2, + new_value_type, + default_value, + inner_border_thickness); + + trace::exiting("mln::world::k2::immerse_with_inner_border"); + return output; + } + + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned inner_border_thickness) + { + trace::entering("mln::world::k2::immerse_with_inner_border"); + mln_precondition(exact(ima).is_valid()); + + typedef mln_value(I) V; + mln_concrete(I) + output = immerse_with_inner_border(ima, 2, V(), + inner_border_thickness); + + trace::exiting("mln::world::k2::immerse_with_inner_border"); + return output; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::world::k2 + + } // end of namespace mln::world + +} // end of namespace mln + + +#endif // ! MLN_WORLD_K2_IMMERSE_WITH_INNER_BORDER_HH diff --git a/milena/mln/world/kn/immerse.hh b/milena/mln/world/kn/immerse.hh index 8d5f578..6359e87 100644 --- a/milena/mln/world/kn/immerse.hh +++ b/milena/mln/world/kn/immerse.hh @@ -32,9 +32,7 @@ # include <mln/core/concept/image.hh> # include <mln/core/concept/box.hh> - -# include <mln/world/kn/internal/immerse_point.hh> -# include <mln/world/kn/safe_cast.hh> +# include <mln/world/kn/immerse_with_inner_border.hh> namespace mln { @@ -88,28 +86,6 @@ namespace mln # ifndef MLN_INCLUDE_ONLY - namespace internal - { - - /// \brief Return the equivalent domain in Kn from a domain in - /// K0. - template <typename B> - inline - B domain_from_K0(const Box<B>& b_, const unsigned n) - { - mln_precondition(exact(b_).is_valid()); - const B& b = exact(b_); - - mln_deduce(B, site, delta) one; - one.set_all(1); - return B(immerse_point(b.pmin(), n) - one, - immerse_point(b.pmax(), n) + one); - } - - } // end of namespace mln::world::kn::internal - - - template <typename I, typename V> mln_ch_value(I, V) @@ -122,12 +98,7 @@ namespace mln (void) new_value_type; mln_ch_value(I,V) - output(internal::domain_from_K0(ima.domain(), n)); - - // Filling Primary 2-Faces - mln_piter(I) p(ima.domain()); - for_all(p) - output(internal::immerse_point(p, n)) = safe_cast(ima(p)); + output = immerse_with_inner_border(ima, n, new_value_type, 0); trace::exiting("mln::world::kn::immerse"); return output; @@ -145,13 +116,8 @@ namespace mln (void) new_value_type; mln_ch_value(I,V) - output(internal::domain_from_K0(ima.domain(), n)); - data::fill(output, default_value); - - // Filling Primary 2-Faces - mln_piter(I) p(ima.domain()); - for_all(p) - output(internal::immerse_point(p, n)) = safe_cast(ima(p)); + output = immerse_with_inner_border(ima, n, new_value_type, + default_value, 0); trace::exiting("mln::world::kn::immerse"); return output; diff --git a/milena/mln/world/kn/immerse_with_inner_border.hh b/milena/mln/world/kn/immerse_with_inner_border.hh new file mode 100644 index 0000000..22453bc --- /dev/null +++ b/milena/mln/world/kn/immerse_with_inner_border.hh @@ -0,0 +1,179 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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_WORLD_KN_IMMERSE_WITH_INNER_BORDER_HH +# define MLN_WORLD_KN_IMMERSE_WITH_INNER_BORDER_HH + +/// \file +/// +/// \brief Immerse a 2D image into Kn with additional border pixels. + +# include <mln/core/concept/image.hh> +# include <mln/data/fill.hh> +# include <mln/world/kn/internal/domain_from_k0.hh> +# include <mln/world/kn/internal/fill_primary_2_faces_from_input.hh> + + +namespace mln +{ + + namespace world + { + + namespace kn + { + /*! \brief Immerse a 2D image into Kn with additional border + /// pixels. + + \param[in] ima A 2D image. + \param[in] n Set in which space K\p n to immerse \p ima. + \param[in] new_value_type An instance of the output value type. + \param[in] inner_border_thickness Define the inner border size. + + By default, the output image is not initialized except the + primary 2-faces. + + \verbatim + 0 1 + + 0 X Y + \endverbatim + + immersion with n = 2 and inner_border_thickness = 1 --> + + \verbatim + 0 4 8 12 + + - + - + - + - + - + - + - + + 0 | b | | b | | b | | b | + + - + - + - + - + - + - + - + + | | | | | | | | + + - + - + - + - + - + - + - + + 4 | b | | X | | Y | | b | + + - + - + - + - + - + - + - + + | | | | | | | | + + - + - + - + - + - + - + - + + 8 | b | | b | | b | | b | + + - + - + - + - + - + - + - + + \endverbatim + */ + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + unsigned n, + const V& new_value_type, + unsigned inner_border_thickness); + + /// \overload + /// This overload initializes the output image with \p + /// default_value. + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima, + unsigned n, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness); + + /// \overload + /// The output image has the same type as \p ima. + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned n, + unsigned inner_border_thickness); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima_, + unsigned n, + const V& new_value_type, + unsigned inner_border_thickness) + { + trace::entering("mln::world::kn::immerse_with_inner_border"); + mln_precondition(exact(ima_).is_valid()); + (void) new_value_type; + + const I& ima = exact(ima_); + + mln_ch_value(I,V) + output(internal::domain_from_k0(ima.domain(), n, + inner_border_thickness)); + + internal::fill_primary_2_faces_from_input(output, n, ima, + inner_border_thickness); + + trace::exiting("mln::world::kn::immerse_with_inner_border"); + return output; + } + + template <typename I, typename V> + mln_ch_value(I,V) + immerse_with_inner_border(const Image<I>& ima_, + unsigned n, + const V& new_value_type, + const V& default_value, + unsigned inner_border_thickness) + { + trace::entering("mln::world::kn::immerse_with_inner_border"); + mln_precondition(exact(ima_).is_valid()); + (void) new_value_type; + + const I& ima = exact(ima_); + + mln_ch_value(I,V) + output(internal::domain_from_k0(ima.domain(), n, + inner_border_thickness)); + data::fill(output, default_value); + + internal::fill_primary_2_faces_from_input(output, n, ima, + inner_border_thickness); + + trace::exiting("mln::world::kn::immerse_with_inner_border"); + return output; + } + + template <typename I> + mln_concrete(I) + immerse_with_inner_border(const Image<I>& ima, + unsigned n, + unsigned inner_border_thickness) + { + typedef mln_value(I) V; + return immerse_with_inner_border(ima, n, V(), inner_border_thickness); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::world::kn + + } // end of namespace mln::world + +} // end of namespace mln + + +#endif // ! MLN_WORLD_KN_IMMERSE_WITH_INNER_BORDER_HH diff --git a/milena/mln/world/kn/internal/domain_from_k0.hh b/milena/mln/world/kn/internal/domain_from_k0.hh new file mode 100644 index 0000000..1950280 --- /dev/null +++ b/milena/mln/world/kn/internal/domain_from_k0.hh @@ -0,0 +1,103 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// +/// \brief Return the equivalent domain in Kn from a domain in +/// K0. + +#ifndef MLN_WORLD_KN_DOMAIN_FROM_K0_HH +# define MLN_WORLD_KN_DOMAIN_FROM_K0_HH + +# include <mln/core/concept/box.hh> +# include <mln/world/kn/internal/immerse_point.hh> + +namespace mln +{ + + namespace world + { + + namespace kn + { + + namespace internal + { + + /// \brief Return the equivalent domain in Kn from a domain in + /// K0. + template <typename B> + B + domain_from_k0(const Box<B>& b, const unsigned n, + unsigned inner_border_thickness); + + /// \overload + /// \p inner_border_thickness is set to 0. + template <typename B> + B + domain_from_k0(const Box<B>& b, const unsigned n); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename B> + B + domain_from_k0(const Box<B>& b_, const unsigned n, + unsigned inner_border_thickness) + { + mln_precondition(exact(b_).is_valid()); + const B& b = exact(b_); + + mln_deduce(B, site, delta) one; + one.set_all(1); + B bout = B(immerse_point(b.pmin(), n, inner_border_thickness) + - (inner_border_thickness * 2 * one) - one, + immerse_point(b.pmax(), n, inner_border_thickness) + + (std::pow(2,n) - 1) * one + (inner_border_thickness * 2 * one)); + return bout; + } + + + template <typename B> + B + domain_from_k0(const Box<B>& b, const unsigned n) + { + return domain_from_K0(b, n, 0); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::work::kn::internal + + } // end of namespace mln::world::kn + + } // end of namespace mln::world + +} // end of namespace mln + +#endif // ! MLN_WORLD_KN_DOMAIN_FROM_K0_HH + + diff --git a/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh b/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh new file mode 100644 index 0000000..5884771 --- /dev/null +++ b/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh @@ -0,0 +1,118 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 +/// +/// \brief Fill primary 2-faces from a Kn image using original pixel +/// as values. + +#ifndef MLN_WORLD_KN_FILL_PRIMARY_2_FACES_FROM_INPUT_HH +# define MLN_WORLD_KN_FILL_PRIMARY_2_FACES_FROM_INPUT_HH + +# include <mln/world/kn/internal/immerse_point.hh> +# include <mln/world/kn/safe_cast.hh> + +namespace mln +{ + + namespace world + { + + namespace kn + { + + namespace internal + { + + /// \brief Fill primary 2-faces from a Kn image using original pixel + /// as values. + template <typename I, typename J> + void + fill_primary_2_faces_from_input(Image<I>& ima_kn, + unsigned n, + const Image<J>& ima, + const unsigned inner_border_thickness); + + /// \overload + /// \p inner_border_thickness is set to 0. + template <typename I, typename J> + void + fill_primary_2_faces_from_input(Image<I>& ima_kn, + unsigned n, + const Image<J>& ima); + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename J> + void + fill_primary_2_faces_from_input(Image<I>& ima_kn_, + unsigned n, + const Image<J>& ima_, + const unsigned inner_border_thickness) + { + trace::entering("mln::world::kn::internal::fill_primary_2_faces_from_input"); + mlc_equal(mln_site(I), mln_site(J))::check(); + mln_precondition(exact(ima_).is_valid()); + mln_precondition(exact(ima_kn_).is_valid()); + mln_precondition(exact(ima_).domain() <= exact(ima_kn_).domain()); + + I& ima_kn = exact(ima_kn_); + const J& ima = exact(ima_); + + // Filling Primary 2-Faces + mln_piter(J) p(ima.domain()); + for_all(p) + { + mln_site(I) pout = internal::immerse_point(p, n, inner_border_thickness); + ima_kn(pout) = safe_cast(ima(p)); + } + + trace::exiting("mln::world::kn::internal::fill_primary_2_faces_from_input"); + } + + + template <typename I, typename J> + void + fill_primary_2_faces_from_input(Image<I>& ima_kn, + unsigned n, + const Image<J>& ima) + { + return fill_primary_2_faces_from_input(ima_kn, n, ima, 0); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::work::kn::internal + + } // end of namespace mln::world::kn + + } // end of namespace mln::world + +} // end of namespace mln + +#endif // ! MLN_WORLD_KN_FILL_PRIMARY_2_FACES_FROM_INPUT_HH + + diff --git a/milena/mln/world/kn/internal/immerse_point.hh b/milena/mln/world/kn/internal/immerse_point.hh index 9dd46c7..538c8ed 100644 --- a/milena/mln/world/kn/internal/immerse_point.hh +++ b/milena/mln/world/kn/internal/immerse_point.hh @@ -30,6 +30,7 @@ #ifndef MLN_WORLD_KN_IMMERSE_POINT_HH # define MLN_WORLD_KN_IMMERSE_POINT_HH +# include <cmath> # include <mln/core/alias/point2d.hh> namespace mln @@ -49,9 +50,21 @@ namespace mln /// in K0. point2d immerse_point(const def::coord& row, const def::coord& col, + const unsigned n, + const unsigned inner_border_thickness); + + /// \overload + /// \p inner_border_thickness is set to 0. + point2d immerse_point(const def::coord& row, + const def::coord& col, const unsigned n); /// \overload + point2d immerse_point(const point2d& p, const unsigned n, + const unsigned inner_border_thickness); + + /// \overload + /// \p inner_border_thickness is set to 0. point2d immerse_point(const point2d& p, const unsigned n); @@ -59,21 +72,39 @@ namespace mln inline + point2d immerse_point(const point2d& p, const unsigned n, + const unsigned inner_border_thickness) + { + return immerse_point(p.row(), p.col(), n, + inner_border_thickness); + } + + inline point2d immerse_point(const point2d& p, const unsigned n) { - return immerse_point(p.row(), p.col(), n); + return immerse_point(p.row(), p.col(), n, 0); } inline point2d immerse_point(const def::coord& row, const def::coord& col, - const unsigned n) + const unsigned n, + const unsigned inner_border_thickness) { - point2d tmp(std::pow(2u, n) * row, std::pow(2u, n) * col); + point2d tmp(std::pow(2u, n) * row + 2 * inner_border_thickness, + std::pow(2u, n) * col + 2* inner_border_thickness); return tmp; } + inline + point2d immerse_point(const def::coord& row, + const def::coord& col, + const unsigned n) + { + return immerse_point(row, col, n, 0); + } + # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/tests/world/k1/Makefile.am b/milena/tests/world/k1/Makefile.am index 5c42124..3ff9c81 100644 --- a/milena/tests/world/k1/Makefile.am +++ b/milena/tests/world/k1/Makefile.am @@ -23,6 +23,7 @@ check_PROGRAMS = \ fill_0_from_primary_faces \ immerse \ immerse_with \ + immerse_with_inner_border \ immerse_and_duplicate_2_to_1_faces \ immerse_and_duplicate_2_to_0_1_faces \ is_primary_face \ @@ -34,6 +35,7 @@ fill_1_from_2_faces_SOURCES = fill_1_from_2_faces.cc fill_0_from_primary_faces_SOURCES = fill_0_from_primary_faces.cc immerse_SOURCES = immerse.cc immerse_with_SOURCES = immerse_with.cc +immerse_with_inner_border_SOURCES = immerse_with_inner_border.cc immerse_and_duplicate_2_to_1_faces_SOURCES = immerse_and_duplicate_2_to_1_faces.cc immerse_and_duplicate_2_to_0_1_faces_SOURCES = immerse_and_duplicate_2_to_0_1_faces.cc is_primary_face_SOURCES = is_primary_face.cc diff --git a/milena/tests/world/k1/immerse_with_inner_border.cc b/milena/tests/world/k1/immerse_with_inner_border.cc new file mode 100644 index 0000000..3c1082b --- /dev/null +++ b/milena/tests/world/k1/immerse_with_inner_border.cc @@ -0,0 +1,93 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 + +#include <mln/core/image/image2d.hh> +#include <mln/world/k1/immerse_with_inner_border.hh> +#include <mln/data/compare.hh> + + +int main() +{ + using namespace mln; + + int ivals[][2] = { + {1, 2}, + {3, 4} + }; + image2d<int> ima = make::image(ivals); + + int val_k1wob[][5] = { + {0, 0, 0, 0, 0}, + {0, 1, 0, 2, 0}, + {0, 0, 0, 0, 0}, + {0, 3, 0, 4, 0}, + {0, 0, 0, 0, 0}, + }; + image2d<int> k1wob = make::image(val_k1wob, point2d(-1,-1)); + + int val_k1b[][9] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 0, 2, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 3, 0, 4, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0} + }; + image2d<int> k1b = make::image(val_k1b, point2d(-1,-1)); + + // K1 with border. + { + image2d<long> immersed = world::k1::immerse_with_inner_border(ima, long(), 1); + mln_assertion(immersed.domain() == k1b.domain()); + mln_assertion(immersed(point2d(2,2)) == 1); + mln_assertion(immersed(point2d(2,4)) == 2); + mln_assertion(immersed(point2d(4,2)) == 3); + mln_assertion(immersed(point2d(4,4)) == 4); + } + { + image2d<long> immersed = world::k1::immerse_with_inner_border(ima, long(), 0l, 1); + mln_assertion(immersed == k1b); + } + { + image2d<int> immersed = world::k1::immerse_with_inner_border(ima, 1); + mln_assertion(immersed.domain() == k1b.domain()); + mln_assertion(immersed(point2d(2,2)) == 1); + mln_assertion(immersed(point2d(2,4)) == 2); + mln_assertion(immersed(point2d(4,2)) == 3); + mln_assertion(immersed(point2d(4,4)) == 4); + } + + // K1 without border. + { + image2d<long> immersed = world::k1::immerse_with_inner_border(ima, long(), 0l, 0); + mln_assertion(immersed == k1wob); + } + +} diff --git a/milena/tests/world/k2/Makefile.am b/milena/tests/world/k2/Makefile.am index 84b0801..c94bd50 100644 --- a/milena/tests/world/k2/Makefile.am +++ b/milena/tests/world/k2/Makefile.am @@ -24,6 +24,7 @@ check_PROGRAMS = \ is_non_primary_2_face_vertical \ is_primary_2_face \ immerse \ + immerse_with_inner_border \ un_immerse fill_non_primary_from_primary_2_faces_SOURCES = fill_non_primary_from_primary_2_faces.cc @@ -33,6 +34,7 @@ is_non_primary_2_face_horizontal_SOURCES = is_non_primary_2_face_horizontal.cc is_non_primary_2_face_vertical_SOURCES = is_non_primary_2_face_vertical.cc is_primary_2_face_SOURCES = is_primary_2_face.cc immerse_SOURCES = immerse.cc +immerse_with_inner_border_SOURCES = immerse_with_inner_border.cc un_immerse_SOURCES = un_immerse.cc TESTS = $(check_PROGRAMS) diff --git a/milena/tests/world/k2/immerse.cc b/milena/tests/world/k2/immerse.cc index d00f095..29fb4e4 100644 --- a/milena/tests/world/k2/immerse.cc +++ b/milena/tests/world/k2/immerse.cc @@ -39,14 +39,16 @@ int main() }; image2d<int> ima = make::image(ivals); - int fvals[][7] = { - {5, 5, 5, 5, 5, 5, 5}, - {5, 1, 5, 5, 5, 2, 5}, - {5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5}, - {5, 3, 5, 5, 5, 4, 5}, - {5, 5, 5, 5, 5, 5, 5} + int fvals[][9] = { + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 1, 5, 5, 5, 2, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 3, 5, 5, 5, 4, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5} }; image2d<int> ref_fill = make::image(fvals, point2d(-1,-1)); diff --git a/milena/tests/world/k2/immerse_with_inner_border.cc b/milena/tests/world/k2/immerse_with_inner_border.cc new file mode 100644 index 0000000..addbb5a --- /dev/null +++ b/milena/tests/world/k2/immerse_with_inner_border.cc @@ -0,0 +1,92 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 + +#include <mln/core/image/image2d.hh> +#include <mln/world/k2/immerse_with_inner_border.hh> +#include <mln/data/compare.hh> + + +int main() +{ + using namespace mln; + + int ivals[][2] = { + {1, 2}, + {3, 4} + }; + image2d<int> ima = make::image(ivals); + + int val_k2wob[][9] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 2, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 3, 0, 0, 0, 4, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + }; + image2d<int> k2wob = make::image(val_k2wob, point2d(-1,-1)); + + int val_k2b[][13] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + }; + image2d<int> k2b = make::image(val_k2b, point2d(-1,-1)); + + // K2 with border + { + image2d<long> immersed = world::k2::immerse_with_inner_border(ima, long(), 0l, 1); + mln_assertion(immersed == k2b); + } + + // K2 without border + { + image2d<long> immersed = world::k2::immerse_with_inner_border(ima, long(), 0l, 0); + mln_assertion(immersed == k2wob); + } + { + image2d<long> immersed = world::k2::immerse_with_inner_border(ima, long(), 0); + mln_assertion(immersed == k2wob); + } + { + image2d<int> immersed = world::k2::immerse_with_inner_border(ima, 0); + mln_assertion(immersed == k2wob); + } +} diff --git a/milena/tests/world/kn/Makefile.am b/milena/tests/world/kn/Makefile.am index f88c698..866ae00 100644 --- a/milena/tests/world/kn/Makefile.am +++ b/milena/tests/world/kn/Makefile.am @@ -24,6 +24,7 @@ check_PROGRAMS = \ fill_1_from_aux_2_faces \ fill_2_from_1_faces \ immerse \ + immerse_with_inner_border \ is_0_face \ is_0_or_1_face \ is_1_face \ @@ -40,6 +41,7 @@ fill_1_from_2_faces_SOURCES = fill_1_from_2_faces.cc fill_1_from_aux_2_faces_SOURCES = fill_1_from_aux_2_faces.cc fill_2_from_1_faces_SOURCES = fill_2_from_1_faces.cc immerse_SOURCES = immerse.cc +immerse_with_inner_border_SOURCES = immerse_with_inner_border.cc is_0_face_SOURCES = is_0_face.cc is_0_or_1_face_SOURCES = is_0_or_1_face.cc is_1_face_SOURCES = is_1_face.cc diff --git a/milena/tests/world/kn/immerse.cc b/milena/tests/world/kn/immerse.cc index 9419a67..7b532e7 100644 --- a/milena/tests/world/kn/immerse.cc +++ b/milena/tests/world/kn/immerse.cc @@ -39,51 +39,48 @@ int main() }; image2d<int> ima = make::image(ivals); - int fvals[][19] = { - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, - {5, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5}, - {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5} + int fvals[][17] = { + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 1, 5, 5, 5, 5, 5, 5, 5, 2, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 3, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, + {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5} }; image2d<int> ref_fill = make::image(fvals, point2d(-1,-1)); { - image2d<int> immersed = world::kn::immerse(ima, 4); - + image2d<int> immersed = world::kn::immerse(ima, 3); mln_assertion(immersed.domain() == ref_fill.domain()); mln_assertion(immersed(point2d(0,0)) == 1); - mln_assertion(immersed(point2d(0,16)) == 2); - mln_assertion(immersed(point2d(16,0)) == 3); - mln_assertion(immersed(point2d(16,16)) == 4); + mln_assertion(immersed(point2d(0,8)) == 2); + mln_assertion(immersed(point2d(8,0)) == 3); + mln_assertion(immersed(point2d(8,8)) == 4); } { - image2d<long> immersed = world::kn::immerse(ima, 4, long()); + image2d<long> immersed = world::kn::immerse(ima, 3, long()); mln_assertion(immersed.domain() == ref_fill.domain()); mln_assertion(immersed(point2d(0,0)) == 1); - mln_assertion(immersed(point2d(0,16)) == 2); - mln_assertion(immersed(point2d(16,0)) == 3); - mln_assertion(immersed(point2d(16,16)) == 4); + mln_assertion(immersed(point2d(0,8)) == 2); + mln_assertion(immersed(point2d(8,0)) == 3); + mln_assertion(immersed(point2d(8,8)) == 4); } { - image2d<long> immersed = world::kn::immerse(ima, 4, long(), 5l); + image2d<long> immersed = world::kn::immerse(ima, 3, long(), 5l); mln_assertion(immersed == ref_fill); } diff --git a/milena/tests/world/kn/immerse_with_inner_border.cc b/milena/tests/world/kn/immerse_with_inner_border.cc new file mode 100644 index 0000000..d0d59c7 --- /dev/null +++ b/milena/tests/world/kn/immerse_with_inner_border.cc @@ -0,0 +1,136 @@ +// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project 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 + +#include <mln/core/image/image2d.hh> +#include <mln/world/kn/immerse_with_inner_border.hh> +#include <mln/data/compare.hh> + + +int main() +{ + using namespace mln; + + int ivals[][2] = { + {1, 2}, + {3, 4} + }; + image2d<int> ima = make::image(ivals); + + int val_k1wob[][5] = { + {0, 0, 0, 0, 0}, + {0, 1, 0, 2, 0}, + {0, 0, 0, 0, 0}, + {0, 3, 0, 4, 0}, + {0, 0, 0, 0, 0}, + }; + image2d<int> k1wob = make::image(val_k1wob, point2d(-1,-1)); + + int val_k1b[][9] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 0, 2, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 3, 0, 4, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0} + }; + image2d<int> k1b = make::image(val_k1b, point2d(-1,-1)); + + int val_k2wob[][9] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 2, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 3, 0, 0, 0, 4, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + }; + image2d<int> k2wob = make::image(val_k2wob, point2d(-1,-1)); + + int val_k2b[][13] = { + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + }; + image2d<int> k2b = make::image(val_k2b, point2d(-1,-1)); + + // K1 with border. + { + image2d<long> immersed = world::kn::immerse_with_inner_border(ima, 1, long(), 1); + mln_assertion(immersed.domain() == k1b.domain()); + mln_assertion(immersed(point2d(2,2)) == 1); + mln_assertion(immersed(point2d(2,4)) == 2); + mln_assertion(immersed(point2d(4,2)) == 3); + mln_assertion(immersed(point2d(4,4)) == 4); + } + { + image2d<long> immersed = world::kn::immerse_with_inner_border(ima, 1, long(), 0l, 1); + mln_assertion(immersed == k1b); + } + { + image2d<int> immersed = world::kn::immerse_with_inner_border(ima, 1, 1); + mln_assertion(immersed.domain() == k1b.domain()); + mln_assertion(immersed(point2d(2,2)) == 1); + mln_assertion(immersed(point2d(2,4)) == 2); + mln_assertion(immersed(point2d(4,2)) == 3); + mln_assertion(immersed(point2d(4,4)) == 4); + } + + // K2 with border + { + image2d<long> immersed = world::kn::immerse_with_inner_border(ima, 2, long(), 0l, 1); + mln_assertion(immersed == k2b); + } + + + // K1 without border. + { + image2d<long> immersed = world::kn::immerse_with_inner_border(ima, 1, long(), 0l, 0); + mln_assertion(immersed == k1wob); + } + + // K2 without border + { + image2d<long> immersed = world::kn::immerse_with_inner_border(ima, 2, long(), 0l, 0); + mln_assertion(immersed == k2wob); + } + +} -- 1.7.2.5
participants (1)
-
Guillaume Lazzara