https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)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.
mln/convert/from_to.hxx | 5 ++
mln/fun/v2v/cast.hh | 5 ++
mln/fun/v2v/convert.hh | 85 ++++++++++++++++++++++++++++++++++++++++++++++
mln/level/convert.hh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
mln/value/rgb.hh | 21 +++++++++++
sandbox/scribo/demat.hh | 2 -
tests/level/Makefile.am | 2 +
tests/level/convert.cc | 56 ++++++++++++++++++++++++++++++
8 files changed, 260 insertions(+), 3 deletions(-)
Index: milena/tests/level/convert.cc
--- milena/tests/level/convert.cc (revision 0)
+++ milena/tests/level/convert.cc (revision 0)
@@ -0,0 +1,56 @@
+// 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);
+ }
+}
Index: milena/tests/level/Makefile.am
--- milena/tests/level/Makefile.am (revision 2695)
+++ milena/tests/level/Makefile.am (working copy)
@@ -11,6 +11,7 @@
assign \
compare \
compute \
+ convert \
fill \
fill_with_value \
fill_with_image \
@@ -35,6 +36,7 @@
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
Index: milena/mln/level/convert.hh
--- milena/mln/level/convert.hh (revision 0)
+++ milena/mln/level/convert.hh (revision 0)
@@ -0,0 +1,87 @@
+// 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
Index: milena/mln/value/rgb.hh
--- milena/mln/value/rgb.hh (revision 2695)
+++ milena/mln/value/rgb.hh (working copy)
@@ -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>
@@ -515,6 +520,22 @@
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
} // end of namespace mln
Index: milena/mln/convert/from_to.hxx
--- milena/mln/convert/from_to.hxx (revision 2695)
+++ milena/mln/convert/from_to.hxx (working copy)
@@ -108,6 +108,11 @@
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
Index: milena/mln/fun/v2v/cast.hh
--- milena/mln/fun/v2v/cast.hh (revision 2695)
+++ milena/mln/fun/v2v/cast.hh (working copy)
@@ -1,4 +1,4 @@
-// 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>
Index: milena/mln/fun/v2v/convert.hh
--- milena/mln/fun/v2v/convert.hh (revision 0)
+++ milena/mln/fun/v2v/convert.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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
Index: milena/sandbox/scribo/demat.hh
--- milena/sandbox/scribo/demat.hh (revision 2695)
+++ milena/sandbox/scribo/demat.hh (working copy)
@@ -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>