Commit d8609516 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Fix various accumulators things.

	Have transform_line fastest.
	
	* milena/mln/accu/transform_line.hh: Add documentation.
	(todo): Remove, done:
	The specialization for fastest images is now up.
	(todo): New.  A version that ignores extensions should
	exist; see commented code in this present file.
	(impl::generic::transform_line): Add extension adjust for
	safety reason.
	Layout.
	(impl::generic::transform_line_fastest): Activate.
	Fix bug.
	(transform_line_dispatch): Revamp to take into account
	accumulator properties.
	(transform_line): Call properly the dispatch mechanism.
	* milena/tests/accu/transform_line.cc: Test both generic and
	fastest versions.

	Fix missing properties for some accumulators.

	* milena/mln/accu/stat/min.hh,
	* milena/mln/accu/stat/max.hh (set_value): New method.
	* milena/mln/accu/stat/max_h.hh (invariant_): New method.
	(max_h): Add calls to invariant_.
	(debug_print_): Augment.
	* milena/mln/accu/math/count.hh,
	* milena/mln/accu/logic/lor.hh,
	* milena/mln/accu/logic/lor_basic.hh,
	* milena/mln/accu/logic/land.hh,
	* milena/mln/accu/logic/land_basic.hh,
	* milena/mln/accu/stat/min.hh,
	* milena/mln/accu/stat/max.hh,
	* milena/mln/accu/stat/min_h.hh,
	* milena/mln/accu/stat/max_h.hh (trait): Add missing traits.

	Misc.

	* milena/mln/morpho/general.spe.hh: Fix layout.
	Remove useless includes.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4352 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 8a14cf76
