Olena-patches
Threads by month
- ----- 2025 -----
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
October 2012
- 9 participants
- 221 discussions
* mln/value/interval.hh,
* tests/value/interval.cc: Rename nvalues() to nelements().
* mln/value/intsub.hh: Add a missing include.
---
milena/ChangeLog | 9 +++++++++
milena/mln/value/interval.hh | 25 +++++++++++++++----------
milena/mln/value/intsub.hh | 1 +
milena/tests/value/interval.cc | 4 ++--
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 11c4862..2bf24a9 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2012-10-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Small fixes.
+
+ * mln/value/interval.hh,
+ * tests/value/interval.cc: Rename nvalues() to nelements().
+
+ * mln/value/intsub.hh: Add a missing include.
+
+2012-10-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add aliases for value::intsub.
* mln/value/intsub.hh
diff --git a/milena/mln/value/interval.hh b/milena/mln/value/interval.hh
index a7cafc7..fbc9da1 100644
--- a/milena/mln/value/interval.hh
+++ b/milena/mln/value/interval.hh
@@ -43,6 +43,10 @@ namespace mln
namespace value
{
+ // Forward declaration.
+ template <unsigned n> class intsub;
+ template <unsigned n> class int_u;
+
/// \brief Interval of values.
template <typename T>
class interval : public value::Interval<interval<T> >
@@ -70,7 +74,7 @@ namespace mln
unsigned index_of(const T& v) const;
/// Return the number of values in this interval.
- unsigned nvalues() const;
+ unsigned nelements() const;
/// Return True if this interval contains only one value.
bool is_degenerated() const;
@@ -88,7 +92,7 @@ namespace mln
private:
T first_;
T last_;
- unsigned nvalues_;
+ unsigned nelements_;
};
// comparison
@@ -184,6 +188,7 @@ namespace mln
std::ostream&
operator<<(std::ostream& ostr, const interval<T>& i);
+
} // end of namespace mln::value
} // end of namespace mln
@@ -226,7 +231,7 @@ namespace mln
first_ = single;
last_ = single;
- nvalues_ = 1;
+ nelements_ = 1;
}
@@ -237,9 +242,9 @@ namespace mln
first_ = first;
last_ = last;
- nvalues_ = 0;
+ nelements_ = 0;
for (T v = first_; v <= last_; value::inc(v))
- ++nvalues_;
+ ++nelements_;
}
template <typename T>
@@ -269,7 +274,7 @@ namespace mln
T
interval<T>::ith_element(unsigned i) const
{
- mln_precondition(i < nvalues());
+ mln_precondition(i < nelements());
return first_ + i * iota<T>::value();
}
@@ -283,9 +288,9 @@ namespace mln
template <typename T>
unsigned
- interval<T>::nvalues() const
+ interval<T>::nelements() const
{
- return nvalues_;
+ return nelements_;
}
template <typename T>
@@ -315,11 +320,11 @@ namespace mln
{
if (is_degenerated())
abort();
- mln_precondition(nvalues_ > 2);
+ mln_precondition(nelements_ > 2);
first += iota<T>::value();
last_ -= iota<T>::value();
- nvalues_ -= 2;
+ nelements_ -= 2;
}
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
index be37291..609bd12 100644
--- a/milena/mln/value/intsub.hh
+++ b/milena/mln/value/intsub.hh
@@ -33,6 +33,7 @@
# include <cstdlib>
# include <iostream>
# include <sstream>
+# include <vector>
# include <algorithm>
# include <mln/core/routine/ops.hh>
# include <mln/value/ops.hh>
diff --git a/milena/tests/value/interval.cc b/milena/tests/value/interval.cc
index 2f57c4c..fe5a183 100644
--- a/milena/tests/value/interval.cc
+++ b/milena/tests/value/interval.cc
@@ -47,7 +47,7 @@ int main()
R r(0, 0);
assert(r.is_degenerated());
assert(r.length() == 0);
- assert(r.nvalues() == 1);
+ assert(r.nelements() == 1);
}
{
@@ -64,7 +64,7 @@ int main()
R r(1, 5);
assert(!r.is_degenerated());
assert(r.length() == 4);
- assert(r.nvalues() == 9);
+ assert(r.nelements() == 9);
int ref_i = 2;
for (intsub<2> v = r.first(); v <= r.last(); inc(v))
--
1.7.2.5
1
0
* mln/value/intsub.hh
* mln/value/intsub_1.hh
* mln/value/intsub_2.hh
* mln/value/intsub_4.hh
---
milena/ChangeLog | 9 +++++++++
milena/mln/value/intsub.hh | 6 ++----
milena/mln/value/{int_u8.hh => intsub_1.hh} | 14 +++++++-------
milena/mln/value/{int_u8.hh => intsub_2.hh} | 14 +++++++-------
milena/mln/value/{int_u8.hh => intsub_4.hh} | 14 +++++++-------
5 files changed, 32 insertions(+), 25 deletions(-)
copy milena/mln/value/{int_u8.hh => intsub_1.hh} (82%)
copy milena/mln/value/{int_u8.hh => intsub_2.hh} (82%)
copy milena/mln/value/{int_u8.hh => intsub_4.hh} (82%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index bc5e138..11c4862 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2012-10-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add aliases for value::intsub.
+
+ * mln/value/intsub.hh
+ * mln/value/intsub_1.hh
+ * mln/value/intsub_2.hh
+ * mln/value/intsub_4.hh
+
+2012-10-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix return type in functions.
* mln/fun/vv2v/max.hh,
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
index 65bef77..be37291 100644
--- a/milena/mln/value/intsub.hh
+++ b/milena/mln/value/intsub.hh
@@ -216,16 +216,13 @@ namespace mln
static intsub<n> value();
};
- typedef intsub<1> intsub1;
- typedef intsub<2> intsub2;
- typedef intsub<4> intsub4;
-
} // end of namespace mln::value
extern const value::intsub<2> half;
extern const value::intsub<4> quarter;
+
# ifndef MLN_INCLUDE_ONLY
// half
@@ -521,6 +518,7 @@ namespace mln
return mean(vec[1], vec[2]);
}
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
diff --git a/milena/mln/value/int_u8.hh b/milena/mln/value/intsub_1.hh
similarity index 82%
copy from milena/mln/value/int_u8.hh
copy to milena/mln/value/intsub_1.hh
index 5260f42..f50ef01 100644
--- a/milena/mln/value/int_u8.hh
+++ b/milena/mln/value/intsub_1.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,14 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_INT_U8_HH
-# define MLN_VALUE_INT_U8_HH
+#ifndef MLN_VALUE_INTSUB_1_HH
+# define MLN_VALUE_INTSUB_1_HH
/// \file
///
-/// Define the alias value::int_u8.
+/// Define the alias value::intsub_1.
-# include <mln/value/int_u.hh>
+# include <mln/value/intsub.hh>
namespace mln
@@ -41,7 +41,7 @@ namespace mln
/// Alias for unsigned 8-bit integers.
- typedef mln::value::int_u<8> int_u8;
+ typedef mln::value::intsub<1> intsub_1;
} // end of namespace mln::value
@@ -49,4 +49,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_INT_U8_HH
+#endif // ! MLN_VALUE_INTSUB_1_HH
diff --git a/milena/mln/value/int_u8.hh b/milena/mln/value/intsub_2.hh
similarity index 82%
copy from milena/mln/value/int_u8.hh
copy to milena/mln/value/intsub_2.hh
index 5260f42..be538a3 100644
--- a/milena/mln/value/int_u8.hh
+++ b/milena/mln/value/intsub_2.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,14 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_INT_U8_HH
-# define MLN_VALUE_INT_U8_HH
+#ifndef MLN_VALUE_INTSUB_2_HH
+# define MLN_VALUE_INTSUB_2_HH
/// \file
///
-/// Define the alias value::int_u8.
+/// Define the alias value::intsub_2.
-# include <mln/value/int_u.hh>
+# include <mln/value/intsub.hh>
namespace mln
@@ -41,7 +41,7 @@ namespace mln
/// Alias for unsigned 8-bit integers.
- typedef mln::value::int_u<8> int_u8;
+ typedef mln::value::intsub<2> intsub_2;
} // end of namespace mln::value
@@ -49,4 +49,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_INT_U8_HH
+#endif // ! MLN_VALUE_INTSUB_2_HH
diff --git a/milena/mln/value/int_u8.hh b/milena/mln/value/intsub_4.hh
similarity index 82%
copy from milena/mln/value/int_u8.hh
copy to milena/mln/value/intsub_4.hh
index 5260f42..b2b8c94 100644
--- a/milena/mln/value/int_u8.hh
+++ b/milena/mln/value/intsub_4.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,14 +23,14 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_INT_U8_HH
-# define MLN_VALUE_INT_U8_HH
+#ifndef MLN_VALUE_INTSUB_4_HH
+# define MLN_VALUE_INTSUB_4_HH
/// \file
///
-/// Define the alias value::int_u8.
+/// Define the alias value::intsub_4.
-# include <mln/value/int_u.hh>
+# include <mln/value/intsub.hh>
namespace mln
@@ -41,7 +41,7 @@ namespace mln
/// Alias for unsigned 8-bit integers.
- typedef mln::value::int_u<8> int_u8;
+ typedef mln::value::intsub<4> intsub_4;
} // end of namespace mln::value
@@ -49,4 +49,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_INT_U8_HH
+#endif // ! MLN_VALUE_INTSUB_4_HH
--
1.7.2.5
1
0
* mln/fun/vv2v/max.hh,
* mln/fun/vv2v/mean.hh,
* mln/fun/vv2v/min.hh: Here.
---
milena/ChangeLog | 8 ++++++++
milena/mln/fun/vv2v/max.hh | 23 ++++++++++++-----------
milena/mln/fun/vv2v/mean.hh | 17 ++++++++---------
milena/mln/fun/vv2v/min.hh | 24 ++++++++++++------------
4 files changed, 40 insertions(+), 32 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 7052b67..bc5e138 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,11 @@
+2012-10-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Fix return type in functions.
+
+ * mln/fun/vv2v/max.hh,
+ * mln/fun/vv2v/mean.hh,
+ * mln/fun/vv2v/min.hh: Here.
+
2012-10-19 Guillaume Lazzara <z(a)lrde.epita.fr>
New comparison functions.
diff --git a/milena/mln/fun/vv2v/max.hh b/milena/mln/fun/vv2v/max.hh
index 8d4a4d9..b04eb68 100644
--- a/milena/mln/fun/vv2v/max.hh
+++ b/milena/mln/fun/vv2v/max.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -42,25 +43,25 @@ namespace mln
namespace vv2v
{
- // FIXME: Doc.
-
/// \brief A functor computing the maximum of two values.
- template <typename V>
- struct max : public Function_vv2v< max<V> >
+ template <typename V, typename R = V>
+ struct max : public Function_vv2v< max<V,R> >,
+ private mlc_converts_to(R,V)::check_t
{
- typedef V result;
- V operator()(const V& v1, const V& v2) const;
+ typedef R result;
+ typedef V argument;
+ R operator()(const V& v1, const V& v2) const;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename V>
+ template <typename V, typename R>
inline
- V
- max<V>::operator()(const V& v1, const V& v2) const
+ R
+ max<V,R>::operator()(const V& v1, const V& v2) const
{
- return mln::math::max(v1, v2);
+ return R(mln::math::max(v1, v2));
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/fun/vv2v/mean.hh b/milena/mln/fun/vv2v/mean.hh
index 510b9a6..65e9f63 100644
--- a/milena/mln/fun/vv2v/mean.hh
+++ b/milena/mln/fun/vv2v/mean.hh
@@ -43,26 +43,25 @@ namespace mln
namespace vv2v
{
- // FIXME: Doc.
-
/// \brief A functor computing the mean of two values.
- template <typename L, typename R = L>
- struct mean : public Function_vv2v< mean<L,R> >,
- private mlc_converts_to(R,L)::check_t
+ template <typename V, typename R = V>
+ struct mean : public Function_vv2v< mean<V,R> >,
+ private mlc_converts_to(R,V)::check_t
{
typedef R result;
- R operator()(const L& v1, const L& v2) const;
+ typedef V argument;
+ R operator()(const V& v1, const V& v2) const;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename R>
+ template <typename V, typename R>
inline
R
- mean<L,R>::operator()(const L& v1, const L& v2) const
+ mean<V,R>::operator()(const V& v1, const V& v2) const
{
- return R(mln::math::mean(v1, v2);
+ return R(mln::math::mean(v1, v2));
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/fun/vv2v/min.hh b/milena/mln/fun/vv2v/min.hh
index 0f885fc..d43981f 100644
--- a/milena/mln/fun/vv2v/min.hh
+++ b/milena/mln/fun/vv2v/min.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009, 2012 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -43,26 +44,25 @@ namespace mln
namespace vv2v
{
- // FIXME: Doc.
-
/// \brief A functor computing the minimum of two values.
- template <typename L, typename R = L>
- struct min : public Function_vv2v< min<L,R> >,
- private mlc_converts_to(R,L)::check_t
+ template <typename V, typename R = V>
+ struct min : public Function_vv2v< min<V,R> >,
+ private mlc_converts_to(R,V)::check_t
{
- typedef L result;
- L operator()(const L& v1, const R& v2) const;
+ typedef R result;
+ typedef V argument;
+ R operator()(const V& v1, const V& v2) const;
};
# ifndef MLN_INCLUDE_ONLY
- template <typename L, typename R>
+ template <typename V, typename R>
inline
- L
- min<L,R>::operator()(const L& v1, const R& v2) const
+ R
+ min<V,R>::operator()(const V& v1, const V& v2) const
{
- return mln::math::min(v1, L(v2));
+ return R(mln::math::min(v1, v2));
}
# endif // ! MLN_INCLUDE_ONLY
--
1.7.2.5
1
0

olena-2.0-115-g5f98fc1 configure.ac: Configure milena/tests/world/k{2, n}/Makefile.am.
by Guillaume Lazzara 22 Oct '12
by Guillaume Lazzara 22 Oct '12
22 Oct '12
---
ChangeLog | 4 ++++
configure.ac | 2 ++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b2d2c6c..e651497 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2012-09-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * configure.ac: Configure milena/tests/world/k{2,n}/Makefile.am.
+
+2012-09-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* configure.ac: Configure milena/tests/world/k1/Makefile.am.
2011-11-16 Guillaume Lazzara <z(a)lrde.epita.fr>
diff --git a/configure.ac b/configure.ac
index 631bc89..84c0093 100644
--- a/configure.ac
+++ b/configure.ac
@@ -536,6 +536,8 @@ AC_CONFIG_FILES([
milena/tests/world/inter_pixel/Makefile
milena/tests/world/inter_pixel/dim2/Makefile
milena/tests/world/k1/Makefile
+ milena/tests/world/k2/Makefile
+ milena/tests/world/kn/Makefile
])
dnl<<lrde
--
1.7.2.5
1
0

19 Oct '12
---
milena/ChangeLog | 4 ++++
milena/tests/world/k1/Makefile.am | 2 +-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 3f2a4c2..0b2e2cf 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * tests/world/k1/Makefile.am: Fix target names.
+
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Replace unsignedh type by intsub.
* mln/value/unsignedh.hh,
diff --git a/milena/tests/world/k1/Makefile.am b/milena/tests/world/k1/Makefile.am
index 0027267..598d8dd 100644
--- a/milena/tests/world/k1/Makefile.am
+++ b/milena/tests/world/k1/Makefile.am
@@ -38,7 +38,7 @@ check_PROGRAMS = \
un_immerse
display_enlarged_SOURCES = display_enlarged.cc
-fill_0_1_faces_border_SOURCES = fill_0_1_faces_border.cc
+fill_0_1_faces_internal_border_SOURCES = fill_0_1_faces_internal_border.cc
fill_0_from_1_faces_SOURCES = fill_0_from_1_faces.cc
fill_0_from_2_faces_SOURCES = fill_0_from_2_faces.cc
fill_0_from_primary_faces_SOURCES = fill_0_from_primary_faces.cc
--
1.7.2.5
1
0
* mln/value/unsignedh.hh,
* tests/value/unsignedh.cc: Remove.
* mln/value/intsub.hh,
* tests/value/intsub.cc: New.
* tests/value/Makefile.am: Change target name.
---
milena/ChangeLog | 12 +
milena/mln/value/intsub.hh | 569 ++++++++++++++++++++++++
milena/mln/value/unsignedh.hh | 415 -----------------
milena/tests/value/Makefile.am | 4 +-
milena/tests/value/{unsignedh.cc => intsub.cc} | 46 ++-
5 files changed, 623 insertions(+), 423 deletions(-)
create mode 100644 milena/mln/value/intsub.hh
delete mode 100644 milena/mln/value/unsignedh.hh
rename milena/tests/value/{unsignedh.cc => intsub.cc} (65%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 26ffbf2..3f2a4c2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,17 @@
2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Replace unsignedh type by intsub.
+
+ * mln/value/unsignedh.hh,
+ * tests/value/unsignedh.cc: Remove.
+
+ * mln/value/intsub.hh,
+ * tests/value/intsub.cc: New.
+
+ * tests/value/Makefile.am: Change target name.
+
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
New routines to browse values into a value set.
* mln/accu/label_used.hh,
diff --git a/milena/mln/value/intsub.hh b/milena/mln/value/intsub.hh
new file mode 100644
index 0000000..fc269a8
--- /dev/null
+++ b/milena/mln/value/intsub.hh
@@ -0,0 +1,569 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_INTSUB_HH
+# define MLN_VALUE_INTSUB_HH
+
+/// \file
+///
+/// Define a subdivided integer value class.
+
+# include <cstdlib>
+# include <iostream>
+# include <sstream>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/internal/limits.hh>
+# include <mln/value/concept/integer.hh>
+# include <mln/value/iota.hh>
+# include <mln/value/prev.hh>
+# include <mln/value/succ.hh>
+
+
+namespace mln
+{
+
+ // Forward declaration
+ namespace value {
+ template <unsigned n> class intsub;
+ }
+
+ namespace trait
+ {
+
+ template <unsigned n>
+ struct set_precise_unary_< op::uminus, mln::value::intsub<n> >
+ {
+ typedef mln::value::intsub<n> ret;
+ };
+
+
+ template <unsigned n>
+ struct value_< mln::value::intsub<n> >
+ {
+ private:
+ typedef mln::value::intsub<n> self_;
+ typedef typename mln::value::internal::encoding_signed_<32>::ret enc_;
+ public:
+
+ enum constants_ {
+ dim = 1,
+ nbits = 32,
+ card = mln_value_card_from_(32/n) // FIXME: Really?
+ };
+
+ typedef trait::value::nature::integer nature;
+ typedef trait::value::kind::data kind;
+ typedef mln_value_quant_from_(card) quant;
+
+ static const self_ max() { return mln::value::internal::limits<int>::max() / n; }
+ static const self_ min() { return - max(); }
+ static const self_ epsilon() { return 0; }
+
+ typedef mln::value::intsub<n> comp;
+
+ typedef mln::value::intsub<n> sum;
+
+ static const char* name()
+ {
+ static std::string
+ s = mln::value::internal::make_generic_name("intsub", n);
+ return s.c_str();
+ }
+
+ };
+
+ } // end of namespace mln::trait
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ class intsub
+ : public Integer< intsub<n> >,
+ public internal::value_like_< int, // Equivalent.
+ typename internal::encoding_signed_<32>::ret, // Enc.
+ int, // Interoperation.
+ intsub<n> > // Exact.
+ {
+ public:
+ intsub();
+ intsub(const intsub<n>& rhs);
+ /// Construct an intsub with value : \p int_part + 1 / \p denominator.
+ intsub(int int_part, unsigned denominator);
+ intsub(int i);
+
+ intsub<n>& operator=(const intsub<n>& rhs);
+ intsub<n>& operator=(int i);
+
+ /// Is an integer value.
+ bool is_integer() const;
+
+ /// Convert this intsub to a larger intsub type.
+ template <unsigned m>
+ operator intsub<m>();
+
+ /*! \internal Increment by value::iota::value() the
+ value to the next one.
+ */
+ void inc_();
+ /*! \internal Decrement by value::iota::value() the
+ value to the next one.
+ */
+ void dec_();
+
+ /*!\internal Return the integer part of this value.
+ */
+ int to_int() const;
+
+ /*!\internal Construct a intsub using an encoding value. */
+ static intsub<n> make_from_enc_(int enc);
+
+ /// Unary operator minus.
+ intsub<n> operator-() const;
+
+ };
+
+
+ // Safety
+ template <> struct intsub<0>;
+
+// rounding
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i);
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i);
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename V>
+ bool operator==(const intsub<n>& l, const V& r);
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r);
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator+(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator+(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator+=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator-(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator-(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator-=(intsub<n>& l, const O& r);
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ intsub<n> operator*(const intsub<n>& l, const O& r);
+ template <typename O, unsigned n>
+ intsub<n> operator*(const O& r, const intsub<n>& l);
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r);
+ template <unsigned n, typename O>
+ void operator*=(intsub<n>& l, const O& r);
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& u1, const intsub<n>& u2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2);
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4);
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i);
+
+ template <unsigned n>
+ struct iota<intsub<n> >
+ {
+ static intsub<n> value();
+ };
+
+ } // end of namespace mln::value
+
+ extern const value::intsub<2> half;
+ extern const value::intsub<4> quarter;
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // half
+
+# ifndef MLN_WO_GLOBAL_VARS
+
+ const value::intsub<2> half = value::intsub<2>(0, 2);
+ const value::intsub<4> quarter = value::intsub<4>(0, 4);
+
+# endif // ! MLN_WO_GLOBAL_VARS
+
+
+
+ namespace value
+ {
+
+ template <unsigned n>
+ intsub<n>::intsub()
+ {
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int i)
+ {
+ this->v_ = n * i;
+ }
+
+ template <unsigned n>
+ intsub<n>::intsub(int int_part, unsigned denominator)
+ {
+ // FIXME: better error handling ?
+ if (denominator > n)
+ std::abort();
+
+ this->v_ = int_part * n + denominator / n;
+ }
+
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(const intsub<n>& rhs)
+ {
+ this->v_ = rhs.v_;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n>&
+ intsub<n>::operator=(int i)
+ {
+ this->v_ = n * i;
+ return *this;
+ }
+
+ template <unsigned n>
+ intsub<n> intsub<n>::make_from_enc_(int enc)
+ {
+ intsub<n> i;
+ i.v_ = enc;
+ return i;
+ }
+
+ template <unsigned n>
+ bool
+ intsub<n>::is_integer() const
+ {
+ return this->v_ % n == 0;
+ }
+
+ template <unsigned n>
+ template <unsigned m>
+ intsub<n>::operator intsub<m>()
+ {
+ // FIXME: better error handling ?
+ if (n > m)
+ std::abort();
+ return intsub<m>::make_from_enc_(this->v_ * (m / n));
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::inc_()
+ {
+ this->v_ += iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ void
+ intsub<n>::dec_()
+ {
+ this->v_ -= iota<intsub<n> >::value().to_enc();
+ }
+
+ template <unsigned n>
+ int
+ intsub<n>::to_int() const
+ {
+ return this->v_ / n;
+ }
+
+ template <unsigned n>
+ intsub<n>
+ intsub<n>::operator-() const
+ {
+ return intsub<n>::make_from_enc_(this->v_ * -1);
+ }
+
+ // Iota
+ template <unsigned n>
+ intsub<n>
+ iota<intsub<n> >::value()
+ {
+ return intsub<n>(0,n);
+ }
+
+
+// rounding
+
+
+ template <unsigned n>
+ intsub<n> floor(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::prev(i);
+ }
+
+ template <unsigned n>
+ intsub<n> ceil(const intsub<n>& i)
+ {
+ return i.is_integer() ? i : value::succ(i);
+ }
+
+
+
+// comparison
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() == r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator==(const intsub<n>& l, const int& r)
+ {
+ return l == intsub<n>(r);
+ }
+
+ template <unsigned n>
+ bool operator<=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return l.to_enc() <= r.to_enc();
+ }
+
+ template <unsigned n>
+ bool operator!=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l == r);
+ }
+
+ template <unsigned n>
+ bool operator>=(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r <= l;
+ }
+
+ template <unsigned n>
+ bool operator>(const intsub<n>& l, const intsub<n>& r)
+ {
+ return ! (l <= r);
+ }
+
+ template <unsigned n>
+ bool operator<(const intsub<n>& l, const intsub<n>& r)
+ {
+ return r > l;
+ }
+
+
+// arithmetics
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() + r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(const intsub<n>& l, int r)
+ {
+ return l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator+(int l, const intsub<n>& r)
+ {
+ return r + l;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l + r;
+ }
+
+ template <unsigned n>
+ void operator+=(intsub<n>& l, int r)
+ {
+ l = l + intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() - r.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(const intsub<n>& l, int r)
+ {
+ return l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator-(int l, const intsub<n>& r)
+ {
+ return - r + l;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l - r;
+ }
+
+ template <unsigned n>
+ void operator-=(intsub<n>& l, int r)
+ {
+ l = l - intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, const intsub<n>& r)
+ {
+ return intsub<n>::make_from_enc_(l.to_enc() * r.to_enc() / n);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(const intsub<n>& l, int r)
+ {
+ return l * intsub<n>(r);
+ }
+
+ template <unsigned n>
+ intsub<n> operator*(int l, const intsub<n>& r)
+ {
+ return r * l;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, const intsub<n>& r)
+ {
+ l = l * r;
+ }
+
+ template <unsigned n>
+ void operator*=(intsub<n>& l, int r)
+ {
+ l = l * intsub<n>(r);
+ }
+
+
+// other ops
+
+ template <unsigned n>
+ intsub<n> min(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() < v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> max(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_(v1.to_enc() > v2.to_enc() ? v1.to_enc() : v2.to_enc());
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()) / 2);
+ }
+
+ template <unsigned n>
+ intsub<n> mean(const intsub<n>& v1, const intsub<n>& v2,
+ const intsub<n>& v3, const intsub<n>& v4)
+ {
+ return intsub<n>::make_from_enc_((v1.to_enc() + v2.to_enc()
+ + v3.to_enc() + v4.to_enc()) / 4);
+ }
+
+
+// <<
+
+ template <unsigned n>
+ std::ostream&
+ operator<<(std::ostream& ostr, const intsub<n>& i)
+ {
+ if (i.is_integer())
+ return ostr << i.to_int();
+ else
+ return ostr << floor(i).to_int() << ".5";
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+#endif // ! MLN_VALUE_INTSUB_HH
diff --git a/milena/mln/value/unsignedh.hh b/milena/mln/value/unsignedh.hh
deleted file mode 100644
index 1f0281c..0000000
--- a/milena/mln/value/unsignedh.hh
+++ /dev/null
@@ -1,415 +0,0 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of Olena.
-//
-// Olena is free software: you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 2 of the License.
-//
-// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
-//
-// As a special exception, you may use this file as part of a free
-// software project 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_UNSIGNEDH_HH
-# define MLN_VALUE_UNSIGNEDH_HH
-
-/// \file
-///
-/// Define a semi-unsigned value class.
-
-# include <cstdlib>
-# include <iostream>
-# include <sstream>
-
-// FIXME: parameterize unsignedh so that we also can have
-// Z/4 and so on...
-
-namespace mln
-{
-
- namespace value
- {
-
-
- class unsignedh
- {
- public:
- unsignedh();
- unsignedh(const unsignedh& rhs);
- unsignedh(unsigned i);
- unsignedh(int i);
-
- unsignedh& operator=(const unsignedh& rhs);
- unsignedh& operator=(unsigned i);
- unsignedh& operator=(int i);
-
- unsigned enc() const;
-
- /// Construct an unsignedh with value v
- static unsignedh make(unsigned v);
- /// Construct an unsignedh with value v. The given value is
- /// rounded to the closest integer or half value.
-// static unsignedh make(float v);
-
- bool is_integer() const;
-
- unsigned to_unsigned() const;
-
- /// Set this unsignedh to its next value and return itself.
- unsignedh& goto_succ();
-
- /// Set this unsignedh to its previous value and return itself.
- unsignedh& goto_pred();
-
- operator std::string() const;
-
- private:
- unsigned enc_;
- };
-
-
- extern const unsignedh half;
-
-
-// next
-
- unsignedh succ(unsignedh i);
- unsignedh pred(unsignedh i);
-
-// rounding
-
- unsignedh floor(unsignedh i);
- unsignedh ceil(unsignedh i);
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r);
- bool operator<=(unsignedh l, unsignedh r);
- bool operator!=(unsignedh l, unsignedh r);
- bool operator>=(unsignedh l, unsignedh r);
- bool operator>(unsignedh l, unsignedh r);
- bool operator<(unsignedh l, unsignedh r);
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r);
- void operator+=(unsignedh& l, unsignedh r);
- unsignedh operator-(unsignedh l, unsignedh r);
- void operator-=(unsignedh& l, unsignedh r);
- unsignedh operator/(unsignedh l, unsigned r);
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2);
- unsignedh max(unsignedh u1, unsignedh u2);
- unsignedh mean(unsignedh u1, unsignedh u2);
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u);
- void encode(unsigned u, unsigned& dst);
- unsigned decode(unsignedh u);
- void encode(unsigned u, unsignedh& dst);
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i);
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- inline
- unsignedh::unsignedh()
- {
- }
-
- inline
- unsignedh::unsignedh(const unsignedh& rhs)
- : enc_(rhs.enc_)
- {
- }
-
-
- inline
- unsignedh::unsignedh(unsigned i)
- {
- enc_ = 2 * i;
- }
-
- inline
- unsignedh::unsignedh(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(const unsignedh& rhs)
- {
- enc_ = rhs.enc_;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(unsigned i)
- {
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::operator=(int i)
- {
- if (i < 0)
- std::abort();
- enc_ = 2 * i;
- return *this;
- }
-
- inline
- unsigned
- unsignedh::enc() const
- {
- return enc_;
- }
-
- inline
- unsignedh unsignedh::make(unsigned enc)
- {
- unsignedh i;
- i.enc_ = enc;
- return i;
- }
-
- inline
- bool
- unsignedh::is_integer() const
- {
- return enc_ % 2 == 0;
- }
-
- inline
- unsigned
- unsignedh::to_unsigned() const
- {
- if (! this->is_integer())
- std::abort();
- return enc_ / 2;
- }
-
- inline
- unsignedh&
- unsignedh::goto_succ()
- {
- enc_ += 1;
- return *this;
- }
-
- inline
- unsignedh&
- unsignedh::goto_pred()
- {
- if (enc_ == 0)
- std::abort();
- enc_ -= 1;
- return *this;
- }
-
- inline
- unsignedh::operator std::string() const
- {
- std::stringstream s;
- s << *this;
- return s.str();
- }
-
-
-
-// half
-
-# ifndef MLN_WO_GLOBAL_VARS
-
- const unsignedh half = unsignedh::make(1u);
-
-# endif // ! MLN_WO_GLOBAL_VARS
-
-
-// next
-
- unsignedh succ(unsignedh i)
- {
- return unsignedh::make(i.enc() + 1);
- }
-
- unsignedh pred(unsignedh i)
- {
- if (i.enc() == 0)
- std::abort();
- return unsignedh::make(i.enc() - 1);
- }
-
-
-
-// rounding
-
- unsignedh floor(unsignedh i)
- {
- return i.is_integer() ? i : pred(i);
- }
-
- unsignedh ceil(unsignedh i)
- {
- return i.is_integer() ? i : succ(i);
- }
-
-
-
-// comparison
-
- bool operator==(unsignedh l, unsignedh r)
- {
- return l.enc() == r.enc();
- }
-
- bool operator<=(unsignedh l, unsignedh r)
- {
- return l.enc() <= r.enc();
- }
-
- bool operator!=(unsignedh l, unsignedh r)
- {
- return ! (l == r);
- }
-
- bool operator>=(unsignedh l, unsignedh r)
- {
- return r <= l;
- }
-
- bool operator>(unsignedh l, unsignedh r)
- {
- return ! (l <= r);
- }
-
- bool operator<(unsignedh l, unsignedh r)
- {
- return r > l;
- }
-
-
-
-// arithmetics
-
- unsignedh operator+(unsignedh l, unsignedh r)
- {
- return unsignedh::make(l.enc() + r.enc());
- }
-
- void operator+=(unsignedh& l, unsignedh r)
- {
- l = l + r;
- }
-
- unsignedh operator-(unsignedh l, unsignedh r)
- {
- if (r > l)
- std::abort();
- return unsignedh::make(l.enc() - r.enc());
- }
-
- void operator-=(unsignedh& l, unsignedh r)
- {
- if (r > l)
- std::abort();
- l = l - r;
- }
-
- unsignedh operator/(unsignedh l, unsigned r)
- {
- if (l.enc() % r != 0)
- std::abort();
- return unsignedh::make(l.enc() / r);
- }
-
-
-
-// other ops
-
- unsignedh min(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() < u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh max(unsignedh u1, unsignedh u2)
- {
- return unsignedh::make(u1.enc() > u2.enc() ? u1.enc() : u2.enc());
- }
-
- unsignedh mean(unsignedh u1, unsignedh u2)
- {
- return (u1 + u2) / 2;
- }
-
-
-// for a transparent use of both unsigned and unsignedh
-// FIXME: is it useful?
-
- unsigned decode(unsigned u)
- {
- return u;
- }
-
- void encode(unsigned u, unsigned& dst)
- {
- dst = u;
- }
-
- unsigned decode(unsignedh u)
- {
- return u.enc();
- }
-
- void encode(unsigned u, unsignedh& dst)
- {
- dst = unsignedh::make(u);
- }
-
-
-// <<
-
- std::ostream&
- operator<<(std::ostream& ostr, const unsignedh& i)
- {
- if (i.is_integer())
- return ostr << i.to_unsigned();
- else
- return ostr << floor(i).to_unsigned() << ".5";
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::value
-
-} // end of namespace mln
-
-#endif // ndef UNSIGNEDH_HH
diff --git a/milena/tests/value/Makefile.am b/milena/tests/value/Makefile.am
index fb654fa..8d6718f 100644
--- a/milena/tests/value/Makefile.am
+++ b/milena/tests/value/Makefile.am
@@ -36,7 +36,7 @@ check_PROGRAMS = \
scalar \
set \
sign \
- unsignedh
+ intsub
# float01
# float01_bis
# float01_f
@@ -61,7 +61,7 @@ rgb8_SOURCES = rgb8.cc
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
sign_SOURCES = sign.cc
-unsignedh_SOURCES = unsignedh.cc
+intsub_SOURCES = intsub.cc
#<<lrde
# FIXME: Not distributed (yet).
diff --git a/milena/tests/value/unsignedh.cc b/milena/tests/value/intsub.cc
similarity index 65%
rename from milena/tests/value/unsignedh.cc
rename to milena/tests/value/intsub.cc
index ca98a59..e324fe3 100644
--- a/milena/tests/value/unsignedh.cc
+++ b/milena/tests/value/intsub.cc
@@ -26,19 +26,53 @@
/// \file
#include <cassert>
-#include <mln/value/unsignedh.hh>
-
+#include <mln/value/intsub.hh>
+#include <mln/value/inc.hh>
+#include <mln/value/dec.hh>
+#include <mln/value/succ.hh>
+#include <mln/value/prev.hh>
+#include <mln/math/mean.hh>
int main()
{
+ using namespace mln;
using namespace mln::value;
- unsignedh i = 2;
- i.goto_succ();
+ // i == 2
+ intsub<2> i = 2;
+ inc(i);
// i == 2.5
- assert(i == 2 + half);
+ mln_assertion(i == half + 2);
// (2.5 + 0.5) / 2 == 1.5
- assert(mean(i, half) == 1 + half);
+ mln_assertion(mean(i, half) == 1 + half);
+
+ // i == 3
+ inc(i);
+ mln_assertion(i == intsub<2>(3));
+
+ // i == 2.5
+ dec(i);
+ mln_assertion(i == intsub<2>(2,2));
+ dec(i);
+
+ // i == 2.5
+ mln_assertion(succ(i) == 2 + half);
+
+ // i == 1.5
+ mln_assertion(prev(i) == 2 - half);
+
+ // i == 6
+ i *= 3;
+ mln_assertion(i == 6);
+
+ // j = 6
+ intsub<4> j = i;
+ mln_assertion(j == 6);
+
+ // j = 6.25
+ inc(j);
+ mln_assertion(j == 6 + quarter);
+
}
--
1.7.2.5
1
0

olena-2.0-91-g82a0e36 New routines to browse values into a value set.
by Guillaume Lazzara 19 Oct '12
by Guillaume Lazzara 19 Oct '12
19 Oct '12
* mln/accu/label_used.hh,
* mln/core/internal/labeled_image_base.hh,
* mln/labeling/colorize.hh,
* mln/labeling/compute.hh,
* mln/labeling/superpose.hh,
* mln/make/relabelfun.hh,
* mln/set/compute_with_weights.hh,
* mln/value/label.hh,
* mln/value/range.hh: Rename value::next to value::succ.
* mln/value/dec.hh,
* mln/value/inc.hh,
* mln/value/iota.hh,
* mln/value/next.hh,
* mln/value/prev.hh,
* mln/value/succ.hh: New.
---
milena/ChangeLog | 21 ++++++
milena/mln/accu/label_used.hh | 2 +-
milena/mln/core/internal/labeled_image_base.hh | 2 +-
milena/mln/labeling/colorize.hh | 2 +-
milena/mln/labeling/compute.hh | 22 +++---
milena/mln/labeling/superpose.hh | 2 +-
milena/mln/make/relabelfun.hh | 4 +-
milena/mln/set/compute_with_weights.hh | 2 +-
milena/mln/value/{next.hh => dec.hh} | 66 +++++++-------------
milena/mln/value/{next.hh => inc.hh} | 66 +++++++-------------
.../{world/k1/is_0_or_1_face.hh => value/iota.hh} | 59 ++++++++++--------
milena/mln/value/label.hh | 6 +-
milena/mln/value/{next.hh => prev.hh} | 54 ++++++----------
milena/mln/value/range.hh | 4 +-
milena/mln/value/{next.hh => succ.hh} | 51 +++++----------
15 files changed, 161 insertions(+), 202 deletions(-)
copy milena/mln/value/{next.hh => dec.hh} (68%)
copy milena/mln/value/{next.hh => inc.hh} (68%)
copy milena/mln/{world/k1/is_0_or_1_face.hh => value/iota.hh} (64%)
copy milena/mln/value/{next.hh => prev.hh} (69%)
rename milena/mln/value/{next.hh => succ.hh} (72%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d66e76f..26ffbf2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,24 @@
+2012-10-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ New routines to browse values into a value set.
+
+ * mln/accu/label_used.hh,
+ * mln/core/internal/labeled_image_base.hh,
+ * mln/labeling/colorize.hh,
+ * mln/labeling/compute.hh,
+ * mln/labeling/superpose.hh,
+ * mln/make/relabelfun.hh,
+ * mln/set/compute_with_weights.hh,
+ * mln/value/label.hh,
+ * mln/value/range.hh: Rename value::next to value::succ.
+
+ * mln/value/dec.hh,
+ * mln/value/inc.hh,
+ * mln/value/iota.hh,
+ * mln/value/next.hh,
+ * mln/value/prev.hh,
+ * mln/value/succ.hh: New.
+
2012-09-28 Guillaume Lazzara <z(a)lrde.epita.fr>
New value types.
diff --git a/milena/mln/accu/label_used.hh b/milena/mln/accu/label_used.hh
index 69121b1..37fb459 100644
--- a/milena/mln/accu/label_used.hh
+++ b/milena/mln/accu/label_used.hh
@@ -118,7 +118,7 @@ namespace mln
label_used<L>::take(const argument& l)
{
if (label_used_.size() <= l)
- label_used_.resize(value::next(l), false);
+ label_used_.resize(value::succ(l), false);
label_used_(l) = true;
}
diff --git a/milena/mln/core/internal/labeled_image_base.hh b/milena/mln/core/internal/labeled_image_base.hh
index 45f3ed2..a80e5b8 100644
--- a/milena/mln/core/internal/labeled_image_base.hh
+++ b/milena/mln/core/internal/labeled_image_base.hh
@@ -281,7 +281,7 @@ namespace mln
labeled_image_base<I,E>::update_data(const fun::i2v::array<mln_value(I)>& relabel_fun)
{
util::array<accu::shape::bbox<mln_psite(I)> >
- new_bboxes(mln::value::next(this->data_->nlabels_));
+ new_bboxes(mln::value::succ(this->data_->nlabels_));
exact(this)->init_update_data_();
diff --git a/milena/mln/labeling/colorize.hh b/milena/mln/labeling/colorize.hh
index ddfbb15..ba876a7 100644
--- a/milena/mln/labeling/colorize.hh
+++ b/milena/mln/labeling/colorize.hh
@@ -198,7 +198,7 @@ namespace mln
// mlc_is_a(mln_value(L), mln::value::Symbolic)::check();
(void) value;
- unsigned label_count = value::next(nlabels);
+ unsigned label_count = value::succ(nlabels);
static fun::i2v::array<V> f(0);
int diff_size = f.size() - label_count;
if (diff_size < 0)
diff --git a/milena/mln/labeling/compute.hh b/milena/mln/labeling/compute.hh
index a9dc791..4ad48b5 100644
--- a/milena/mln/labeling/compute.hh
+++ b/milena/mln/labeling/compute.hh
@@ -211,7 +211,7 @@ namespace mln
const A& a = exact(a_);
const L& label = exact(label_);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(L) p(label.domain());
for_all(p)
@@ -245,12 +245,12 @@ namespace mln
trace::entering("labeling::impl::generic::compute");
internal::compute_tests(A(), label_, nlabels);
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
const L& label = exact(label_);
@@ -292,7 +292,7 @@ namespace mln
const I& input = exact(input_);
const L& label = exact(label_);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(I) p(input.domain());
for_all(p)
@@ -331,12 +331,12 @@ namespace mln
const L& label = exact(label_);
(void) nlabels;
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
mln_piter(I) p(input.domain());
@@ -384,7 +384,7 @@ namespace mln
// FIXME: check image properties + add doc.
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
unsigned ncols = geom::ncols(label);
@@ -439,12 +439,12 @@ namespace mln
const L& label = exact(label_);
(void) nlabels;
- if (value::next(nlabels) != accus.size())
+ if (value::succ(nlabels) != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
- accus.resize(value::next(nlabels));
+ accus.resize(value::succ(nlabels));
}
unsigned ncols = geom::ncols(label);
@@ -757,7 +757,7 @@ namespace mln
typedef util::array<mln_result(A)> R;
R res = internal::compute_dispatch(accus, label, nlabels);
- mln_postcondition(res.nelements() == value::next(nlabels));
+ mln_postcondition(res.nelements() == value::succ(nlabels));
trace::exiting("labeling::compute");
return res;
@@ -779,7 +779,7 @@ namespace mln
typedef util::array<mln_result(A)> R;
R res = internal::compute_dispatch(a, label, nlabels);
- mln_postcondition(res.nelements() == value::next(nlabels));
+ mln_postcondition(res.nelements() == value::succ(nlabels));
trace::exiting("labeling::compute");
return res;
diff --git a/milena/mln/labeling/superpose.hh b/milena/mln/labeling/superpose.hh
index 1df647c..e063912 100644
--- a/milena/mln/labeling/superpose.hh
+++ b/milena/mln/labeling/superpose.hh
@@ -98,7 +98,7 @@ namespace mln
mln_concrete(I) output = duplicate(lhs);
util::array<mln_value(J)>
- rebase_lbl(value::next(rhs_nlabels));
+ rebase_lbl(value::succ(rhs_nlabels));
rebase_lbl(0) = 0;
for (unsigned i = 1; i <= rhs_nlabels; ++i)
diff --git a/milena/mln/make/relabelfun.hh b/milena/mln/make/relabelfun.hh
index bc423fb..3ec38cb 100644
--- a/milena/mln/make/relabelfun.hh
+++ b/milena/mln/make/relabelfun.hh
@@ -88,7 +88,7 @@ namespace mln
const F& fv2b = exact(fv2b_);
- unsigned nlabels_i = value::next(nlabels);
+ unsigned nlabels_i = value::succ(nlabels);
V tmp_nlabels = literal::zero;
fun::i2v::array<V> fi2v(nlabels_i, literal::zero);
for (V i = 1; i < nlabels_i; ++i)
@@ -111,7 +111,7 @@ namespace mln
const F& fv2v = exact(fv2v_);
- unsigned nlabels_i = value::next(nlabels);
+ unsigned nlabels_i = value::succ(nlabels);
util::array<V> new_labels(nlabels_i, mln_max(V));
new_labels(0) = literal::zero;
diff --git a/milena/mln/set/compute_with_weights.hh b/milena/mln/set/compute_with_weights.hh
index 24da256..2612498 100644
--- a/milena/mln/set/compute_with_weights.hh
+++ b/milena/mln/set/compute_with_weights.hh
@@ -189,7 +189,7 @@ namespace mln
internal::compute_with_weights_tests(a, w, label);
- util::array<A> accus(value::next(nlabels), a);
+ util::array<A> accus(value::succ(nlabels), a);
mln_piter(I) p(w.domain());
for_all(p)
diff --git a/milena/mln/value/next.hh b/milena/mln/value/dec.hh
similarity index 68%
copy from milena/mln/value/next.hh
copy to milena/mln/value/dec.hh
index b9bc06e..7b0e05b 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/dec.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_DEC_HH
+# define MLN_VALUE_DEC_HH
/// \file
///
-/// Return the next value.
+/// Return the dec value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -42,8 +42,8 @@ namespace mln
{
template <typename V>
- V
- next(const V&);
+ void
+ dec(V&);
# ifndef MLN_INCLUDE_ONLY
@@ -58,30 +58,20 @@ namespace mln
{
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ dec(V& v)
{
- return v + 1;
+ v -= mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
- inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ template <typename V>
+ void
+ dec_label(V& v)
{
- return mln::value::succ(v);
+ --v;
}
} // end of namespace mln::value::implementation
@@ -94,26 +84,17 @@ namespace mln
{
template <unsigned n>
- inline
- label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ void
+ dec_dispatch(label<n>& v)
{
- return implementation::next_unsignedh(v);
+ implementation::dec_label(v);
}
template <typename V>
- inline
- V
- next_dispatch(const V& v)
+ void
+ dec_dispatch(V& v)
{
- return implementation::generic::next(v);
+ implementation::generic::dec(v);
}
} // end of namespace mln::value::internal
@@ -123,11 +104,10 @@ namespace mln
// Facade
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ dec(V& v)
{
- return internal::next_dispatch(v);
+ internal::dec_dispatch(v);
}
@@ -138,4 +118,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_DEC_HH
diff --git a/milena/mln/value/next.hh b/milena/mln/value/inc.hh
similarity index 68%
copy from milena/mln/value/next.hh
copy to milena/mln/value/inc.hh
index b9bc06e..80fc625 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/inc.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_INC_HH
+# define MLN_VALUE_INC_HH
/// \file
///
-/// Return the next value.
+/// Return the inc value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -42,8 +42,8 @@ namespace mln
{
template <typename V>
- V
- next(const V&);
+ void
+ inc(V&);
# ifndef MLN_INCLUDE_ONLY
@@ -58,30 +58,20 @@ namespace mln
{
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ inc(V& v)
{
- return v + 1;
+ v += mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
- inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ template <typename V>
+ void
+ inc_label(V& v)
{
- return mln::value::succ(v);
+ ++v;
}
} // end of namespace mln::value::implementation
@@ -94,26 +84,17 @@ namespace mln
{
template <unsigned n>
- inline
- label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ void
+ inc_dispatch(label<n>& v)
{
- return implementation::next_unsignedh(v);
+ implementation::inc_label(v);
}
template <typename V>
- inline
- V
- next_dispatch(const V& v)
+ void
+ inc_dispatch(V& v)
{
- return implementation::generic::next(v);
+ implementation::generic::inc(v);
}
} // end of namespace mln::value::internal
@@ -123,11 +104,10 @@ namespace mln
// Facade
template <typename V>
- inline
- V
- next(const V& v)
+ void
+ inc(V& v)
{
- return internal::next_dispatch(v);
+ internal::inc_dispatch(v);
}
@@ -138,4 +118,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_INC_HH
diff --git a/milena/mln/world/k1/is_0_or_1_face.hh b/milena/mln/value/iota.hh
similarity index 64%
copy from milena/mln/world/k1/is_0_or_1_face.hh
copy to milena/mln/value/iota.hh
index 6f3f47a..bdad60c 100644
--- a/milena/mln/world/k1/is_0_or_1_face.hh
+++ b/milena/mln/value/iota.hh
@@ -23,49 +23,58 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
+#ifndef MLN_VALUE_IOTA_HH
+# define MLN_VALUE_IOTA_HH
+
/// \file
///
-/// \brief Check if site is a 1 face.
-
-#ifndef MLN_WORLD_K1_IS_0_OR_1_FACE_HH
-# define MLN_WORLD_K1_IS_0_OR_1_FACE_HH
-
-# include <mln/core/alias/point2d.hh>
-# include <mln/world/k1/internal/face_dim.hh>
-
+/// Define a functor returning the smallest next value in a given
+/// type.
namespace mln
{
- namespace world
+ namespace value
{
- namespace k1
+ /// Define a functor returning the smallest next value in a
+ /// given type.
+ template <typename T>
+ struct iota;
+
+ /// Specialization of \ref mln::value::internal::iota for unsigned.
+ template <>
+ struct iota<unsigned>
{
+ static unsigned value();
+ };
- /// \brief Check if site is a 1 face
- bool is_0_or_1_face(const point2d& p);
+ /// Specialization of \ref mln::value::internal::iota for int.
+ template <>
+ struct iota<int>
+ {
+ static int value();
+ };
# ifndef MLN_INCLUDE_ONLY
+ unsigned
+ iota<unsigned>::value()
+ {
+ return 1u;
+ }
- // Facade
-
- inline
- bool is_0_or_1_face(const point2d& p)
- {
- unsigned dim = internal::face_dim(p);
- return dim == 0 || dim == 1;
- }
-
+ int
+ iota<int>::value()
+ {
+ return 1;
+ }
# endif // ! MLN_INCLUDE_ONLY
- } // end of namespace mln::world::k1
-
- } // end of namespace mln::world
+ } // end of namespace mln::value
} // end of namespace mln
-#endif // ! MLN_WORLD_K1_IS_0_OR_1_FACE_HH
+#endif // MLN_VALUE_IOTA_HH
diff --git a/milena/mln/value/label.hh b/milena/mln/value/label.hh
index dd0f924..a28889f 100644
--- a/milena/mln/value/label.hh
+++ b/milena/mln/value/label.hh
@@ -136,8 +136,8 @@ namespace mln
/// Self decrement.
label<n>& operator--();
- /// Return the next value.
- label<n> next() const;
+ /// Return the successive value.
+ label<n> succ() const;
/// Return the previous value.
label<n> prev() const;
@@ -260,7 +260,7 @@ namespace mln
template <unsigned n>
inline
label<n>
- label<n>::next() const
+ label<n>::succ() const
{
return label<n>(this->v_ + 1);
}
diff --git a/milena/mln/value/next.hh b/milena/mln/value/prev.hh
similarity index 69%
copy from milena/mln/value/next.hh
copy to milena/mln/value/prev.hh
index b9bc06e..93221c5 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/prev.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2010, 2012 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,15 +23,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_PREV_HH
+# define MLN_VALUE_PREV_HH
/// \file
///
-/// Return the next value.
+/// Return the prev value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -43,7 +42,7 @@ namespace mln
template <typename V>
V
- next(const V&);
+ prev(const V&);
# ifndef MLN_INCLUDE_ONLY
@@ -60,28 +59,20 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ prev(const V& v)
{
- return v + 1;
+ return v - mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
+ template <typename V>
inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ V
+ prev_method(const V& v)
{
- return mln::value::succ(v);
+ return v.prev();
}
} // end of namespace mln::value::implementation
@@ -96,24 +87,17 @@ namespace mln
template <unsigned n>
inline
label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ prev_dispatch(const label<n>& v)
{
- return implementation::next_unsignedh(v);
+ return implementation::prev_method(v);
}
template <typename V>
inline
V
- next_dispatch(const V& v)
+ prev_dispatch(const V& v)
{
- return implementation::generic::next(v);
+ return implementation::generic::prev(v);
}
} // end of namespace mln::value::internal
@@ -125,9 +109,9 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ prev(const V& v)
{
- return internal::next_dispatch(v);
+ return internal::prev_dispatch(v);
}
@@ -138,4 +122,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_PREV_HH
diff --git a/milena/mln/value/range.hh b/milena/mln/value/range.hh
index ca8f2f4..5c90de7 100644
--- a/milena/mln/value/range.hh
+++ b/milena/mln/value/range.hh
@@ -233,7 +233,7 @@ namespace mln
{
unsigned n = 1;
T v = lower_;
- for (; v != upper_; v = value::next(v))
+ for (; v != upper_; v = value::succ(v))
n += 1;
return n;
@@ -323,7 +323,7 @@ namespace mln
are_adjacent(const range<T>& r1, const range<T>& r2)
{
return span(r1, r2).length() == r1.length() + r2.length()
- + (value::next(r2.lower()) - r2.lower());
+ + (value::succ(r2.lower()) - r2.lower());
}
template <typename T>
diff --git a/milena/mln/value/next.hh b/milena/mln/value/succ.hh
similarity index 72%
rename from milena/mln/value/next.hh
rename to milena/mln/value/succ.hh
index b9bc06e..4877727 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/succ.hh
@@ -24,15 +24,15 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_VALUE_NEXT_HH
-# define MLN_VALUE_NEXT_HH
+#ifndef MLN_VALUE_SUCC_HH
+# define MLN_VALUE_SUCC_HH
/// \file
///
-/// Return the next value.
+/// Return the succ value.
+# include <mln/value/iota.hh>
# include <mln/value/label.hh>
-# include <mln/value/unsignedh.hh>
namespace mln
@@ -43,7 +43,7 @@ namespace mln
template <typename V>
V
- next(const V&);
+ succ(const V&);
# ifndef MLN_INCLUDE_ONLY
@@ -60,28 +60,20 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ succ(const V& v)
{
- return v + 1;
+ return v + mln::value::iota<V>::value();
}
} // end of namespace mln::value::implementation::generic
- template <unsigned n>
- inline
- mln::value::label<n>
- next_label(const mln::value::label<n>& v)
- {
- return v.next();
- }
-
-
+ template <typename V>
inline
- mln::value::unsignedh
- next_unsignedh(const mln::value::unsignedh& v)
+ V
+ succ_method(const V& v)
{
- return mln::value::succ(v);
+ return v.succ();
}
} // end of namespace mln::value::implementation
@@ -96,24 +88,17 @@ namespace mln
template <unsigned n>
inline
label<n>
- next_dispatch(const label<n>& v)
- {
- return implementation::next_label(v);
- }
-
- inline
- unsignedh
- next_dispatch(const unsignedh& v)
+ succ_dispatch(const label<n>& v)
{
- return implementation::next_unsignedh(v);
+ return implementation::succ_method(v);
}
template <typename V>
inline
V
- next_dispatch(const V& v)
+ succ_dispatch(const V& v)
{
- return implementation::generic::next(v);
+ return implementation::generic::succ(v);
}
} // end of namespace mln::value::internal
@@ -125,9 +110,9 @@ namespace mln
template <typename V>
inline
V
- next(const V& v)
+ succ(const V& v)
{
- return internal::next_dispatch(v);
+ return internal::succ_dispatch(v);
}
@@ -138,4 +123,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_VALUE_NEXT_HH
+#endif // ! MLN_VALUE_SUCC_HH
--
1.7.2.5
1
0
* mln/value/next.hh: Add support for unsignedh.
* mln/value/range.hh,
* mln/value/unsignedh.hh,
* tests/value/range.cc,
* tests/value/unsignedh.cc: New.
* tests/value/Makefile.am: Add targets.
---
milena/ChangeLog | 13 +
milena/mln/value/next.hh | 20 +-
milena/mln/value/range.hh | 425 ++++++++++++++++++++
milena/mln/value/unsignedh.hh | 415 +++++++++++++++++++
milena/tests/value/Makefile.am | 16 +-
.../range.cc} | 62 ++--
.../tests/{fun/i2v/array.cc => value/unsignedh.cc} | 22 +-
7 files changed, 930 insertions(+), 43 deletions(-)
create mode 100644 milena/mln/value/range.hh
create mode 100644 milena/mln/value/unsignedh.hh
copy milena/tests/{world/k1/fill_0_1_faces_internal_border.cc => value/range.cc} (61%)
copy milena/tests/{fun/i2v/array.cc => value/unsignedh.cc} (80%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 174267b..d66e76f 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2012-09-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+ New value types.
+
+ * mln/value/next.hh: Add support for unsignedh.
+
+ * mln/value/range.hh,
+ * mln/value/unsignedh.hh,
+ * tests/value/range.cc,
+ * tests/value/unsignedh.cc: New.
+
+ * tests/value/Makefile.am: Add targets.
+
+2012-09-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
New routine for filling internal border in K1.
* mln/world/k1/fill_0_1_faces_internal_border.hh,
diff --git a/milena/mln/value/next.hh b/milena/mln/value/next.hh
index e1dac48..b9bc06e 100644
--- a/milena/mln/value/next.hh
+++ b/milena/mln/value/next.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2012 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -28,9 +29,10 @@
/// \file
///
-/// Return a given value incremented by 1.
+/// Return the next value.
# include <mln/value/label.hh>
+# include <mln/value/unsignedh.hh>
namespace mln
@@ -74,6 +76,14 @@ namespace mln
return v.next();
}
+
+ inline
+ mln::value::unsignedh
+ next_unsignedh(const mln::value::unsignedh& v)
+ {
+ return mln::value::succ(v);
+ }
+
} // end of namespace mln::value::implementation
@@ -91,6 +101,12 @@ namespace mln
return implementation::next_label(v);
}
+ inline
+ unsignedh
+ next_dispatch(const unsignedh& v)
+ {
+ return implementation::next_unsignedh(v);
+ }
template <typename V>
inline
diff --git a/milena/mln/value/range.hh b/milena/mln/value/range.hh
new file mode 100644
index 0000000..ca8f2f4
--- /dev/null
+++ b/milena/mln/value/range.hh
@@ -0,0 +1,425 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_RANGE_HH
+# define MLN_VALUE_RANGE_HH
+
+/// \file
+///
+/// Define a range value.
+
+# include <cstdlib>
+# include <iostream>
+# include <mln/value/next.hh>
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ template <typename T>
+ class range
+ {
+ public:
+ range();
+
+ template <typename T_>
+ range(T_ value);
+
+ range(T lower, T upper);
+
+ range& operator=(const range& rhs);
+
+ template <typename T_>
+ range& operator=(T_ value);
+
+ bool has(const T& v) const;
+
+ T length() const;
+
+ unsigned nelements() const;
+
+ bool is_degenerated() const;
+
+ const T& lower() const;
+ const T& upper() const;
+
+ const T& first() const;
+ const T& last() const;
+
+ operator T() const;
+
+ private:
+ T lower_;
+ T upper_;
+ };
+
+// comparison
+
+ template <typename T>
+ bool
+ operator==(const range<T>& lhs, const range<T>& rhs);
+
+ template <typename T>
+ bool
+ operator!=(const range<T>& lhs, const range<T>& rhs);
+
+// deactivation of ordering related operators
+
+ template <typename T>
+ void operator<(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator<=(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator>(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator>=(const range<T>&, const range<T>&);
+
+// set ops
+
+ template <typename T>
+ bool
+ are_adjacent(const range<T>& r1, const range<T>& r2);
+
+ template <typename T>
+ bool
+ do_intersect(const range<T>& r1, const range<T>& r2);
+
+ template <typename T>
+ range<T>
+ inter(const range<T>& r1, const range<T>& r2);
+
+// min / max
+
+ template <typename T>
+ range<T>
+ min(const range<T>& r1, const range<T>& r2);
+
+ template <typename T>
+ range<T>
+ max(const range<T>& r1, const range<T>& r2);
+
+// mean
+
+ template <typename T>
+ range<T>
+ mean(const range<T>& r1, const range<T>& r2);
+
+// span
+
+ template <typename T>
+ range<T>
+ span(const range<T>& r1, const range<T>& r2);
+
+// op<<
+
+ template <typename T>
+ std::ostream&
+ operator<<(std::ostream& ostr, const range<T>& i);
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+// for sorting purpose
+
+namespace std
+{
+
+ template <typename T>
+ struct less< mln::value::range<T> >
+ {
+ bool operator()(const mln::value::range<T>& l,
+ const mln::value::range<T>& r) const;
+ };
+
+} // std
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ template <typename T>
+ range<T>::range()
+ {
+ }
+
+ template <typename T>
+ template <typename T_>
+ range<T>::range(T_ value)
+ {
+ lower_ = upper_ = value;
+ }
+
+ template <typename T>
+ range<T>::range(T lower, T upper)
+ {
+ if (upper < lower)
+ std::abort();
+ lower_ = lower;
+ upper_ = upper;
+ }
+
+ template <typename T>
+ range<T>&
+ range<T>::operator=(const range& rhs)
+ {
+ lower_ = rhs.lower_;
+ upper_ = rhs.upper_;
+ return *this;
+ }
+
+ template <typename T>
+ template <typename T_>
+ range<T>&
+ range<T>::operator=(T_ value)
+ {
+ lower_ = upper_ = value;
+ return *this;
+ }
+
+ template <typename T>
+ bool
+ range<T>::has(const T& v) const
+ {
+ return lower_ <= v && v <= upper_;
+ }
+
+ template <typename T>
+ T
+ range<T>::length() const
+ {
+ return upper_ - lower_;
+ }
+
+ template <typename T>
+ unsigned
+ range<T>::nelements() const
+ {
+ unsigned n = 1;
+ T v = lower_;
+ for (; v != upper_; v = value::next(v))
+ n += 1;
+
+ return n;
+ }
+
+ template <typename T>
+ bool
+ range<T>::is_degenerated() const
+ {
+ return upper_ == lower_;
+ }
+
+ template <typename T>
+ const T&
+ range<T>::lower() const
+ {
+ return lower_;
+ }
+
+ template <typename T>
+ const T&
+ range<T>::upper() const
+ {
+ return upper_;
+ }
+
+ template <typename T>
+ const T&
+ range<T>::first() const
+ {
+ return lower_;
+ }
+
+ template <typename T>
+ const T&
+ range<T>::last() const
+ {
+ return upper_;
+ }
+
+ template <typename T>
+ range<T>::operator T() const
+ {
+ if (! is_degenerated())
+ std::abort();
+ return upper_;
+ }
+
+
+// comparison
+
+ template <typename T>
+ bool
+ operator==(const range<T>& lhs, const range<T>& rhs)
+ {
+ return lhs.lower() == rhs.lower() && lhs.upper() == rhs.upper();
+ }
+
+ template <typename T>
+ bool
+ operator!=(const range<T>& lhs, const range<T>& rhs)
+ {
+ return ! (lhs == rhs);
+ }
+
+
+// deactivation of ordering related operators
+
+ template <typename T>
+ void operator<(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator<=(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator>(const range<T>&, const range<T>&);
+
+ template <typename T>
+ void operator>=(const range<T>&, const range<T>&);
+
+
+
+// set ops
+
+ template <typename T>
+ bool
+ are_adjacent(const range<T>& r1, const range<T>& r2)
+ {
+ return span(r1, r2).length() == r1.length() + r2.length()
+ + (value::next(r2.lower()) - r2.lower());
+ }
+
+ template <typename T>
+ bool
+ do_intersect(const range<T>& r1, const range<T>& r2)
+ {
+ return span(r1, r2).length() <= r1.length() + r2.length();
+ }
+
+ template <typename T>
+ range<T>
+ inter(const range<T>& r1, const range<T>& r2)
+ {
+ if (! do_intersect(r1, r2))
+ std::abort();
+ return range<T>(std::max(r1.lower(), r2.lower()),
+ std::min(r1.upper(), r2.upper()));
+ }
+
+
+
+// min / max
+
+ template <typename T>
+ range<T>
+ min(const range<T>& r1, const range<T>& r2)
+ {
+ return range<T>(std::min(r1.lower(), r2.lower()),
+ std::min(r1.upper(), r2.upper()));
+ }
+
+ template <typename T>
+ range<T>
+ max(const range<T>& r1, const range<T>& r2)
+ {
+ return range<T>(std::max(r1.lower(), r2.lower()),
+ std::max(r1.upper(), r2.upper()));
+ }
+
+
+// mean
+
+ template <typename T>
+ range<T>
+ mean(const range<T>& r1, const range<T>& r2)
+ {
+ return range<T>(mean(r1.lower(), r2.lower()),
+ mean(r1.upper(), r2.upper()));
+ }
+
+
+// span
+
+ template <typename T>
+ range<T>
+ span(const range<T>& r1, const range<T>& r2)
+ {
+ return range<T>(std::min(r1.lower(), r2.lower()),
+ std::max(r1.upper(), r2.upper()));
+ }
+
+
+
+// op<<
+
+ template <typename T>
+ std::ostream&
+ operator<<(std::ostream& ostr, const range<T>& i)
+ {
+ if (i.is_degenerated())
+ return ostr << i.lower();
+ else
+ return ostr << '[' << i.lower() << ',' << i.upper() << ']';
+ }
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+namespace std
+{
+
+ template <typename T>
+ bool less< mln::value::range<T> >::operator()(const mln::value::range<T>& l,
+ const mln::value::range<T>& r) const
+ {
+ if (! l.is_degenerated() || ! r.is_degenerated())
+ std::abort();
+ return l.lower() < r.lower();
+ }
+
+} // std
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+#endif // ndef MLN_VALUE_RANGE_HH
diff --git a/milena/mln/value/unsignedh.hh b/milena/mln/value/unsignedh.hh
new file mode 100644
index 0000000..1f0281c
--- /dev/null
+++ b/milena/mln/value/unsignedh.hh
@@ -0,0 +1,415 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_UNSIGNEDH_HH
+# define MLN_VALUE_UNSIGNEDH_HH
+
+/// \file
+///
+/// Define a semi-unsigned value class.
+
+# include <cstdlib>
+# include <iostream>
+# include <sstream>
+
+// FIXME: parameterize unsignedh so that we also can have
+// Z/4 and so on...
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ class unsignedh
+ {
+ public:
+ unsignedh();
+ unsignedh(const unsignedh& rhs);
+ unsignedh(unsigned i);
+ unsignedh(int i);
+
+ unsignedh& operator=(const unsignedh& rhs);
+ unsignedh& operator=(unsigned i);
+ unsignedh& operator=(int i);
+
+ unsigned enc() const;
+
+ /// Construct an unsignedh with value v
+ static unsignedh make(unsigned v);
+ /// Construct an unsignedh with value v. The given value is
+ /// rounded to the closest integer or half value.
+// static unsignedh make(float v);
+
+ bool is_integer() const;
+
+ unsigned to_unsigned() const;
+
+ /// Set this unsignedh to its next value and return itself.
+ unsignedh& goto_succ();
+
+ /// Set this unsignedh to its previous value and return itself.
+ unsignedh& goto_pred();
+
+ operator std::string() const;
+
+ private:
+ unsigned enc_;
+ };
+
+
+ extern const unsignedh half;
+
+
+// next
+
+ unsignedh succ(unsignedh i);
+ unsignedh pred(unsignedh i);
+
+// rounding
+
+ unsignedh floor(unsignedh i);
+ unsignedh ceil(unsignedh i);
+
+
+// comparison
+
+ bool operator==(unsignedh l, unsignedh r);
+ bool operator<=(unsignedh l, unsignedh r);
+ bool operator!=(unsignedh l, unsignedh r);
+ bool operator>=(unsignedh l, unsignedh r);
+ bool operator>(unsignedh l, unsignedh r);
+ bool operator<(unsignedh l, unsignedh r);
+
+// arithmetics
+
+ unsignedh operator+(unsignedh l, unsignedh r);
+ void operator+=(unsignedh& l, unsignedh r);
+ unsignedh operator-(unsignedh l, unsignedh r);
+ void operator-=(unsignedh& l, unsignedh r);
+ unsignedh operator/(unsignedh l, unsigned r);
+
+// other ops
+
+ unsignedh min(unsignedh u1, unsignedh u2);
+ unsignedh max(unsignedh u1, unsignedh u2);
+ unsignedh mean(unsignedh u1, unsignedh u2);
+
+// for a transparent use of both unsigned and unsignedh
+// FIXME: is it useful?
+
+ unsigned decode(unsigned u);
+ void encode(unsigned u, unsigned& dst);
+ unsigned decode(unsignedh u);
+ void encode(unsigned u, unsignedh& dst);
+
+// <<
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const unsignedh& i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ inline
+ unsignedh::unsignedh()
+ {
+ }
+
+ inline
+ unsignedh::unsignedh(const unsignedh& rhs)
+ : enc_(rhs.enc_)
+ {
+ }
+
+
+ inline
+ unsignedh::unsignedh(unsigned i)
+ {
+ enc_ = 2 * i;
+ }
+
+ inline
+ unsignedh::unsignedh(int i)
+ {
+ if (i < 0)
+ std::abort();
+ enc_ = 2 * i;
+ }
+
+ inline
+ unsignedh&
+ unsignedh::operator=(const unsignedh& rhs)
+ {
+ enc_ = rhs.enc_;
+ return *this;
+ }
+
+ inline
+ unsignedh&
+ unsignedh::operator=(unsigned i)
+ {
+ enc_ = 2 * i;
+ return *this;
+ }
+
+ inline
+ unsignedh&
+ unsignedh::operator=(int i)
+ {
+ if (i < 0)
+ std::abort();
+ enc_ = 2 * i;
+ return *this;
+ }
+
+ inline
+ unsigned
+ unsignedh::enc() const
+ {
+ return enc_;
+ }
+
+ inline
+ unsignedh unsignedh::make(unsigned enc)
+ {
+ unsignedh i;
+ i.enc_ = enc;
+ return i;
+ }
+
+ inline
+ bool
+ unsignedh::is_integer() const
+ {
+ return enc_ % 2 == 0;
+ }
+
+ inline
+ unsigned
+ unsignedh::to_unsigned() const
+ {
+ if (! this->is_integer())
+ std::abort();
+ return enc_ / 2;
+ }
+
+ inline
+ unsignedh&
+ unsignedh::goto_succ()
+ {
+ enc_ += 1;
+ return *this;
+ }
+
+ inline
+ unsignedh&
+ unsignedh::goto_pred()
+ {
+ if (enc_ == 0)
+ std::abort();
+ enc_ -= 1;
+ return *this;
+ }
+
+ inline
+ unsignedh::operator std::string() const
+ {
+ std::stringstream s;
+ s << *this;
+ return s.str();
+ }
+
+
+
+// half
+
+# ifndef MLN_WO_GLOBAL_VARS
+
+ const unsignedh half = unsignedh::make(1u);
+
+# endif // ! MLN_WO_GLOBAL_VARS
+
+
+// next
+
+ unsignedh succ(unsignedh i)
+ {
+ return unsignedh::make(i.enc() + 1);
+ }
+
+ unsignedh pred(unsignedh i)
+ {
+ if (i.enc() == 0)
+ std::abort();
+ return unsignedh::make(i.enc() - 1);
+ }
+
+
+
+// rounding
+
+ unsignedh floor(unsignedh i)
+ {
+ return i.is_integer() ? i : pred(i);
+ }
+
+ unsignedh ceil(unsignedh i)
+ {
+ return i.is_integer() ? i : succ(i);
+ }
+
+
+
+// comparison
+
+ bool operator==(unsignedh l, unsignedh r)
+ {
+ return l.enc() == r.enc();
+ }
+
+ bool operator<=(unsignedh l, unsignedh r)
+ {
+ return l.enc() <= r.enc();
+ }
+
+ bool operator!=(unsignedh l, unsignedh r)
+ {
+ return ! (l == r);
+ }
+
+ bool operator>=(unsignedh l, unsignedh r)
+ {
+ return r <= l;
+ }
+
+ bool operator>(unsignedh l, unsignedh r)
+ {
+ return ! (l <= r);
+ }
+
+ bool operator<(unsignedh l, unsignedh r)
+ {
+ return r > l;
+ }
+
+
+
+// arithmetics
+
+ unsignedh operator+(unsignedh l, unsignedh r)
+ {
+ return unsignedh::make(l.enc() + r.enc());
+ }
+
+ void operator+=(unsignedh& l, unsignedh r)
+ {
+ l = l + r;
+ }
+
+ unsignedh operator-(unsignedh l, unsignedh r)
+ {
+ if (r > l)
+ std::abort();
+ return unsignedh::make(l.enc() - r.enc());
+ }
+
+ void operator-=(unsignedh& l, unsignedh r)
+ {
+ if (r > l)
+ std::abort();
+ l = l - r;
+ }
+
+ unsignedh operator/(unsignedh l, unsigned r)
+ {
+ if (l.enc() % r != 0)
+ std::abort();
+ return unsignedh::make(l.enc() / r);
+ }
+
+
+
+// other ops
+
+ unsignedh min(unsignedh u1, unsignedh u2)
+ {
+ return unsignedh::make(u1.enc() < u2.enc() ? u1.enc() : u2.enc());
+ }
+
+ unsignedh max(unsignedh u1, unsignedh u2)
+ {
+ return unsignedh::make(u1.enc() > u2.enc() ? u1.enc() : u2.enc());
+ }
+
+ unsignedh mean(unsignedh u1, unsignedh u2)
+ {
+ return (u1 + u2) / 2;
+ }
+
+
+// for a transparent use of both unsigned and unsignedh
+// FIXME: is it useful?
+
+ unsigned decode(unsigned u)
+ {
+ return u;
+ }
+
+ void encode(unsigned u, unsigned& dst)
+ {
+ dst = u;
+ }
+
+ unsigned decode(unsignedh u)
+ {
+ return u.enc();
+ }
+
+ void encode(unsigned u, unsignedh& dst)
+ {
+ dst = unsignedh::make(u);
+ }
+
+
+// <<
+
+ std::ostream&
+ operator<<(std::ostream& ostr, const unsignedh& i)
+ {
+ if (i.is_integer())
+ return ostr << i.to_unsigned();
+ else
+ return ostr << floor(i).to_unsigned() << ".5";
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+#endif // ndef UNSIGNEDH_HH
diff --git a/milena/tests/value/Makefile.am b/milena/tests/value/Makefile.am
index 975d471..fb654fa 100644
--- a/milena/tests/value/Makefile.am
+++ b/milena/tests/value/Makefile.am
@@ -31,15 +31,17 @@ check_PROGRAMS = \
interop \
label \
proxy \
+ range \
rgb8 \
scalar \
set \
- sign
-# float01
-# float01_bis
-# float01_f
-# graylevel
-# graylevel_f
+ sign \
+ unsignedh
+# float01
+# float01_bis
+# float01_f
+# graylevel
+# graylevel_f
bool_SOURCES = bool.cc
equiv_SOURCES = equiv.cc
@@ -54,10 +56,12 @@ int_u8_SOURCES = int_u8.cc
interop_SOURCES = interop.cc
label_SOURCES = label.cc
proxy_SOURCES = proxy.cc
+range_SOURCES = range.cc
rgb8_SOURCES = rgb8.cc
scalar_SOURCES = scalar.cc
set_SOURCES = set.cc
sign_SOURCES = sign.cc
+unsignedh_SOURCES = unsignedh.cc
#<<lrde
# FIXME: Not distributed (yet).
diff --git a/milena/tests/world/k1/fill_0_1_faces_internal_border.cc b/milena/tests/value/range.cc
similarity index 61%
copy from milena/tests/world/k1/fill_0_1_faces_internal_border.cc
copy to milena/tests/value/range.cc
index fbb9f73..22421ed 100644
--- a/milena/tests/world/k1/fill_0_1_faces_internal_border.cc
+++ b/milena/tests/value/range.cc
@@ -25,35 +25,47 @@
/// \file
-#include <mln/core/image/image2d.hh>
-#include <mln/make/box2d.hh>
-#include <mln/data/compare.hh>
-#include <mln/world/k1/fill_0_1_faces_internal_border.hh>
+#include <cassert>
+#include <vector>
+#include <algorithm>
+
+#include <mln/value/unsignedh.hh>
+#include <mln/value/range.hh>
+
+static const char *ref[] = { "1", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", "5" };
int main()
{
- using namespace mln;
-
- int refvals[5][5] = {
- {1, 1, 1, 1, 1 },
- {1, 2, 0, 2, 1 },
- {1, 0, 0, 0, 1 },
- {1, 2, 0, 2, 1 },
- {1, 1, 1, 1, 1 }
- };
- image2d<int> ref = make::image(refvals, point2d(-1, -1));
-
- int vals[5][5] = {
- {0, 0, 0, 0, 0 },
- {0, 2, 0, 2, 0 },
- {0, 0, 0, 0, 0 },
- {0, 2, 0, 2, 0 },
- {0, 0, 0, 0, 0 }
- };
- image2d<int> imak1 = make::image(vals, point2d(-1, -1));
+ using namespace mln::value;
+
+ typedef range<unsignedh> R;
+
+ {
+ R r(0, 0);
+ assert(r.is_degenerated());
+ assert(r.length() == 0);
+ assert(r.nelements() == 1);
+ }
+
+ {
+ assert(are_adjacent(R(0,1), R(1+half,2)));
+ }
{
- world::k1::fill_0_1_faces_internal_border(imak1, 1);
- mln_assertion(ref == imak1);
+ std::vector<R> v;
+ v.push_back(R(0,0));
+ std::sort(v.begin(), v.end(), std::less<R>());
}
+
+ {
+ R r(1, 5);
+ assert(!r.is_degenerated());
+ assert(r.length() == 4);
+ assert(r.nelements() == 9);
+
+ int ref_i = 0;
+ for (unsignedh v = r.first(); v != r.last(); v.goto_succ())
+ mln_assertion(static_cast<std::string>(v) == ref[ref_i++]);
+ }
+
}
diff --git a/milena/tests/fun/i2v/array.cc b/milena/tests/value/unsignedh.cc
similarity index 80%
copy from milena/tests/fun/i2v/array.cc
copy to milena/tests/value/unsignedh.cc
index 2633b41..ca98a59 100644
--- a/milena/tests/fun/i2v/array.cc
+++ b/milena/tests/value/unsignedh.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,20 +23,22 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#include <mln/fun/i2v/array.hh>
+/// \file
+
+#include <cassert>
+#include <mln/value/unsignedh.hh>
int main()
{
- using namespace mln;
+ using namespace mln::value;
- fun::i2v::array<int> f;
- mln_assertion(f.size() == 0u);
+ unsignedh i = 2;
+ i.goto_succ();
- f.append(0);
- mln_assertion(f(0) == 0);
+ // i == 2.5
+ assert(i == 2 + half);
- f.append(1);
- mln_assertion(f(1) == 1);
- mln_assertion(f.size() == 2u);
+ // (2.5 + 0.5) / 2 == 1.5
+ assert(mean(i, half) == 1 + half);
}
--
1.7.2.5
1
0

olena-2.0-89-g7aacabf New routine for filling internal border in K1.
by Guillaume Lazzara 19 Oct '12
by Guillaume Lazzara 19 Oct '12
19 Oct '12
* mln/world/k1/fill_0_1_faces_internal_border.hh,
* tests/world/k1/fill_0_1_faces_internal_border.cc: New.
* tests/world/k1/Makefile.am: New target.
---
milena/ChangeLog | 9 ++
..._faces.hh => fill_0_1_faces_internal_border.hh} | 79 +++++++++----------
milena/tests/world/k1/Makefile.am | 2 +
...mmerse.cc => fill_0_1_faces_internal_border.cc} | 29 ++++---
4 files changed, 65 insertions(+), 54 deletions(-)
copy milena/mln/world/k1/{fill_0_from_primary_faces.hh => fill_0_1_faces_internal_border.hh} (53%)
copy milena/tests/world/k1/{un_immerse.cc => fill_0_1_faces_internal_border.cc} (76%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6d98f7d..174267b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,12 @@
+2012-09-28 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ New routine for filling internal border in K1.
+
+ * mln/world/k1/fill_0_1_faces_internal_border.hh,
+ * tests/world/k1/fill_0_1_faces_internal_border.cc: New.
+
+ * tests/world/k1/Makefile.am: New target.
+
2012-09-27 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/world/k1/neighb2d.hh: New neighborhoods.
diff --git a/milena/mln/world/k1/fill_0_from_primary_faces.hh b/milena/mln/world/k1/fill_0_1_faces_internal_border.hh
similarity index 53%
copy from milena/mln/world/k1/fill_0_from_primary_faces.hh
copy to milena/mln/world/k1/fill_0_1_faces_internal_border.hh
index db3aed8..0ee3d27 100644
--- a/milena/mln/world/k1/fill_0_from_primary_faces.hh
+++ b/milena/mln/world/k1/fill_0_1_faces_internal_border.hh
@@ -25,13 +25,13 @@
/// \file
///
-/// \brief Fill 1 faces in a K1 2D image using its primary faces.
+/// \brief Fill 0 and 1 faces border with a value in a K1 2D image.
-#ifndef MLN_WORLD_K1_FILL_0_FROM_PRIMARY_FACES_HH
-# define MLN_WORLD_K1_FILL_0_FROM_PRIMARY_FACES_HH
+#ifndef MLN_WORLD_K1_FILL_0_1_FACES_INTERNAL_BORDER_HH
+# define MLN_WORLD_K1_FILL_0_1_FACES_INTERNAL_BORDER_HH
# include <mln/core/alias/point2d.hh>
-# include <mln/world/k1/fill_0_from_2_faces.hh>
+# include <mln/world/k1/is_0_face.hh>
namespace mln
@@ -43,27 +43,23 @@ namespace mln
namespace k1
{
- /*! \brief Fill 0 faces in a K1 2D image using its primary faces.
+ /*! \brief Fill 0 and 1 faces border with a value in a K1 2D image.
\param[in,out] inout A 2D image immersed in K1.
- \param[in,out] f A functor computing a result from four values.
+ \param[in] v The border value.
- This function use the following neighborhood:
-
- \verbatim
- x x
- .
- x x
- \endverbatim
+ Example with \p v=1:
+ . - . - . 1 1 1 1 1
+ | o | o | 1 o | o 1
+ . - . - . -> 1 - . - 1
+ | o | o | 1 o | o 1
+ . - . - . 1 1 1 1 1
*/
- template <typename I, typename F>
- void fill_0_from_primary_faces(Image<I>& inout, Function_vvvv2v<F>& f);
+ template <typename I>
+ void fill_0_1_faces_internal_border(Image<I>& inout, const mln_value(I)& v);
- /// \overload
- template <typename I, typename A>
- void fill_0_from_primary_faces(Image<I>& inout, const Accumulator<A>& accu);
# ifndef MLN_INCLUDE_ONLY
@@ -72,32 +68,31 @@ namespace mln
// Facade
- template <typename I, typename F>
- void fill_0_from_primary_faces(Image<I>& inout, Function_vvvv2v<F>& f)
- {
- trace::entering("mln::world::k1::fill_0_from_primary_faces");
-
- mln_precondition(exact(inout).is_valid());
-
- fill_0_from_2_faces(inout, f);
-
- trace::exiting("mln::world::k1::fill_0_from_primary_faces");
- }
-
-
- template <typename I, typename A>
- void fill_0_from_primary_faces(Image<I>& inout, const Accumulator<A>& accu)
+ template <typename I>
+ void fill_0_1_faces_internal_border(Image<I>& inout_, const mln_value(I)& v)
{
- trace::entering("mln::world::k1::fill_0_from_primary_faces");
-
- mln_precondition(exact(inout).is_valid());
-
- fill_0_from_2_faces(inout, accu);
-
- trace::exiting("mln::world::k1::fill_0_from_primary_faces");
+ trace::entering("mln::world::k1::fill_0_1_faces_internal_border");
+
+ mln_precondition(exact(inout_).is_valid());
+ I& inout = exact(inout_);
+
+ // Horizontal borders
+ for (mln::def::coord col = geom::min_col(inout); col <= geom::max_col(inout); ++col)
+ {
+ inout.at_(geom::min_row(inout), col) = v;
+ inout.at_(geom::max_row(inout), col) = v;
+ }
+
+ // Vertical borders
+ for (mln::def::coord row = geom::min_row(inout); row <= geom::max_row(inout); ++row)
+ {
+ inout.at_(row, geom::min_col(inout)) = v;
+ inout.at_(row, geom::max_col(inout)) = v;
+ }
+
+ trace::exiting("mln::world::k1::fill_0_1_faces_internal_border");
}
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::world::k1
@@ -106,4 +101,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_WORLD_K1_FILL_0_FROM_PRIMARY_FACES_HH
+#endif // ! MLN_WORLD_K1_FILL_0_1_FACES_INTERNAL_BORDER_HH
diff --git a/milena/tests/world/k1/Makefile.am b/milena/tests/world/k1/Makefile.am
index 68866fb..0027267 100644
--- a/milena/tests/world/k1/Makefile.am
+++ b/milena/tests/world/k1/Makefile.am
@@ -18,6 +18,7 @@ include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
display_enlarged \
+ fill_0_1_faces_internal_border \
fill_0_from_1_faces \
fill_0_from_2_faces \
fill_0_from_primary_faces \
@@ -37,6 +38,7 @@ check_PROGRAMS = \
un_immerse
display_enlarged_SOURCES = display_enlarged.cc
+fill_0_1_faces_border_SOURCES = fill_0_1_faces_border.cc
fill_0_from_1_faces_SOURCES = fill_0_from_1_faces.cc
fill_0_from_2_faces_SOURCES = fill_0_from_2_faces.cc
fill_0_from_primary_faces_SOURCES = fill_0_from_primary_faces.cc
diff --git a/milena/tests/world/k1/un_immerse.cc b/milena/tests/world/k1/fill_0_1_faces_internal_border.cc
similarity index 76%
copy from milena/tests/world/k1/un_immerse.cc
copy to milena/tests/world/k1/fill_0_1_faces_internal_border.cc
index 47e06e4..fbb9f73 100644
--- a/milena/tests/world/k1/un_immerse.cc
+++ b/milena/tests/world/k1/fill_0_1_faces_internal_border.cc
@@ -26,29 +26,34 @@
/// \file
#include <mln/core/image/image2d.hh>
-#include <mln/world/k1/un_immerse.hh>
#include <mln/make/box2d.hh>
#include <mln/data/compare.hh>
+#include <mln/world/k1/fill_0_1_faces_internal_border.hh>
int main()
{
using namespace mln;
- int refvals[2][2] = {
- {3, 3},
- {3, 3}
+ int refvals[5][5] = {
+ {1, 1, 1, 1, 1 },
+ {1, 2, 0, 2, 1 },
+ {1, 0, 0, 0, 1 },
+ {1, 2, 0, 2, 1 },
+ {1, 1, 1, 1, 1 }
};
- image2d<int> ref = make::image(refvals);
+ image2d<int> ref = make::image(refvals, point2d(-1, -1));
int vals[5][5] = {
- {1, 2, 1, 2, 1 },
- {2, 3, 2, 3, 2 },
- {1, 2, 1, 2, 1 },
- {2, 3, 2, 3, 2 },
- {1, 2, 1, 2, 1 }
+ {0, 0, 0, 0, 0 },
+ {0, 2, 0, 2, 0 },
+ {0, 0, 0, 0, 0 },
+ {0, 2, 0, 2, 0 },
+ {0, 0, 0, 0, 0 }
};
image2d<int> imak1 = make::image(vals, point2d(-1, -1));
- image2d<int> imak0 = world::k1::un_immerse(imak1);
- mln_assertion(imak0 == ref);
+ {
+ world::k1::fill_0_1_faces_internal_border(imak1, 1);
+ mln_assertion(ref == imak1);
+ }
}
--
1.7.2.5
1
0

19 Oct '12
---
milena/ChangeLog | 4 +
milena/mln/world/k1/neighb2d.hh | 143 +++++++++++++++++++++++++++++++++++++++
2 files changed, 147 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/world/k1/neighb2d.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d778238..6d98f7d 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,9 @@
2012-09-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * mln/world/k1/neighb2d.hh: New neighborhoods.
+
+2012-09-27 Guillaume Lazzara <z(a)lrde.epita.fr>
+
More routines working on images immersed in K1.
* mln/core/concept/function.hh: Add Function_vvvv2v concept.
diff --git a/milena/mln/world/k1/neighb2d.hh b/milena/mln/world/k1/neighb2d.hh
new file mode 100644
index 0000000..7681af1
--- /dev/null
+++ b/milena/mln/world/k1/neighb2d.hh
@@ -0,0 +1,143 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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.
+
+/// \file
+///
+/// \brief 2D neighborhood working in K1.
+
+#ifndef MLN_WORLD_K1_NEIGHB2D_HH
+# define MLN_WORLD_K1_NEIGHB2D_HH
+
+# include <mln/core/alias/point2d.hh>
+# include <mln/core/alias/neighb2d.hh>
+# include <mln/win/multiple.hh>
+# include <mln/make/double_neighb2d.hh>
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace k1
+ {
+
+ /*! \brief 2 faces to 1 faces neighborhood.
+
+ \verbatim
+ -
+ |x|
+ -
+ \endverbatim
+ */
+ const neighb2d& 2to1_faces();
+
+
+ /*! \brief 1 faces to 2 faces neighborhood.
+
+ \verbatim
+ o
+ oxo or x
+ o
+ \endverbatim
+
+ */
+ const dbl_neighb2d& 1to2_faces();
+
+
+ /*! \brief 1 faces to 1 faces neighborhood.
+
+ \verbatim
+ |
+ - - | |
+ x or - -
+ - - | |
+ |
+ \endverbatim
+ */
+ const dbl_neighb2d& 1to1_faces()
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ inline
+ bool is_row_odd(const point2d& p)
+ {
+ return p.row() % 2;
+ }
+
+ }
+
+ typedef neighb< win::multiple<window2d, bool(*)(const point2d&)> > dbl_neighb2d;
+
+
+ const neighb2d& 2to1_faces()
+ {
+ return c4();
+ }
+
+ const dbl_neighb2d& 1to2_faces()
+ {
+ static bool 1face_h[] = { 0, 1, 0,
+ 0, 0, 0,
+ 0, 1, 0 };
+ static bool 1face_v[] = { 0, 0, 0,
+ 1, 0, 1,
+ 0, 0, 0 };
+ static dbl_neighb2d nbh = make::double_neighb2d(internal::is_row_odd, e2p_h, e2p_v);
+ return nbh;
+ }
+
+
+ const dbl_neighb2d& 1to1_faces()
+ {
+ static bool e2e_h[] = { 0, 0, 1, 0, 0,
+ 0, 1, 0, 1, 0,
+ 0, 0, 0, 0, 0,
+ 0, 1, 0, 1, 0,
+ 0, 0, 1, 0, 0 };
+ static bool e2e_v[] = { 0, 0, 0, 0, 0,
+ 0, 1, 0, 1, 0,
+ 1, 0, 0, 0, 1,
+ 0, 1, 0, 1, 0,
+ 0, 0, 0, 0, 0 };
+ static dbl_neighb2d nbh = make::double_neighb2d(internal::is_row_odd, e2e_h, e2e_v);
+ return nbh;
+ }
+
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::world::k1
+
+ } // end of namespace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_K1_NEIGHB2D_HH
--
1.7.2.5
1
0