* mln/fun/v2b/compare.hh,
* mln/fun/v2b/threshold_ge.hh,
* mln/fun/v2b/threshold_gt.hh,
* mln/fun/v2b/threshold_le.hh,
* mln/fun/v2b/threshold_lt.hh: Generalize these functors.
* mln/world/kn/level.hh: Do not pass the equivalent value to the
functor.
* tests/world/kn/level.cc: Fix test using intervals instead of
int.
---
milena/ChangeLog | 16 ++++++++++++++++
milena/mln/fun/v2b/compare.hh | 17 +++++++++--------
milena/mln/fun/v2b/threshold_ge.hh | 22 +++++++++++-----------
milena/mln/fun/v2b/threshold_gt.hh | 20 +++++++++++---------
milena/mln/fun/v2b/threshold_le.hh | 21 ++++++++++-----------
milena/mln/fun/v2b/threshold_lt.hh | 17 +++++++++--------
milena/mln/world/kn/level.hh | 15 ++++++++++-----
milena/tests/world/kn/level.cc | 9 ++++++---
8 files changed, 82 insertions(+), 55 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index dcfadaf..04ceae2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,21 @@
2012-10-29 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Fix level comparisons.
+
+ * mln/fun/v2b/compare.hh,
+ * mln/fun/v2b/threshold_ge.hh,
+ * mln/fun/v2b/threshold_gt.hh,
+ * mln/fun/v2b/threshold_le.hh,
+ * mln/fun/v2b/threshold_lt.hh: Generalize these functors.
+
+ * mln/world/kn/level.hh: Do not pass the equivalent value to the
+ functor.
+
+ * tests/world/kn/level.cc: Fix test using intervals instead of
+ int.
+
+2012-10-29 Guillaume Lazzara <z(a)lrde.epita.fr>
+
More safe cast overloads.
* mln/world/kn/safe_cast.hh: New overloads.
diff --git a/milena/mln/fun/v2b/compare.hh b/milena/mln/fun/v2b/compare.hh
index 22f5d88..de17eb6 100644
--- a/milena/mln/fun/v2b/compare.hh
+++ b/milena/mln/fun/v2b/compare.hh
@@ -44,30 +44,31 @@ namespace mln
/// Comparison function.
/// f(v) = (v == ref).
- template <typename V>
- struct compare : public Function_v2b< compare<V> >
+ template <typename V, typename T = V>
+ struct compare : public Function_v2b< compare<V,T> >
{
typedef bool result;
+ compare(const T& a);
+
bool operator()(const V& v) const;
- compare(const V& a);
- V a;
+ T a;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
+ template <typename V, typename T>
inline
- compare<V>::compare(const V& a)
+ compare<V,T>::compare(const T& a)
: a(a)
{
}
- template <typename V>
+ template <typename V, typename T>
inline
bool
- compare<V>::operator()(const V& v) const
+ compare<V,T>::operator()(const V& v) const
{
return v == a;
}
diff --git a/milena/mln/fun/v2b/threshold_ge.hh b/milena/mln/fun/v2b/threshold_ge.hh
index c5fef9e..7820d44 100644
--- a/milena/mln/fun/v2b/threshold_ge.hh
+++ b/milena/mln/fun/v2b/threshold_ge.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009, 2011 EPITA Research and Development
+// Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -45,30 +45,30 @@ namespace mln
/// Threshold function.
/// f(v) = (v >= threshold).
- template <typename V>
- struct threshold_ge : public Function_v2b< threshold_ge<V> >
+ template <typename V, typename T = V>
+ struct threshold_ge : public Function_v2b< threshold_ge<V,T> >
{
typedef bool result;
+
+ threshold_ge(const T& a);
+
bool operator()(const V& v) const;
- threshold_ge(const V& a);
- V a;
+ T a;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
- inline
- threshold_ge<V>::threshold_ge(const V& a)
+ template <typename V, typename T>
+ threshold_ge<V,T>::threshold_ge(const T& a)
: a(a)
{
}
- template <typename V>
- inline
+ template <typename V, typename T>
bool
- threshold_ge<V>::operator()(const V& v) const
+ threshold_ge<V,T>::operator()(const V& v) const
{
// Here the test seems to be inversed compared to the usual
// use. Indeed, we want to preserve the following convention:
diff --git a/milena/mln/fun/v2b/threshold_gt.hh b/milena/mln/fun/v2b/threshold_gt.hh
index 05edd97..a5744e0 100644
--- a/milena/mln/fun/v2b/threshold_gt.hh
+++ b/milena/mln/fun/v2b/threshold_gt.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009, 2011 EPITA Research and Development
+// Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -45,30 +45,32 @@ namespace mln
/// Threshold function.
/// f(v) = (v > threshold).
- template <typename V>
- struct threshold_gt : public Function_v2b< threshold_gt<V> >
+ template <typename V, typename T = V>
+ struct threshold_gt : public Function_v2b< threshold_gt<V,T> >
{
typedef bool result;
+
+ threshold_gt(const T& a);
+
bool operator()(const V& v) const;
- threshold_gt(const V& a);
- V a;
+ T a;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
+ template <typename V, typename T>
inline
- threshold_gt<V>::threshold_gt(const V& a)
+ threshold_gt<V,T>::threshold_gt(const T& a)
: a(a)
{
}
- template <typename V>
+ template <typename V, typename T>
inline
bool
- threshold_gt<V>::operator()(const V& v) const
+ threshold_gt<V,T>::operator()(const V& v) const
{
// Here the test seems to be inversed compared to the usual
// use. Indeed, we want to preserve the following convention:
diff --git a/milena/mln/fun/v2b/threshold_le.hh b/milena/mln/fun/v2b/threshold_le.hh
index 21964c8..698d2be 100644
--- a/milena/mln/fun/v2b/threshold_le.hh
+++ b/milena/mln/fun/v2b/threshold_le.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009, 2011 EPITA Research and Development
+// Copyright (C) 2008, 2009, 2011, 2012 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
@@ -45,30 +45,29 @@ namespace mln
/// Threshold function.
/// f(v) = (v <= threshold).
- template <typename V>
- struct threshold_le : public Function_v2b< threshold_le<V> >
+ template <typename V, typename T = V>
+ struct threshold_le : public Function_v2b< threshold_le<V,T> >
{
typedef bool result;
+ threshold_le(const T& a);
+
bool operator()(const V& v) const;
- threshold_le(const V& a);
- V a;
+ T a;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
- inline
- threshold_le<V>::threshold_le(const V& a)
+ template <typename V, typename T>
+ threshold_le<V,T>::threshold_le(const T& a)
: a(a)
{
}
- template <typename V>
- inline
+ template <typename V, typename T>
bool
- threshold_le<V>::operator()(const V& v) const
+ threshold_le<V,T>::operator()(const V& v) const
{
// Here the test seems to be inversed compared to the usual
// use. Indeed, we want to preserve the following convention:
diff --git a/milena/mln/fun/v2b/threshold_lt.hh b/milena/mln/fun/v2b/threshold_lt.hh
index dd82305..d12ca5b 100644
--- a/milena/mln/fun/v2b/threshold_lt.hh
+++ b/milena/mln/fun/v2b/threshold_lt.hh
@@ -44,30 +44,31 @@ namespace mln
/// Threshold function.
/// f(v) = (v < threshold).
- template <typename V>
- struct threshold_lt : public Function_v2b< threshold_lt<V> >
+ template <typename V, typename T = V>
+ struct threshold_lt : public Function_v2b< threshold_lt<V,T> >
{
typedef bool result;
+ threshold_lt(const T& a);
+
bool operator()(const V& v) const;
- threshold_lt(const V& a);
- V a;
+ T a;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
+ template <typename V, typename T>
inline
- threshold_lt<V>::threshold_lt(const V& a)
+ threshold_lt<V,T>::threshold_lt(const T& a)
: a(a)
{
}
- template <typename V>
+ template <typename V, typename T>
inline
bool
- threshold_lt<V>::operator()(const V& v) const
+ threshold_lt<V,T>::operator()(const V& v) const
{
// Here the test seems to be inversed compared to the usual
// use. Indeed, we want to preserve the following convention:
diff --git a/milena/mln/world/kn/level.hh b/milena/mln/world/kn/level.hh
index eabba44..8c5f700 100644
--- a/milena/mln/world/kn/level.hh
+++ b/milena/mln/world/kn/level.hh
@@ -195,35 +195,40 @@ namespace mln
mln_ch_value(I,bool)
operator<(const Image<I>& ima, const world::kn::level_t<U>&
v)
{
- return data::transform(ima, fun::v2b::threshold_lt<mln_value(I)>(v.value));
+ typedef world::kn::level_t<U> T;
+ return data::transform(ima, fun::v2b::threshold_lt<mln_value(I),T>(v));
}
template <typename I, typename U>
mln_ch_value(I,bool)
operator<=(const Image<I>& ima, const world::kn::level_t<U>&
v)
{
- return data::transform(ima, fun::v2b::threshold_le<mln_value(I)>(v.value));
+ typedef world::kn::level_t<U> T;
+ return data::transform(ima, fun::v2b::threshold_le<mln_value(I),T>(v));
}
template <typename I, typename U>
mln_ch_value(I,bool)
operator>(const Image<I>& ima, const world::kn::level_t<U>&
v)
{
- return data::transform(ima, fun::v2b::threshold_gt<mln_value(I)>(v.value));
+ typedef world::kn::level_t<U> T;
+ return data::transform(ima, fun::v2b::threshold_gt<mln_value(I),T>(v));
}
template <typename I, typename U>
mln_ch_value(I,bool)
operator>=(const Image<I>& ima, const world::kn::level_t<U>&
v)
{
- return data::transform(ima, fun::v2b::threshold_ge<mln_value(I)>(v.value));
+ typedef world::kn::level_t<U> T;
+ return data::transform(ima, fun::v2b::threshold_ge<mln_value(I),T>(v));
}
template <typename I, typename U>
mln_ch_value(I,bool)
operator==(const Image<I>& ima, const world::kn::level_t<U>& v)
{
- return data::transform(ima, fun::v2b::compare<mln_value(I)>(v.value));
+ typedef world::kn::level_t<U> T;
+ return data::transform(ima, fun::v2b::compare<mln_value(I),T>(v));
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/tests/world/kn/level.cc b/milena/tests/world/kn/level.cc
index 9f902a3..55ab5b4 100644
--- a/milena/tests/world/kn/level.cc
+++ b/milena/tests/world/kn/level.cc
@@ -24,13 +24,13 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/debug/iota.hh>
#include <mln/world/kn/level.hh>
#include <mln/data/compare.hh>
#include <mln/make/image2d.hh>
#include <mln/value/interval.hh>
#include <mln/value/intsub.hh>
+
int main ()
{
using namespace mln;
@@ -74,8 +74,11 @@ int main ()
image2d<bool> ref_ge = make::image2d(vref_ge);
- image2d<unsigned> ima(5,5);
- debug::iota(ima);
+ int i = 0;
+ image2d<value::interval<int> > ima(5,5);
+ mln_piter_(image2d<value::interval<int> >) p(ima.domain());
+ for_all(p)
+ ima(p) = ++i;
// Comparison with images
{
--
1.7.2.5