* mln/canvas/labeling/all.hh,
* mln/canvas/labeling/essential.hh: New.
* mln/canvas/labeling.hh: Move and split into...
* mln/canvas/labeling/generic.hh,
* mln/canvas/labeling/internal/find_root_fastest.hh,
* mln/canvas/labeling/internal/tests.hh,
* mln/canvas/labeling/sorted.hh,
* mln/canvas/labeling/video.hh: ... these files.
* tests/labeling/flat_zones.cc,
* 6tests/labeling/foreground.cc,
* mln/canvas/all.hh,
* mln/canvas/essential.hh,
* mln/labeling/flat_zones.hh,
* mln/labeling/regional_maxima.hh,
* mln/labeling/regional_minima.hh,
* mln/labeling/value.hh: Update includes and function calls.
---
milena/ChangeLog | 24 +
milena/mln/canvas/all.hh | 2 +-
milena/mln/canvas/essential.hh | 5 +-
milena/mln/canvas/labeling.hh | 616 --------------------
milena/mln/canvas/{ => labeling}/all.hh | 31 +-
milena/mln/canvas/{ => labeling}/essential.hh | 21 +-
milena/mln/canvas/labeling/generic.hh | 193 ++++++
.../internal/find_root_fastest.hh} | 52 ++-
.../canvas/{all.hh => labeling/internal/tests.hh} | 59 ++-
milena/mln/canvas/labeling/sorted.hh | 283 +++++++++
milena/mln/canvas/labeling/video.hh | 262 +++++++++
milena/mln/labeling/flat_zones.hh | 8 +-
milena/mln/labeling/regional_maxima.hh | 9 +-
milena/mln/labeling/regional_minima.hh | 13 +-
milena/mln/labeling/value.hh | 11 +-
milena/tests/labeling/flat_zones.cc | 21 +-
milena/tests/labeling/foreground.cc | 9 +-
17 files changed, 908 insertions(+), 711 deletions(-)
delete mode 100644 milena/mln/canvas/labeling.hh
copy milena/mln/canvas/{ => labeling}/all.hh (68%)
copy milena/mln/canvas/{ => labeling}/essential.hh (73%)
create mode 100644 milena/mln/canvas/labeling/generic.hh
copy milena/mln/canvas/{all.hh => labeling/internal/find_root_fastest.hh} (59%)
copy milena/mln/canvas/{all.hh => labeling/internal/tests.hh} (52%)
create mode 100644 milena/mln/canvas/labeling/sorted.hh
create mode 100644 milena/mln/canvas/labeling/video.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1d495c1..896aad1 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,27 @@
+2009-08-21 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
+
+ Split canvas/labeling.hh into separate files.
+
+ * mln/canvas/labeling/all.hh,
+ * mln/canvas/labeling/essential.hh: New.
+
+ * mln/canvas/labeling.hh: Move and split into...
+
+ * mln/canvas/labeling/generic.hh,
+ * mln/canvas/labeling/internal/find_root_fastest.hh,
+ * mln/canvas/labeling/internal/tests.hh,
+ * mln/canvas/labeling/sorted.hh,
+ * mln/canvas/labeling/video.hh: ... these files.
+
+ * tests/labeling/flat_zones.cc,
+ * tests/labeling/foreground.cc,
+ * mln/canvas/all.hh,
+ * mln/canvas/essential.hh,
+ * mln/labeling/flat_zones.hh,
+ * mln/labeling/regional_maxima.hh,
+ * mln/labeling/regional_minima.hh,
+ * mln/labeling/value.hh: Update includes and function calls.
+
2009-08-21 Yann Jacquelet <jacquelet(a)lrde.epita.fr>
Remove extra ";" to compile.
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/all.hh
index b5ae38c..76ee819 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/all.hh
@@ -50,7 +50,7 @@ namespace mln
# include <mln/canvas/chamfer.hh>
# include <mln/canvas/distance_front.hh>
# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/all.hh>
#endif // ! MLN_CANVAS_ALL_HH
diff --git a/milena/mln/canvas/essential.hh b/milena/mln/canvas/essential.hh
index 88ea809..5184aae 100644
--- a/milena/mln/canvas/essential.hh
+++ b/milena/mln/canvas/essential.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -34,6 +35,6 @@
# include <mln/canvas/browsing/essential.hh>
# include <mln/canvas/morpho/essential.hh>
# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/essential.hh>
#endif // ! MLN_CANVAS_ESSENTIAL_HH
diff --git a/milena/mln/canvas/labeling.hh b/milena/mln/canvas/labeling.hh
deleted file mode 100644
index c999380..0000000
--- a/milena/mln/canvas/labeling.hh
+++ /dev/null
@@ -1,616 +0,0 @@
-// Copyright (C) 2007, 2008, 2009 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_CANVAS_LABELING_HH
-# define MLN_CANVAS_LABELING_HH
-
-/// \file
-///
-/// Connected component labeling of the object part in a binary image.
-///
-/// \todo Can we get rid of 'deja_vu' (while playing with the border)
-/// in the fastest video version?
-
-# include <mln/core/concept/image.hh>
-# include <mln/data/fill.hh>
-# include <mln/literal/zero.hh>
-# include <mln/convert/to_upper_window.hh>
-# include <mln/extension/adjust_fill.hh>
-
-# include <mln/data/sort_psites.hh>
-# include <mln/data/sort_offsets.hh>
-
-
-namespace mln
-{
-
- namespace canvas
- {
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_video(const Image<I>& input, const Neighborhood<N>& nbh,
L& nlabels,
- F& functor);
-
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_sorted(const Image<I>& input, const Neighborhood<N>&
nbh, L& nlabels,
- F& functor, bool increasing);
-
-
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- // Tests.
-
- namespace internal
- {
-
- template <typename I, typename N, typename L,
- typename F>
- void
- labeling_tests(const Image<I>& input_, const Neighborhood<N>&
nbh_, const L& nlabels,
- const F& f)
- {
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- mln_precondition(input.is_valid());
- // mln_precondition(nbh.is_valid());
-
- (void) input;
- (void) nbh;
- (void) nlabels;
- (void) f;
- }
-
- } // end of namespace mln::canvas::internal
-
-
-
- // Implementations.
-
- namespace impl
- {
-
- namespace generic
- {
-
- template <typename I>
- static inline
- mln_psite(I)
- find_root(I& parent, const mln_psite(I)& x)
- {
- if (parent(x) == x)
- return x;
- else
- return parent(x) = find_root(parent, parent(x));
- }
-
- template <typename I, typename N, typename L,
- typename S, typename F>
- mln_ch_value(I, L)
- labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
L& nlabels,
- const Site_Set<S>& s_, F& f)
- {
- trace::entering("canvas::impl::generic::labeling");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
- const S& s = exact(s_);
-
- // Local type.
- typedef mln_psite(I) P;
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, P) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status; // FIXME: Is-it useful?
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, false);
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init(); // Client initialization.
- }
-
- // First Pass.
- {
- mln_bkd_piter(S) p(s); // Backward.
- mln_niter(N) n(nbh, p);
- for_all(p) if (f.handles(p))
- {
- // Make-Set.
- parent(p) = p;
- f.init_attr(p);
-
- for_all(n)
- if (input.domain().has(n) && deja_vu(n))
- {
- if (f.equiv(n, p))
- {
- // Do-Union.
- P r = find_root(parent, n);
- if (r != p)
- {
- parent(r) = p;
- f.merge_attr(r, p);
- }
- }
- else
- f.do_no_union(n, p);
- }
- deja_vu(p) = true;
- }
- }
-
- // Second Pass.
- {
- mln_fwd_piter(S) p(s); // Forward.
- for_all(p) if (f.handles(p))
- {
- if (parent(p) == p) // if p is root
- {
- if (f.labels(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels \
- for this label type: nlabels > \
- max(label_type).");
-
- return output;
- }
- output(p) = ++nlabels;
- }
- }
- else
- output(p) = output(parent(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::generic::labeling");
- return output;
- }
-
- } // end of namespace mln::canvas::impl::generic
-
-
-
- // Fastest video version.
-
- template <typename I>
- static inline
- unsigned
- find_root_fastest(I& parent, unsigned x)
- {
- if (parent.element(x) == x)
- return x;
- else
- return parent.element(x) = find_root_fastest(parent, parent.element(x));
- }
-
-
- template <typename I, typename N, typename L,
- typename F>
- mln_ch_value(I, L)
- labeling_video_fastest(const Image<I>& input_, const
Neighborhood<N>& nbh_,
- L& nlabels, F& f)
- {
- trace::entering("canvas::impl::labeling_video_fastest");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- extension::adjust(input, nbh);
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, unsigned) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status;
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, true);
- extension::fill(deja_vu, false); // So that the extension is ignored.
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init_(); // Client initialization.
- }
-
- // First Pass.
- {
- util::array<int> dp = positive_offsets_wrt(input, nbh);
- const unsigned n_nbhs = dp.nelements();
-
- mln_bkd_pixter(const I) px(input); // Backward.
- for_all(px)
- {
- unsigned p = px.offset();
- if (! f.handles_(p))
- continue;
-
- // Make-Set.
- parent.element(p) = p;
- f.init_attr_(p);
- for (unsigned i = 0; i < n_nbhs; ++i)
- {
- unsigned n = p + dp[i];
- if (deja_vu.element(n)) // Only false in the external border.
- {
- if (f.equiv_(n, p))
- {
- // Do-Union.
- unsigned r = find_root_fastest(parent, n);
- if (r != p)
- {
- parent.element(r) = p;
- f.merge_attr_(r, p);
- }
- }
- else
- f.do_no_union_(n, p);
- }
- }
- }
- }
-
- // Second Pass.
- {
- mln_fwd_pixter(const I) px(input); // Forward.
- for_all(px)
- {
- unsigned p = px.offset();
- if (! f.handles_(p))
- continue;
- if (parent.element(p) == p) // if p is root
- {
- if (f.labels_(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels for \
- this label type: nlabels > \
- max(label_type).");
- return output;
- }
- output.element(p) = ++nlabels;
- }
- }
- else
- output.element(p) = output.element(parent.element(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::labeling_video_fastest");
- return output;
- }
-
-
-
- // Fastest sorted version
-
- template <typename I, typename N, typename L,
- typename S, typename F>
- mln_ch_value(I, L)
- labeling_sorted_fastest(const Image<I>& input_, const
Neighborhood<N>& nbh_, L& nlabels,
- const S& s, F& f)
- {
- trace::entering("canvas::impl::labeling_sorted_fastest");
-
- // FIXME: Test?!
-
- const I& input = exact(input_);
- const N& nbh = exact(nbh_);
-
- extension::adjust(input, nbh);
-
- // Local type.
- typedef mln_psite(I) P;
-
- // Auxiliary data.
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, unsigned) parent;
-
- // Output.
- mln_ch_value(I, L) output;
- bool status;
-
- // Initialization.
- {
- initialize(deja_vu, input);
- mln::data::fill(deja_vu, false);
- extension::fill(deja_vu, false); // So that the extension is ignored.
-
- initialize(parent, input);
-
- initialize(output, input);
- mln::data::fill(output, L(literal::zero));
- nlabels = 0;
-
- f.init_(); // Client initialization.
- }
-
- util::array<int> dp = offsets_wrt(input, nbh);
- const unsigned n_nbhs = dp.nelements();
-
- const unsigned n_points = s.nelements();
-
- // First Pass.
- {
- for (int i = n_points - 1; i >=0; --i) // Backward.
- {
- unsigned p = s[i];
- if (! f.handles_(p))
- continue;
-
- // Make-Set.
- parent.element(p) = p;
- f.init_attr_(p);
-
- for (unsigned j = 0; j < n_nbhs; ++j)
- {
- unsigned n = p + dp[j];
- if (! deja_vu.element(n))
- continue;
-
- if (f.equiv_(n, p))
- {
- // Do-Union.
- unsigned r = find_root_fastest(parent, n);
- if (r != p)
- {
- parent.element(r) = p;
- f.merge_attr_(r, p);
- }
- }
- else
- f.do_no_union_(n, p);
- }
- deja_vu.element(p) = true;
- }
- }
-
- // Second Pass.
- {
- for (unsigned i = 0; i < n_points; ++i) // Forward.
- {
- unsigned p = s[i];
- if (! f.handles_(p))
- continue;
-
- if (parent.element(p) == p) // if p is root
- {
- if (f.labels_(p))
- {
- if (nlabels == mln_max(L))
- {
- status = false;
- trace::warning("labeling aborted! Too many labels \
- for this label type: nlabels > \
- max(label_type).");
- return output;
- }
- output.element(p) = ++nlabels;
- }
- }
- else
- output.element(p) = output.element(parent.element(p));
- }
- status = true;
- }
-
- trace::exiting("canvas::impl::labeling_sorted_fastest");
- return output;
- }
-
- } // end of namespace mln::canvas::impl
-
-
-
- // Dispatch.
-
- namespace internal
- {
-
- // Video
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(metal::false_,
- const Image<I>& input, const Neighborhood<N>& nbh, L&
nlabels,
- F& functor)
- {
- return impl::generic::labeling(input, nbh, nlabels, exact(input).domain(),
- functor);
- }
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(metal::true_,
- const Image<I>& input, const Neighborhood<N>& nbh, L&
nlabels,
- F& functor)
- {
- return impl::labeling_video_fastest(input, nbh, nlabels, functor);
- }
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video_dispatch(const Image<I>& input, const
Neighborhood<N>& nbh, L& nlabels,
- F& functor)
- {
- enum {
- test = mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value
- &&
- mln_is_simple_neighborhood(N)::value
- };
- return labeling_video_dispatch(metal::bool_<test>(),
- input, nbh, nlabels,
- functor);
- }
-
-
- // Sorted dispatch.
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(metal::false_,
- const Image<I>& input, const Neighborhood<N>& nbh, L&
nlabels,
- F& functor, bool increasing)
- {
- p_array<mln_psite(I)> s =
- increasing ?
- data::sort_psites_increasing(input) :
- data::sort_psites_decreasing(input);
- return impl::generic::labeling(input, nbh, nlabels, s,
- functor);
- }
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(metal::true_,
- const Image<I>& input, const Neighborhood<N>& nbh, L&
nlabels,
- F& functor, bool increasing)
- {
- util::array<unsigned> s =
- increasing ?
- data::sort_offsets_increasing(input) :
- data::sort_offsets_decreasing(input);
- return impl::labeling_sorted_fastest(input, nbh, nlabels, s,
- functor);
- }
-
- template <typename I, typename N, typename L, typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted_dispatch(const Image<I>& input, const
Neighborhood<N>& nbh, L& nlabels,
- F& functor, bool increasing)
- {
- enum {
- test = mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value
- &&
- mln_is_simple_neighborhood(N)::value
- };
- return labeling_sorted_dispatch(metal::bool_<test>(),
- input, nbh, nlabels,
- functor, increasing);
- }
-
-
- } // end of namespace mln::canvas::internal
-
-
-
- // Facades.
-
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_video(const Image<I>& input, const Neighborhood<N>& nbh,
L& nlabels,
- F& functor)
- {
- trace::entering("canvas::labeling_video");
-
- internal::labeling_tests(input, nbh, nlabels, functor);
-
- mln_ch_value(I, L) output;
- output = internal::labeling_video_dispatch(input, nbh, nlabels,
- functor);
-
- trace::exiting("canvas::labeling_video");
- return output;
- }
-
-
- template <typename I, typename N, typename L,
- typename F>
- inline
- mln_ch_value(I, L)
- labeling_sorted(const Image<I>& input, const Neighborhood<N>&
nbh, L& nlabels,
- F& functor, bool increasing)
- {
- trace::entering("canvas::labeling_sorted");
-
- internal::labeling_tests(input, nbh, nlabels, functor);
-
- mln_ch_value(I, L) output;
- output = internal::labeling_sorted_dispatch(input, nbh, nlabels,
- functor, increasing);
-
- trace::exiting("canvas::labeling_sorted");
- return output;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::canvas
-
-} // end of namespace mln
-
-
-#endif // ! MLN_CANVAS_LABELING_HH
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/labeling/all.hh
similarity index 68%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/all.hh
index b5ae38c..5ee97de 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/all.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,12 +23,12 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_ALL_HH
+# define MLN_CANVAS_LABELING_ALL_HH
/// \file
///
-/// File that includes all canvas-related routines.
+/// File that includes all labeling canvas-related routines.
namespace mln
@@ -38,19 +38,22 @@ namespace mln
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ /// Namespace of labeling canvas.
+ namespace labeling
+ {
+
+ /// Implementation namespace of labeling canvas namespace.
+ namespace impl {}
+
+ }
}
}
-
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/blobs.hh>
+# include <mln/canvas/labeling/generic.hh>
+# include <mln/canvas/labeling/video.hh>
+# include <mln/canvas/labeling/sorted.hh>
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_ALL_HH
diff --git a/milena/mln/canvas/essential.hh b/milena/mln/canvas/labeling/essential.hh
similarity index 73%
copy from milena/mln/canvas/essential.hh
copy to milena/mln/canvas/labeling/essential.hh
index 88ea809..a68bec4 100644
--- a/milena/mln/canvas/essential.hh
+++ b/milena/mln/canvas/labeling/essential.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,17 +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_CANVAS_ESSENTIAL_HH
-# define MLN_CANVAS_ESSENTIAL_HH
+#ifndef MLN_CANVAS_LABELING_ESSENTIAL_HH
+# define MLN_CANVAS_LABELING_ESSENTIAL_HH
-/*! \file
- *
- * \brief File that includes the most useful canvas-related routines.
- */
+/// \file
+///
+/// File that includes essential labeling canvas-related routines.
-# include <mln/canvas/browsing/essential.hh>
-# include <mln/canvas/morpho/essential.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/labeling.hh>
-#endif // ! MLN_CANVAS_ESSENTIAL_HH
+# include <mln/canvas/labeling/all.hh>
+
+#endif // ! MLN_CANVAS_LABELING_ESSENTIAL_HH
diff --git a/milena/mln/canvas/labeling/generic.hh
b/milena/mln/canvas/labeling/generic.hh
new file mode 100644
index 0000000..b701e42
--- /dev/null
+++ b/milena/mln/canvas/labeling/generic.hh
@@ -0,0 +1,193 @@
+// Copyright (C) 2009 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_CANVAS_LABELING_GENERIC_HH
+# define MLN_CANVAS_LABELING_GENERIC_HH
+
+/// \file
+///
+/// Generic Connected component labeling of the object part in a
+/// binary image.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/site_set.hh>
+
+# include <mln/data/fill.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ namespace impl
+ {
+
+ namespace generic
+ {
+
+ /// Generic Connected component labeling of the object part in a
+ /// binary image.
+ //
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, const Site_Set<S>& s_, F& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ static inline
+ mln_psite(I)
+ find_root(I& parent, const mln_psite(I)& x)
+ {
+ if (parent(x) == x)
+ return x;
+ else
+ return parent(x) = find_root(parent, parent(x));
+ }
+
+
+
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ labeling(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ L& nlabels, const Site_Set<S>& s_, F& f)
+ {
+ trace::entering("canvas::labeling::impl::generic::labeling");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+ const S& s = exact(s_);
+
+ // Local type.
+ typedef mln_psite(I) P;
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, P) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status; // FIXME: Is-it useful?
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, false);
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init(); // <-- f.init() - Client initialization.
+ }
+
+ // First Pass.
+ {
+ mln_bkd_piter(S) p(s); // Backward.
+ mln_niter(N) n(nbh, p);
+ for_all(p) if (f.handles(p)) // <-- f.handles()
+ {
+ // Make-Set.
+ parent(p) = p;
+ f.init_attr(p);
+
+ for_all(n)
+ if (input.domain().has(n) && deja_vu(n))
+ {
+ if (f.equiv(n, p)) // <-- f.equiv()
+ {
+ // Do-Union.
+ P r = find_root(parent, n);
+ if (r != p)
+ {
+ parent(r) = p;
+ f.merge_attr(r, p); // <-- f.merge_attr()
+ }
+ }
+ else
+ f.do_no_union(n, p); // <-- f.do_no_union()
+ }
+ deja_vu(p) = true;
+ }
+ }
+
+ // Second Pass.
+ {
+ mln_fwd_piter(S) p(s); // Forward.
+ for_all(p) if (f.handles(p)) // <-- f.handles()
+ {
+ if (parent(p) == p) // if p is root
+ {
+ if (f.labels(p)) // <-- f.labels()
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels \
+ for this label type: nlabels > \
+ max(label_type).");
+
+ return output;
+ }
+ output(p) = ++nlabels;
+ }
+ }
+ else
+ output(p) = output(parent(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::labeling::impl::generic::labeling");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling::impl::generic
+
+ } // end of namespace mln::canvas::labeling::impl
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_GENERIC_HH
diff --git a/milena/mln/canvas/all.hh
b/milena/mln/canvas/labeling/internal/find_root_fastest.hh
similarity index 59%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/internal/find_root_fastest.hh
index b5ae38c..8af3eac 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/internal/find_root_fastest.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,34 +23,52 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
+# define MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
/// \file
///
-/// File that includes all canvas-related routines.
-
+/// Shared 'find root' function for labeling canvas.
namespace mln
{
- /// Namespace of canvas.
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ namespace labeling
+ {
+
+ namespace internal
+ {
+
+ template <typename I>
+ unsigned
+ find_root_fastest(I& parent, unsigned x);
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I>
+ inline
+ unsigned
+ find_root_fastest(I& parent, unsigned x)
+ {
+ if (parent.element(x) == x)
+ return x;
+ else
+ return parent.element(x) = find_root_fastest(parent,
+ parent.element(x));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace mln::canvas::internal
+ } // end of namespace mln::canvas::labeling
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+ } // end of namespace mln::canvas
+} // end of namespace mln
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_INTERNAL_FIND_ROOT_FASTEST_HH
diff --git a/milena/mln/canvas/all.hh b/milena/mln/canvas/labeling/internal/tests.hh
similarity index 52%
copy from milena/mln/canvas/all.hh
copy to milena/mln/canvas/labeling/internal/tests.hh
index b5ae38c..d1b9cf7 100644
--- a/milena/mln/canvas/all.hh
+++ b/milena/mln/canvas/labeling/internal/tests.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,34 +23,59 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_CANVAS_ALL_HH
-# define MLN_CANVAS_ALL_HH
+#ifndef MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
+# define MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
/// \file
///
-/// File that includes all canvas-related routines.
-
+/// Shared tests for labeling canvas arguments.
namespace mln
{
- /// Namespace of canvas.
namespace canvas
{
- /// Implementation namespace of canvas namespace.
- namespace impl {}
+ namespace labeling
+ {
+
+ namespace internal
+ {
+
+
+ template <typename I, typename N, typename L, typename F>
+ void
+ labeling_tests(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ const L& nlabels, const F& f);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename N, typename L, typename F>
+ void
+ labeling_tests(const Image<I>& input_, const Neighborhood<N>& nbh_,
+ const L& nlabels, const F& f)
+ {
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(input.is_valid());
+ // mln_precondition(nbh.is_valid());
+
+ (void) input;
+ (void) nbh;
+ (void) nlabels;
+ (void) f;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace mln::canvas::internal
+ } // end of namespace mln::canvas::labeling
-# include <mln/canvas/browsing/all.hh>
-# include <mln/canvas/morpho/all.hh>
-# include <mln/canvas/chamfer.hh>
-# include <mln/canvas/distance_front.hh>
-# include <mln/canvas/distance_geodesic.hh>
-# include <mln/canvas/labeling.hh>
+ } // end of namespace mln::canvas
+} // end of namespace mln
-#endif // ! MLN_CANVAS_ALL_HH
+#endif // ! MLN_CANVAS_LABELING_INTERNAL_TESTS_HH
diff --git a/milena/mln/canvas/labeling/sorted.hh b/milena/mln/canvas/labeling/sorted.hh
new file mode 100644
index 0000000..4f7dd5f
--- /dev/null
+++ b/milena/mln/canvas/labeling/sorted.hh
@@ -0,0 +1,283 @@
+// Copyright (C) 2009 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_CANVAS_LABELING_SORTED_HH
+# define MLN_CANVAS_LABELING_SORTED_HH
+
+/// \file
+///
+/// Fast connected component labeling of the object part in a binary image.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/fill.hh>
+# include <mln/literal/zero.hh>
+# include <mln/extension/adjust_fill.hh>
+
+# include <mln/data/sort_psites.hh>
+# include <mln/data/sort_offsets.hh>
+
+# include <mln/canvas/labeling/generic.hh>
+# include <mln/canvas/labeling/internal/tests.hh>
+# include <mln/canvas/labeling/internal/find_root_fastest.hh>
+
+
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor, bool increasing);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ // Fastest sorted version
+
+ template <typename I, typename N, typename L,
+ typename S, typename F>
+ mln_ch_value(I, L)
+ sorted_fastest(const Image<I>& input_,
+ const Neighborhood<N>& nbh_, L& nlabels,
+ const S& s, F& f)
+ {
+ trace::entering("canvas::impl::labeling::sorted_fastest");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ extension::adjust(input, nbh);
+
+ // Local type.
+ typedef mln_psite(I) P;
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, unsigned) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status;
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, false);
+ extension::fill(deja_vu, false); // So that the extension is ignored.
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init_(); // Client initialization.
+ }
+
+ util::array<int> dp = offsets_wrt(input, nbh);
+ const unsigned n_nbhs = dp.nelements();
+
+ const unsigned n_points = s.nelements();
+
+ // First Pass.
+ {
+ for (int i = n_points - 1; i >=0; --i) // Backward.
+ {
+ unsigned p = s[i];
+ if (! f.handles_(p))
+ continue;
+
+ // Make-Set.
+ parent.element(p) = p;
+ f.init_attr_(p);
+
+ for (unsigned j = 0; j < n_nbhs; ++j)
+ {
+ unsigned n = p + dp[j];
+ if (! deja_vu.element(n))
+ continue;
+
+ if (f.equiv_(n, p))
+ {
+ // Do-Union.
+ unsigned r = internal::find_root_fastest(parent, n);
+ if (r != p)
+ {
+ parent.element(r) = p;
+ f.merge_attr_(r, p);
+ }
+ }
+ else
+ f.do_no_union_(n, p);
+ }
+ deja_vu.element(p) = true;
+ }
+ }
+
+ // Second Pass.
+ {
+ for (unsigned i = 0; i < n_points; ++i) // Forward.
+ {
+ unsigned p = s[i];
+ if (! f.handles_(p))
+ continue;
+
+ if (parent.element(p) == p) // if p is root
+ {
+ if (f.labels_(p))
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels \
+ for this label type: nlabels > \
+ max(label_type).");
+ return output;
+ }
+ output.element(p) = ++nlabels;
+ }
+ }
+ else
+ output.element(p) = output.element(parent.element(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::impl::labeling::sorted_fastest");
+ return output;
+ }
+
+ } // end of namespace mln::canvas::impl
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(metal::false_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ p_array<mln_psite(I)> s =
+ increasing ?
+ data::sort_psites_increasing(input) :
+ data::sort_psites_decreasing(input);
+ return impl::generic::labeling(input, nbh, nlabels, s,
+ functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(metal::true_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ util::array<unsigned> s =
+ increasing ?
+ data::sort_offsets_increasing(input) :
+ data::sort_offsets_decreasing(input);
+ return impl::sorted_fastest(input, nbh, nlabels, s,
+ functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted_dispatch(const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor, bool increasing)
+ {
+ enum {
+ test = mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ };
+ return sorted_dispatch(metal::bool_<test>(),
+ input, nbh, nlabels,
+ functor, increasing);
+ }
+
+
+ } // end of namespace mln::canvas::internal
+
+
+
+ // Facades.
+
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ sorted(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor, bool increasing)
+ {
+ trace::entering("canvas::labeling::sorted");
+
+ internal::labeling_tests(input, nbh, nlabels, functor);
+
+ mln_ch_value(I, L) output;
+ output = internal::sorted_dispatch(input, nbh, nlabels,
+ functor, increasing);
+
+ trace::exiting("canvas::labeling::sorted");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_SORTED_HH
diff --git a/milena/mln/canvas/labeling/video.hh b/milena/mln/canvas/labeling/video.hh
new file mode 100644
index 0000000..31afda4
--- /dev/null
+++ b/milena/mln/canvas/labeling/video.hh
@@ -0,0 +1,262 @@
+// Copyright (C) 2007, 2008, 2009 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_CANVAS_LABELING_VIDEO_HH
+# define MLN_CANVAS_LABELING_VIDEO_HH
+
+/// \file
+///
+/// Fast connected component labeling of the object part in a binary image.
+///
+/// \todo Can we get rid of 'deja_vu' (while playing with the border)
+/// in the fastest video version?
+
+# include <mln/core/concept/image.hh>
+# include <mln/data/fill.hh>
+# include <mln/literal/zero.hh>
+# include <mln/extension/adjust_fill.hh>
+
+# include <mln/canvas/labeling/internal/tests.hh>
+# include <mln/canvas/labeling/internal/find_root_fastest.hh>
+# include <mln/canvas/labeling/generic.hh>
+
+namespace mln
+{
+
+ namespace canvas
+ {
+
+ namespace labeling
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ video(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+ namespace impl
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ mln_ch_value(I, L)
+ video_fastest(const Image<I>& input_,
+ const Neighborhood<N>& nbh_,
+ L& nlabels, F& f)
+ {
+ trace::entering("canvas::impl::video_fastest");
+
+ // FIXME: Test?!
+
+ const I& input = exact(input_);
+ const N& nbh = exact(nbh_);
+
+ extension::adjust(input, nbh);
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, unsigned) parent;
+
+ // Output.
+ mln_ch_value(I, L) output;
+ bool status;
+
+ // Initialization.
+ {
+ initialize(deja_vu, input);
+ mln::data::fill(deja_vu, true);
+ extension::fill(deja_vu, false); // So that the extension is ignored.
+
+ initialize(parent, input);
+
+ initialize(output, input);
+ mln::data::fill(output, L(literal::zero));
+ nlabels = 0;
+
+ f.init_(); // Client initialization.
+ }
+
+ // First Pass.
+ {
+ util::array<int> dp = positive_offsets_wrt(input, nbh);
+ const unsigned n_nbhs = dp.nelements();
+
+ mln_bkd_pixter(const I) px(input); // Backward.
+ for_all(px)
+ {
+ unsigned p = px.offset();
+ if (! f.handles_(p))
+ continue;
+
+ // Make-Set.
+ parent.element(p) = p;
+ f.init_attr_(p);
+ for (unsigned i = 0; i < n_nbhs; ++i)
+ {
+ unsigned n = p + dp[i];
+ if (deja_vu.element(n)) // Only false in the external border.
+ {
+ if (f.equiv_(n, p))
+ {
+ // Do-Union.
+ unsigned r = internal::find_root_fastest(parent, n);
+ if (r != p)
+ {
+ parent.element(r) = p;
+ f.merge_attr_(r, p);
+ }
+ }
+ else
+ f.do_no_union_(n, p);
+ }
+ }
+ }
+ }
+
+ // Second Pass.
+ {
+ mln_fwd_pixter(const I) px(input); // Forward.
+ for_all(px)
+ {
+ unsigned p = px.offset();
+ if (! f.handles_(p))
+ continue;
+ if (parent.element(p) == p) // if p is root
+ {
+ if (f.labels_(p))
+ {
+ if (nlabels == mln_max(L))
+ {
+ status = false;
+ trace::warning("labeling aborted! Too many labels for \
+ this label type: nlabels > \
+ max(label_type).");
+ return output;
+ }
+ output.element(p) = ++nlabels;
+ }
+ }
+ else
+ output.element(p) = output.element(parent.element(p));
+ }
+ status = true;
+ }
+
+ trace::exiting("canvas::impl::video_fastest");
+ return output;
+ }
+
+ } // end of namespace mln::canvas::impl
+
+
+
+ // Dispatch.
+
+ namespace internal
+ {
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(metal::false_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ return impl::generic::labeling(input, nbh, nlabels,
+ exact(input).domain(), functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(metal::true_,
+ const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ return impl::video_fastest(input, nbh, nlabels, functor);
+ }
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video_dispatch(const Image<I>& input,
+ const Neighborhood<N>& nbh, L& nlabels,
+ F& functor)
+ {
+ enum {
+ test = mlc_equal(mln_trait_image_speed(I),
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ };
+ return video_dispatch(metal::bool_<test>(),
+ input, nbh, nlabels,
+ functor);
+ }
+
+
+ } // end of namespace mln::canvas::internal
+
+
+
+ // Facades.
+
+
+ template <typename I, typename N, typename L, typename F>
+ inline
+ mln_ch_value(I, L)
+ video(const Image<I>& input, const Neighborhood<N>& nbh,
+ L& nlabels, F& functor)
+ {
+ trace::entering("canvas::video");
+
+ internal::labeling_tests(input, nbh, nlabels, functor);
+
+ mln_ch_value(I, L) output;
+ output = internal::video_dispatch(input, nbh, nlabels,
+ functor);
+
+ trace::exiting("canvas::video");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::canvas::labeling
+
+ } // end of namespace mln::canvas
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CANVAS_LABELING_VIDEO_HH
diff --git a/milena/mln/labeling/flat_zones.hh b/milena/mln/labeling/flat_zones.hh
index cab9dc8..66bc44d 100644
--- a/milena/mln/labeling/flat_zones.hh
+++ b/milena/mln/labeling/flat_zones.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/video.hh>
namespace mln
@@ -118,7 +119,8 @@ namespace mln
// Call the labeling canvas.
typedef impl::flat_zones_functor<I> F;
F f(input);
- mln_ch_value(I, L) output = canvas::labeling_video(input, nbh, nlabels, f);
+ mln_ch_value(I, L)
+ output = canvas::labeling::video(input, nbh, nlabels, f);
trace::exiting("labeling::flat_zones");
return output;
diff --git a/milena/mln/labeling/regional_maxima.hh
b/milena/mln/labeling/regional_maxima.hh
index 824c5e9..a3c12eb 100644
--- a/milena/mln/labeling/regional_maxima.hh
+++ b/milena/mln/labeling/regional_maxima.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/sorted.hh>
# include <mln/data/fill.hh>
# include <mln/data/sort_psites.hh>
@@ -137,8 +138,8 @@ namespace mln
typedef impl::regional_maxima_functor<I> F;
F f(exact(input));
- mln_ch_value(I, L) output = canvas::labeling_sorted(input, nbh, nlabels,
- f, true);
+ mln_ch_value(I, L)
+ output = canvas::labeling::sorted(input, nbh, nlabels, f, true);
trace::exiting("labeling::regional_maxima");
return output;
diff --git a/milena/mln/labeling/regional_minima.hh
b/milena/mln/labeling/regional_minima.hh
index 7ad798f..ae0e7e9 100644
--- a/milena/mln/labeling/regional_minima.hh
+++ b/milena/mln/labeling/regional_minima.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/sorted.hh>
# include <mln/data/fill.hh>
# include <mln/data/sort_psites.hh>
@@ -136,8 +137,8 @@ namespace mln
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- regional_minima(const Image<I>& input_, const Neighborhood<N>&
nbh_,
- L& nlabels)
+ regional_minima(const Image<I>& input_, const Neighborhood<N>&
nbh_,
+ L& nlabels)
{
trace::entering("labeling::regional_minima");
@@ -150,8 +151,8 @@ namespace mln
typedef impl::regional_minima_functor<I> F;
F f(exact(input));
- mln_ch_value(I, L) output = canvas::labeling_sorted(input, nbh, nlabels,
- f, false);
+ mln_ch_value(I, L)
+ output = canvas::labeling::sorted(input, nbh, nlabels, f, false);
trace::exiting("labeling::regional_minima");
return output;
diff --git a/milena/mln/labeling/value.hh b/milena/mln/labeling/value.hh
index 1495570..5a16ca4 100644
--- a/milena/mln/labeling/value.hh
+++ b/milena/mln/labeling/value.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -32,7 +33,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
-# include <mln/canvas/labeling.hh>
+# include <mln/canvas/labeling/video.hh>
# include <mln/data/fill.hh>
@@ -139,8 +140,8 @@ namespace mln
template <typename I, typename N, typename L>
mln_ch_value(I, L)
- value(const Image<I>& input, const mln_value(I)& val, const
Neighborhood<N>& nbh,
- L& nlabels)
+ value(const Image<I>& input, const mln_value(I)& val,
+ const Neighborhood<N>& nbh, L& nlabels)
{
trace::entering("labeling::value");
@@ -148,7 +149,7 @@ namespace mln
mln_ch_value(I, L) output;
impl::value_functor<I> f(input, val);
- output = canvas::labeling_video(input, nbh, nlabels, f);
+ output = canvas::labeling::video(input, nbh, nlabels, f);
trace::exiting("labeling::value");
return output;
diff --git a/milena/tests/labeling/flat_zones.cc b/milena/tests/labeling/flat_zones.cc
index 5a05ebc..6b4b37e 100644
--- a/milena/tests/labeling/flat_zones.cc
+++ b/milena/tests/labeling/flat_zones.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -67,16 +68,16 @@ int main()
labeling::impl::flat_zones_functor<I> f(lena);
unsigned nlabels_generic, nlabels_fastest;
- mln_assertion(canvas::impl::generic::labeling(lena,
- c4(),
- nlabels_generic,
- lena.domain(),
- f)
+ mln_assertion(canvas::labeling::impl::generic::labeling(lena,
+ c4(),
+ nlabels_generic,
+ lena.domain(),
+ f)
==
- canvas::impl::labeling_video_fastest(lena,
- c4(),
- nlabels_fastest,
- f));
+ canvas::labeling::impl::video_fastest(lena,
+ c4(),
+ nlabels_fastest,
+ f));
mln_assertion(nlabels_generic == nlabels_fastest);
}
diff --git a/milena/tests/labeling/foreground.cc b/milena/tests/labeling/foreground.cc
index 8f95ffd..acdecb6 100644
--- a/milena/tests/labeling/foreground.cc
+++ b/milena/tests/labeling/foreground.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -56,9 +57,9 @@ int main()
labeling::impl::value_functor<I> f(pic, true);
unsigned n_;
- ref = canvas::impl::generic::labeling(pic, nbh, n_,
- pic.domain(),
- f);
+ ref = canvas::labeling::impl::generic::labeling(pic, nbh, n_,
+ pic.domain(),
+ f);
mln_invariant(n_ == n);
mln_invariant(ref == out);
}
--
1.5.6.5