Commit 3157c44c authored by Nicolas Ballas's avatar Nicolas Ballas
Browse files

Adapt the accumulators histo, min_h, max_h to histo/data.

	* tests/accu/max_h.cc,
	* tests/accu/min_h.cc: Update.
	* mln/histo/data.hh: Add a new method nvalues.
	* mln/core/routine/ops.hh: delete trailing whitespace.
	* mln/accu/nil.hh,
	* mln/accu/min.hh,
	* mln/accu/count_adjacent_vertices.hh,
	* mln/accu/max.hh,
	* mln/accu/count.hh,
	* mln/accu/tuple.hh,
	* mln/accu/bbox.hh,
	* mln/accu/pair.hh,
	* mln/accu/median.hh,
	* mln/accu/median_alt.hh,
	* mln/accu/p.hh,
	* mln/accu/rank_high_quant.hh,
	* mln/accu/sum.hh,
	* mln/accu/v.hh,
	* mln/accu/rank_bool.hh,
	* mln/accu/volume.hh,
	* mln/accu/height.hh,
	* mln/accu/mean.hh,
	* mln/accu/internal/base.hh: Rename base_ to base.
	* mln/accu/max_h.hh,
	* mln/accu/min_h.hh,
	* mln/accu/histo.hh: Adapt to histo/data.
	* mln/value/int_u.hh: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2227 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 2b2ce8a7
2008-09-12 Nicolas Ballas <ballas@lrde.epita.fr>
Adapt the accumulators histo, min_h, max_h to histo/data.
* tests/accu/max_h.cc,
* tests/accu/min_h.cc: Update.
* mln/histo/data.hh: Add a new method nvalues.
* mln/core/routine/ops.hh: delete trailing whitespace.
* mln/accu/nil.hh,
* mln/accu/min.hh,
* mln/accu/count_adjacent_vertices.hh,
* mln/accu/max.hh,
* mln/accu/count.hh,
* mln/accu/tuple.hh,
* mln/accu/bbox.hh,
* mln/accu/pair.hh,
* mln/accu/median.hh,
* mln/accu/median_alt.hh,
* mln/accu/p.hh,
* mln/accu/rank_high_quant.hh,
* mln/accu/sum.hh,
* mln/accu/v.hh,
* mln/accu/rank_bool.hh,
* mln/accu/volume.hh,
* mln/accu/height.hh,
* mln/accu/mean.hh,
* mln/accu/internal/base.hh: Rename base_ to base.
* mln/accu/max_h.hh,
* mln/accu/min_h.hh,
* mln/accu/histo.hh: Adapt to histo/data.
* mln/value/int_u.hh: Update.
2008-09-12 Guillaume Lazzara <z@lrde.epita.fr>
 
