Commit 48a4a5ff authored by Thierry Geraud's avatar Thierry Geraud
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1157 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent e4a85151
2007-09-24 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.
2007-09-24 Simon Nivault <simon.nivault@lrde.epita.fr>
Add test of rotation and fix.
......
// 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
......@@ -52,14 +52,16 @@ namespace mln
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;
......@@ -79,6 +81,22 @@ namespace mln
init();
}
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)
......@@ -121,16 +139,9 @@ namespace mln
b_.pmax()[i] = o_b.pmax()[i];
}
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_;
......
// 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
......@@ -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 @@ namespace mln
/*! 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
......
......@@ -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 @@ namespace mln
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 @@ namespace mln
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;
......@@ -174,6 +178,13 @@ namespace mln
{
return h_;
}
template <typename S>
const std::vector<std::size_t>&
histo<S>::to_result() const
{
return h_;
}
template <typename S>
const S&
......
......@@ -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 @@ namespace mln
* 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 @@ namespace mln
};
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()
{
if (v > v_)
v_ = v;
v_ = mln_min(V);
}
template <typename V>
void
max<V>::take(const max<V>& other)
max_<V>::take_as_init(const value& v)
{
if (other.v_ > v_)
v_ = other.v_;
v_ = v;
}
template <typename V>
void
max<V>::init()
max_<V>::take(const value& v)
{
v_ = mln_min(V);
if (v > v_)
v_ = v;
}
template <typename V>
void
max_<V>::take(const max_<V>& other)
{
if (other.v_ > v_)
v_ = other.v_;
}
template <typename V>
V
max<V>::to_value() const
max_<V>::to_result() const
{
return v_;
}
......
......@@ -51,6 +51,7 @@ namespace mln
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 @@ namespace mln
unsigned card() const { return h_.sum(); }
value to_value() const;
value to_result() const;
const accu::histo<S>& histo() const;
......@@ -212,7 +213,7 @@ namespace mln
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 @@ namespace mln
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
......
......@@ -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 @@ namespace mln
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