olena-2.0-121-gf7f868a Move util::level to world::kn and add new operators.

* mln/util/level.hh, * tests/util/level.cc: Move... * mln/world/kn/level.hh, * tests/world/kn/level.cc: ... Here. * tests/util/Makefile.am, * tests/world/kn/Makefile.am: Update targets. * mln/value/interval.hh: Remove operators. --- milena/ChangeLog | 15 ++ milena/mln/util/level.hh | 143 ------------------ milena/mln/value/interval.hh | 45 ------ milena/mln/world/kn/level.hh | 233 ++++++++++++++++++++++++++++++ milena/tests/util/Makefile.am | 2 - milena/tests/world/kn/Makefile.am | 2 + milena/tests/{util => world/kn}/level.cc | 46 +++++-- 7 files changed, 287 insertions(+), 199 deletions(-) delete mode 100644 milena/mln/util/level.hh create mode 100644 milena/mln/world/kn/level.hh rename milena/tests/{util => world/kn}/level.cc (68%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9fcc238..9b113d5 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,20 @@ 2012-10-22 Guillaume Lazzara <z@lrde.epita.fr> + Move util::level to world::kn and add new operators. + + * mln/util/level.hh, + * tests/util/level.cc: Move... + + * mln/world/kn/level.hh, + * tests/world/kn/level.cc: ... Here. + + * tests/util/Makefile.am, + * tests/world/kn/Makefile.am: Update targets. + + * mln/value/interval.hh: Remove operators. + +2012-10-22 Guillaume Lazzara <z@lrde.epita.fr> + Revamp khalimsky directory. * mln/world/k1/immerse_with.hh, diff --git a/milena/mln/util/level.hh b/milena/mln/util/level.hh deleted file mode 100644 index 3aa6fa0..0000000 --- a/milena/mln/util/level.hh +++ /dev/null @@ -1,143 +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_UTIL_LEVEL_HH -# define MLN_UTIL_LEVEL_HH - -# include <mln/core/concept/value.hh> -# include <mln/value/scalar.hh> -# include <mln/data/transform.hh> -# include <mln/fun/v2b/threshold_lt.hh> -# include <mln/fun/v2b/threshold_le.hh> -# include <mln/fun/v2b/threshold_gt.hh> -# include <mln/fun/v2b/threshold_ge.hh> -# include <mln/fun/v2b/compare.hh> - -/// \file -/// -/// Definition of a level tag. - -namespace mln -{ - - namespace util - { - - /// \brief Level tag structure. - template <typename T> - struct level_t - : public Object<level_t<T> > - { - const T& value; - explicit level_t(const T& value); - }; - - /// \brief construct a level tag. - template <typename T> - level_t<T> level(const T& value); - - - // Comparison Operators - - template <typename I, typename U> - mln_ch_value(I,bool) - operator<(const Image<I>& ima, const level_t<U>& v); - - template <typename I, typename U> - mln_ch_value(I,bool) - operator==(const Image<I>& ima, const level_t<U>& v); - - - template <typename I, typename U> - mln_ch_value(I,bool) - operator>(const Image<I>& ima, const level_t<U>& v); - - template <typename I, typename U> - mln_ch_value(I,bool) - operator>=(const Image<I>& ima, const level_t<U>& v); - - -# ifndef MLN_INCLUDE_ONLY - - template <typename T> - level_t<T>::level_t(const T& value) - : value(value) - { - } - - // Helpers - - template <typename T> - inline - level_t<T> level(const T& value) - { - return level_t<T>(value); - } - - - // Operators - - template <typename I, typename U> - mln_ch_value(I,bool) - operator<(const Image<I>& ima, const level_t<U>& v) - { - return data::transform(ima, fun::v2b::threshold_lt<mln_value(I)>(v.value)); - } - - template <typename I, typename U> - mln_ch_value(I,bool) - operator<=(const Image<I>& ima, const level_t<U>& v) - { - return data::transform(ima, fun::v2b::threshold_le<mln_value(I)>(v.value)); - } - - template <typename I, typename U> - mln_ch_value(I,bool) - operator>(const Image<I>& ima, const level_t<U>& v) - { - return data::transform(ima, fun::v2b::threshold_gt<mln_value(I)>(v.value)); - } - - template <typename I, typename U> - mln_ch_value(I,bool) - operator>=(const Image<I>& ima, const level_t<U>& v) - { - return data::transform(ima, fun::v2b::threshold_ge<mln_value(I)>(v.value)); - } - - template <typename I, typename U> - mln_ch_value(I,bool) - operator==(const Image<I>& ima, const level_t<U>& v) - { - return data::transform(ima, fun::v2b::compare<mln_value(I)>(v.value)); - } - -# endif // ! MLN_INCLUDE_ONLY - - } // end of namespace mln::util - -} // end of namespace mln - -#endif // ! MLN_UTIL_LEVEL_HH diff --git a/milena/mln/value/interval.hh b/milena/mln/value/interval.hh index fbc9da1..e2e9855 100644 --- a/milena/mln/value/interval.hh +++ b/milena/mln/value/interval.hh @@ -34,7 +34,6 @@ # include <iostream> # include <mln/value/inc.hh> # include <mln/value/concept/interval.hh> -# include <mln/util/level.hh> namespace mln @@ -43,9 +42,6 @@ namespace mln namespace value { - // Forward declaration. - template <unsigned n> class intsub; - template <unsigned n> class int_u; /// \brief Interval of values. template <typename T> @@ -344,47 +340,6 @@ namespace mln return ! (lhs == rhs); } - // thresholding - - template <typename T, typename U> - inline - bool - operator<=(const interval<T>& i, const util::level_t<U>& v) - { - return i.first() <= v.value; - } - - template <typename T, typename U> - inline - bool - operator>(const interval<T>& i, const util::level_t<U>& v) - { - return ! (i <= v); - } - - template <typename T, typename U> - inline - bool - operator>=(const interval<T>& i, const util::level_t<U>& v) - { - return v.value <= i.last(); - } - - template <typename T, typename U> - inline - bool - operator<(const interval<T>& i, const util::level_t<U>& v) - { - return ! (i >= v); - } - - template <typename T, typename U> - inline - bool - operator==(const interval<T>& i, const util::level_t<U>& v) - { - return i >= v && i <= v; - } // set ops diff --git a/milena/mln/world/kn/level.hh b/milena/mln/world/kn/level.hh new file mode 100644 index 0000000..eabba44 --- /dev/null +++ b/milena/mln/world/kn/level.hh @@ -0,0 +1,233 @@ +// 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_WORLD_KN_LEVEL_HH +# define MLN_WORLD_KN_LEVEL_HH + +# include <mln/core/concept/value.hh> +# include <mln/value/interval.hh> +# include <mln/data/transform.hh> +# include <mln/fun/v2b/threshold_lt.hh> +# include <mln/fun/v2b/threshold_le.hh> +# include <mln/fun/v2b/threshold_gt.hh> +# include <mln/fun/v2b/threshold_ge.hh> +# include <mln/fun/v2b/compare.hh> + +/// \file +/// +/// Definition of a level tag. + +namespace mln +{ + + namespace world + { + + namespace kn + { + + /// \brief Level tag structure. + template <typename T> + struct level_t + : public Object<level_t<T> > + { + const T& value; + explicit level_t(const T& value); + }; + + /// \brief construct a level tag. + template <typename T> + level_t<T> level(const T& value); + + + } // end of namespace mln::world::kn + + } // end of namespace mln::world + + namespace value + { + // Comparison operators with intervals + + template <typename T, typename U> + bool + operator<=(const interval<T>& i, const world::kn::level_t<U>& v); + + template <typename T, typename U> + bool + operator>(const interval<T>& i, const world::kn::level_t<U>& v); + + template <typename T, typename U> + bool + operator>=(const interval<T>& i, const world::kn::level_t<U>& v); + + template <typename T, typename U> + bool + operator<(const interval<T>& i, const world::kn::level_t<U>& v); + + template <typename T, typename U> + bool + operator==(const interval<T>& i, const world::kn::level_t<U>& v); + + } // end of namespace mln::value + + + // Comparison operators with images. + + template <typename I, typename U> + mln_ch_value(I,bool) + operator<(const Image<I>& ima, const world::kn::level_t<U>& v); + + template <typename I, typename U> + mln_ch_value(I,bool) + operator==(const Image<I>& ima, const world::kn::level_t<U>& v); + + + template <typename I, typename U> + mln_ch_value(I,bool) + operator>(const Image<I>& ima, const world::kn::level_t<U>& v); + + template <typename I, typename U> + mln_ch_value(I,bool) + operator>=(const Image<I>& ima, const world::kn::level_t<U>& v); + + +# ifndef MLN_INCLUDE_ONLY + + namespace world + { + + namespace kn + { + + template <typename T> + level_t<T>::level_t(const T& value) + : value(value) + { + } + + // Helpers + + template <typename T> + inline + level_t<T> level(const T& value) + { + return level_t<T>(value); + } + + } // end of namespace mln::world::kn + + } // end of namespace mln::world + + + namespace value + { + + // Comparison operators with intervals + + template <typename T, typename U> + inline + bool + operator<=(const interval<T>& i, const world::kn::level_t<U>& v) + { + return i.first() <= v.value; + } + + template <typename T, typename U> + inline + bool + operator>(const interval<T>& i, const world::kn::level_t<U>& v) + { + return ! (i <= v); + } + + template <typename T, typename U> + inline + bool + operator>=(const interval<T>& i, const world::kn::level_t<U>& v) + { + return v.value <= i.last(); + } + + template <typename T, typename U> + inline + bool + operator<(const interval<T>& i, const world::kn::level_t<U>& v) + { + return ! (i >= v); + } + + template <typename T, typename U> + inline + bool + operator==(const interval<T>& i, const world::kn::level_t<U>& v) + { + return i >= v && i <= v; + } + + } // end of namespace mln::value + + + // Comparison Operators with images + + template <typename I, typename U> + mln_ch_value(I,bool) + operator<(const Image<I>& ima, const world::kn::level_t<U>& v) + { + return data::transform(ima, fun::v2b::threshold_lt<mln_value(I)>(v.value)); + } + + template <typename I, typename U> + mln_ch_value(I,bool) + operator<=(const Image<I>& ima, const world::kn::level_t<U>& v) + { + return data::transform(ima, fun::v2b::threshold_le<mln_value(I)>(v.value)); + } + + template <typename I, typename U> + mln_ch_value(I,bool) + operator>(const Image<I>& ima, const world::kn::level_t<U>& v) + { + return data::transform(ima, fun::v2b::threshold_gt<mln_value(I)>(v.value)); + } + + template <typename I, typename U> + mln_ch_value(I,bool) + operator>=(const Image<I>& ima, const world::kn::level_t<U>& v) + { + return data::transform(ima, fun::v2b::threshold_ge<mln_value(I)>(v.value)); + } + + template <typename I, typename U> + mln_ch_value(I,bool) + operator==(const Image<I>& ima, const world::kn::level_t<U>& v) + { + return data::transform(ima, fun::v2b::compare<mln_value(I)>(v.value)); + } + +# endif // ! MLN_INCLUDE_ONLY + +} // end of namespace mln + +#endif // ! MLN_WORLD_KN_LEVEL_HH diff --git a/milena/tests/util/Makefile.am b/milena/tests/util/Makefile.am index 5bf503f..f60b0d8 100644 --- a/milena/tests/util/Makefile.am +++ b/milena/tests/util/Makefile.am @@ -27,7 +27,6 @@ check_PROGRAMS = \ graph \ lazy_set \ lemmings \ - level \ line_graph \ ord \ ord_pair \ @@ -45,7 +44,6 @@ fibonacci_heap_SOURCES = fibonacci_heap.cc graph_SOURCES = graph.cc lazy_set_SOURCES = lazy_set.cc lemmings_SOURCES = lemmings.cc -level_SOURCES = level.cc line_graph_SOURCES = line_graph.cc ord_SOURCES = ord.cc ord_pair_SOURCES = ord_pair.cc diff --git a/milena/tests/world/kn/Makefile.am b/milena/tests/world/kn/Makefile.am index 6996528..f88c698 100644 --- a/milena/tests/world/kn/Makefile.am +++ b/milena/tests/world/kn/Makefile.am @@ -30,6 +30,7 @@ check_PROGRAMS = \ is_1_face_vertical \ is_1_face_horizontal \ is_2_face \ + level \ un_immerse fill_0_1_faces_internal_border_SOURCES = fill_0_1_faces_internal_border.cc @@ -45,6 +46,7 @@ is_1_face_SOURCES = is_1_face.cc is_1_face_vertical_SOURCES = is_1_face_vertical.cc is_1_face_horizontal_SOURCES = is_1_face_horizontal.cc is_2_face_SOURCES = is_2_face.cc +level_SOURCES = level.cc un_immerse_SOURCES = un_immerse.cc diff --git a/milena/tests/util/level.cc b/milena/tests/world/kn/level.cc similarity index 68% rename from milena/tests/util/level.cc rename to milena/tests/world/kn/level.cc index 3626cef..9f902a3 100644 --- a/milena/tests/util/level.cc +++ b/milena/tests/world/kn/level.cc @@ -25,13 +25,17 @@ #include <mln/core/image/image2d.hh> #include <mln/debug/iota.hh> -#include <mln/util/level.hh> +#include <mln/world/kn/level.hh> #include <mln/data/compare.hh> #include <mln/make/image2d.hh> +#include <mln/value/interval.hh> +#include <mln/value/intsub.hh> int main () { using namespace mln; + using namespace mln::value; + using namespace mln::world::kn; bool vref_lt[] = { 1, 1, 1, 1, 1, @@ -73,15 +77,39 @@ int main () image2d<unsigned> ima(5,5); debug::iota(ima); - image2d<bool> imab_lt = (ima < util::level(15)); - mln_assertion(imab_lt == ref_lt); + // Comparison with images + { + image2d<bool> imab_lt = (ima < level(15)); + mln_assertion(imab_lt == ref_lt); - image2d<bool> imab_le = (ima <= util::level(15)); - mln_assertion(imab_le == ref_le); + image2d<bool> imab_le = (ima <= level(15)); + mln_assertion(imab_le == ref_le); - image2d<bool> imab_gt = (ima > util::level(15)); - mln_assertion(imab_gt == ref_gt); + image2d<bool> imab_gt = (ima > level(15)); + mln_assertion(imab_gt == ref_gt); - image2d<bool> imab_ge = (ima >= util::level(15)); - mln_assertion(imab_ge == ref_ge); + image2d<bool> imab_ge = (ima >= level(15)); + mln_assertion(imab_ge == ref_ge); + } + + // Comparison with intervals + { + + interval<intsub<2> > i(3, 10); + + mln_assertion(i < level(11)); + mln_assertion(i <= level(3)); + mln_assertion(i > level(2)); + mln_assertion(i >= level(10)); + } + + { + // i is degenerated. + interval<intsub<2> > i(3, 3); + mln_assertion(i == level(3)); + mln_assertion(i < level(4)); + mln_assertion(i <= level(3)); + mln_assertion(i > level(2)); + mln_assertion(i >= level(2)); + } } -- 1.7.2.5
participants (1)
-
Guillaume Lazzara