olena-2.0-112-g4bae71d Refine util::level operators.

* mln/util/level.hh: Add comparison operators with images. * tests/util/level.cc: New tests. --- milena/ChangeLog | 8 ++++ milena/mln/util/level.hh | 79 ++++++++++++++++++++++++++------------------ milena/tests/util/level.cc | 63 ++++++++++++++++++++++++++++++----- 3 files changed, 109 insertions(+), 41 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index fd1f830..b248164 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,11 @@ +2012-10-19 Guillaume Lazzara <z@lrde.epita.fr> + + Refine util::level operators. + + * mln/util/level.hh: Add comparison operators with images. + + * tests/util/level.cc: New tests. + 2012-10-18 Guillaume Lazzara <z@lrde.epita.fr> Let the user specify conversion functions in K2 immersion. diff --git a/milena/mln/util/level.hh b/milena/mln/util/level.hh index ea7f3f3..3aa6fa0 100644 --- a/milena/mln/util/level.hh +++ b/milena/mln/util/level.hh @@ -28,6 +28,12 @@ # include <mln/core/concept/value.hh> # include <mln/value/scalar.hh> +# include <mln/data/transform.hh> +# include <mln/fun/v2b/threshold_lt.hh> +# include <mln/fun/v2b/threshold_le.hh> +# include <mln/fun/v2b/threshold_gt.hh> +# include <mln/fun/v2b/threshold_ge.hh> +# include <mln/fun/v2b/compare.hh> /// \file /// @@ -55,21 +61,22 @@ namespace mln // Comparison Operators - template <typename T, typename U> - bool - operator<(const Object<T>& i, const level_t<U>& v); + template <typename I, typename U> + mln_ch_value(I,bool) + operator<(const Image<I>& ima, const level_t<U>& v); - template <typename T, typename U> - bool - operator<(const level_t<U>& v, const Object<T>& i); + template <typename I, typename U> + mln_ch_value(I,bool) + operator==(const Image<I>& ima, const level_t<U>& v); - template <typename T, typename U> - bool - operator==(const Object<T>& i, const level_t<U>& v); - template <typename T, typename U> - bool - operator==(const level_t<U>& v, const Object<T>& i); + template <typename I, typename U> + mln_ch_value(I,bool) + operator>(const Image<I>& ima, const level_t<U>& v); + + template <typename I, typename U> + mln_ch_value(I,bool) + operator>=(const Image<I>& ima, const level_t<U>& v); # ifndef MLN_INCLUDE_ONLY @@ -80,6 +87,8 @@ namespace mln { } + // Helpers + template <typename T> inline level_t<T> level(const T& value) @@ -87,36 +96,42 @@ namespace mln return level_t<T>(value); } - template <typename T, typename U> - inline - bool - operator<(const Object<T>& i, const level_t<U>& v) + + // Operators + + template <typename I, typename U> + mln_ch_value(I,bool) + operator<(const Image<I>& ima, const level_t<U>& v) { - return exact(i) < v.value; + return data::transform(ima, fun::v2b::threshold_lt<mln_value(I)>(v.value)); } - template <typename T, typename U> - inline - bool - operator<(const level_t<U>& v, const Object<T>& i) + template <typename I, typename U> + mln_ch_value(I,bool) + operator<=(const Image<I>& ima, const level_t<U>& v) { - return v.value < exact(i); + return data::transform(ima, fun::v2b::threshold_le<mln_value(I)>(v.value)); } - template <typename T, typename U> - inline - bool - operator==(const Object<T>& i, const level_t<U>& v) + template <typename I, typename U> + mln_ch_value(I,bool) + operator>(const Image<I>& ima, const level_t<U>& v) { - return exact(i) == v.value; + return data::transform(ima, fun::v2b::threshold_gt<mln_value(I)>(v.value)); } - template <typename T, typename U> - inline - bool - operator==(const level_t<U>& v, const Object<T>& i) + template <typename I, typename U> + mln_ch_value(I,bool) + operator>=(const Image<I>& ima, const level_t<U>& v) + { + return data::transform(ima, fun::v2b::threshold_ge<mln_value(I)>(v.value)); + } + + template <typename I, typename U> + mln_ch_value(I,bool) + operator==(const Image<I>& ima, const level_t<U>& v) { - return v.value == exact(i); + return data::transform(ima, fun::v2b::compare<mln_value(I)>(v.value)); } # endif // ! MLN_INCLUDE_ONLY diff --git a/milena/tests/util/level.cc b/milena/tests/util/level.cc index 3f0c8bf..3626cef 100644 --- a/milena/tests/util/level.cc +++ b/milena/tests/util/level.cc @@ -23,20 +23,65 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. +#include <mln/core/image/image2d.hh> +#include <mln/debug/iota.hh> #include <mln/util/level.hh> -#include <mln/value/int_u8.hh> +#include <mln/data/compare.hh> +#include <mln/make/image2d.hh> int main () { using namespace mln; - util::level_t<int> l(3); - mln_assertion(2 < l); - mln_assertion(l > 2); - mln_assertion(l == 3); + bool vref_lt[] = { + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 + }; + image2d<bool> ref_lt = make::image2d(vref_lt); - value::int_u8 v = 4; - mln_assertion(!(v < l)); - mln_assertion(v > l); - mln_assertion(!(v == l)); + bool vref_le[] = { + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0 + }; + image2d<bool> ref_le = make::image2d(vref_le); + + bool vref_gt[] = { + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + }; + image2d<bool> ref_gt = make::image2d(vref_gt); + + bool vref_ge[] = { + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + }; + image2d<bool> ref_ge = make::image2d(vref_ge); + + + image2d<unsigned> ima(5,5); + debug::iota(ima); + + image2d<bool> imab_lt = (ima < util::level(15)); + mln_assertion(imab_lt == ref_lt); + + image2d<bool> imab_le = (ima <= util::level(15)); + mln_assertion(imab_le == ref_le); + + image2d<bool> imab_gt = (ima > util::level(15)); + mln_assertion(imab_gt == ref_gt); + + image2d<bool> imab_ge = (ima >= util::level(15)); + mln_assertion(imab_ge == ref_ge); } -- 1.7.2.5
participants (1)
-
Guillaume Lazzara