2009-08-15 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Fix various accumulators things.
Have transform_line fastest.
* milena/mln/accu/transform_line.hh: Add documentation.
(todo): Remove, done:
The specialization for fastest images is now up.
(todo): New. A version that ignores extensions should
exist; see commented code in this present file.
(impl::generic::transform_line): Add extension adjust for
safety reason.
Layout.
(impl::generic::transform_line_fastest): Activate.
Fix bug.
(transform_line_dispatch): Revamp to take into account
accumulator properties.
(transform_line): Call properly the dispatch mechanism.
* milena/tests/accu/transform_line.cc: Test both generic and
fastest versions.
Fix missing properties for some accumulators.
* milena/mln/accu/stat/min.hh,
* milena/mln/accu/stat/max.hh (set_value): New method.
* milena/mln/accu/stat/max_h.hh (invariant_): New method.
(max_h): Add calls to invariant_.
(debug_print_): Augment.
* milena/mln/accu/math/count.hh,
* milena/mln/accu/logic/lor.hh,
* milena/mln/accu/logic/lor_basic.hh,
* milena/mln/accu/logic/land.hh,
* milena/mln/accu/logic/land_basic.hh,
* milena/mln/accu/stat/min.hh,
* milena/mln/accu/stat/max.hh,
* milena/mln/accu/stat/min_h.hh,
* milena/mln/accu/stat/max_h.hh (trait): Add missing traits.
Misc.
* milena/mln/morpho/general.spe.hh: Fix layout.
Remove useless includes.
2009-07-24 Guillaume Lazzara <lazzara@lrde.epita.fr>
* configure.ac: Look for tesseract during configure.
......
......@@ -39,14 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace logic {
struct land;
}
}
// Traits.
namespace trait
{
namespace logic
template <>
struct accumulator_< accu::logic::land >
{
// Forward declaration.
struct land;
}
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace accu
{
namespace meta
{
......@@ -66,6 +85,7 @@ namespace mln
} // end of namespace mln::accu::meta::logic
} // end of namespace mln::accu::meta
namespace logic
{
......
......@@ -39,14 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace logic {
struct land_basic;
}
}
// Traits.
namespace trait
{
namespace logic
template <>
struct accumulator_< accu::logic::land_basic >
{
// Forward declaration.
struct land_basic;
}
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::yes has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace accu
{
namespace meta
{
......
......@@ -39,14 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace logic {
struct lor;
}
}
// Traits.
namespace trait
{
namespace logic
template <>
struct accumulator_< accu::logic::lor >
{
// Forward declaration.
struct lor;
}
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace accu
{
namespace meta
{
......
......@@ -39,14 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace logic {
struct lor_basic;
}
}
// Traits.
namespace trait
{
namespace logic
template <>
struct accumulator_< accu::logic::lor_basic >
{
// Forward declaration.
struct lor_basic;
}
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::yes has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
} // end of namespace mln::trait
namespace accu
{
namespace meta
{
......
......@@ -29,6 +29,8 @@
/// \file
///
/// Define an accumulator that counts.
///
/// \todo Add an optional parameter to set the type of the counter.
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
......@@ -37,18 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace math {
template <typename T> struct count;
}
}
// Traits.
namespace trait
{
namespace math
template <typename T>
struct accumulator_< accu::math::count<T> >
{
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::yes has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_none when_pix;
};
// Forward declaration.
template <typename T>
struct count;
} // end of namespace mln::trait
} // end of namespace mln::accu::math
namespace accu
{
namespace meta
{
......@@ -70,26 +87,6 @@ namespace mln
} // end of namespace mln::accu::meta
} // end of namespace mln::accu
// Traits.
namespace trait
{
template <typename T>
struct accumulator_< accu::math::count<T> >
{
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::yes has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_pix when_pix;
};
} // end of namespace mln::trait
namespace accu
{
namespace math
{
......@@ -132,9 +129,8 @@ namespace mln
};
# ifndef MLN_INCLUDE_ONLY
# ifndef MLN_INCLUDE_ONLY
template <typename T>
inline
......
......@@ -39,18 +39,34 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace stat {
template <typename T> struct max;
}
}
// Traits.
namespace trait
{
namespace stat
template <typename T>
struct accumulator_< accu::stat::max<T> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::yes has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
// Forward declaration.
template <typename T>
struct max;
} // end of namespace mln::trait
} // end of namespace mln::accu::stat
namespace accu
{
namespace meta
{
......@@ -96,6 +112,9 @@ namespace mln
void take(const max<T>& other);
/// \}
/// Force the value of the min to \a t.
void set_value(const T& t);
/// Get the value of the accumulator.
const T& to_result() const;
......@@ -111,6 +130,7 @@ namespace mln
template <typename I> struct max< util::pix<I> >;
# ifndef MLN_INCLUDE_ONLY
template <typename T>
......@@ -154,6 +174,14 @@ namespace mln
t_ = other.t_;
}
template <typename T>
inline
void
max<T>::set_value(const T& t)
{
t_ = t;
}
template <typename T>
inline
const T&
......
......@@ -39,17 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace stat {
template <typename V> struct max_h;
}
}
// Traits.
namespace trait
{
namespace stat
template <typename V>
struct accumulator_< accu::stat::max_h<V> >
{
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
// Forward declaration.
template <typename V>
struct max_h;
} // end of namespace mln::trait
} // end of namespace mln::accu::stat
namespace accu
{
namespace meta
{
......@@ -114,15 +130,22 @@ namespace mln
mutable accu::histo<V> h_;
const value::set<V>& s_; // derived from h_
mutable unsigned sum_;
mutable bool valid_;
mutable unsigned i_; // the max index
mutable argument t_; // the max argument
mutable unsigned sum_; // number of taken values > t_
mutable unsigned i_; // the current max index ('current' means 'last known')
mutable argument t_; // the current max argument
mutable bool valid_; // validity of the current indent / argument
// when valid_ is false, an update of i_ and t_ is required
// Dev note: we can have at the same time (sum_ == 0) and
// (valid_ == false) because of the 'untake' method.
// Auxiliary methods
void update_() const;
void go_minus_() const;
void go_plus_() const;
void invariant_() const;
};
......@@ -130,6 +153,15 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
template <typename V>
inline
void
max_h<V>::invariant_() const
{
// valid_ => (sum_ == 0)
mln_invariant(! valid_ || (sum_ == 0));
}
template <typename V>
inline
max_h<V>::max_h()
......@@ -137,6 +169,7 @@ namespace mln
s_(h_.vset())
{
init();
invariant_();
}
template <typename V>
......@@ -155,6 +188,7 @@ namespace mln
++sum_;
valid_ = false;
}
invariant_();
}
template <typename V>
......@@ -166,8 +200,10 @@ namespace mln
h_.take(other.h_);
for (unsigned i = this->card() - 1; i > i_; --i)
sum_ += other.h_[i];
valid_ = false;
if (valid_ && sum_ != 0)
valid_ = false;
// FIXME: Optimize.
invariant_();
}
template <typename V>
......@@ -191,6 +227,7 @@ namespace mln
else
if (t == t_ && h_[i_] == 0)
valid_ = false;
invariant_();
}
template <typename V>
......@@ -204,6 +241,11 @@ namespace mln
if (h_[i_] == 0)
go_minus_();
valid_ = true;
mln_postcondition(sum_ == 0);
mln_postcondition(h_[i_] != 0);
for (unsigned j = i_ + 1; j < h_.nvalues(); ++j)
mln_postcondition(h_[j] == 0);
}
template <typename V>
......@@ -263,6 +305,7 @@ namespace mln
{
if (! valid_)
update_();
invariant_();
return t_;
}
......@@ -287,7 +330,7 @@ namespace mln
void
max_h<V>::debug_print_() const
{
std::cout << "h={" << h_ << "} ";
std::cout << "h={" << h_ << "} h.sum = " << h_.sum() << ' ';
std::cout << "sum=" << sum_ << ' '
<< "valid=" << valid_ << ' '
<< "i=" << i_ << ' '
......
......@@ -39,17 +39,34 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace stat {
template <typename T> struct min;
}
}
// Traits.
namespace trait
{
namespace stat
template <typename T>
struct accumulator_< accu::stat::min<T> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::yes has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
// Forward declaration.
template <typename T>
struct min;
} // end of namespace mln::trait
} // end of namespace mln::accu::stat
namespace accu
{
namespace meta
{
......@@ -96,6 +113,9 @@ namespace mln
void take(const min<T>& other);
/// \}
/// Force the value of the min to \a t.
void set_value(const T& t);
/// Get the value of the accumulator.
const T& to_result() const;
......@@ -153,6 +173,14 @@ namespace mln
t_ = other.t_;
}
template <typename T>
inline
void
min<T>::set_value(const T& t)
{
t_ = t;
}
template <typename T>
inline
const T&
......
......@@ -39,17 +39,33 @@
namespace mln
{
namespace accu
// Forward declaration.
namespace accu {
namespace stat {
template <typename V> struct min_h;
}
}
// Traits.
namespace trait
{
namespace stat
template <typename V>
struct accumulator_< accu::stat::min_h<V> >
{
typedef accumulator::has_untake::yes has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_v when_pix;
};
// Forward declaration.
template <typename V>
struct min_h;
} // end of namespace mln::trait
} // end of namespace mln::accu::stat
namespace accu
{
namespace meta
{
......
......@@ -31,17 +31,20 @@
///
/// Run an accumulator over a line (in a particular direction).
///
/// This operator takes into account a possible domain extension so
/// the user has to adjust and set the extension before calling
/// accu::transform_line.
///
/// \todo Import code from sandox/geraud/browsing/fwd.cc to handle the
/// case of no-domain-extension.
///
/// \todo Specialize for fastest images.
/// \todo Make a particular version that ignores any domain extension.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/meta_accumulator.hh>
# include <mln/extension/adjust.hh>