
* mln/level/convert.hh: Add a specialization while the conversion value type is equal to the image value type. * tests/level/convert.cc: add a new test. --- milena/ChangeLog | 15 ++++- milena/mln/level/convert.hh | 115 ++++++++++++++++++++++++++++++++++++---- milena/tests/level/convert.cc | 23 ++++++--- 3 files changed, 131 insertions(+), 22 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 8216a5f..d961175 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,4 +1,13 @@ -2009-03-02 Guillaume Lazzara <lazzara@lrde.epita.fr> +2009-03-03 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add a specialization of level::convert. + + * mln/level/convert.hh: Add a specialization while the conversion + value type is equal to the image value type. + + * tests/level/convert.cc: add a new test. + +2009-03-03 Guillaume Lazzara <lazzara@lrde.epita.fr> Introduce distance_and_closest_point_geodesic. @@ -24,7 +33,7 @@ Update according modifications in distance_and_closest_point_geodesic.hh. -2009-03-02 Guillaume Lazzara <lazzara@lrde.epita.fr> +2009-03-03 Guillaume Lazzara <lazzara@lrde.epita.fr> Add util::couple. @@ -33,7 +42,7 @@ * mln/util/all.hh, * mln/util/essential.hh: include new header. -2009-03-02 Guillaume Lazzara <lazzara@lrde.epita.fr> +2009-03-03 Guillaume Lazzara <lazzara@lrde.epita.fr> configure.ac: configure milena/tests/transform. diff --git a/milena/mln/level/convert.hh b/milena/mln/level/convert.hh index 3c7a827..39da091 100644 --- a/milena/mln/level/convert.hh +++ b/milena/mln/level/convert.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2008, 2009 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 @@ -8,7 +9,7 @@ // 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. +// 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 @@ -34,6 +35,7 @@ /// /// \todo Re-write doc. +# include <mln/core/routine/duplicate.hh> # include <mln/fun/v2v/convert.hh> # include <mln/level/transform.hh> @@ -44,12 +46,11 @@ namespace mln namespace level { - /*! Convert the image \p input by changing the value type. - * - * \param[in] v A value of the destination type. - * \param[in] input The input image. - * \param[out] output The result image. - */ + /// Convert the image \p input by changing the value type. + /// + /// \param[in] v A value of the destination type. + /// \param[in] input The input image. + /// \param[out] output The result image. template <typename V, typename I> mln_ch_value(I, V) convert(const V&, const Image<I>& input); @@ -58,18 +59,108 @@ namespace mln # ifndef MLN_INCLUDE_ONLY + namespace internal + { + + template <typename V, typename I> + inline + void + convert_tests(const V&, const Image<I>& input) + { + mln_precondition(exact(input).is_valid()); + (void) input; + } + + } // using namespace mln::level::internal + + namespace impl + { + + namespace generic + { + + template <typename V, typename I> + inline + mln_ch_value(I, V) + convert(const V& v, const Image<I>& input) + { + trace::entering("level::impl::generic::convert"); + internal::convert_tests(v, input); + + fun::v2v::convert<V> f; + mln_ch_value(I, V) output = level::transform(input, f); + + trace::exiting("level::impl::generic::convert"); + return output; + } + + } // end of namespace mln::level::impl::generic + + + template <typename V, typename I> + inline + mln_concrete(I) + convert_identity(const V& v, const Image<I>& input) + { + trace::entering("level::impl::convert_identity"); + internal::convert_tests(v, input); + + mln_concrete(I) output = duplicate(input); + + trace::exiting("level::impl::convert_identity"); + return output; + } + + + } // end of namespace mln::level::impl + + namespace internal + { + + template <typename V, typename I> + inline + mln_ch_value(I, V) + convert_dispatch(metal::bool_<true>, + const V& v, const Image<I>& input) + { + return impl::convert_identity(v, input); + } + + template <typename V, typename I> + inline + mln_ch_value(I, V) + convert_dispatch(metal::bool_<false>, + const V& v, const Image<I>& input) + { + return impl::generic::convert(v, input); + } + + template <typename V, typename I> + inline + mln_ch_value(I, V) + convert_dispatch(const V& v, const Image<I>& input) + { + enum { + test = mlc_equal(V, mln_value(I))::value + }; + return convert_dispatch(metal::bool_<test>(), + v, input); + } + + } // end of namespace mln::level::internal + // Facade. template <typename V, typename I> inline mln_ch_value(I, V) - convert(const V&, const Image<I>& input) + convert(const V& v, const Image<I>& input) { trace::entering("level::convert"); - mln_precondition(exact(input).is_valid()); - fun::v2v::convert<V> f; - mln_ch_value(I, V) output = level::transform(input, f); + internal::convert_tests(v, input); + + mln_ch_value(I, V) output = internal::convert_dispatch(v, input); trace::exiting("level::convert"); return output; diff --git a/milena/tests/level/convert.cc b/milena/tests/level/convert.cc index 9b1fd1f..f9b42ab 100644 --- a/milena/tests/level/convert.cc +++ b/milena/tests/level/convert.cc @@ -1,4 +1,5 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory +// Copyright (C) 2008, 2009 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 @@ -25,13 +26,13 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/level/convert.cc - * - * \brief Tests on mln::level::convert - */ +/// \file tests/level/convert.cc +/// +/// Tests on mln::level::convert #include <mln/core/image/image2d.hh> #include <mln/level/convert.hh> +#include <mln/level/compare.hh> #include <mln/value/rgb8.hh> #include <mln/literal/grays.hh> @@ -43,8 +44,6 @@ int main() using namespace mln; using value::rgb8; -// trace::quiet = false; - // bool -> rgb8 { image2d<bool> ima(1, 2); @@ -54,4 +53,14 @@ int main() mln_assertion(opt::at(out, 0, 0) == literal::black); mln_assertion(opt::at(out, 0, 1) == literal::white); } + // bool -> bool + { + image2d<bool> ima(1, 2); + data::fill(ima, true); + opt::at(ima, 0, 0) = false; + image2d<bool> out = level::convert(bool(), ima); + mln_assertion(out == ima); + mln_assertion(out.buffer() != ima.buffer()); + } + } -- 1.5.6.5