Propagate few renamings.
......
......@@ -49,7 +49,7 @@ namespace mln
* The parameter \c P is the type of points.
*/
template <typename P>
struct bbox : public mln::accu::internal::base_< const box<P>& , bbox<P> >
struct bbox : public mln::accu::internal::base< const box<P>& , bbox<P> >
{
typedef P argument;
typedef const box<P>& result;
......
......@@ -43,7 +43,7 @@ namespace mln
/// \brief Generic counter accumulator class.
/// The parameter \a T is the type to be count.
template <typename T>
struct count_ : public mln::accu::internal::base_< std::size_t , count_<T> >
struct count_ : public mln::accu::internal::base< std::size_t , count_<T> >
{
typedef T argument;
......
......@@ -53,9 +53,9 @@ namespace mln
/// This accumulator is used by mln::closing_area_on_vertices and
/// mln::opening_area_on_vertices.
template <typename P, typename V>
struct count_adjacent_vertices_
: public mln::accu::internal::base_< std::size_t,
count_adjacent_vertices_<P, V> >
struct count_adjacent_vertices_
: public mln::accu::internal::base< std::size_t,
count_adjacent_vertices_<P, V> >
{
typedef mln::util::pix< mln::line_graph_image<P, V> > argument;
......
......@@ -59,7 +59,7 @@ namespace mln
/// of pixels is built.
template <typename I>
struct height_
: public mln::accu::internal::base_< std::size_t , height_<I> >
: public mln::accu::internal::base< std::size_t , height_<I> >
{
/// \brief The accumulated data type.
///
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -41,7 +41,7 @@
# include <mln/core/concept/value_set.hh>
# include <mln/accu/internal/base.hh>
# include <mln/value/set.hh>
# include <mln/histo/data.hh>
namespace mln
{
......@@ -51,19 +51,20 @@ namespace mln
/*!
* \brief Generic histogram class over a value set with type \c S.
* \brief Generic histogram class over a value set with type \c V.
*/
template <typename S>
struct histo : public mln::accu::internal::base_< const std::vector<std::size_t>& , histo<S> >
template <typename V>
struct histo :
public mln::accu::internal::base<const std::vector<std::size_t>& ,
histo<V> >
{
histo(const Value_Set<S>& s);
histo();
typedef mln_value(S) argument;
typedef V argument;
typedef const std::vector<std::size_t>& result;
void take(const argument& t);
void take(const histo<S>& other);
void take(const histo<V>& other);
void untake(const argument& t);
void init();
......@@ -75,142 +76,130 @@ namespace mln
const std::vector<std::size_t>& vect() const;
const std::vector<std::size_t>& to_result() const;
const S& vset() const;
const value::set<V>& vset() const;
protected:
const S& s_;
std::vector<std::size_t> h_;
mln::histo::data<V> h_;
std::size_t sum_;
};
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const histo<S>& h);
template <typename V>
std::ostream& operator<<(std::ostream& ostr, const histo<V>& h);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
inline
histo<S>::histo(const Value_Set<S>& s)
: s_(exact(s)),
h_(s_.nvalues(), 0),
sum_(0)
{
}
template <typename S>
template <typename V>
inline
histo<S>::histo()
: s_(S::the()),
h_(s_.nvalues(), 0),
histo<V>::histo()
: h_(),
sum_(0)
{
}
template <typename S>
template <typename V>
inline
void
histo<S>::take(const argument& t)
histo<V>::take(const argument& t)
{
++h_[s_.index_of(t)];
++h_[h_.vset().index_of(t)];
++sum_;
}
template <typename S>
template <typename V>
inline
void
histo<S>::take(const histo<S>& other)
histo<V>::take(const histo<V>& other)
{
for (unsigned i = 0; i < h_.size(); ++i)
for (unsigned i = 0; i < h_.nvalues(); ++i)
h_[i] += other.h_[i];
sum_ += other.sum_;
}
template <typename S>
template <typename V>
inline
void
histo<S>::untake(const argument& t)
histo<V>::untake(const argument& t)
{
mln_precondition(h_[s_.index_of(t)] > 0);
mln_precondition(h_[h_.vset().index_of(t)] > 0);
mln_precondition(sum_ > 0);
--h_[s_.index_of(t)];
--h_[h_.vset().index_of(t)];
--sum_;
}
template <typename S>
template <typename V>
inline
void
histo<S>::init()
histo<V>::init()
{
std::fill(h_.begin(), h_.end(), 0);
sum_ = 0;
h_.clear();
}
template <typename S>
template <typename V>
inline
std::size_t
histo<S>::operator()(const argument& t) const
histo<V>::operator()(const argument& t) const
{
return h_[s_.index_of(t)];
return h_[h_.vset().index_of(t)];
}
template <typename S>
template <typename V>
inline
std::size_t
histo<S>::operator[](unsigned i) const
histo<V>::operator[](unsigned i) const
{
mln_precondition(i < s_.nvalues());
mln_precondition(i < h_.vset().nvalues());
return h_[i];
}
template <typename S>
template <typename V>
inline
unsigned
histo<S>::nvalues() const
histo<V>::nvalues() const
{
return s_.nvalues();
return h_.vset().nvalues();
}
template <typename S>
template <typename V>
inline
std::size_t
histo<S>::sum() const
histo<V>::sum() const
{
return sum_;
}
template <typename S>
template <typename V>
inline
const std::vector<std::size_t>&
histo<S>::vect() const
histo<V>::vect() const
{
return h_;
return h_.vect();
}
template <typename S>
template <typename V>
inline
const std::vector<std::size_t>&
histo<S>::to_result() const
histo<V>::to_result() const
{
return h_;
return this->vect();
}
template <typename S>
template <typename V>
inline
const S&
histo<S>::vset() const
const value::set<V>&
histo<V>::vset() const
{
return s_;
return h_.vset();
}
template <typename S>
template <typename V>
inline
std::ostream& operator<<(std::ostream& ostr, const histo<S>& h)
std::ostream& operator<<(std::ostream& ostr, const histo<V>& h)
{
mln_viter(S) v(h.vset());
mln_viter(V) v(h.vset());
for_all(v)
if (h(v) != 0)
ostr << v << ':' << h(v) << ' ';
......
......@@ -50,8 +50,8 @@ namespace mln
* Base class for implementation of accumulator classes.
*/
template <typename R, typename E>
class base_ : public Accumulator<E>,
public mln::internal::proxy_impl< R, E >
class base : public Accumulator<E>,
public mln::internal::proxy_impl< R, E >
{
public:
......@@ -62,7 +62,7 @@ namespace mln
typedef R result;
protected:
base_();
base();
};
......@@ -70,14 +70,14 @@ namespace mln
template <typename R, typename E>
inline
base_<R,E>::base_()
base<R,E>::base()
{
}
template <typename R, typename E>
inline
R
base_<R,E>::subj_()
base<R,E>::subj_()
{
return exact(this)->to_result();
}
......
......@@ -51,7 +51,7 @@ namespace mln
* The parameter \c T is the type of values.
*/
template <typename T>
struct max_ : public mln::accu::internal::base_< T , max_<T> >
struct max_ : public mln::accu::internal::base< T , max_<T> >
{
typedef T argument;
typedef T result;
......
......@@ -45,33 +45,32 @@ namespace mln
/*! \brief Generic max function based on histogram over a value set with
* type \c S.
* type \c V.
*/
template <typename S>
struct max_h : public mln::accu::internal::base_< mln_value(S) , max_h<S> >
template <typename V>
struct max_h : public mln::accu::internal::base< V, max_h<V> >
{
typedef mln_value(S) argument;
typedef V argument;
typedef argument result;
max_h(const Value_Set<S>& s);
max_h();
void init();
void take(const argument& t);
void take_as_init(const argument& t);
void take(const max_h<S>& other);
void take(const max_h<V>& other);
void untake(const argument& t);
unsigned card() const { return h_.sum(); }
argument to_result() const;
const accu::histo<S>& histo() const;
const accu::histo<V>& histo() const;
protected:
mutable accu::histo<S> h_;
const S& s_; // derived from h_
mutable accu::histo<V> h_;
const value::set<V>& s_; // derived from h_
mutable std::size_t sum_;
mutable bool valid_;
......@@ -87,28 +86,19 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
template <typename S>
template <typename V>
inline
max_h<S>::max_h(const Value_Set<S>& s)
: h_(s),
s_(h_.vset())
{
init();
}
template <typename S>
inline
max_h<S>::max_h()
max_h<V>::max_h()
: h_(),
s_(h_.vset())
{
init();
}
template <typename S>
template <typename V>
inline
void
max_h<S>::take(const argument& t)
max_h<V>::take(const argument& t)
{
h_.take(t);
if (h_.sum() == 1)
......@@ -123,10 +113,10 @@ namespace mln
}
}
template <typename S>
template <typename V>
inline
void
max_h<S>::take(const max_h<S>& other)
max_h<V>::take(const max_h<V>& other)
{
// h_
h_.take(other.h_);
......@@ -136,10 +126,10 @@ namespace mln
// FIXME: Optimize.
}
template <typename S>
template <typename V>
inline
void
max_h<S>::untake(const argument& t)
max_h<V>::untake(const argument& t)
{
mln_precondition(h_(t) != 0);
h_.untake(t);
......@@ -159,10 +149,10 @@ namespace mln
valid_ = false;
}
template <typename S>
template <typename V>
inline
void
max_h<S>::update_() const
max_h<V>::update_() const
{
if (sum_ != 0)
go_plus_();
......@@ -172,10 +162,10 @@ namespace mln
valid_ = true;
}
template <typename S>
template <typename V>
inline
void
max_h<S>::go_minus_() const
max_h<V>::go_minus_() const
{
do
--i_;
......@@ -183,10 +173,10 @@ namespace mln
t_ = s_[i_];
}
template <typename S>
template <typename V>
inline
void
max_h<S>::go_plus_() const
max_h<V>::go_plus_() const
{
do
{
......@@ -197,10 +187,10 @@ namespace mln
t_ = s_[i_];
}
template <typename S>
template <typename V>
inline
void
max_h<S>::init()
max_h<V>::init()
{
h_.init();
sum_ = 0;
......@@ -209,10 +199,10 @@ namespace mln
valid_ = true;
}
template <typename S>
template <typename V>
inline
void
max_h<S>::take_as_init(const argument& t)
max_h<V>::take_as_init(const argument& t)
{
h_.take(t);
sum_ = 0;
......@@ -221,27 +211,27 @@ namespace mln
valid_ = true;
}
template <typename S>
template <typename V>
inline
typename max_h<S>::argument
max_h<S>::to_result() const
typename max_h<V>::argument
max_h<V>::to_result() const
{
if (! valid_)
update_();
return t_;
}
template <typename S>
template <typename V>
inline
const accu::histo<S>&
max_h<S>::histo() const
const accu::histo<V>&
max_h<V>::histo() const
{
return h_;
}
template <typename S>
template <typename V>
inline
std::ostream& operator<<(std::ostream& ostr, const max_h<S>& m)
std::ostream& operator<<(std::ostream& ostr, const max_h<V>& m)
{
return ostr << m.to_result();
}
......
......@@ -58,7 +58,7 @@ namespace mln
template <typename T,
typename S = mln_sum(T),
typename M = S>
struct mean_ : public mln::accu::internal::base_< M , mean_<T,S,M> >
struct mean_ : public mln::accu::internal::base< M , mean_<T,S,M> >
{
typedef T argument;
typedef M result;
......
......@@ -48,7 +48,7 @@ namespace mln
* set with type \c S.
*/
template <typename S>
struct median : public mln::accu::internal::base_< mln_value(S), median<S> >
struct median : public mln::accu::internal::base< mln_value(S), median<S> >
{ // FIXME: Should median be named 'median_' like other accumulators ?
typedef mln_value(S) argument;
typedef argument result;
......
......@@ -48,7 +48,7 @@ namespace mln
* value set with type \c S.
*/
template <typename S>
struct median_alt : public mln::accu::internal::base_< mln_value(S), median_alt<S> >
struct median_alt : public mln::accu::internal::base< mln_value(S), median_alt<S> >
{
typedef mln_value(S) argument;
......
......@@ -51,7 +51,7 @@ namespace mln
* The parameter \c T is the type of values.
*/
template <typename T>
struct min_ : public mln::accu::internal::base_< T, min_<T> >
struct min_ : public mln::accu::internal::base< T, min_<T> >
{
typedef T argument;
typedef T result;
......
......@@ -35,6 +35,7 @@
# include <mln/accu/internal/base.hh>
# include <mln/accu/histo.hh>
# include <mln/value/set.hh>
namespace mln
......@@ -45,38 +46,37 @@ namespace mln
/*! \brief Generic min function based on histogram over a value
* set with type \c S.
* set with type \c V.
*/
template <typename S>
struct min_h : public mln::accu::internal::base_< mln_value(S) , min_h<S> >
template <typename V>
struct min_h : public mln::accu::internal::base< V , min_h<V> >
{
typedef mln_value(S) argument;
typedef V argument;
typedef argument result;