
https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Allow some state to be transmitted fom meta cuu to accu. * mln/core/concept/meta_accumulator.hh (unmeta): New. * mln/core/concept/object.hh (include): Add metal abort. * mln/metal/abort.hh: Upgrade doc style. * mln/accu/rank.hh: Likewise. (rank::k): New method. (rank::n): New method. (meta::rank): New attributes, resp. k and n. (unmeta): New overload for meta::rank. * mln/accu/transform.hh: Use unmeta. * tests/accu/rank.cc: Augment. * mln/morpho/erosion.spe.hh: Shorten checks in lines dispatch. mln/accu/rank.hh | 44 ++++++++++++++++++++++++++------ mln/accu/transform.hh | 7 ++--- mln/core/concept/meta_accumulator.hh | 41 ++++++++++++++++++++++++++---- mln/core/concept/object.hh | 8 ++--- mln/metal/abort.hh | 7 ++--- mln/morpho/erosion.spe.hh | 47 ++++++++++++++--------------------- tests/accu/rank.cc | 43 ++++++++++++++++++++------------ 7 files changed, 131 insertions(+), 66 deletions(-) Index: tests/accu/rank.cc --- tests/accu/rank.cc (revision 2843) +++ tests/accu/rank.cc (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// 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 @@ -25,18 +25,17 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file tests/accu/rank.cc - * - * \brief Tests on mln::accu::rank. - */ +/// \file tests/accu/rank.cc +/// +/// Tests on mln::accu::rank. #include <mln/accu/rank.hh> #include <mln/value/int_u8.hh> -using namespace mln; + template <typename A> -void fill(Accumulator<A>& accu_) +void fill(mln::Accumulator<A>& accu_) { A& accu = exact(accu_); accu.take(2); @@ -49,45 +48,59 @@ accu.take(5); } + int main() { + using namespace mln; + using value::int_u8; + + { + accu::meta::rank r; + r.k = 4; + r.n = 9; + accu::rank<int_u8> a = accu::unmeta(r, int_u8()); + mln_assertion(a.k() == 4 && a.n() == 9); +// Meta_Accumulator<accu::meta::rank>& R = r; +// accu::unmeta(R, int_u8()); + } + { - accu::rank<value::int_u8> accu(0, 8); + accu::rank<int_u8> accu(0, 8); fill(accu); mln_assertion(accu.to_result() == 1u); } { - accu::rank<value::int_u8> accu(1, 8); + accu::rank<int_u8> accu(1, 8); fill(accu); mln_assertion(accu.to_result() == 2u); } { - accu::rank<value::int_u8> accu(2, 8); + accu::rank<int_u8> accu(2, 8); fill(accu); mln_assertion(accu.to_result() == 2u); } { - accu::rank<value::int_u8> accu(3, 8); + accu::rank<int_u8> accu(3, 8); fill(accu); mln_assertion(accu.to_result() == 3u); } { - accu::rank<value::int_u8> accu(4, 8); + accu::rank<int_u8> accu(4, 8); fill(accu); mln_assertion(accu.to_result() == 4u); } { - accu::rank<value::int_u8> accu(5, 8); + accu::rank<int_u8> accu(5, 8); fill(accu); mln_assertion(accu.to_result() == 5u); } { - accu::rank<value::int_u8> accu(6, 8); + accu::rank<int_u8> accu(6, 8); fill(accu); mln_assertion(accu.to_result() == 5u); } { - accu::rank<value::int_u8> accu(7, 8); + accu::rank<int_u8> accu(7, 8); fill(accu); mln_assertion(accu.to_result() == 5u); } Index: mln/core/concept/meta_accumulator.hh --- mln/core/concept/meta_accumulator.hh (revision 2843) +++ mln/core/concept/meta_accumulator.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// 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 +28,9 @@ #ifndef MLN_CORE_CONCEPT_META_ACCUMULATOR_HH # define MLN_CORE_CONCEPT_META_ACCUMULATOR_HH -/*! \file mln/core/concept/meta_accumulator.hh - * - * \brief Definition of the concept of mln::Meta_Accumulator. - */ +/// \file mln/core/concept/meta_accumulator.hh +/// +/// Definition of the concept of mln::Meta_Accumulator. # include <mln/core/concept/object.hh> # include <mln/core/concept/accumulator.hh> @@ -83,6 +82,23 @@ }; + namespace accu + { + + // To be specialized when some state (attributes) have to be transfered + // from the meta-accumulator to the accumulator. + // Warning: the first argument has to be an object with the exact type. + template <typename M, typename T> + mln_accu_with(M, T) + unmeta(const M&, T); + + template <typename M, typename T> + void + unmeta(const Meta_Accumulator<M>&, T); // Safety. + + } // end of namespace mln::accu + + # ifndef MLN_INCLUDE_ONLY @@ -93,6 +109,21 @@ // FIXME: Check "with" on E. } + namespace accu + { + + template <typename M, typename T> + inline + mln_accu_with(M, T) + unmeta(const M&, T) + { + mlc_is_a(M, Meta_Accumulator)::check(); + mln_accu_with(M, T) a; + return a; + } + + } // end of namespace mln::accu + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/concept/object.hh --- mln/core/concept/object.hh (revision 2843) +++ mln/core/concept/object.hh (working copy) @@ -29,10 +29,9 @@ #ifndef MLN_CORE_CONCEPT_OBJECT_HH # define MLN_CORE_CONCEPT_OBJECT_HH -/*! \file mln/core/concept/object.hh - * - * \brief Definition of the top Milena class mln::Object. - */ +/// \file mln/core/concept/object.hh +/// +/// Definition of the top Milena class mln::Object. # include <cassert> # include <iostream> @@ -44,6 +43,7 @@ # include <mln/trace/all.hh> // metal +# include <mln/metal/abort.hh> # include <mln/metal/is_a.hh> # include <mln/metal/is_not_a.hh> # include <mln/metal/is.hh> Index: mln/metal/abort.hh --- mln/metal/abort.hh (revision 2843) +++ mln/metal/abort.hh (working copy) @@ -29,10 +29,9 @@ #ifndef MLN_METAL_ABORT_HH # define MLN_METAL_ABORT_HH -/*! \file mln/metal/abort.hh - * - * \brief FIXME: Document. - */ +/// \file mln/metal/abort.hh +/// +/// FIXME: Document. # include <mln/metal/bool.hh> Index: mln/accu/transform.hh --- mln/accu/transform.hh (revision 2843) +++ mln/accu/transform.hh (working copy) @@ -148,7 +148,7 @@ template <typename I, typename A, typename W> mln_ch_value(I, mln_accu_with(A, mln_value(I))::result) transform(const Image<I>& input, - const Meta_Accumulator<A>&, + const Meta_Accumulator<A>& a, const Window<W>& win) { trace::entering("accu::transform"); @@ -157,9 +157,10 @@ // mln_precondition(exact(win).is_valid()); typedef mln_accu_with(A, mln_value(I)) A_; - A_ a; + A_ a_ = accu::unmeta(exact(a), mln_value(I)()); + mln_ch_value(I, mln_result(A_)) output; - output = internal::transform_dispatch(input, a, win); + output = internal::transform_dispatch(input, a_, win); trace::exiting("accu::transform"); return output; Index: mln/accu/rank.hh --- mln/accu/rank.hh (revision 2843) +++ mln/accu/rank.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory +// 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,13 +28,12 @@ #ifndef MLN_ACCU_RANK_HH # define MLN_ACCU_RANK_HH -/*! \file mln/accu/rank.hh - * - * \brief Define an rank accumulator. - * - * \todo It should be renamed as rank_h since it relies on histogram - * (thus low quantization). - */ +/// \file mln/accu/rank.hh +/// +/// Define an rank accumulator. +/// +/// \todo It should be renamed as rank_h since it relies on histogram +/// (thus low quantization). # include <vector> # include <mln/accu/internal/base.hh> @@ -80,6 +79,12 @@ /// Always true here. bool is_valid() const; + /// Give the rank. + unsigned k() const; + + /// Give the total number of elements. + unsigned n() const; + protected: unsigned k_; // 0 <= k_ < n @@ -116,11 +121,20 @@ { typedef accu::rank<T> ret; }; + unsigned k, n; }; } // end of namespace mln::accu::meta + template <typename T> + rank<T> unmeta(const meta::rank& m, T) + { + rank<T> a(m.k, m.n); + return a; + } + + # ifndef MLN_INCLUDE_ONLY @@ -137,7 +151,21 @@ init(); } + template <typename T> + inline + unsigned + rank<T>::k() const + { + return k_; + } + template <typename T> + inline + unsigned + rank<T>::n() const + { + return n_; + } template <typename T> inline Index: mln/morpho/erosion.spe.hh --- mln/morpho/erosion.spe.hh (revision 2843) +++ mln/morpho/erosion.spe.hh (working copy) @@ -1444,11 +1444,10 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_a(mln_pset(I), Box) test_box; - typedef mlc_equal(mln_trait_image_quant(I), - mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_box, test_lowq) tests; - return erosion_dispatch_wrt_win(typename tests::eval (), + enum { test = mlc_is_a(mln_pset(I), Box)::value + && mlc_equal(mln_trait_image_quant(I), + mln::trait::image::quant::low)::value }; + return erosion_dispatch_wrt_win(metal::bool_<test>(), input, win); } } @@ -1456,7 +1455,6 @@ /// \} - /// Handling win::vline2d. /// \{ @@ -1486,11 +1484,10 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_a(mln_pset(I), Box) test_box; - typedef mlc_equal(mln_trait_image_quant(I), - mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_box, test_lowq) tests; - return erosion_dispatch_wrt_win(typename tests::eval (), + enum { test = mlc_is_a(mln_pset(I), Box)::value + && mlc_equal(mln_trait_image_quant(I), + mln::trait::image::quant::low)::value }; + return erosion_dispatch_wrt_win(metal::bool_<test>(), input, win); } } @@ -1527,14 +1524,12 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_not(mln_trait_image_kind(I), - mln::trait::image::kind::logic) test_not_logic; - typedef mlc_is_a(mln_pset(I), Box) test_box; - typedef mlc_equal(mln_trait_image_quant(I), - mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_not_logic, test_box) temp; - typedef mlc_and(temp, test_lowq) tests; - return erosion_dispatch_wrt_win(typename tests::eval (), + enum { test = mlc_is_not(mln_trait_image_kind(I), + mln::trait::image::kind::logic)::value + && mlc_is_a(mln_pset(I), Box)::value + && mlc_equal(mln_trait_image_quant(I), + mln::trait::image::quant::low)::value }; + return erosion_dispatch_wrt_win(metal::bool_<test>(), input, win); } } @@ -1571,14 +1566,12 @@ return erosion_dispatch_for_generic(input, win); else { - typedef mlc_is_not(mln_trait_image_kind(I), - mln::trait::image::kind::logic) test_not_logic; - typedef mlc_is_a(mln_pset(I), Box) test_box; - typedef mlc_equal(mln_trait_image_quant(I), - mln::trait::image::quant::low) test_lowq; - typedef mlc_and(test_not_logic, test_box) temp; - typedef mlc_and(temp, test_lowq) tests; - return erosion_dispatch_wrt_win(typename tests::eval (), + enum { test = mlc_is_not(mln_trait_image_kind(I), + mln::trait::image::kind::logic)::value + && mlc_is_a(mln_pset(I), Box)::value + && mlc_equal(mln_trait_image_quant(I), + mln::trait::image::quant::low)::value }; + return erosion_dispatch_wrt_win(metal::bool_<test>(), input, win); } }