https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add convert::to and conversion from v2v; fix misc stuff.
* doc/tutorial/examples/vec.cc: New.
* doc/tutorial/examples/box.cc: Augment.
* mln/core/site_set/p_run.hh: Fix missing include.
* mln/value/glf.hh: Fix doc.
* mln/value/concept/all.hh: Fix missing files.
* mln/convert/to.hh: New.
* mln/convert/impl/from_image_to_site_set.hh: Fix typo.
* mln/convert/impl/all.hh: Update.
* mln/convert/impl/from_value_to_value.hh: New.
* mln/convert/from_to.hh (from_to): New overload for
'from' being 'float' and 'int'.
doc/tutorial/examples/box.cc | 6 +
doc/tutorial/examples/vec.cc | 14 +++
mln/convert/from_to.hh | 67 ++++++++++++++++
mln/convert/impl/all.hh | 1
mln/convert/impl/from_image_to_site_set.hh | 2
mln/convert/impl/from_value_to_value.hh | 119 +++++++++++++++++++++++++++++
mln/convert/to.hh | 83 ++++++++++++++++++++
mln/core/site_set/p_run.hh | 1
mln/value/concept/all.hh | 10 +-
mln/value/glf.hh | 4
10 files changed, 299 insertions(+), 8 deletions(-)
Index: doc/tutorial/examples/vec.cc
--- doc/tutorial/examples/vec.cc (revision 0)
+++ doc/tutorial/examples/vec.cc (revision 0)
@@ -0,0 +1,14 @@
+# include <mln/convert/to.hh>
+# include <mln/core/alias/point2d.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ algebra::vec<2,float> v;
+ v[0] = 5.14;
+ v[1] = 1.99;
+ std::cout << convert::to<point2d>(v) << std::endl;
+}
Index: doc/tutorial/examples/box.cc
--- doc/tutorial/examples/box.cc (revision 2189)
+++ doc/tutorial/examples/box.cc (working copy)
@@ -25,6 +25,12 @@
{
using namespace mln;
+ {
+ box2d b = make::box2d(2, 3);
+ picture(b);
+ }
+ {
box2d b = make::box2d(1,1, 3,2);
picture(b);
}
+}
Index: mln/core/site_set/p_run.hh
--- mln/core/site_set/p_run.hh (revision 2189)
+++ mln/core/site_set/p_run.hh (working copy)
@@ -36,6 +36,7 @@
*/
# include <mln/core/internal/site_set_base.hh>
+# include <mln/core/site_set/box.hh>
# include <mln/core/internal/pseudo_site_base.hh>
# include <mln/util/index.hh>
Index: mln/value/glf.hh
--- mln/value/glf.hh (revision 2189)
+++ mln/value/glf.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
@@ -43,7 +43,7 @@
{
- /// Alias for 8 bit graylevel.
+ /// Alias for graylevels encoded by float.
typedef graylevel_f glf;
Index: mln/value/concept/all.hh
--- mln/value/concept/all.hh (revision 2189)
+++ mln/value/concept/all.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
@@ -33,12 +33,14 @@
* \brief File that includes every sub-concept of the Value concept.
*/
-# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/built_in.hh>
+# include <mln/value/concept/data.hh>
# include <mln/value/concept/floating.hh>
-# include <mln/value/concept/vectorial.hh>
+# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/scalar.hh>
# include <mln/value/concept/structured.hh>
# include <mln/value/concept/symbolic.hh>
-# include <mln/value/concept/data.hh>
+# include <mln/value/concept/vectorial.hh>
#endif // ! MLN_VALUE_CONCEPT_ALL_HH
Index: mln/convert/to.hh
--- mln/convert/to.hh (revision 0)
+++ mln/convert/to.hh (revision 0)
@@ -0,0 +1,83 @@
+// 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_CONVERT_TO_HH
+# define MLN_CONVERT_TO_HH
+
+/*! \file mln/convert/to.hh
+ *
+ * \brief General conversion procedure given the destination type.
+ *
+ * \todo Prefer a static check that fails in the "unknown" case.
+ */
+
+# include <mln/convert/from_to.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+
+ /// Conversion of the object \p from towards an object with type \c T.
+ template <typename T, typename O>
+ inline
+ T
+ to(const O& from);
+
+ // This is no "Object" here to remain as general as possible. For
+ // instance, the conversion "float -> glf" should occur.
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename T, typename O>
+ inline
+ T
+ to(const O& from)
+ {
+ mlc_equal(T, mln_exact(T))::check();
+ trace::entering("convert::to");
+
+ T tmp;
+ impl::from_to_(exact(from), tmp);
+
+ trace::exiting("convert::to");
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_HH
Index: mln/convert/impl/from_image_to_site_set.hh
--- mln/convert/impl/from_image_to_site_set.hh (revision 2189)
+++ mln/convert/impl/from_image_to_site_set.hh (working copy)
@@ -54,7 +54,7 @@
namespace impl
{
- /// Convertion of an image \p from towards a site set \p to.
+ /// Conversion of an image \p from towards a site set \p to.
template <typename I, typename S>
void
from_image_to_site_set(const Image<I>& from, Site_Set<S>& to);
Index: mln/convert/impl/all.hh
--- mln/convert/impl/all.hh (revision 2189)
+++ mln/convert/impl/all.hh (working copy)
@@ -35,6 +35,7 @@
# include <mln/convert/impl/from_image_to_site_set.hh>
+# include <mln/convert/impl/from_value_to_value.hh>
#endif // ! MLN_CONVERT_IMPL_ALL_HH
Index: mln/convert/impl/from_value_to_value.hh
--- mln/convert/impl/from_value_to_value.hh (revision 0)
+++ mln/convert/impl/from_value_to_value.hh (revision 0)
@@ -0,0 +1,119 @@
+// 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_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH
+# define MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH
+
+/*! \file mln/convert/from_to.hh
+ *
+ * \brief General conversion procedure from a value to a value.
+ *
+ * \todo Augment code + add checks.
+ */
+
+# include <utility>
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/site_set.hh>
+# include <mln/value/concept/all.hh>
+
+# include <mln/core/site_set/p_run.hh>
+# include <mln/metal/converts_to.hh>
+
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ namespace impl
+ {
+
+ /// Conversion of a value \p from towards a value \p to.
+ template <typename V, typename W>
+ void
+ from_value_to_value(const Value<V>& from, Value<W>& to);
+
+ /// Specialization.
+ template <typename V>
+ void
+ from_value_to_value(const Value<V>& from, Value<V>& to);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Case 1:
+
+ template <typename V, typename W>
+ void
+ from_value_to_value_(const mln::value::Vectorial<V>& from,
+ mln::value::Vectorial<W>& to)
+ {
+ exact(to) = exact(from).to_equiv();
+ }
+
+ // Case 2:
+
+ template <typename V, typename W>
+ void
+ from_value_to_value_(const mln::value::Scalar<V>& from,
+ mln::value::Scalar<W>& to)
+ {
+ exact(to) = exact(from).to_equiv();
+ }
+
+
+ // Facades.
+
+ template <typename V, typename W>
+ inline
+ void
+ from_value_to_value(const Value<V>& from, Value<W>& to)
+ {
+ from_value_to_value_(exact(from), exact(to));
+ }
+
+ template <typename V>
+ inline
+ void
+ from_value_to_value(const Value<V>& from, Value<V>& to)
+ {
+ exact(to) = exact(from);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert::impl
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_IMPL_FROM_VALUE_TO_VALUE_HH
Index: mln/convert/from_to.hh
--- mln/convert/from_to.hh (revision 2189)
+++ mln/convert/from_to.hh (working copy)
@@ -33,13 +33,21 @@
* \brief General conversion procedure between two objects.
*
* \todo Prefer a static check that fails in the "unknown" case.
+ *
+ * \todo Use 'round' instead of static_cast in vec->Gpoint.
*/
# include <mln/core/concept/object.hh>
+# include <mln/core/concept/gpoint.hh>
+# include <mln/value/concept/all.hh>
+
# include <mln/convert/impl/all.hh>
+
+# include <mln/algebra/vec.hh>
# include <mln/metal/is.hh>
+
namespace mln
{
@@ -47,13 +55,25 @@
{
- /// Convertion of an object \p from towards an object \p to.
+ /// Conversion of an object \p from towards an object \p to.
+
template <typename F, typename T>
inline
void
from_to(const Object<F>& from, Object<T>& to);
+ template <typename T>
+ inline
+ void
+ from_to(const float& from, Object<T>& to);
+
+
+ template <typename T>
+ inline
+ void
+ from_to(const int& from, Object<T>& to);
+
# ifndef MLN_INCLUDE_ONLY
@@ -78,10 +98,34 @@
mln::convert::impl::from_image_to_site_set(from, to);
}
+ // algebra::vec -> Gpoint.
+ template <unsigned n, typename T, typename P>
+ inline
+ void
+ from_to_(const algebra::vec<n,T>& from, Gpoint<P>& to_)
+ {
+ mlc_bool(P::dim == n)::check();
+ P& to = exact(to_);
+ for (unsigned i = 0; i < n; ++i)
+ to[i] = static_cast< typename P::coord >(from[i]);
+ }
+
+
+ template <typename F, typename T>
+ inline
+ void
+ from_to_(const Value<F>& from, Value<T>& to)
+ {
+ mln::convert::impl::from_value_to_value(from, to);
+ }
} // end of namespace mln::convert::impl
+
+ // Facades.
+
+
template <typename F, typename T>
inline
void
@@ -92,6 +136,27 @@
trace::exiting("convert::from_to");
}
+
+ template <typename T>
+ inline
+ void
+ from_to(const float& from, Object<T>& to)
+ {
+ mlc_is_a(T, mln::value::Floating)::check();
+ exact(to) = from;
+ }
+
+
+ template <typename T>
+ inline
+ void
+ from_to(const int& from, Object<T>& to)
+ {
+ mlc_is_a(T, mln::value::Integer)::check();
+ exact(to) = from;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert