* mln/accu/all.hh: include new accumulators.
* mln/accu/count_labels.hh: count how many different labels are in an
image.
* mln/accu/label_used.hh: Reference all the different labels used.
---
milena/ChangeLog | 11 +++
milena/mln/accu/all.hh | 2 +
milena/mln/accu/count_labels.hh | 175 +++++++++++++++++++++++++++++++++++++++
milena/mln/accu/label_used.hh | 159 +++++++++++++++++++++++++++++++++++
4 files changed, 347 insertions(+), 0 deletions(-)
create mode 100644 milena/mln/accu/count_labels.hh
create mode 100644 milena/mln/accu/label_used.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index f07f826..c7c171e 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,14 @@
+2009-04-07 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Add new accumulators related to labels.
+
+ * mln/accu/all.hh: include new accumulators.
+
+ * mln/accu/count_labels.hh: count how many different labels are in an
+ image.
+
+ * mln/accu/label_used.hh: Reference all the different labels used.
+
2009-04-06 Frederic Bour <bour(a)lrde.epita.fr>
Clean new fun implementation.
diff --git a/milena/mln/accu/all.hh b/milena/mln/accu/all.hh
index 0e4d72d..5dfe51e 100644
--- a/milena/mln/accu/all.hh
+++ b/milena/mln/accu/all.hh
@@ -58,10 +58,12 @@ namespace mln
# include <mln/accu/bbox.hh>
# include <mln/accu/count.hh>
+# include <mln/accu/count_labels.hh>
# include <mln/accu/center.hh>
//# include <mln/accu/count_adjacent_vertices.hh>
# include <mln/accu/height.hh>
# include <mln/accu/histo.hh>
+# include <mln/accu/label_used.hh>
# include <mln/accu/land.hh>
# include <mln/accu/land_basic.hh>
# include <mln/accu/line.hh>
diff --git a/milena/mln/accu/count_labels.hh b/milena/mln/accu/count_labels.hh
new file mode 100644
index 0000000..533e736
--- /dev/null
+++ b/milena/mln/accu/count_labels.hh
@@ -0,0 +1,175 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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_ACCU_COUNT_LABELS_HH
+# define MLN_ACCU_COUNT_LABELS_HH
+
+/// \file mln/accu/count_labels.hh
+///
+/// Define an accumulator that counts the number of different labels.
+
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/metal/is_a.hh>
+
+namespace mln
+{
+
+ // Forward declaration.
+ namespace value { template <typename E> struct Symbolic; }
+
+ namespace accu
+ {
+
+ /// Generic counter accumulator class.
+ /// The parameter \a L is the label type to be count.
+ template <typename L>
+ struct count_labels
+ : public mln::accu::internal::base< unsigned , count_labels<L> >,
+ mlc_is_a(L, mln::value::Symbolic)::check_t
+ {
+ typedef L argument;
+
+ count_labels();
+
+ /// Manipulators.
+ /// \{
+ void init();
+ void take(const argument&);
+ void take(const count_labels<L>& other);
+
+ /// Force the value of the counter to \a c.
+ void set_value(unsigned c);
+ /// \}
+
+ /// Get the value of the accumulator.
+ unsigned to_result() const;
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+ /// The value of the counter.
+ unsigned count_labels_;
+ std::vector<bool> deja_vu_;
+ };
+
+
+ namespace meta
+ {
+
+ /// Meta accumulator for count_labels.
+ struct count_labels : public Meta_Accumulator< count_labels >
+ {
+ template <typename L>
+ struct with
+ {
+ typedef accu::count_labels<L> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ inline
+ count_labels<L>::count_labels()
+ {
+ init();
+ }
+
+ template <typename L>
+ inline
+ void
+ count_labels<L>::init()
+ {
+ count_labels_ = 0;
+ deja_vu_.resize(mln_max(L), false);
+ }
+
+ template <typename L>
+ inline
+ void
+ count_labels<L>::take(const argument& l)
+ {
+ if (!deja_vu_[l])
+ {
+ ++count_labels_;
+ deja_vu_[l] = true;
+ }
+ //else
+ // No-op
+ }
+
+ template <typename L>
+ inline
+ void
+ count_labels<L>::take(const count_labels<L>& other)
+ {
+ count_labels_ += other.count_labels_;
+ for (unsigned i = 0; i < deja_vu_.size(); ++i)
+ deja_vu_[i] = deja_vu_[i] || other.deja_vu_[i];
+ }
+
+ template <typename L>
+ inline
+ unsigned
+ count_labels<L>::to_result() const
+ {
+ // The background label MUST not be counted.
+ return count_labels_ - 1;
+ }
+
+ template <typename L>
+ inline
+ void
+ count_labels<L>::set_value(unsigned c)
+ {
+ count_labels_ = c;
+ }
+
+ template <typename L>
+ inline
+ bool
+ count_labels<L>::is_valid() const
+ {
+ return true;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_COUNT_LABELS_HH
diff --git a/milena/mln/accu/label_used.hh b/milena/mln/accu/label_used.hh
new file mode 100644
index 0000000..6323d3e
--- /dev/null
+++ b/milena/mln/accu/label_used.hh
@@ -0,0 +1,159 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory
+// (LRDE)
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library 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 this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library 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_ACCU_LABEL_USED_HH
+# define MLN_ACCU_LABEL_USED_HH
+
+/// \file mln/accu/label_used.hh
+///
+/// Define an accumulator that references all the labels used.
+
+# include <mln/accu/internal/base.hh>
+# include <mln/core/concept/meta_accumulator.hh>
+# include <mln/math/max.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+ /// Define an accumulator that references all the labels used.
+ /// The parameter \a L is the label type.
+ template <typename L>
+ struct label_used : public mln::accu::internal::base< const
fun::i2v::array<bool>& , label_used<L> >
+ {
+ typedef L argument;
+
+ label_used();
+
+ /// Initialize accumulator attributes.
+ void init();
+
+ /// Manipulators.
+ /// \{
+ void take(const argument&);
+ void take(const label_used<L>& other);
+ /// \}
+
+ /// Get the value of the accumulator.
+ const fun::i2v::array<bool>& to_result() const;
+
+ /// Check whether this accu is able to return a result.
+ /// Always true here.
+ bool is_valid() const;
+
+ protected:
+ /// True if a label is used.
+ fun::i2v::array<bool> label_used_;
+ };
+
+
+ namespace meta
+ {
+
+ /// Meta accumulator for label_used.
+ struct label_used : public Meta_Accumulator< label_used >
+ {
+ template <typename L>
+ struct with
+ {
+ typedef accu::label_used<L> ret;
+ };
+ };
+
+ } // end of namespace mln::accu::meta
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ inline
+ label_used<L>::label_used()
+ {
+ init();
+ }
+
+ template <typename L>
+ inline
+ void
+ label_used<L>::init()
+ {
+ label_used_.resize(1, true);
+ }
+
+ template <typename L>
+ inline
+ void
+ label_used<L>::take(const argument& l)
+ {
+ if (label_used_.size() <= l)
+ label_used_.resize(l.next(), false);
+
+ label_used_(l) = true;
+ }
+
+ template <typename L>
+ inline
+ void
+ label_used<L>::take(const label_used<L>& other)
+ {
+ unsigned
+ max_size = math::max(other.to_result().size(), label_used_.size());
+
+ label_used_.resize(max_size, false);
+ for (unsigned i = 1; i < label_used_.size(); ++i)
+ label_used_(i) = label_used_(i) || other.to_result()(i);
+ }
+
+ template <typename L>
+ inline
+ const fun::i2v::array<bool>&
+ label_used<L>::to_result() const
+ {
+ return label_used_;
+ }
+
+ template <typename L>
+ inline
+ bool
+ label_used<L>::is_valid() const
+ {
+ return true;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_LABEL_USED_HH
--
1.5.6.5