Commit e100ef6c authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add fun::v2v::convert and level::convert.

	* milena/mln/fun/v2v/convert.hh: New.
	* milena/mln/fun/v2v/cast.hh (todo): New.
	* milena/mln/level/convert.hh: New.
	* milena/tests/level/convert.cc: New.
	* milena/tests/level/Makefile.am: Update.
	* milena/mln/value/rgb.hh (todo): New.
	(from_to): New overload for bool->rgbn.
	* milena/mln/convert/from_to.hxx
	(from_to): New decl for bool->rgbn.
	* milena/sandbox/scribo/demat.hh
	(include): Remove obsolete dependency.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2696 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 8b75c1a1
2008-10-27 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add fun::v2v::convert and level::convert.
* milena/mln/fun/v2v/convert.hh: New.
* milena/mln/fun/v2v/cast.hh (todo): New.
* milena/mln/level/convert.hh: New.
* milena/tests/level/convert.cc: New.
* milena/tests/level/Makefile.am: Update.
* milena/mln/value/rgb.hh (todo): New.
(from_to): New overload for bool->rgbn.
* milena/mln/convert/from_to.hxx
(from_to): New decl for bool->rgbn.
* milena/sandbox/scribo/demat.hh
(include): Remove obsolete dependency.
2008-10-15 Roland Levillain <roland@lrde.epita.fr>
* configure.ac: Configure milena/tests/io/off/Makefile.
......
......@@ -108,6 +108,11 @@ namespace mln
void
from_to(const algebra::vec<3,T>& from, value::rgb<m>& to);
// bool -> rgb.
template <unsigned m>
void
from_to(bool from, value::rgb<m>& to);
// Value -> Value
template <typename F, typename T>
void
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// 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
......@@ -31,6 +31,9 @@
/*! \file mln/fun/v2v/cast.hh
*
* \brief FIXME.
*
* \todo The function is intrisically meta; how to handle that
* particular case?
*/
# include <mln/core/concept/function.hh>
......
// 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_FUN_V2V_CONVERT_HH
# define MLN_FUN_V2V_CONVERT_HH
/*! \file mln/fun/v2v/convert.hh
*
* \brief FIXME.
*
* \todo The function is intrisically meta; how to handle that
* particular case?
*/
# include <mln/core/concept/function.hh>
# include <mln/convert/to.hh>
namespace mln
{
namespace fun
{
namespace v2v
{
// FIXME: Doc!
template <typename V>
struct convert : public Function_v2v< convert<V> >
{
typedef V result;
template <typename W>
V operator()(const W& w) const;
};
# ifndef MLN_INCLUDE_ONLY
template <typename V>
template <typename W>
inline
V
convert<V>::operator()(const W& w) const
{
return mln::convert::to<V>(w);
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::fun::v2v
} // end of namespace mln::fun
} // end of namespace mln
#endif // ! MLN_FUN_V2V_CONVERT_HH
// 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_CONVERT_HH
# define MLN_LEVEL_CONVERT_HH
/*! \file mln/level/convert.hh
*
* \brief Convert the contents of an image into another one.
*
* \todo Re-write doc.
*/
# include <mln/fun/v2v/convert.hh>
# include <mln/level/transform.hh>
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.
*/
template <typename V, typename I>
mln_ch_value(I, V)
convert(const V&, const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
// Facade.
template <typename V, typename I>
inline
mln_ch_value(I, V)
convert(const V&, const Image<I>& input)
{
trace::entering("level::convert");
mln_precondition(exact(input).has_data());
fun::v2v::convert<V> f;
mln_ch_value(I, V) output = level::transform(input, f);
trace::exiting("level::convert");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::level
} // end of namespace mln
#endif // ! MLN_LEVEL_CONVERT_HH
......@@ -32,6 +32,11 @@
*
* \brief Color class for red-green-blue where every component is
* n-bit encoded.
*
* \todo Split decl and def for from_to.
*
* \todo Introduce the concept of Color, then generalize from_to to
* colors.
*/
# include <mln/value/ops.hh>
......@@ -514,6 +519,22 @@ namespace mln
to = value::rgb<m>(tmp);
}
// bool -> rgb.
template <unsigned m>
void
from_to(bool from, value::rgb<m>& to)
{
static literal::white_t* white_ = 0;
static literal::black_t* black_ = 0;
// We do not use literal::white (the object) so that we
// do not introduce any coupling with the file where
// literals are defined.
if (from)
to = *white_;
else
to = *black_;
}
} // end of namespace mln::convert
......
......@@ -55,8 +55,6 @@
# include <mln/draw/box.hh>
# include <mln/estim/nsites.hh>
# include <mln/fun/i2v/array.hh>
# include <mln/io/pbm/load.hh>
......
......@@ -11,6 +11,7 @@ check_PROGRAMS = \
assign \
compare \
compute \
convert \
fill \
fill_with_value \
fill_with_image \
......@@ -35,6 +36,7 @@ apply_SOURCES = apply.cc
assign_SOURCES = assign.cc
compare_SOURCES = compare.cc
compute_SOURCES = compute.cc
convert_SOURCES = convert.cc
fill_SOURCES = fill.cc
fill_with_value_SOURCES = fill_with_value.cc
fill_with_image_SOURCES = fill_with_image.cc
......
// 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.
/*! \file tests/level/convert.cc
*
* \brief Tests on mln::level::convert
*/
#include <mln/core/image/image2d.hh>
#include <mln/level/convert.hh>
#include <mln/value/rgb8.hh>
#include <mln/literal/grays.hh>
int main()
{
using namespace mln;
using value::rgb8;
// trace::quiet = false;
// bool -> rgb8
{
image2d<bool> ima(1, 2);
ima.at(0, 0) = false;
ima.at(0, 1) = true;
image2d<rgb8> out = level::convert(rgb8(), ima);
mln_assertion(out.at(0, 0) == literal::black);
mln_assertion(out.at(0, 1) == literal::white);
}
}
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