Commit 8b9996bc authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Make value::set works for any type.

	* mln/value/set.hh: Rename as...
	* mln/value/internal/iterable_set.hh: ...this.
	(the): Remove.
	(E): New.
	* mln/value/set.hh: New.

	* tests/vset.cc,
	* tests/histo.cc,
	* TODO,
	* mln/core/macros.hh,
	* mln/core/trait/is_lowq.hh,
	* mln/core/fimage.hh,
	* mln/core/image2d_b.hh,
	* mln/level/naive/median.hh,
	* mln/level/was.median.hh,
	* mln/level/fast_median.hh,
	* mln/level/transform.hh,
	* mln/level/median.hh,
	* mln/accu/histo.hh,
	* mln/accu/median.hh,
	* mln/accu/median_alt.hh,
	* mln/value/props.hh,
	* mln/value/cast.hh,
	* mln/value/int_u.hh: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1036 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent dd2ed9b3
2007-07-24 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Make value::set works for any type.
* mln/value/set.hh: Rename as...
* mln/value/internal/iterable_set.hh: ...this.
(the): Remove.
(E): New.
* mln/value/set.hh: New.
* tests/vset.cc,
* tests/histo.cc,
* TODO,
* mln/core/macros.hh,
* mln/core/trait/is_lowq.hh,
* mln/core/fimage.hh,
* mln/core/image2d_b.hh,
* mln/level/naive/median.hh,
* mln/level/was.median.hh,
* mln/level/fast_median.hh,
* mln/level/transform.hh,
* mln/level/median.hh,
* mln/accu/histo.hh,
* mln/accu/median.hh,
* mln/accu/median_alt.hh,
* mln/value/props.hh,
* mln/value/cast.hh,
* mln/value/int_u.hh: Update.
2007-07-24 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Handle constness properly in pixel iterators.
......
......@@ -18,7 +18,6 @@ Weighted_Window
value::proxy to dispatch read/write + the corresponding image type
a mean_value object { sum; count } and operator+
t_image to "transpose" the 0 and the i-th coordinates
image defined by f/pset
** extensions
......@@ -35,7 +34,6 @@ mlc into metal
* clean-up
accu::histo and median: remove inheritance
select_function in fun::internal::selector_p2? etc.
......
......@@ -51,9 +51,10 @@ namespace mln
/*! Generic histogram class over a value set with type \c S.
*/
template <typename S>
struct histo_on_set : public Accumulator< histo_on_set<S> >
struct histo : public Accumulator< histo<S> >
{
histo_on_set(const Value_Set<S>& s);
histo(const Value_Set<S>& s);
histo();
typedef mln_value(S) value;
......@@ -79,41 +80,32 @@ namespace mln
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h);
/*! Generic histogram class over the set of values of type \c T.
*
* \todo Inheritance is badly formed since this concrete class
* derives from another concrete class.
*/
template <typename T>
struct histo_on_type : public histo_on_set< value::set_<T> >
{
histo_on_type();
};
std::ostream& operator<<(std::ostream& ostr, const histo<S>& h);
# ifndef MLN_INCLUDE_ONLY
// histo_on_set<S>
template <typename S>
histo_on_set<S>::histo_on_set(const Value_Set<S>& s)
histo<S>::histo(const Value_Set<S>& s)
: s_(exact(s)),
h_(exact(s).nvalues(), 0),
h_(s_.nvalues(), 0),
sum_(0)
{
}
template <typename S>
histo<S>::histo()
: s_(S::the()),
h_(s_.nvalues(), 0),
sum_(0)
{
}
template <typename S>
void
histo_on_set<S>::take(const value& v)
histo<S>::take(const value& v)
{
++h_[s_.index_of(v)];
++sum_;
......@@ -121,7 +113,7 @@ namespace mln
template <typename S>
void
histo_on_set<S>::untake(const value& v)
histo<S>::untake(const value& v)
{
mln_precondition(h_[s_.index_of(v)] > 0);
mln_precondition(sum_ > 0);
......@@ -131,7 +123,7 @@ namespace mln
template <typename S>
void
histo_on_set<S>::init()
histo<S>::init()
{
std::fill(h_.begin(), h_.end(), 0);
sum_ = 0;
......@@ -139,14 +131,14 @@ namespace mln
template <typename S>
std::size_t
histo_on_set<S>::operator()(const value& v) const
histo<S>::operator()(const value& v) const
{
return h_[s_.index_of(v)];
}
template <typename S>
std::size_t
histo_on_set<S>::operator[](std::size_t i) const
histo<S>::operator[](std::size_t i) const
{
mln_precondition(i < s_.nvalues());
return h_[i];
......@@ -154,54 +146,42 @@ namespace mln
template <typename S>
std::size_t
histo_on_set<S>::nvalues() const
histo<S>::nvalues() const
{
return s_.nvalues();
}
template <typename S>
std::size_t
histo_on_set<S>::sum() const
histo<S>::sum() const
{
return sum_;
}
template <typename S>
const std::vector<std::size_t>&
histo_on_set<S>::vec() const
histo<S>::vec() const
{
return h_;
}
template <typename S>
const S&
histo_on_set<S>::vset() const
histo<S>::vset() const
{
return s_;
}
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const histo_on_set<S>& h)
std::ostream& operator<<(std::ostream& ostr, const histo<S>& h)
{
mln_viter(S) v(h.vset());
for_all(v)
if (h(v) != 0)
ostr << v << ':' << h(v) << ' ';
ostr << std::endl;
return ostr;
}
// histo_on_type<T>
template <typename T>
histo_on_type<T>::histo_on_type()
: histo_on_set< value::set_<T> >(value::set_<T>::the())
{
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
......
......@@ -53,6 +53,7 @@ namespace mln
typedef mln_value(S) value;
median(const Value_Set<S>& s);
median();
void take(const value& v);
void untake(const value& v);
......@@ -63,20 +64,11 @@ namespace mln
operator mln_value(S) () const;
value to_value() const;
const histo_on_set<S>& histo() const;
// FIXME: remove
void debug__() const
{
std::cout << " i = " << i_
<< " v = " << v_
<< " s = " << sum_minus_ << " ; " << h_[i_] << " ; " << sum_plus_ << " = " << h_.sum()
<< std::endl;
}
const accu::histo<S>& histo() const;
protected:
mutable histo_on_set<S> h_;
mutable accu::histo<S> h_;
const S& s_; // derived from h_
mutable std::size_t sum_minus_, sum_plus_;
......@@ -92,24 +84,8 @@ namespace mln
};
/*! Generic median class over the set of values of type \c T.
*
* \todo Inheritance is badly formed since this concrete class
* derives from another concrete class.
*/
template <typename T>
struct median_on : public median< value::set_<T> >
{
median_on()
: median< value::set_<T> >(value::set_<T>::the())
{
}
};
# ifndef MLN_INCLUDE_ONLY
template <typename S>
median<S>::median(const Value_Set<S>& s)
: h_(s),
......@@ -118,6 +94,13 @@ namespace mln
init();
}
template <typename S>
median<S>::median()
: h_(),
s_(h_.vset())
{
init();
}
template <typename S>
void
......@@ -134,7 +117,6 @@ namespace mln
valid_ = false;
}
template <typename S>
void
median<S>::untake(const value& v)
......@@ -150,7 +132,6 @@ namespace mln
if (valid_)
valid_ = false;
}
template <typename S>
void
......@@ -177,7 +158,6 @@ namespace mln
}
}
template <typename S>
void
median<S>::go_minus_() const
......@@ -194,7 +174,6 @@ namespace mln
v_ = s_[i_];
}
template <typename S>
void
median<S>::go_plus_() const
......@@ -211,7 +190,6 @@ namespace mln
v_ = s_[i_];
}
template <typename S>
void
median<S>::init()
......@@ -224,7 +202,6 @@ namespace mln
valid_ = true;
}
template <typename S>
median<S>::operator mln_value(S) () const
{
......@@ -241,7 +218,7 @@ namespace mln
}
template <typename S>
const histo_on_set<S>&
const accu::histo<S>&
median<S>::histo() const
{
return h_;
......@@ -250,11 +227,9 @@ namespace mln
template <typename S>
std::ostream& operator<<(std::ostream& ostr, const median<S>& m)
{
m.debug__();
return ostr << m.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
......
......@@ -86,10 +86,10 @@ namespace mln
template <typename T>
struct median_alt_on : public median_alt< value::set_<T> >
struct median_alt_on : public median_alt< value::set<T> >
{
median_alt_on()
: median_alt< value::set_<T> >(value::set_<T>::the())
: median_alt< value::set<T> >(value::set<T>::the())
{
}
};
......
......@@ -63,7 +63,7 @@ namespace mln
typedef void lvalue; // FIXME
/// Value set associated type.
typedef mln::value::set_<mln_result(F)> vset;
typedef mln::value::set<mln_result(F)> vset;
/// Constructor.
......@@ -156,7 +156,7 @@ namespace mln
}
template <typename F, typename S>
const mln::value::set_<mln_result(F)>&
const mln::value::set<mln_result(F)>&
fimage<F,S>::values() const
{
return vset::the();
......
......@@ -119,7 +119,7 @@ namespace mln
};
/// Value_Set associated type.
typedef mln::value::set_<T> vset;
typedef mln::value::set<T> vset;
/// Constructor without argument.
......
......@@ -149,7 +149,10 @@
# define mln_value(T) typename T::value
/// Shortcut to the kind of values for an image with type \c I.
# define mln_value_kind(T) typename mln::value::props< mln_value(I) >::kind
# define mln_value_kind(I) typename mln::value::props< mln_value(I) >::kind
/// Shortcut to test if the values of an image with type \c I are lowly quantifized.
# define mln_is_value_lowq(I) typename mln::trait::is_lowq< mln_value(I) >::ret
/// Shortcut to access the type of value set (vset) associated to T.
# define mln_vset(T) typename T::vset
......
......@@ -37,7 +37,7 @@
# include <mln/value/props.hh>
# define mln_is_lowq(I) typename mln::trait::is_lowq< I >::ret
# define mln_is_lowq(T) typename mln::trait::is_lowq< T >::ret
......@@ -50,10 +50,10 @@ namespace mln
// FIXME: Doc!
template <typename I>
template <typename T>
struct is_lowq
{
typedef typename metal::bool_<( mln_card(mln_value(I)) != 0 )>::type ret;
typedef typename metal::bool_<( mln_card(T) != 0 )>::type ret;
};
......
......@@ -84,7 +84,7 @@ namespace mln
win_bot = win - (win + up),
win_top = (win + up) - win;
accu::median_on<mln_value(I)> med;
accu::median<mln_vset(I)> med(input.values());
// initialization
......
......@@ -80,10 +80,10 @@ namespace mln
// aux data
accu::median<mln_vset(I)> med;
mln_point(I) p;
window2d win_fp, win_fm, win_bp, win_bm, win_dp, win_dm;
mln_qiter(W) q_fp, q_fm, q_bp, q_bm, q_dp, q_dm;
accu::median_on<mln_value(I)> med;
// ctor
......@@ -94,6 +94,7 @@ namespace mln
win(exact(win_)),
output(exact(output_)),
// aux data
med(input.values()),
p(),
win_fp(win - (win + left)), win_fm((win + left) - win),
win_bp(win - (win + right)), win_bm((win + right) - win),
......@@ -171,7 +172,7 @@ namespace mln
coord& row = p.row();
coord& col = p.col();
accu::median_on<mln_value(I)> med;
accu::median<mln_vset(I)> med(input.values());
for (row = input.min_row(); row <= max_row; ++row)
{
......
......@@ -78,7 +78,7 @@ namespace mln
{
mln_piter(I) p(input.domain());
mln_qiter(W) q(win, p);
accu::median_on<mln_value(I)> med;
accu::median<mln_vset(I)> med(input.values());
for_all(p)
{
......
......@@ -120,7 +120,7 @@ namespace mln
void transform(const Image<I>& input, const Function_v2v<F>& f, Image<O>& output)
{
mln_precondition(exact(output).domain() >= exact(input).domain());
impl::transform(mln_is_lowq(I)(),
impl::transform(mln_is_value_lowq(I)(),
exact(input), exact(f), exact(output));
}
......
......@@ -72,7 +72,7 @@ namespace mln
q_bp(win_bkd_plus, p), q_bm(win_bkd_minus, p),
q_top(win_top, p), q_bot(win_bot, p);
accu::median_on<mln_value(I)> med;
accu::median<mln_vset(I)> med(input.values());
// initialization
......@@ -146,7 +146,7 @@ namespace mln
int& row = p.row();
int& col = p.col();
accu::median_on<mln_value(I)> med;
accu::median<mln_vset(I)> med(input.values());
for (row = input.min_row(); row <= max_row; ++row)
{
......
......@@ -47,7 +47,7 @@ namespace mln
*
*/
template <typename T, typename I>
struct cast_image : public internal::image_base_< mln_pset(I), cast_image<T,I> >
struct cast_image : public mln::internal::image_base_< mln_pset(I), cast_image<T,I> >
{
/// Point_Site associated type.
typedef mln_psite(I) psite;
......@@ -65,7 +65,7 @@ namespace mln
typedef void lvalue; // FIXME
/// Value set associated type.
typedef mln::value::set_<T> vset;
typedef mln::value::set<T> vset;
/// Constructor.
......@@ -159,7 +159,7 @@ namespace mln
}
template <typename T, typename I>
const mln::value::set_<T>&
const mln::value::set<T>&
cast_image<T,I>::values() const
{
return vset::the();
......
......@@ -33,10 +33,10 @@
* \brief Define a generic class for unsigned integers.
*/
# include <mln/core/concept/value.hh>
# include <mln/metal/math.hh>
# include <mln/value/internal/value_like.hh>
# include <mln/value/props.hh>
# include <mln/value/set.hh>
namespace mln
......@@ -89,15 +89,11 @@ namespace mln
};
// Fwd decl.
template <typename T> struct vset_;
/// Alias for unsigned 8bit integers.
typedef int_u_<8> int_u8;
/// Alias for the set of unsigned 8bit integers.
typedef vset_<int_u8> int_u8_set;
typedef set<int_u8> int_u8_set;
......
// 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_VALUE_INTERNAL_ITERABLE_SET_HH
# define MLN_VALUE_INTERNAL_ITERABLE_SET_HH
/*! \file mln/value/internal/iterable_set.hh
*
* \brief Define the iterable value set derived from a type.
*/
# include <mln/core/concept/value_set.hh>
# include <mln/value/props.hh>
namespace mln
{
namespace value
{
// Fwd decls.
template <typename S> struct fwd_viter_;
template <typename S> struct bkd_viter_;
namespace internal
{
/*! Class that defines the set of values of type \c T.
*
* This is the exhaustive iterable_set of values obtainable from type \c T.
*/
template <typename T, typename E>
struct iterable_set : public Value_Set<E>
{
/// Value associated type.
typedef T value;
/// Forward Value_Iterator associated type.
typedef fwd_viter_<E> fwd_viter;
/// Backward Value_Iterator associated type.
typedef bkd_viter_<E> bkd_viter;
/// Test if \p v belongs to this iterable_set: always true!
bool has(const T& v) const;
/// Give the \p i-th value.
T operator[](std::size_t i) const;