* mln/convert/from_to.hxx: add new definitions.
* mln/core/concept/accumulator.hh: add default from_to.
* mln/labeling/compute.hh: use from_to.
* mln/util/array.hh: add from_to(array<T1>, array<T2>).
---
milena/ChangeLog | 12 ++++
milena/mln/convert/from_to.hxx | 12 ++++
milena/mln/core/concept/accumulator.hh | 58 +++++++++++++----
milena/mln/labeling/compute.hh | 113 +++++++++++++++-----------------
milena/mln/util/array.hh | 51 ++++++++++++++-
5 files changed, 171 insertions(+), 75 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 7c72bd2..7831512 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2008-11-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add new from_to overloads.
+
+ * mln/convert/from_to.hxx: add new definitions.
+
+ * mln/core/concept/accumulator.hh: add default from_to.
+
+ * mln/labeling/compute.hh: use from_to.
+
+ * mln/util/array.hh: add from_to(array<T1>, array<T2>).
+
+2008-11-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Cleanup various files.
* doc/examples/mk_graph.cc: use int_u16 instead of int_u8.
diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx
index 1876401..9dbd0c8 100644
--- a/milena/mln/convert/from_to.hxx
+++ b/milena/mln/convert/from_to.hxx
@@ -45,6 +45,7 @@ namespace mln
// Forward declarations.
+ template <typename E> struct Accumulator;
template <typename E> struct Gdpoint;
template <typename E> struct Gpoint;
template <typename E> struct Image;
@@ -230,6 +231,17 @@ namespace mln
void
from_to(const std::vector<T>& from, fun::i2v::array<T>& to);
+ // util::array<T1> -> util::array<T2>
+ template <typename T1, typename T2>
+ void
+ from_to(const util::array<T1>& from, util::array<T2>& to);
+
+
+ // Accumulator<A> -> mln_result(A)
+ template <typename A>
+ void
+ from_to(const Accumulator<A>& from, mln_result(A)& to);
+
} // end of namespace mln::convert
} // end of namespace mln
diff --git a/milena/mln/core/concept/accumulator.hh
b/milena/mln/core/concept/accumulator.hh
index a4f4c74..5fcbf29 100644
--- a/milena/mln/core/concept/accumulator.hh
+++ b/milena/mln/core/concept/accumulator.hh
@@ -1,4 +1,5 @@
// Copyright (C) 2007, 2008 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
@@ -28,10 +29,9 @@
#ifndef MLN_CORE_CONCEPT_ACCUMULATOR_HH
# define MLN_CORE_CONCEPT_ACCUMULATOR_HH
-/*! \file mln/core/concept/accumulator.hh
- *
- * \brief Definition of the concept of mln::Accumulator.
- */
+/// \file mln/core/concept/accumulator.hh
+///
+/// Definition of the concept of mln::Accumulator.
# include <mln/core/concept/proxy.hh>
# include <mln/metal/fix_return.hh>
@@ -41,9 +41,20 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
template <typename E> struct Accumulator;
+
+ namespace convert
+ {
+
+ template <typename A>
+ void
+ from_to(const Accumulator<A>& from, mln_result(A)& to);
+
+ } // end of namespace mln::convert
+
+
// Accumulator category flag type.
template <>
struct Accumulator<void>
@@ -53,13 +64,13 @@ namespace mln
- /*! \brief Base class for implementation of accumulators.
- *
- * The parameter \a E is the exact type.
- *
- * \see mln::doc::Accumulator for a complete documentation of this
- * class contents.
- */
+ /// \brief Base class for implementation of accumulators.
+ ///
+ /// The parameter \a E is the exact type.
+ ///
+ /// \see mln::doc::Accumulator for a complete documentation of this
+ /// class contents.
+ ///
template <typename E>
struct Accumulator : public Proxy<E>
{
@@ -91,6 +102,29 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename A>
+ void
+ from_to(const Accumulator<A>& from_, mln_result(A)& to)
+ {
+ const A& from = exact(from_);
+ if (from.is_valid())
+ to = from.to_result();
+ else
+ to = mln_result(A)();
+ }
+
+ } // end of namespace mln::convert
+
+
+
+ // Accumulator<E>
+
template <typename E>
inline
Accumulator<E>::Accumulator()
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
index 1206c3d..6233979 100644
--- a/milena/mln/labeling/compute.hh
+++ b/milena/mln/labeling/compute.hh
@@ -37,6 +37,7 @@
# include <mln/core/concept/accumulator.hh>
# include <mln/core/concept/meta_accumulator.hh>
# include <mln/util/array.hh>
+# include <mln/convert/to.hh>
namespace mln
@@ -55,12 +56,12 @@ namespace mln
/// \return A mln::p_array of accumulator result. One result per component in
/// \p label.
///
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
util::array<mln_result(A)>
compute(const Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels);
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
/// Compute an accumulator onto the pixel values of the image \p input.
/// for each component of the image \p label.
@@ -72,12 +73,12 @@ namespace mln
/// \return A mln::p_array of accumulator result. One result per component in
/// \p label.
///
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
util::array<mln_accu_with(A, mln_value(I))::result>
compute(const Meta_Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels);
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
/// Compute an accumulator onto the pixel sites of each component domain of
/// \p label.
@@ -88,11 +89,11 @@ namespace mln
/// \return A mln::p_array of accumulator result. One result per component in
/// \p label.
///
- template <typename A, typename J>
+ template <typename A, typename L>
util::array<mln_result(A)>
compute(const Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels);
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
/// Compute an accumulator onto the pixel sites of each component domain of
/// \p label.
@@ -103,11 +104,11 @@ namespace mln
/// \return A mln::p_array of accumulator result. One result per component in
/// \p label.
///
- template <typename A, typename J>
- util::array<mln_accu_with(A, mln_psite(J))::result>
+ template <typename A, typename L>
+ util::array<mln_accu_with(A, mln_psite(L))::result>
compute(const Meta_Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels);
+ const Image<L>& label,
+ const mln_value(L)& nlabels);
@@ -116,12 +117,12 @@ namespace mln
namespace internal
{
- template <typename A, typename J>
+ template <typename A, typename L>
inline
void
compute_tests(const Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
mln_precondition(exact(label).has_data());
(void) a;
@@ -130,13 +131,13 @@ namespace mln
}
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
inline
void
compute_tests(const Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
mln_precondition(exact(input).has_data());
mln_precondition(exact(label).has_data());
@@ -157,49 +158,44 @@ namespace mln
namespace generic
{
- template <typename A, typename J>
+ template <typename A, typename L>
inline
util::array<mln_result(A)>
compute(const Accumulator<A>& a_,
- const Image<J>& label_,
- const mln_value(J)& nlabels)
+ const Image<L>& label_,
+ const mln_value(L)& nlabels)
{
trace::entering("labeling::impl::generic::compute");
internal::compute_tests(a_, label_, nlabels);
const A& a = exact(a_);
- const J& label = exact(label_);
+ const L& label = exact(label_);
util::array<A> accus(nlabels + 1, a);
- mln_piter(J) p(label.domain());
+ mln_piter(L) p(label.domain());
for_all(p)
accus[label(p)].take(p);
- util::array<mln_result(A)> arr(nlabels + 1);
- for (unsigned i = 0; i < accus.nelements(); ++i)
- if (accus[i].is_valid())
- arr[i] = accus[i];
-
trace::exiting("labeling::impl::generic::compute");
- return arr;
+ return convert::to< util::array<mln_result(A)> >(accus);
}
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute(const Accumulator<A>& a_,
const Image<I>& input_,
- const Image<J>& label_,
- const mln_value(J)& nlabels)
+ const Image<L>& label_,
+ const mln_value(L)& nlabels)
{
trace::entering("labeling::impl::generic::compute");
internal::compute_tests(a_, input_, label_, nlabels);
const A& a = exact(a_);
const I& input = exact(input_);
- const J& label = exact(label_);
+ const L& label = exact(label_);
util::array<A> accus (nlabels + 1, a);
@@ -207,13 +203,8 @@ namespace mln
for_all(p)
accus[label(p)].take(input(p));
- util::array<mln_result(A)> res(nlabels + 1);
- for (unsigned i = 0; i < accus.nelements(); ++i)
- if (accus[i].is_valid())
- res[i] = accus[i];
-
trace::exiting("labeling::impl::generic::compute");
- return res;
+ return convert::to< util::array<mln_result(A)> >(accus);
}
} // end of namespace mln::labeling::impl::internal
@@ -225,24 +216,24 @@ namespace mln
namespace internal
{
- template <typename A, typename J>
+ template <typename A, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(const Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
return impl::generic::compute(a, label, nlabels);
}
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(const Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
return impl::generic::compute(a, input, label, nlabels);
}
@@ -253,13 +244,13 @@ namespace mln
/// Facades.
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute(const Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
trace::entering("labeling::compute");
@@ -272,13 +263,13 @@ namespace mln
return res;
}
- template <typename A, typename I, typename J>
+ template <typename A, typename I, typename L>
inline
util::array<mln_accu_with(A, mln_value(I))::result>
compute(const Meta_Accumulator<A>& a,
const Image<I>& input,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
typedef mln_accu_with(A, mln_value(I)) A_;
A_ a_ = accu::unmeta(exact(a), mln_value(I)());
@@ -287,12 +278,12 @@ namespace mln
}
- template <typename A, typename J>
+ template <typename A, typename L>
inline
util::array<mln_result(A)>
compute(const Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
trace::entering("labeling::compute");
@@ -306,15 +297,15 @@ namespace mln
}
- template <typename A, typename J>
+ template <typename A, typename L>
inline
- util::array<mln_accu_with(A, mln_psite(J))::result>
+ util::array<mln_accu_with(A, mln_psite(L))::result>
compute(const Meta_Accumulator<A>& a,
- const Image<J>& label,
- const mln_value(J)& nlabels)
+ const Image<L>& label,
+ const mln_value(L)& nlabels)
{
- typedef mln_accu_with(A, mln_psite(J)) A_;
- A_ a_ = accu::unmeta(exact(a), mln_psite(J)());
+ typedef mln_accu_with(A, mln_psite(L)) A_;
+ A_ a_ = accu::unmeta(exact(a), mln_psite(L)());
return internal::compute_dispatch(a_, label, nlabels);
}
diff --git a/milena/mln/util/array.hh b/milena/mln/util/array.hh
index 9658919..b5e2534 100644
--- a/milena/mln/util/array.hh
+++ b/milena/mln/util/array.hh
@@ -49,6 +49,28 @@ namespace mln
namespace util
{
+ /// Forward declaration.
+ template <typename T>
+ class array;
+
+ } // end of namespace mln::util
+
+
+
+ namespace convert
+ {
+
+ template <typename T1, typename T2>
+ void
+ from_to(const util::array<T1>& from, util::array<T2>& to);
+
+ } // end of namespace mln::convert
+
+
+
+ namespace util
+ {
+
// Forward declarations.
template <typename T> class array_fwd_iter;
template <typename T> class array_bkd_iter;
@@ -239,10 +261,33 @@ namespace mln
const array<T>* a_;
};
+ } // end of namespace mln::util
+
# ifndef MLN_INCLUDE_ONLY
+
+ // convert::from_to
+
+ namespace convert
+ {
+
+ template <typename T1, typename T2>
+ void
+ from_to(const util::array<T1>& from, util::array<T2>& to)
+ {
+ to.resize(from.nelements());
+ for (unsigned i = 0; i < from.nelements(); ++i)
+ from_to(from[i], to[i]);
+ }
+
+ } // end of namespace mln::convert
+
+
+ namespace util
+ {
+
// util::array<T>
@@ -576,11 +621,13 @@ namespace mln
return ostr;
}
+ } // end of namespace mln::util
+
+
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::util
-} // end of namespace mln
+} // end of namespace mln
#endif // ! MLN_UTIL_ARRAY_HH
--
1.5.6.5