* mln/topo/skeleton/priority_driven_thinning.hh
(mln::topo::skeleton::priority_driven_thinning): Catch up
with mln::topo::skeleton::breadth_first_thinning.
* mln/topo/detach_point.hh: Turn into a functor to match the new
interface of thinning algorithms.
* tests/topo/skeleton/breadth_first_thinning.cc
* tests/topo/skeleton/breadth_first_thinning_constrained.cc
* tests/topo/skeleton/priority_driven_thinning.cc
* tests/topo/skeleton/priority_driven_thinning_constrained.cc:
Adjust.
---
milena/ChangeLog | 15 +++++
milena/mln/topo/detach_point.hh | 66 +++++++++++++++++---
.../mln/topo/skeleton/priority_driven_thinning.hh | 23 +++++--
.../tests/topo/skeleton/breadth_first_thinning.cc | 6 +-
.../skeleton/breadth_first_thinning_constrained.cc | 6 +-
.../topo/skeleton/priority_driven_thinning.cc | 6 +-
.../priority_driven_thinning_constrained.cc | 6 +-
7 files changed, 104 insertions(+), 24 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d4d9a23..a4a1345 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,20 @@
2011-02-24 Roland Levillain <roland(a)lrde.epita.fr>
+ Make the interface of thinning algorithms uniform w.r.t. functors.
+
+ * mln/topo/skeleton/priority_driven_thinning.hh
+ (mln::topo::skeleton::priority_driven_thinning): Catch up
+ with mln::topo::skeleton::breadth_first_thinning.
+ * mln/topo/detach_point.hh: Turn into a functor to match the new
+ interface of thinning algorithms.
+ * tests/topo/skeleton/breadth_first_thinning.cc
+ * tests/topo/skeleton/breadth_first_thinning_constrained.cc
+ * tests/topo/skeleton/priority_driven_thinning.cc
+ * tests/topo/skeleton/priority_driven_thinning_constrained.cc:
+ Adjust.
+
+2011-02-24 Roland Levillain <roland(a)lrde.epita.fr>
+
State a cell is not simple if it does not correspond to a facet.
* mln/topo/is_simple_cell.hh
diff --git a/milena/mln/topo/detach_point.hh b/milena/mln/topo/detach_point.hh
index 818f7cd..6e4d22d 100644
--- a/milena/mln/topo/detach_point.hh
+++ b/milena/mln/topo/detach_point.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -29,8 +29,7 @@
/// \file
/// \brief Detaching a point from a binary image.
-// FIXME: Not generic. Swap arguments and use Image<I> and
-// mln_psite(I) as types.
+# include <mln/metal/equal.hh>
# include <mln/core/image/image2d.hh>
# include <mln/core/alias/point2d.hh>
@@ -41,19 +40,68 @@ namespace mln
namespace topo
{
- /// \brief Detach a point from a binary image.
- inline
- void
- detach_point(const mln::point2d& p, mln::image2d<bool>& ima);
+ /// \brief Functor detaching a point from a binary image.
+ template <typename I>
+ class detach_point
+ {
+ public:
+ /// Build a functor.
+ detach_point();
+
+ /// Build a functor, and assign an image to it.
+ ///
+ /// \param ima The image.
+ detach_point(Image<I>& ima);
+
+ /// Set the underlying image.
+ void set_image(Image<I>& ima);
+
+ /// \brief Detach point \a p from the image.
+ void operator()(const mln_psite(I)& p) const;
+
+ private:
+ /// The image.
+ I* ima_;
+ };
+
# ifndef MLN_INCLUDE_ONLY
+ template <typename I>
+ inline
+ detach_point<I>::detach_point()
+ : ima_(0)
+ {
+ // Ensure I is a binary image type.
+ /* FIXME: Not compatible with proxy/morphers on values. */
+ mlc_equal(mln_value(I), bool)::check();
+ }
+
+ template <typename I>
+ inline
+ detach_point<I>::detach_point(Image<I>& ima)
+ : ima_(exact(&ima))
+ {
+ // Ensure I is a binary image type.
+ /* FIXME: Not compatible with proxy/morphers on values. */
+ mlc_equal(mln_value(I), bool)::check();
+ }
+
+ template <typename I>
+ inline
+ void
+ detach_point<I>::set_image(Image<I>& ima)
+ {
+ ima_ = exact(&ima);
+ }
+
+ template <typename I>
inline
void
- detach_point(const mln::point2d& p, mln::image2d<bool>& ima)
+ detach_point<I>::operator()(const mln_psite(I)& p) const
{
- ima(p) = false;
+ (*ima_)(p) = false;
}
# endif // MLN_INCLUDE_ONLY
diff --git a/milena/mln/topo/skeleton/priority_driven_thinning.hh
b/milena/mln/topo/skeleton/priority_driven_thinning.hh
index e29062f..ad8e63d 100644
--- a/milena/mln/topo/skeleton/priority_driven_thinning.hh
+++ b/milena/mln/topo/skeleton/priority_driven_thinning.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -62,10 +63,14 @@ namespace mln
(sites). This functor must provide a method
<tt>void set_image(const Image<I>&)</tt>.
\param detach A function used to detach a cell from \a input.
+ This functor must provide a method
+ <tt>void set_image(const Image<I>&)</tt>.
\param priority A priority function expressed as an image.
\param constraint A constraint on point (site); if it
returns \c false for a point, this point
- will not be removed. */
+ will not be removed.
+
+ Keywords: skeletons, simple points. */
template <typename I, typename N, typename F, typename G, typename J,
typename H>
mln_concrete(I)
@@ -87,9 +92,12 @@ namespace mln
\param is_simple The predicate on the simplicity of points
(sites). This functor must provide a method
<tt>void set_image(const Image<I>&)</tt>.
- \param detach A function used to detach a cell from
- \a input.
- \param priority A priority function expressed as an image. */
+ \param detach A function used to detach a cell from \a input.
+ This functor must provide a method
+ <tt>void set_image(const Image<I>&)</tt>.
+ \param priority A priority function expressed as an image.
+
+ Keywords: skeletons, simple points. */
template <typename I, typename N, typename F, typename G, typename J>
mln_concrete(I)
priority_driven_thinning(const Image<I>& input,
@@ -121,8 +129,9 @@ namespace mln
const H& constraint = exact(constraint_);
mln_concrete(I) output = duplicate(input);
- // Attach the work image to IS_SIMPLE.
+ // Attach the work image to IS_SIMPLE and DETACH.
is_simple.set_image(output);
+ detach.set_image(output);
typedef mln_psite(I) psite;
typedef p_queue_fast<psite> queue_t;
@@ -141,7 +150,7 @@ namespace mln
psite p = queue.pop_front();
if (output(p) && constraint(p) && is_simple(p))
{
- detach(p, output);
+ detach(p);
mln_niter(N) n(nbh, p);
for_all(n)
{
diff --git a/milena/tests/topo/skeleton/breadth_first_thinning.cc
b/milena/tests/topo/skeleton/breadth_first_thinning.cc
index e77421a..1ed7260 100644
--- a/milena/tests/topo/skeleton/breadth_first_thinning.cc
+++ b/milena/tests/topo/skeleton/breadth_first_thinning.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -64,9 +64,11 @@ int main()
// Simplicity criterion functor.
topo::is_simple_point2d<I, N> is_simple(nbh_fg, nbh_bg);
+ // Simple point detach procedure.
+ topo::detach_point<I> detach;
I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
is_simple,
- topo::detach_point);
+ detach);
io::pbm::save(output, "breadth_first_thinning-small.pbm");
}
diff --git a/milena/tests/topo/skeleton/breadth_first_thinning_constrained.cc
b/milena/tests/topo/skeleton/breadth_first_thinning_constrained.cc
index 8ec213a..c8fbe52 100644
--- a/milena/tests/topo/skeleton/breadth_first_thinning_constrained.cc
+++ b/milena/tests/topo/skeleton/breadth_first_thinning_constrained.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -65,12 +65,14 @@ int main()
// Simplicity criterion functor.
topo::is_simple_point2d<I, N> is_simple(nbh_fg, nbh_bg);
+ // Simple point detach procedure.
+ topo::detach_point<I> detach;
// Constraint: do not collapse end points.
topo::is_not_end_point<I, N> constraint(nbh_fg, input);
I output = topo::skeleton::breadth_first_thinning(input, nbh_fg,
is_simple,
- topo::detach_point,
+ detach,
constraint);
io::pbm::save(output, "breadth_first_thinning_constrained-small.pbm");
}
diff --git a/milena/tests/topo/skeleton/priority_driven_thinning.cc
b/milena/tests/topo/skeleton/priority_driven_thinning.cc
index 36470d1..6cfacae 100644
--- a/milena/tests/topo/skeleton/priority_driven_thinning.cc
+++ b/milena/tests/topo/skeleton/priority_driven_thinning.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -68,6 +68,8 @@ int main()
// Simplicity criterion functor.
topo::is_simple_point2d<I, N> is_simple(nbh_fg, nbh_bg);
+ // Simple point detach procedure.
+ topo::detach_point<I> detach;
// Distance type.
typedef value::int_u8 D;
@@ -84,7 +86,7 @@ int main()
I output = topo::skeleton::priority_driven_thinning(input, nbh_fg,
is_simple,
- topo::detach_point,
+ detach,
priority);
io::pbm::save(output, "priority_driven_thinning-small.pbm");
}
diff --git a/milena/tests/topo/skeleton/priority_driven_thinning_constrained.cc
b/milena/tests/topo/skeleton/priority_driven_thinning_constrained.cc
index 822d5cd..32e17a1 100644
--- a/milena/tests/topo/skeleton/priority_driven_thinning_constrained.cc
+++ b/milena/tests/topo/skeleton/priority_driven_thinning_constrained.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -69,6 +69,8 @@ int main()
// Simplicity criterion functor.
topo::is_simple_point2d<I, N> is_simple(nbh_fg, nbh_bg);
+ // Simple point detach procedure.
+ topo::detach_point<I> detach;
// Constraint: do not collapse end points.
topo::is_not_end_point<I, N> constraint(nbh_fg, input);
@@ -87,7 +89,7 @@ int main()
I output = topo::skeleton::priority_driven_thinning(input, nbh_fg,
is_simple,
- topo::detach_point,
+ detach,
priority,
constraint);
io::pbm::save(output, "priority_driven_thinning_constrained-small.pbm");
--
1.5.6.5