olena-2.0-32-ge5977cb 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. --- 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 | 8 +- 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, 162 insertions(+), 203 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 4ff88af..ea274e2 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,24 @@ +2012-10-03 Guillaume Lazzara <z@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@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 5c983e5..f74662f 100644 --- a/milena/mln/value/label.hh +++ b/milena/mln/value/label.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009, 2010, 2011 EPITA Research and +// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 EPITA Research and // Development Laboratory (LRDE) // // This file is part of Olena. @@ -173,8 +173,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; @@ -335,7 +335,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
participants (1)
-
Guillaume Lazzara