
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> introduce meta accumulators and better accumulators. New material for accumulators. * tests/accu_nil.cc: New. * tests/labeling_estimate.cc: New. * tests/accu_min.cc: New. * tests/accu_all.cc: New. * mln/accu/nil.hh: New. * mln/accu/take.hh: New. * mln/accu/pair.hh: New. * mln/accu/p.hh: New. * mln/accu/v.hh: New. * mln/accu/all.hh: New. * mln/accu/compute.hh: New. * mln/make/pix.hh: New. * mln/labeling/estimate.hh: New. * mln/util/ignore.hh: New. * mln/util/eat.hh: New. Renaming to disambiguate. * mln/core/concept/accumulator.hh (value, to_value): Rename as... (result, to_result): ...these. Introduce meta accumulators. * mln/core/concept/meta_accumulator.hh: New. * mln/accu/min.hh, * mln/accu/max.hh, * mln/accu/min_max.hh, * mln/accu/count.hh, * mln/accu/sum.hh, * mln/accu/mean.hh (<name>): Rename accumulators as... (<name_>): ...these. (<name>): New meta accumulators. Propagate updates. * mln/accu/bbox.hh, * mln/accu/histo.hh, * mln/accu/max_h.hh, * mln/accu/median_alt.hh, * mln/accu/median.hh, * mln/accu/min_h.hh, * mln/estim/sum.hh, * mln/estim/min_max.hh, * mln/estim/mean.hh, * mln/core/internal/run_pset.hh, * mln/core/queue_p.hh, * mln/core/vec_p.hh, * mln/core/set_p.hh, * mln/morpho/opening_attribute.hh, * mln/morpho/opening_area.hh, * mln/morpho/erosion_fast.hh, * mln/morpho/dilation.hh, * mln/morpho/erosion.hh, * mln/morpho/dilation_fast.hh, * mln/level/take.hh, * mln/level/median.hh, * mln/level/naive/median.hh, * mln/level/fast_median.hh, * mln/level/compute.hh, * mln/canvas/morpho/algebraic_union_find.hh: Update. Misc. * tests/core_clone.cc: Augment. * mln/geom/bbox.hh (bbox): New overload for Box. * mln/core/image_if.hh: Add FIXMEs. (operator |): New overloads. * mln/core/image2d_b.hh: Remove dead code. * mln/util/pix.hh (p_of): New. Clean interface. mln/accu/all.hh | 65 ++++++++++++ mln/accu/bbox.hh | 31 +++-- mln/accu/compute.hh | 101 ++++++++++++++++++ mln/accu/count.hh | 44 +++++--- mln/accu/histo.hh | 11 ++ mln/accu/max.hh | 54 +++++++--- mln/accu/max_h.hh | 7 - mln/accu/mean.hh | 45 ++++++-- mln/accu/median.hh | 7 - mln/accu/median_alt.hh | 6 - mln/accu/min.hh | 44 ++++++-- mln/accu/min_h.hh | 7 - mln/accu/min_max.hh | 90 +--------------- mln/accu/nil.hh | 126 +++++++++++++++++++++++ mln/accu/p.hh | 144 ++++++++++++++++++++++++++ mln/accu/pair.hh | 162 ++++++++++++++++++++++++++++++ mln/accu/sum.hh | 47 +++++--- mln/accu/take.hh | 99 ++++++++++++++++++ mln/accu/v.hh | 154 ++++++++++++++++++++++++++++ mln/canvas/morpho/algebraic_union_find.hh | 2 mln/core/concept/accumulator.hh | 29 +---- mln/core/concept/meta_accumulator.hh | 82 +++++++++++++++ mln/core/image2d_b.hh | 14 -- mln/core/image_if.hh | 89 +++++++++++++++- mln/core/internal/run_pset.hh | 2 mln/core/queue_p.hh | 2 mln/core/set_p.hh | 2 mln/core/vec_p.hh | 2 mln/estim/mean.hh | 7 - mln/estim/min_max.hh | 11 -- mln/estim/sum.hh | 8 - mln/geom/bbox.hh | 28 ++++- mln/labeling/estimate.hh | 73 +++++++++++++ mln/level/compute.hh | 51 +++++++-- mln/level/fast_median.hh | 6 - mln/level/median.hh | 12 +- mln/level/naive/median.hh | 2 mln/level/take.hh | 12 +- mln/make/pix.hh | 66 ++++++++++++ mln/morpho/dilation.hh | 4 mln/morpho/dilation_fast.hh | 6 - mln/morpho/erosion.hh | 4 mln/morpho/erosion_fast.hh | 6 - mln/morpho/opening_area.hh | 5 mln/morpho/opening_attribute.hh | 5 mln/util/eat.hh | 84 +++++++++++++++ mln/util/ignore.hh | 75 +++++++++++++ mln/util/pix.hh | 59 +++++----- tests/accu_all.cc | 56 ++++++++++ tests/accu_min.cc | 62 +++++++++++ tests/accu_nil.cc | 46 ++++++++ tests/core_clone.cc | 3 tests/labeling_estimate.cc | 62 +++++++++++ 53 files changed, 1914 insertions(+), 307 deletions(-) Index: tests/core_clone.cc --- tests/core_clone.cc (revision 1156) +++ tests/core_clone.cc (working copy) @@ -49,6 +49,9 @@ { box2d b = make::box2d(2,2); std::cout << border::get( clone(ima | b) ) << std::endl; + + debug::println(ima | b); + debug::println(clone(ima | b)); } // { Index: tests/accu_nil.cc --- tests/accu_nil.cc (revision 0) +++ tests/accu_nil.cc (revision 0) @@ -0,0 +1,46 @@ +// Copyright (C) 2007 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/accu_nil.cc + * + * \brief Tests on mln::accu::nil. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/value/int_u8.hh> + +#include <mln/accu/nil.hh> +#include <mln/level/compute.hh> + + +int main() +{ + using namespace mln; + image2d_b<value::int_u8> ima(3, 3); + accu::nil a; + level::compute<accu::nil>(ima); +} Index: tests/labeling_estimate.cc --- tests/labeling_estimate.cc (revision 0) +++ tests/labeling_estimate.cc (revision 0) @@ -0,0 +1,62 @@ +// Copyright (C) 2007 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/labeling_foreground.cc + * + * \brief Test on mln::labeling::foreground. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/core/neighb2d.hh> +#include <mln/value/int_u8.hh> +#include <mln/pw/all.hh> + +#include <mln/io/pgm/load.hh> +#include <mln/labeling/foreground.hh> +#include <mln/labeling/estimate.hh> +#include <mln/accu/count.hh> + + +int main() +{ + using namespace mln; + using value::int_u8; + + image2d_b<int_u8> lena = io::pgm::load("../img/tiny.pgm"), + out(lena.domain()); + + unsigned n; + labeling::foreground((pw::value(lena) > pw::cst(127)) | lena.domain(), + c4(), out, n); + mln_assertion(n = 14); + + unsigned sum = 0; + for (int_u8 i = 0; i <= n; ++i) + sum += labeling::estimate< accu::count >(out, i); + // FIXME: use of pix so that (center, mean) etc. + mln_assertion(sum = lena.npoints()); +} Index: tests/accu_min.cc --- tests/accu_min.cc (revision 0) +++ tests/accu_min.cc (revision 0) @@ -0,0 +1,62 @@ +// Copyright (C) 2007 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/accu_min.cc + * + * \brief Tests on mln::accu::min. + */ + +#include <mln/core/image2d_b.hh> +#include <mln/debug/iota.hh> + +#include <mln/accu/nil.hh> +#include <mln/accu/min.hh> +#include <mln/accu/p.hh> +#include <mln/accu/v.hh> +#include <mln/accu/compute.hh> + +#include <mln/level/compute.hh> + + +int main() +{ + using namespace mln; + image2d_b<int> ima(3, 3); + debug::iota(ima); + mln_assertion(level::compute< accu::min >(ima) = 1); + mln_assertion(level::compute< accu::min_<int> >(ima) = 1); + +// accu::compute< accu::nil >(ima); // No-op. + +// accu::compute< accu::min >(ima); + + std::cout << accu::compute< accu::val<accu::min> >(ima) + << std::endl; + +// std::cout << accu::compute< accu::min >(ima) +// << std::endl; +} Index: tests/accu_all.cc --- tests/accu_all.cc (revision 0) +++ tests/accu_all.cc (revision 0) @@ -0,0 +1,56 @@ +// Copyright (C) 2007 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/accu_all.cc + * + * \brief Tests on all files in mln/accu. + */ + +#include <mln/accu/all.hh> +#include <mln/core/point2d.hh> +#include <mln/value/set.hh> + + +int main() +{ + using namespace mln; + using namespace mln::accu; + + + bbox<point2d> b; + count_<int> c; + histo< value::set<bool> > h; + max_<int> ma; + mean_<int> me; + median< value::set<bool> > med; + min_<int> mi; + min_h< value::set<bool> > mh; + min_max_<int> mm; + nil n; + pair_< min_<int>, max_<int> > p; + sum_<int> s; +} Index: mln/estim/sum.hh --- mln/estim/sum.hh (revision 1156) +++ mln/estim/sum.hh (working copy) @@ -31,6 +31,8 @@ /*! \file mln/estim/sum.hh * * \brief Compute the sum pixel value. + * + * \todo Sum works on level so move into mln/level; otherwise on pix then ambiguous. */ # include <mln/accu/sum.hh> @@ -67,15 +69,15 @@ mln_sum(mln_value(I)) sum(const Image<I>& input) { mln_precondition(exact(input).has_data()); - return level::compute(input, accu::sum<mln_value(I)>()).to_value(); + return level::compute<accu::sum>(input); } template <typename I, typename S> void sum(const Image<I>& input, S& result) { mln_precondition(exact(input).has_data()); - result = level::compute(input, - accu::sum<mln_value(I), S>()).to_value(); + typedef accu::sum_<mln_value(I), S> A; + result = level::compute(input, A()); } # endif // ! MLN_INCLUDE_ONLY Index: mln/estim/min_max.hh --- mln/estim/min_max.hh (revision 1156) +++ mln/estim/min_max.hh (working copy) @@ -34,7 +34,7 @@ */ # include <mln/accu/min_max.hh> -# include <mln/level/take.hh> +# include <mln/level/compute.hh> namespace mln @@ -61,11 +61,10 @@ mln_value(I)& min, mln_value(I)& max) { mln_precondition(exact(input).has_data()); - accu::min_max<mln_value(I)> a; - a.init(); - level::take(a, input); - min = a.min(); - max = a.max(); + typedef accu::min_max_<mln_value(I)> A; + mln_result(A) mm = level::compute<A>(input); + min = mm.first; + max = mm.second; } # endif // ! MLN_INCLUDE_ONLY Index: mln/estim/mean.hh --- mln/estim/mean.hh (revision 1156) +++ mln/estim/mean.hh (working copy) @@ -70,16 +70,15 @@ mln_sum(mln_value(I)) mean(const Image<I>& input) { mln_precondition(exact(input).has_data()); - return level::compute(input, - accu::mean<mln_value(I)>()).to_value(); + return level::compute<accu::mean>(input); } template <typename S, typename I, typename M> void mean(const Image<I>& input, M& result) { mln_precondition(exact(input).has_data()); - result = level::compute(input, - accu::mean<mln_value(I), S, M>()).to_value(); + typedef accu::mean_<mln_value(I), S, M> A; + result = level::compute(input, A()); } # endif // ! MLN_INCLUDE_ONLY Index: mln/geom/bbox.hh --- mln/geom/bbox.hh (revision 1156) +++ mln/geom/bbox.hh (working copy) @@ -35,7 +35,7 @@ */ # include <mln/core/concept/image.hh> -# include <mln/core/concept/point_set.hh> +# include <mln/core/concept/box.hh> # include <mln/core/concept/window.hh> # include <mln/core/concept/weighted_window.hh> # include <mln/geom/pmin_pmax.hh> @@ -93,20 +93,38 @@ return bbox(exact(w_win).win()); } + + namespace impl + { + template <typename S> - box_<mln_point(S)> bbox(const Point_Set<S>& pset_) + box_<mln_point(S)> bbox_(const Point_Set<S>& pset_) { const S& pset = exact(pset_); - mln_precondition(pset.npoints() != 0); - typedef mln_point(S) P; std::pair<P, P> pp = geom::pmin_pmax(pset); - box_<P> tmp(pp.first, pp.second); + return tmp; + } + + template <typename B> + box_<mln_point(B)> bbox_(const Box<B>& pset_) + { + return exact(pset_); + } + + } // end of namespace mln::geom::impl + + template <typename S> + box_<mln_point(S)> bbox(const Point_Set<S>& pset) + { + mln_precondition(exact(pset).npoints() != 0); + box_<mln_point(S)> tmp = impl::bbox_(exact(pset)); // FIXME: mln_postcondition(tmp <= pset.bbox()); return tmp; } + template <typename I> box_<mln_point(I)> bbox(const Image<I>& ima_) { Index: mln/core/image_if.hh --- mln/core/image_if.hh (revision 1156) +++ mln/core/image_if.hh (working copy) @@ -35,6 +35,7 @@ # include <mln/core/internal/image_base.hh> # include <mln/core/pset_if.hh> +# include <mln/pw/all.hh> namespace mln @@ -54,6 +55,9 @@ pset_if<mln_pset(I), F> pset_; F f_; I ima_; + // FIXME for matthieu: f_ is *also* in pset_; pb: redundancy!!! + // FIXME for matthieu: ctor arg list and attr list should be the *same*! + // FIXME for matthieu: do *not* change order of those lists elements! }; } // end of namespace mln::internal @@ -63,11 +67,17 @@ * */ template <typename I, typename F> - struct image_if : public internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > + struct image_if + : public internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > + // FIXME for matthieu: *not* image_base_ *but* image_domain_morpher_ { // Parent typedef internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > super_; + // FIXME for matthieu: this should *not* be public! + // FIXME for matthieu: comments end with a '.' + // FIXME for matthieu: we do not say "parent" but "super". + /// Skeleton. typedef image_if< tag::image<I>, tag::function<F> > skeleton; @@ -76,9 +86,10 @@ /// Point_Set associated type. typedef pset_if<mln_pset(I), F> pset; - /// Constructor from an \p image. + /// Constructor from an image \p ima and a predicate \p f. image_if(I& ima, const F& f); + /// Constructor without argument. image_if(); /// Test if a pixel value is accessible at \p p. @@ -91,10 +102,15 @@ operator image_if<const I, F>() const; using super_::data_; + // FIXME for matthieu: this should *not* be public! typedef image_if<I,F> self_; - /// FIXME : to put into an identity morpher + // FIXME : to put into an identity morpher + // FIXME for matthieu: nope... + + + // FIXME for matthieu: most of those typedefs and methods are useless... /// Point_Site associated type. typedef mln_point(I) point; @@ -123,13 +139,30 @@ + // Operators. + template <typename I, typename F> image_if<I, F> - operator | (Image<I>& ima, const Function_p2b<F>& f) - { - image_if<I, F> tmp(exact(ima), exact(f)); - return tmp; - } + operator | (Image<I>& ima, const Function_p2b<F>& f); + + template <typename I, typename F> + image_if<const I, F> + operator | (const Image<I>& ima, const Function_p2b<F>& f); + + template <typename I> + image_if< I, + fun::equal_p2b_expr_< pw::value_<I>, + pw::cst_<mln_value(I)> > > + operator | (Image<I>& ima, const mln_value(I)& v); + + template <typename I> + image_if< const I, + fun::equal_p2b_expr_< pw::value_<I>, + pw::cst_<mln_value(I)> > > + operator | (Image<I>& ima, const mln_value(I)& v); + + // FIXME: Add the notion of "interval of values"... + // FIXME: so we can write: ima | from_to(v1, v2) @@ -150,6 +183,8 @@ } // end of namespace mln::internal + // image_if<I,F> + template <typename I, typename F> image_if<I,F>::image_if() { @@ -205,6 +240,44 @@ { return data_->ima_.values(); } + + + // Operators. + + template <typename I, typename F> + image_if<I, F> + operator | (Image<I>& ima, const Function_p2b<F>& f) + { + image_if<I, F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I, typename F> + image_if<const I, F> + operator | (const Image<I>& ima, const Function_p2b<F>& f) + { + image_if<const I, F> tmp(exact(ima), exact(f)); + return tmp; + } + + template <typename I> + image_if< I, + fun::equal_p2b_expr_< pw::value_<I>, + pw::cst_<mln_value(I)> > > + operator | (Image<I>& ima, const mln_value(I)& v) + { + return ima | (pw::value(ima) = pw::cst(v)); + } + + template <typename I> + image_if< const I, + fun::equal_p2b_expr_< pw::value_<I>, + pw::cst_<mln_value(I)> > > + operator | (const Image<I>& ima, const mln_value(I)& v) + { + return ima | (pw::value(ima) = pw::cst(v)); + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/internal/run_pset.hh --- mln/core/internal/run_pset.hh (revision 1156) +++ mln/core/internal/run_pset.hh (working copy) @@ -117,7 +117,7 @@ const box_<P>& run_pset_<P>::bbox() const { - return fb_.to_value(); + return fb_.to_result(); } template <typename P> Index: mln/core/image2d_b.hh --- mln/core/image2d_b.hh (revision 1156) +++ mln/core/image2d_b.hh (working copy) @@ -42,6 +42,7 @@ # include <mln/core/line_piter.hh> # include <mln/border/get.hh> # include <mln/debug/println.hh> +# include <mln/geom/bbox.hh> // FIXME: @@ -153,17 +154,6 @@ void init_with_(const box2d& b, unsigned bdr = border::thickness); -// /// Initialize an empty image. -// template <typename I> -// void init_with_(const Image<I>& other) // FIXME: Remove this soon obsolete code! -// { -// mln_precondition(this->data_ = 0); -// mln_precondition(exact(other).has_data()); -// this->data_ = new internal::data_< image2d_b<T> >(exact(other).bbox(), -// exact(other).border()); -// } - - /// Test if \p p is valid. bool owns_(const point2d& p) const; @@ -235,7 +225,7 @@ template <typename T, typename J> void init_with_(image2d_b<T>& target, const J& model) { - box2d b = model.bbox(); + box2d b = geom::bbox(model); unsigned bdr = border::get(model); target.init_with_(b, bdr); } Index: mln/core/queue_p.hh --- mln/core/queue_p.hh (revision 1156) +++ mln/core/queue_p.hh (working copy) @@ -175,7 +175,7 @@ mln_precondition(npoints() != 0); if (bb_needs_update_) bb_update_(); - return bb_.to_value(); + return bb_.to_result(); } template <typename P> Index: mln/core/vec_p.hh --- mln/core/vec_p.hh (revision 1156) +++ mln/core/vec_p.hh (working copy) @@ -175,7 +175,7 @@ mln_precondition(npoints() != 0); if (bb_needs_update_) update_bb_(); - return bb_.to_value(); + return bb_.to_result(); } template <typename P> Index: mln/core/concept/meta_accumulator.hh --- mln/core/concept/meta_accumulator.hh (revision 0) +++ mln/core/concept/meta_accumulator.hh (revision 0) @@ -0,0 +1,82 @@ +// Copyright (C) 2007 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_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. + */ + +# include <mln/core/concept/object.hh> +# include <mln/core/concept/accumulator.hh> + + +# define mln_accu_with(A, T) \ +typename A::template with< T >::ret + + +# define mln_accu_result(A, T) \ +typename A::template with< T >::ret::result + + + +namespace mln +{ + + + /*! \brief Base class for implementation of meta accumulators. + * + * The parameter \a E is the exact type. + * + * \see mln::doc::Meta_Accumulator for a complete documentation of + * this class contents. + */ + template <typename E> + struct Meta_Accumulator : public Object<E> + { + protected: + Meta_Accumulator(); + }; + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename E> + Meta_Accumulator<E>::Meta_Accumulator() + { + // FIXME: Check "with" on E. + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + + +#endif // ! MLN_CORE_CONCEPT_META_ACCUMULATOR_HH Index: mln/core/concept/accumulator.hh --- mln/core/concept/accumulator.hh (revision 1156) +++ mln/core/concept/accumulator.hh (working copy) @@ -31,6 +31,8 @@ /*! \file mln/core/concept/accumulator.hh * * \brief Definition of the concept of mln::Accumulator. + * + * \todo Rename value as argument. */ # include <mln/core/concept/object.hh> @@ -52,9 +54,11 @@ { /* typedef value; + typedef result; void init(); void take(const value& v); void take(const E& other); + result to_result() const; */ // Default impl. @@ -66,19 +70,6 @@ }; - /*! \brief Merge two accumulators. - * - * The parameter \a E is the accumulator exact type. - * - * \param[in] lhs An accumulator. - * \param[in] rhs Another accumulator. - * \result A temporary accumulator. - * - * \see relates mln::Accumulator - */ - template <typename E> - E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs); - # ifndef MLN_INCLUDE_ONLY @@ -86,12 +77,16 @@ Accumulator<E>::Accumulator() { typedef mln_value(E) value; + typedef mln_result(E) result; + void (E::*m1)() = & E::init; m1 = 0; void (E::*m2)(const value&) = & E::take; m2 = 0; void (E::*m3)(const E&) = & E::take; m3 = 0; + result (E::*m4)() const = & E::to_result; + m4 = 0; } template <typename E> @@ -103,14 +98,6 @@ exact(this)->take(t); } - template <typename E> - E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs) - { - E tmp(exact(lhs)); - tmp.take(exact(rhs)); - return tmp; - } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln Index: mln/core/set_p.hh --- mln/core/set_p.hh (revision 1156) +++ mln/core/set_p.hh (working copy) @@ -145,7 +145,7 @@ set_p<P>::bbox() const { mln_precondition(npoints() != 0); - return bb_.to_value(); + return bb_.to_result(); } # endif // ! MLN_INCLUDE_ONLY Index: mln/morpho/opening_attribute.hh --- mln/morpho/opening_attribute.hh (revision 1156) +++ mln/morpho/opening_attribute.hh (working copy) @@ -36,6 +36,7 @@ # include <mln/morpho/includes.hh> # include <mln/canvas/morpho/algebraic_union_find.hh> # include <mln/level/sort_points.hh> +# include <mln/util/pix.hh> namespace mln @@ -70,7 +71,7 @@ typedef N_ N; typedef O_ O; typedef vec_p<P> S; - typedef util::pix_<I> pix_t; + typedef util::pix<I> pix_t; const I& input; const N& nbh; @@ -86,7 +87,7 @@ bool is_active(const A& attr) const { - return attr.to_value() < lambda; + return attr.to_result() < lambda; } void inactivate(A& attr) Index: mln/morpho/opening_area.hh --- mln/morpho/opening_area.hh (revision 1156) +++ mln/morpho/opening_area.hh (working copy) @@ -57,8 +57,9 @@ Image<O>& output) { mln_precondition(exact(output).domain() = exact(input).domain()); - typedef util::pix_<I> pix_t; - opening_attribute< accu::count<pix_t> >(input, nbh, lambda, output); + typedef util::pix<I> pix_t; + // FIXME: Change sig of opening_attribute! + opening_attribute< accu::count_<pix_t> >(input, nbh, lambda, output); } # endif // ! MLN_INCLUDE_ONLY Index: mln/morpho/erosion_fast.hh --- mln/morpho/erosion_fast.hh (revision 1156) +++ mln/morpho/erosion_fast.hh (working copy) @@ -133,7 +133,7 @@ min.untake(input(q_dm)); for_all(q_dp) if (input.has(q_dp)) min.take(input(q_dp)); - output(p) = min.to_value(); + output(p) = min.to_result(); } void fwd() @@ -142,7 +142,7 @@ min.untake(input(q_fm)); for_all(q_fp) if (input.has(q_fp)) min.take(input(q_fp)); - output(p) = min.to_value(); + output(p) = min.to_result(); } void bkd() @@ -151,7 +151,7 @@ min.untake(input(q_bm)); for_all(q_bp) if (input.has(q_bp)) min.take(input(q_bp)); - output(p) = min.to_value(); + output(p) = min.to_result(); } }; // end of erosion_fast_t Index: mln/morpho/dilation.hh --- mln/morpho/dilation.hh (revision 1156) +++ mln/morpho/dilation.hh (working copy) @@ -66,7 +66,7 @@ const W& win = exact(win_); O& output = exact(output_); - accu::max<mln_value(I)> max; + accu::max_<mln_value(I)> max; mln_piter(I) p(input.domain()); mln_qiter(W) q(win, p); @@ -75,7 +75,7 @@ max.init(); for_all(q) if (input.has(q)) max.take(input(q)); - output(p) = max.to_value(); + output(p) = max.to_result(); } } Index: mln/morpho/erosion.hh --- mln/morpho/erosion.hh (revision 1156) +++ mln/morpho/erosion.hh (working copy) @@ -66,7 +66,7 @@ const W& win = exact(win_); O& output = exact(output_); - accu::min<mln_value(I)> min; + accu::min_<mln_value(I)> min; mln_piter(I) p(input.domain()); mln_qiter(W) q(win, p); @@ -75,7 +75,7 @@ min.init(); for_all(q) if (input.has(q)) min.take(input(q)); - output(p) = min.to_value(); + output(p) = min.to_result(); } } Index: mln/morpho/dilation_fast.hh --- mln/morpho/dilation_fast.hh (revision 1156) +++ mln/morpho/dilation_fast.hh (working copy) @@ -133,7 +133,7 @@ max.untake(input(q_dm)); for_all(q_dp) if (input.has(q_dp)) max.take(input(q_dp)); - output(p) = max.to_value(); + output(p) = max.to_result(); } void fwd() @@ -142,7 +142,7 @@ max.untake(input(q_fm)); for_all(q_fp) if (input.has(q_fp)) max.take(input(q_fp)); - output(p) = max.to_value(); + output(p) = max.to_result(); } void bkd() @@ -151,7 +151,7 @@ max.untake(input(q_bm)); for_all(q_bp) if (input.has(q_bp)) max.take(input(q_bp)); - output(p) = max.to_value(); + output(p) = max.to_result(); } }; // end of dilation_fast_t Index: mln/level/take.hh --- mln/level/take.hh (revision 1156) +++ mln/level/take.hh (working copy) @@ -45,8 +45,8 @@ /*! Make an accumulator take the values of the image \p input. * - * \param[in,out] a The accumulator. * \param[in] input The input image. + * \param[in,out] a The accumulator. * * This routine runs: \n * for all p of \p input, \p a.take( \p input(p) ) \n @@ -54,7 +54,7 @@ * \warning This routine does not perform a.init(). */ template <typename A, typename I> - void take(Accumulator<A>& a, const Image<I>& input); + void take(const Image<I>& input, Accumulator<A>& a); # ifndef MLN_INCLUDE_ONLY @@ -63,7 +63,7 @@ { template <typename A, typename I> - void take(A& a, const Image<I>& input_) + void take(const Image<I>& input_, A& a) { const I& input = exact(input_); mln_piter(I) p(input.domain()); @@ -72,7 +72,7 @@ } template <typename A, typename I> - void take(A& a, const Fast_Image<I>& input_) + void take(const Fast_Image<I>& input_, A& a) { const I& input = exact(input_); mln_pixter(const I) pxl(input); @@ -86,10 +86,10 @@ // Facade. template <typename A, typename I> - void take(Accumulator<A>& a, const Image<I>& input) + void take(const Image<I>& input, Accumulator<A>& a) { mln_precondition(exact(input).has_data()); - impl::take(exact(a), exact(input)); + impl::take(exact(input), exact(a)); } # endif // ! MLN_INCLUDE_ONLY Index: mln/level/median.hh --- mln/level/median.hh (revision 1156) +++ mln/level/median.hh (working copy) @@ -151,7 +151,7 @@ med.untake(input(q_dm)); for_all(q_dp) if (input.has(q_dp)) med.take(input(q_dp)); - output(p) = med.to_value(); + output(p) = med.to_result(); } void fwd() @@ -160,7 +160,7 @@ med.untake(input(q_fm)); for_all(q_fp) if (input.has(q_fp)) med.take(input(q_fp)); - output(p) = med.to_value(); + output(p) = med.to_result(); } void bkd() @@ -169,7 +169,7 @@ med.untake(input(q_bm)); for_all(q_bp) if (input.has(q_bp)) med.take(input(q_bp)); - output(p) = med.to_value(); + output(p) = med.to_result(); } }; // end of median_t @@ -243,7 +243,7 @@ if (input.has(pt)) med.take(input(pt)); if (output.has(p)) - output(p) = med.to_value(); + output(p) = med.to_result(); } // middle columns (both take and untake) @@ -255,7 +255,7 @@ if (input.has(pu)) med.untake(input(pu)); if (output.has(p)) - output(p) = med.to_value(); + output(p) = med.to_result(); } // right columns (now just untake old points) @@ -264,7 +264,7 @@ if (input.has(pu)) med.untake(input(pu)); if (output.has(p)) - output(p) = med.to_value(); + output(p) = med.to_result(); } } Index: mln/level/naive/median.hh --- mln/level/naive/median.hh (revision 1156) +++ mln/level/naive/median.hh (working copy) @@ -85,7 +85,7 @@ med.init(); for_all(q) if (input.has(q)) med.take(input(q)); - output(p) = med.to_value(); + output(p) = med.to_result(); } } Index: mln/level/fast_median.hh --- mln/level/fast_median.hh (revision 1156) +++ mln/level/fast_median.hh (working copy) @@ -121,7 +121,7 @@ for_all(q_bot) med.take(q_bot.val()); - output(p) = med.to_value(); + output(p) = med.to_result(); if (fwd) // browse line fwd @@ -132,7 +132,7 @@ med.untake(q_fm.val()); for_all(q_fp) med.take(q_fp.val()); - output(p) = med.to_value(); + output(p) = med.to_result(); } else // browse line bkd @@ -143,7 +143,7 @@ med.untake(q_bm.val()); for_all(q_bp) med.take(q_bp.val()); - output(p) = med.to_value(); + output(p) = med.to_result(); } // change browsing fwd = ! fwd; Index: mln/level/compute.hh --- mln/level/compute.hh (revision 1156) +++ mln/level/compute.hh (working copy) @@ -33,7 +33,10 @@ * \brief Compute an accumulator onto image pixel values. */ +# include <mln/core/concept/meta_accumulator.hh> # include <mln/level/take.hh> +# include <mln/metal/is_a.hh> + namespace mln @@ -46,27 +49,51 @@ * * \param[in] input The input image. * \param[in] a The accumulator. - * \return A resulting accumulator. + * \return The accumulator result. * - * This routine computes: \n - * res = \p a \n - * res.init() \n - * level::take(res, \p input) \n - * return res \n + * This routine runs: \n + * tmp = \p a \n + * tmp.init() \n + * level::take(\p input, tmp) \n + * return tmp.to_result() \n */ template <typename I, typename A> - A compute(const Image<I>& input, const Accumulator<A>& a); + mln_result(A) + compute(const Image<I>& input, const Accumulator<A>& a); + + template <typename A, typename I> + mln_accu_with(A, mln_value(I))::result + compute(const Image<I>& input); # ifndef MLN_INCLUDE_ONLY template <typename I, typename A> - A compute(const Image<I>& input, const Accumulator<A>& a) + mln_result(A) + compute(const Image<I>& input, const Accumulator<A>& a_) + { + mln_precondition(exact(input).has_data()); + A a = exact(a_); // Cpy. + a.init(); + level::take(input, a); + return a.to_result(); + } + + template <typename A, typename I> + mln_result(A) + compute(const Image<I>& input) + { + mln_precondition(exact(input).has_data()); + return level::compute(input, A()); + } + + template <typename A, typename I> + mln_accu_with(A, mln_value(I))::result + compute(const Image<I>& input) { - A res = exact(a); - res.init(); - level::take(res, input); - return res; + mlc_is_a(A, Meta_Accumulator)::check(); + return compute(input, + mln_accu_with(A, mln_value(I))()); } # endif // ! MLN_INCLUDE_ONLY Index: mln/canvas/morpho/algebraic_union_find.hh --- mln/canvas/morpho/algebraic_union_find.hh (revision 1156) +++ mln/canvas/morpho/algebraic_union_find.hh (working copy) @@ -119,7 +119,7 @@ void make_set(const point& p) { parent(p) = p; - data(p).take_as_init(util::pix(f.input, p)); + data(p).take_as_init(make::pix(f.input, p)); } bool is_root(const point& p) const Index: mln/accu/nil.hh --- mln/accu/nil.hh (revision 0) +++ mln/accu/nil.hh (revision 0) @@ -0,0 +1,126 @@ +// Copyright (C) 2007 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_ACCU_NIL_HH +# define MLN_ACCU_NIL_HH + +/*! \file mln/accu/nil.hh + * + * \brief Define an accumulator that does nothing. + * + * \todo A macro to generate the meta version. + */ + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/core/concept/accumulator.hh> +# include <mln/util/eat.hh> +# include <mln/util/ignore.hh> + + +namespace mln +{ + + namespace accu + { + + /*! Define an accumulator that does nothing. + */ + template <typename T> + struct nil_ : public Accumulator< nil_<T> > + { + typedef util::eat value; + typedef util::ignore result; + + nil_(); + + void init(); + void take_as_init(const value&); + void take(const value&); + void take(const nil_<T>&); + + util::ignore to_result() const; + }; + + + + // FIXME: Doc! + struct nil : public Meta_Accumulator< nil > + { + template <typename V> + struct with + { + typedef nil_<V> ret; + }; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename T> + nil_<T>::nil_() + { + } + + template <typename T> + void + nil_<T>::init() + { + } + + template <typename T> + void + nil_<T>::take(const value&) + { + } + + template <typename T> + void + nil_<T>::take_as_init(const value&) + { + } + + template <typename T> + void + nil_<T>::take(const nil_<T>&) + { + } + + template <typename T> + util::ignore + nil_<T>::to_result() const + { + return util::ignore(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_NIL_HH Index: mln/accu/min.hh --- mln/accu/min.hh (revision 1156) +++ mln/accu/min.hh (working copy) @@ -33,8 +33,9 @@ * \brief Define an accumulator that computes a min. */ -# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/meta_accumulator.hh> # include <mln/value/props.hh> +# include <mln/util/pix.hh> namespace mln @@ -49,17 +50,19 @@ * The parameter \c V is the type of values. */ template <typename V> - struct min : public Accumulator< min<V> > + struct min_ : public Accumulator< min_<V> > { typedef V value; + typedef V result; - min(); + min_(); - void take(const value& v); - void take(const min<V>& other); void init(); + void take_as_init(const value& v); + void take(const value& v); + void take(const min_<V>& other); - V to_value() const; + V to_result() const; protected: @@ -67,24 +70,43 @@ }; + template <typename I> struct min_< util::pix<I> >; + + + // FIXME: Doc! + struct min : public Meta_Accumulator< min > + { + template <typename V> + struct with + { + typedef min_<V> ret; + }; + }; + # ifndef MLN_INCLUDE_ONLY template <typename V> - min<V>::min() + min_<V>::min_() { init(); } template <typename V> void - min<V>::init() + min_<V>::init() { v_ = mln_max(V); } template <typename V> - void min<V>::take(const value& v) + void min_<V>::take_as_init(const value& v) + { + v_ = v; + } + + template <typename V> + void min_<V>::take(const value& v) { if (v < v_) v_ = v; @@ -92,7 +114,7 @@ template <typename V> void - min<V>::take(const min<V>& other) + min_<V>::take(const min_<V>& other) { if (other.v_ < v_) v_ = other.v_; @@ -100,7 +122,7 @@ template <typename V> V - min<V>::to_value() const + min_<V>::to_result() const { return v_; } Index: mln/accu/take.hh --- mln/accu/take.hh (revision 0) +++ mln/accu/take.hh (revision 0) @@ -0,0 +1,99 @@ +// Copyright (C) 2007 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_ACCU_TAKE_HH +# define MLN_ACCU_TAKE_HH + +/*! \file mln/accu/take.hh + * + * \brief Make an accumulator take image pixels. + */ + +# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/image.hh> +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace accu + { + + /*! Make an accumulator take the pixels of the image \p input. + * + * \param[in] input The input image. + * \param[in,out] a The accumulator. + * + * This routine runs: \n + * for all p of \p input, \p a.take( pix(\p input, p) ) \n + * + * \warning This routine does not perform a.init(). + */ + template <typename A, typename I> + void take(const Image<I>& input, Accumulator<A>& a); + + + // FIXME: Overload for point sets. + + +# ifndef MLN_INCLUDE_ONLY + + namespace impl + { + + template <typename A, typename I> + void take(const Image<I>& input_, A& a) + { + const I& input = exact(input_); + mln_piter(I) p(input.domain()); + for_all(p) + a.take(make::pix(input, p)); + } + + // FIXME: We need an impl for pixels of fast images. + + } // end of namespace mln::accu::impl + + + // Facade. + + template <typename A, typename I> + void take(const Image<I>& input, Accumulator<A>& a) + { + mln_precondition(exact(input).has_data()); + impl::take(exact(input), exact(a)); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_TAKE_HH Index: mln/accu/max.hh --- mln/accu/max.hh (revision 1156) +++ mln/accu/max.hh (working copy) @@ -33,8 +33,9 @@ * \brief Define an accumulator that computes a max. */ -# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/meta_accumulator.hh> # include <mln/value/props.hh> +# include <mln/util/pix.hh> namespace mln @@ -49,17 +50,19 @@ * The parameter \c V is the type of values. */ template <typename V> - struct max : public Accumulator< max<V> > + struct max_ : public Accumulator< max_<V> > { typedef V value; + typedef V result; - max(); + max_(); - void take(const value& v); - void take(const max<V>& other); void init(); + void take_as_init(const value& v); + void take(const value& v); + void take(const max_<V>& other); - V to_value() const; + V to_result() const; protected: @@ -67,41 +70,62 @@ }; + template <typename I> struct max_< util::pix<I> >; + + + // FIXME: Doc! + struct max : public Meta_Accumulator< max > + { + template <typename V> + struct with + { + typedef max_<V> ret; + }; + }; + + # ifndef MLN_INCLUDE_ONLY template <typename V> - max<V>::max() + max_<V>::max_() { init(); } template <typename V> void - max<V>::take(const value& v) + max_<V>::init() + { + v_ = mln_min(V); + } + + template <typename V> + void + max_<V>::take_as_init(const value& v) { - if (v > v_) v_ = v; } template <typename V> void - max<V>::take(const max<V>& other) + max_<V>::take(const value& v) { - if (other.v_ > v_) - v_ = other.v_; + if (v > v_) + v_ = v; } template <typename V> void - max<V>::init() + max_<V>::take(const max_<V>& other) { - v_ = mln_min(V); + if (other.v_ > v_) + v_ = other.v_; } template <typename V> V - max<V>::to_value() const + max_<V>::to_result() const { return v_; } Index: mln/accu/histo.hh --- mln/accu/histo.hh (revision 1156) +++ mln/accu/histo.hh (working copy) @@ -31,6 +31,8 @@ /*! \file mln/accu/histo.hh * * \brief Define a generic histogram accumulator class. + * + * \todo Use histo::data instead of std::vector! */ # include <vector> @@ -57,6 +59,7 @@ histo(); typedef mln_value(S) value; + typedef const std::vector<std::size_t>& result; void take(const value& v); void take(const histo<S>& other); @@ -69,6 +72,7 @@ std::size_t sum() const; const std::vector<std::size_t>& vect() const; + const std::vector<std::size_t>& to_result() const; const S& vset() const; @@ -176,6 +180,13 @@ } template <typename S> + const std::vector<std::size_t>& + histo<S>::to_result() const + { + return h_; + } + + template <typename S> const S& histo<S>::vset() const { Index: mln/accu/min_max.hh --- mln/accu/min_max.hh (revision 1156) +++ mln/accu/min_max.hh (working copy) @@ -31,12 +31,17 @@ /*! \file mln/accu/min_max.hh * * \brief Define an accumulator that computes a min and a max. + * + * \todo A macro to create such accumulators. */ # include <utility> +# include <mln/accu/pair.hh> # include <mln/accu/min.hh> # include <mln/accu/max.hh> +# include <mln/value/props.hh> +# include <mln/util/pix.hh> namespace mln @@ -45,99 +50,22 @@ namespace accu { - /*! Generic min and max accumulator class. * * The parameter \c V is the type of values. */ template <typename V> - struct min_max : public Accumulator< min_max<V> > + struct min_max_ : public pair_< min_<V>, max_<V> > { - typedef V value; - - min_max(); - - void take(const value& v); - void take(const min_max<V>& other); - void init(); - - V min() const; - V max() const; - - std::pair<V,V> to_value() const; - void values(V& min, V& max) const; - - protected: - - accu::min<V> min_; - accu::max<V> max_; }; + template <typename I> struct min_max_< util::pix<I> >; -# ifndef MLN_INCLUDE_ONLY - template <typename V> - min_max<V>::min_max() - { - init(); - } - - template <typename V> - void - min_max<V>::init() - { - min_.init(); - max_.init(); - } - - template <typename V> - void min_max<V>::take(const value& v) - { - min_.take(v); - max_.take(v); - } - - template <typename V> - void - min_max<V>::take(const min_max<V>& other) - { - min_.take(other.min_); - max_.take(other.max_); - } - - template <typename V> - V - min_max<V>::min() const - { - return min_.to_value(); - } - - template <typename V> - V - min_max<V>::max() const - { - return max_.to_value(); - } - - template <typename V> - std::pair<V,V> - min_max<V>::to_value() const - { - std::pair<V,V> tmp(min_.to_value(), - max_.to_value()); - return tmp; - } - - template <typename V> - void - min_max<V>::values(V& min, V& max) const - { - min = min_.to_value(); - max = max_.to_value(); - } + // FIXME: Doc! + typedef pair<min,max> min_max; -# endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::accu Index: mln/accu/count.hh --- mln/accu/count.hh (revision 1156) +++ mln/accu/count.hh (working copy) @@ -33,7 +33,7 @@ * \brief Define an accumulator that counts. */ -# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/meta_accumulator.hh> namespace mln @@ -46,68 +46,78 @@ /*! Generic counter accumulator class. */ template <typename V> - struct count : public Accumulator< count<V> > + struct count_ : public Accumulator< count_<V> > { typedef V value; typedef std::size_t result; // FIXME: Up in Accumulator. - count(); + count_(); void init(); void take(const value&); - void take(const count<V>& other); + void take(const count_<V>& other); - std::size_t to_value() const; + std::size_t to_result() const; void set_value(std::size_t c); protected: - std::size_t count_; + std::size_t count__; }; + // FIXME: Doc! + struct count : public Meta_Accumulator< count > + { + template <typename V> + struct with + { + typedef count_<V> ret; + }; + }; + # ifndef MLN_INCLUDE_ONLY template <typename V> - count<V>::count() + count_<V>::count_() { init(); } template <typename V> void - count<V>::init() + count_<V>::init() { - count_ = 0; + count__ = 0; } template <typename V> void - count<V>::take(const value&) + count_<V>::take(const value&) { - ++count_; + ++count__; } template <typename V> void - count<V>::take(const count<V>& other) + count_<V>::take(const count_<V>& other) { - count_ += other.count_; + count__ += other.count__; } template <typename V> std::size_t - count<V>::to_value() const + count_<V>::to_result() const { - return count_; + return count__; } template <typename V> void - count<V>::set_value(std::size_t c) + count_<V>::set_value(std::size_t c) { - count_ = c; + count__ = c; } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/min_h.hh --- mln/accu/min_h.hh (revision 1156) +++ mln/accu/min_h.hh (working copy) @@ -51,6 +51,7 @@ struct min_h : public Accumulator< min_h<S> > { typedef mln_value(S) value; + typedef value result; min_h(const Value_Set<S>& s); min_h(); @@ -63,7 +64,7 @@ unsigned card() const { return h_.sum(); } - value to_value() const; + value to_result() const; const accu::histo<S>& histo() const; @@ -213,7 +214,7 @@ template <typename S> typename min_h<S>::value - min_h<S>::to_value() const + min_h<S>::to_result() const { if (! valid_) update_(); @@ -230,7 +231,7 @@ template <typename S> std::ostream& operator<<(std::ostream& ostr, const min_h<S>& m) { - return ostr << m.to_value(); + return ostr << m.to_result(); } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/bbox.hh --- mln/accu/bbox.hh (revision 1156) +++ mln/accu/bbox.hh (working copy) @@ -52,14 +52,16 @@ struct bbox : public Accumulator< bbox<P> > { typedef P value; + typedef const box_<P>& result; bbox(); + void init(); + void take_as_init(const P& p); void take(const P& p); void take(const bbox<P>& other); - void init(); - const box_<P>& to_value() const; + const box_<P>& to_result() const; bool is_valid() const; @@ -81,6 +83,22 @@ template <typename P> void + bbox<P>::init() + { + is_valid_ = false; + } + + template <typename P> + void + bbox<P>::take_as_init(const P& p) + { + b_.pmin() = p; + b_.pmax() = p; + is_valid_ = true; + } + + template <typename P> + void bbox<P>::take(const P& p) { if (! is_valid_) @@ -122,15 +140,8 @@ } template <typename P> - void - bbox<P>::init() - { - is_valid_ = false; - } - - template <typename P> const box_<P>& - bbox<P>::to_value() const + bbox<P>::to_result() const { mln_precondition(is_valid_); return b_; Index: mln/accu/pair.hh --- mln/accu/pair.hh (revision 0) +++ mln/accu/pair.hh (revision 0) @@ -0,0 +1,162 @@ +// Copyright (C) 2007 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_ACCU_PAIR_HH +# define MLN_ACCU_PAIR_HH + +/*! \file mln/accu/pair.hh + * + * \brief Define a pair of accumulators. + */ + +# include <utility> + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/metal/is_a.hh> +# include <mln/metal/unqualif.hh> + + +namespace mln +{ + + namespace accu + { + + + /*! Generic pair of accumulators. + * + * The parameter \c V is the type of values. + * + * \todo Check that, when V is not provided, A1 and A2 have the same value. + */ + template <typename A1, typename A2, typename V = mln_value(A1)> + struct pair_ : public Accumulator< pair_<A1,A2,V> > + { + typedef V value; + + typedef mlc_unqualif(mln_result(A1)) result_1; + typedef mlc_unqualif(mln_result(A2)) result_2; + typedef std::pair<result_1, result_2> result; + + pair_(); + pair_(const A1& a1, const A2& a2); + + void init(); + void take_as_init(const value& v); + void take(const value& v); + void take(const pair_<A1,A2,V>& other); + + result to_result() const; + void get_result(result_1& r1, result_2& r2) const; + + protected: + + A1 a1_; + A2 a2_; + }; + + + + // FIXME: Doc! + template <typename A1, typename A2> + struct pair : public Meta_Accumulator< pair<A1,A2> > + { + template <typename V> + struct with + { + typedef mln_accu_with(A1, V) A1_V; + typedef mln_accu_with(A2, V) A2_V; + typedef pair_<A1_V, A2_V, V> ret; + }; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A1, typename A2, typename V> + pair_<A1,A2,V>::pair_() + { + init(); + } + + template <typename A1, typename A2, typename V> + void + pair_<A1,A2,V>::init() + { + a1_.init(); + a2_.init(); + } + + template <typename A1, typename A2, typename V> + void + pair_<A1,A2,V>::take_as_init(const value& v) + { + a1_.take_as_init(v); + a2_.take_as_init(v); + } + + template <typename A1, typename A2, typename V> + void + pair_<A1,A2,V>::take(const value& v) + { + a1_.take(v); + a2_.take(v); + } + + template <typename A1, typename A2, typename V> + void + pair_<A1,A2,V>::take(const pair_<A1,A2,V>& other) + { + a1_.take(other.a1_); + a2_.take(other.a2_); + } + + template <typename A1, typename A2, typename V> + typename pair_<A1,A2,V>::result + pair_<A1,A2,V>::to_result() const + { + result tmp(a1_.to_result(), a2_.to_result()); + return tmp; + } + + template <typename A1, typename A2, typename V> + void + pair_<A1,A2,V>::get_result(result_1& r1, + result_2& r2) const + { + r1 = a1_.to_result(); + r2 = a2_.to_result(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_PAIR_HH Index: mln/accu/max_h.hh --- mln/accu/max_h.hh (revision 1156) +++ mln/accu/max_h.hh (working copy) @@ -51,6 +51,7 @@ struct max_h : public Accumulator< max_h<S> > { typedef mln_value(S) value; + typedef value result; max_h(const Value_Set<S>& s); max_h(); @@ -63,7 +64,7 @@ unsigned card() const { return h_.sum(); } - value to_value() const; + value to_result() const; const accu::histo<S>& histo() const; @@ -212,7 +213,7 @@ template <typename S> typename max_h<S>::value - max_h<S>::to_value() const + max_h<S>::to_result() const { if (! valid_) update_(); @@ -229,7 +230,7 @@ template <typename S> std::ostream& operator<<(std::ostream& ostr, const max_h<S>& m) { - return ostr << m.to_value(); + return ostr << m.to_result(); } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/median_alt.hh --- mln/accu/median_alt.hh (revision 1156) +++ mln/accu/median_alt.hh (working copy) @@ -58,7 +58,7 @@ void init(); operator mln_value(S) () const; - value to_value() const; + value to_result() const; // FIXME: remove void debug__() const @@ -256,7 +256,7 @@ template <typename S> typename median_alt<S>::value - median_alt<S>::to_value() const + median_alt<S>::to_result() const { return v_; } @@ -265,7 +265,7 @@ std::ostream& operator<<(std::ostream& ostr, const median_alt<S>& m) { m.debug__(); - return ostr << m.to_value(); + return ostr << m.to_result(); } Index: mln/accu/median.hh --- mln/accu/median.hh (revision 1156) +++ mln/accu/median.hh (working copy) @@ -51,6 +51,7 @@ struct median : public Accumulator< median<S> > { typedef mln_value(S) value; + typedef value result; median(const Value_Set<S>& s); median(); @@ -62,7 +63,7 @@ unsigned card() const { return h_.sum(); } - value to_value() const; + value to_result() const; const accu::histo<S>& histo() const; @@ -223,7 +224,7 @@ template <typename S> typename median<S>::value - median<S>::to_value() const + median<S>::to_result() const { if (! valid_) update_(); @@ -240,7 +241,7 @@ template <typename S> std::ostream& operator<<(std::ostream& ostr, const median<S>& m) { - return ostr << m.to_value(); + return ostr << m.to_result(); } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/p.hh --- mln/accu/p.hh (revision 0) +++ mln/accu/p.hh (revision 0) @@ -0,0 +1,144 @@ +// Copyright (C) 2007 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_ACCU_P_HH +# define MLN_ACCU_P_HH + +/*! \file mln/accu/p.hh + * + * \brief Define an accumulator that computes a min and a max. + */ + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/core/concept/accumulator.hh> +# include <mln/metal/is_a.hh> + + +namespace mln +{ + + namespace accu + { + + + /*! Generic p of accumulators. + * + * The parameter \c V is the type of values. + */ + template <typename A> + struct p_ : public Accumulator< p_<A> > + { + typedef mln_value(A) value; + typedef mln_result(A) result; + + + p_(); + p_(const A& a); + + void init(); + void take_as_init(const value& v); + void take(const value& v); + void take(const p_<A>& other); + + result to_result() const; + + protected: + A a_; + }; + + + + // FIXME: Doc! + template <typename mA> + struct p : public Meta_Accumulator< p<mA> > + { + template <typename V> + struct with + { + typedef mln_accu_with(mA, mln_psite(V)) ret; + }; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A> + p_<A>::p_() + { + init(); + } + + template <typename A> + p_<A>::p_(const A& a) + : a_(a) + { + init(); + } + + template <typename A> + void + p_<A>::init() + { + a_.init(); + } + + template <typename A> + void + p_<A>::take_as_init(const value& v) + { + a_.take_as_init(v.p()); // FIXME: Generalize with "psite(v)". + } + + template <typename A> + void + p_<A>::take(const value& v) + { + a_.take(v.p()); + } + + template <typename A> + void + p_<A>::take(const p_<A>& other) + { + a_.take(other.a_); + } + + template <typename A> + typename p_<A>::result + p_<A>::to_result() const + { + return a_.to_result(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_P_HH Index: mln/accu/sum.hh --- mln/accu/sum.hh (revision 1156) +++ mln/accu/sum.hh (working copy) @@ -33,8 +33,9 @@ * \brief Define an accumulator that computes a sum. */ -# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/meta_accumulator.hh> # include <mln/value/props.hh> +# include <mln/util/pix.hh> namespace mln @@ -51,21 +52,37 @@ * \c S is the summation type (property) of \c V. */ template <typename V, typename S = mln_sum(V)> - struct sum : public Accumulator< sum<V,S> > + struct sum_ : public Accumulator< sum_<V,S> > { typedef V value; + typedef S result; - sum(); + sum_(); void init(); void take(const value& v); - void take(const sum<V,S>& other); + void take(const sum_<V,S>& other); - S to_value() const; + S to_result() const; protected: - S sum_; + S s_; + }; + + + template <typename I, typename S> + struct sum_< util::pix<I>, S >; + + + // FIXME: Doc! + struct sum : public Meta_Accumulator< sum > + { + template <typename V, typename S = mln_sum(V)> + struct with + { + typedef sum_<V, S> ret; + }; }; @@ -73,36 +90,36 @@ # ifndef MLN_INCLUDE_ONLY template <typename V, typename S> - sum<V,S>::sum() + sum_<V,S>::sum_() { init(); } template <typename V, typename S> void - sum<V,S>::init() + sum_<V,S>::init() { - sum_ = 0; + s_ = 0; } template <typename V, typename S> - void sum<V,S>::take(const value& v) + void sum_<V,S>::take(const value& v) { - sum_ += v; + s_ += v; } template <typename V, typename S> void - sum<V,S>::take(const sum<V,S>& other) + sum_<V,S>::take(const sum_<V,S>& other) { - sum_ += other.sum_; + s_ += other.s_; } template <typename V, typename S> S - sum<V,S>::to_value() const + sum_<V,S>::to_result() const { - return sum_; + return s_; } # endif // ! MLN_INCLUDE_ONLY Index: mln/accu/v.hh --- mln/accu/v.hh (revision 0) +++ mln/accu/v.hh (revision 0) @@ -0,0 +1,154 @@ +// Copyright (C) 2007 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_ACCU_V_HH +# define MLN_ACCU_V_HH + +/*! \file mln/accu/v.hh + * + * \brief Define an accumulator that computes a min and a max. + */ + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/core/concept/accumulator.hh> +# include <mln/metal/is_a.hh> + + +namespace mln +{ + + namespace accu + { + + + /*! Generic v of accumulators. + */ + template <typename A> + struct val_ : public Accumulator< val_<A> > + { + typedef mln_value(A) value; + typedef mln_result(A) result; + + val_(); + val_(const A& a); + + void init(); + void take_as_init(const value& v); + void take(const value& v); + void take(const val_<A>& other); + + template <typename I> + void take_as_init(const util::pix<I>& pix) + { + a_.take_as_init(pix.v()); // FIXME: Generalize with "value(pix)". + } + + template <typename I> + void take(const util::pix<I>& pix) + { + a_.take(pix.v()); + } + + result to_result() const; + + protected: + A a_; + }; + + + + // FIXME: Doc! + template <typename mA> + struct val : public Meta_Accumulator< val<mA> > + { + template <typename V> + struct with + { + typedef mln_accu_with(mA, mln_value(V)) A; + typedef val_<A> ret; + }; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A> + val_<A>::val_() + { + init(); + } + + template <typename A> + val_<A>::val_(const A& a) + : a_(a) + { + init(); + } + + template <typename A> + void + val_<A>::init() + { + a_.init(); + } + + template <typename A> + void + val_<A>::take_as_init(const value& v) + { + a_.take_as_init(v); + } + + template <typename A> + void + val_<A>::take(const value& v) + { + a_.take(v); + } + + template <typename A> + void + val_<A>::take(const val_<A>& other) + { + a_.take(other.a_); + } + + template <typename A> + typename val_<A>::result + val_<A>::to_result() const + { + return a_.to_result(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_VAL_HH Index: mln/accu/all.hh --- mln/accu/all.hh (revision 0) +++ mln/accu/all.hh (revision 0) @@ -0,0 +1,65 @@ +// Copyright (C) 2007 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_ACCU_ALL_HH +# define MLN_ACCU_ALL_HH + +/*! \file mln/accu/all.hh + * + * \brief File that includes all accumulator types. + * + * \todo Update accumulators s.a. count so that they are like min_/min. + * + * \todo Propagate those updates to mln/estim/. + */ + + +namespace mln +{ + + /*! Namespace of accumulators. + */ + namespace accu {} + +} + + +# include <mln/accu/bbox.hh> +# include <mln/accu/count.hh> +# include <mln/accu/histo.hh> +# include <mln/accu/max.hh> +# include <mln/accu/mean.hh> +# include <mln/accu/median.hh> +# include <mln/accu/min.hh> +# include <mln/accu/min_h.hh> +# include <mln/accu/min_max.hh> +# include <mln/accu/nil.hh> +# include <mln/accu/pair.hh> +# include <mln/accu/sum.hh> + + +#endif // ! MLN_ACCU_ALL_HH Index: mln/accu/compute.hh --- mln/accu/compute.hh (revision 0) +++ mln/accu/compute.hh (revision 0) @@ -0,0 +1,101 @@ +// Copyright (C) 2007 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_ACCU_COMPUTE_HH +# define MLN_ACCU_COMPUTE_HH + +/*! \file mln/accu/compute.hh + * + * \brief Make an accumulator compute image pixels. + */ + +# include <mln/core/concept/meta_accumulator.hh> +# include <mln/core/concept/accumulator.hh> +# include <mln/core/concept/image.hh> +# include <mln/metal/is_a.hh> +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace accu + { + + /*! Make an accumulator compute the pixels of the image \p input. + * + * \param[in] input The input image. + * + * This routine runs: \n + * FIXME + * + * \warning This routine does not perform a.init(). + */ + template <typename A, typename I> + mln_result(A) + compute(const Image<I>& input); + + + // FIXME: Doc! + template <typename A, typename I> + mln_accu_with(A, util::pix<I>)::result + compute(const Image<I>& input); + + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A, typename I> + mln_result(A) + compute(const Image<I>& input_) + { + mlc_is_a(A, Accumulator)::check(); + const I& input = exact(input_); + A a; + mln_piter(I) p(input.domain()); + for_all(p) + a.take(make::pix(input, p)); + return a.to_result(); + } + + template <typename A, typename I> + mln_accu_with(A, util::pix<I>)::result + compute(const Image<I>& input) + { + mlc_is_a(A, Meta_Accumulator)::check(); + typedef mln_accu_with(A, util::pix<I>) A_; + return compute<A_>(input); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_COMPUTE_HH Index: mln/accu/mean.hh --- mln/accu/mean.hh (revision 1156) +++ mln/accu/mean.hh (working copy) @@ -31,6 +31,8 @@ /*! \file mln/accu/mean.hh * * \brief Define an accumulator that computes a mean. + * + * \todo Use accu::pair just like in accu::min_max. */ # include <mln/accu/count.hh> @@ -55,44 +57,63 @@ template <typename V, typename S = mln_sum(V), typename M = S> - struct mean : public Accumulator< mean<V,S,M> > + struct mean_ : public Accumulator< mean_<V,S,M> > { typedef V value; + typedef M result; - mean(); + mean_(); void init(); void take(const value& v); - void take(const mean<V,S,M>& other); + void take(const mean_<V,S,M>& other); - M to_value() const; + M to_result() const; protected: - accu::count<V> count_; - accu::sum<V,S> sum_; + accu::count_<V> count_; + accu::sum_<V,S> sum_; }; + template <typename I, typename S, typename M> + struct mean_< util::pix<I>, S,M >; + + + + // FIXME: Doc! + struct mean : public Meta_Accumulator< mean > + { + template < typename V, + typename S = mln_sum(V), + typename M = S > + struct with + { + typedef mean_<V,S,M> ret; + }; + }; + + # ifndef MLN_INCLUDE_ONLY template <typename V, typename S, typename M> - mean<V,S,M>::mean() + mean_<V,S,M>::mean_() { init(); } template <typename V, typename S, typename M> void - mean<V,S,M>::init() + mean_<V,S,M>::init() { count_.init(); sum_.init(); } template <typename V, typename S, typename M> - void mean<V,S,M>::take(const value& v) + void mean_<V,S,M>::take(const value& v) { count_.take(v); sum_.take(v); @@ -100,7 +121,7 @@ template <typename V, typename S, typename M> void - mean<V,S,M>::take(const mean<V,S,M>& other) + mean_<V,S,M>::take(const mean_<V,S,M>& other) { count_.take(other.count_); sum_.take(other.sum_); @@ -108,9 +129,9 @@ template <typename V, typename S, typename M> M - mean<V,S,M>::to_value() const + mean_<V,S,M>::to_result() const { - return sum_.to_value() / count_.to_value(); + return sum_.to_result() / count_.to_result(); } # endif // ! MLN_INCLUDE_ONLY Index: mln/make/pix.hh --- mln/make/pix.hh (revision 0) +++ mln/make/pix.hh (revision 0) @@ -0,0 +1,66 @@ +// Copyright (C) 2007 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_MAKE_PIX_HH +# define MLN_MAKE_PIX_HH + +/*! \file mln/make/pix.hh + * + * \brief Routine to construct an mln::util::pix. + */ + +# include <mln/util/pix.hh> + + +namespace mln +{ + + namespace make + { + + /// Create an mln::pix from an image \p ima and a psite \p p. + template <typename I> + mln::util::pix<I> pix(const Image<I>& ima, const mln_psite(I)& p); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename I> + mln::util::pix<I> pix(const Image<I>& ima, const mln_psite(I)& p) + { + mln::util::pix<I> tmp(ima, p); + return tmp; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::make + +} // end of namespace mln + + +#endif // ! MLN_MAKE_PIX_HH Index: mln/labeling/estimate.hh --- mln/labeling/estimate.hh (revision 0) +++ mln/labeling/estimate.hh (revision 0) @@ -0,0 +1,73 @@ +// Copyright (C) 2007 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_LABELING_ESTIMATE_HH +# define MLN_LABELING_ESTIMATE_HH + +/*! \file mln/labeling/estimate.hh + * + * \brief Compute the estimate pixel value. + */ + +# include <mln/core/image_if.hh> +# include <mln/accu/compute.hh> + + +namespace mln +{ + + namespace labeling + { + + /*! \brief FIXME: Compute an estimate over the pixels of image \p + * input with value \p val. + * + * \param[in] input The image. + * \result The estimate value. + */ + template <typename A, typename I> + mln_accu_with(A, util::pix<I>)::result + estimate(const Image<I>& input, const mln_value(I)& val); + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A, typename I> + mln_accu_with(A, util::pix<I>)::result + estimate(const Image<I>& input, const mln_value(I)& val) + { + return accu::compute<A>(input | val); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::labeling + +} // end of namespace mln + + +#endif // ! MLN_LABELING_ESTIMATE_HH Index: mln/util/ignore.hh --- mln/util/ignore.hh (revision 0) +++ mln/util/ignore.hh (revision 0) @@ -0,0 +1,75 @@ +// Copyright (C) 2007 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_UTIL_IGNORE_HH +# define MLN_UTIL_IGNORE_HH + +/*! \file mln/util/ignore.hh + * + * \brief Definition of an "ignorer" object. + */ + +# include <mln/core/concept/object.hh> + + +namespace mln +{ + + namespace util + { + + /// Ignore structure. + struct ignore + { + ignore(); + + template <typename T> + operator T() const; + }; + +# ifndef MLN_INCLUDE_ONLY + + // ignore + + ignore::ignore() + { + } + + template <typename T> + ignore::operator T() const + { + return T(); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::util + +} // end of namespace mln + + +#endif // ! MLN_UTIL_IGNORE_HH Index: mln/util/eat.hh --- mln/util/eat.hh (revision 0) +++ mln/util/eat.hh (revision 0) @@ -0,0 +1,84 @@ +// Copyright (C) 2007 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_UTIL_EAT_HH +# define MLN_UTIL_EAT_HH + +/*! \file mln/util/eat.hh + * + * \brief Definition of an "eater" object. + */ + +# include <mln/core/concept/object.hh> + + +namespace mln +{ + + namespace util + { + + /// Eat structure. + struct eat + { + eat(); + + template <typename T> + eat(const T&); + + template <typename T> + eat& operator=(const T&); + }; + +# ifndef MLN_INCLUDE_ONLY + + // eat + + eat::eat() + { + } + + template <typename T> + eat::eat(const T&) + { + } + + template <typename T> + eat& + eat::operator=(const T&) + { + return *this; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::util + +} // end of namespace mln + + +#endif // ! MLN_UTIL_EAT_HH Index: mln/util/pix.hh --- mln/util/pix.hh (revision 1156) +++ mln/util/pix.hh (working copy) @@ -39,35 +39,44 @@ namespace mln { + namespace select + { + + template <typename P> + struct p_of : P + { + operator typename P::psite() const + { + return this->p(); + } + }; + + } + namespace util { /// Pix structure. template <typename I> - struct pix_ + struct pix { - pix_(const Image<I>& ima, const mln_point(I)& p); + typedef mln_psite(I) psite; + typedef mln_value(I) value; + + pix(const Image<I>& ima, const mln_psite(I)& p); const I& ima() const; - const mln_point(I)& p() const; - operator mln_rvalue(I)() const; + const mln_psite(I)& p() const; + mln_rvalue(I) v() const; private: const I& ima_; - const mln_point(I)& p_; + const mln_psite(I)& p_; }; - /// Routine to construct a pix on the fly. - template <typename I> - pix_<I> - pix(const Image<I>& ima, const mln_point(I)& p); - - # ifndef MLN_INCLUDE_ONLY - // pix_<I> - template <typename I> - pix_<I>::pix_(const Image<I>& ima, const mln_point(I)& p) + pix<I>::pix(const Image<I>& ima, const mln_psite(I)& p) : ima_(exact(ima)), p_(p) { @@ -75,34 +84,25 @@ template <typename I> const I& - pix_<I>::ima() const + pix<I>::ima() const { return ima_; } template <typename I> - const mln_point(I)& - pix_<I>::p() const + const mln_psite(I)& + pix<I>::p() const { return p_; } template <typename I> - pix_<I>::operator mln_rvalue(I)() const + mln_rvalue(I) + pix<I>::v() const { return ima_(p_); } - // pix - - template <typename I> - pix_<I> - pix(const Image<I>& ima, const mln_point(I)& p) - { - pix_<I> tmp(ima, p); - return tmp; - } - # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::util @@ -110,4 +110,7 @@ } // end of namespace mln +# include <mln/make/pix.hh> + + #endif // ! MLN_UTIL_PIX_HH