Commit e56dcf93 authored by Roland Levillain's avatar Roland Levillain
Browse files

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.
parent d95b8eb4
2011-02-24 Roland Levillain <roland@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@lrde.epita.fr>
 
State a cell is not simple if it does not correspond to a facet.
// 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
......
// 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)
{
......
// 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");
}
// 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");
}
// 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");
}
// 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");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment