Commit a1ca9a44 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

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.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3468 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 975f71e7
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.
 
// 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;
......
// 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());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment