Commit 0544c364 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Make area_on_vertices work with new algebraic code [POST-RUSH].

	* mln/morpho/attribute/count_adjacent_vertices.hh,
	* mln/morpho/closing/area_on_vertices.hh,
	* mln/morpho/opening/area_on_vertices.hh:
	  Make area_on_vertices work with new algebraic code, and
	adapt count_adjacent_vertices accumulator as a morpho attribute.

	* mln/morpho/closing_area_on_vertices.hh,
	* mln/morpho/closing_attribute.hh,
	* mln/morpho/opening_area_on_vertices.hh,
	* mln/morpho/opening_attribute.hh:
	  Delete old implementations.

	* tests/morpho/artificial_line_graph_image_wst.cc,
	* tests/morpho/lena_line_graph_image_wst2.cc:
	  Update test files using area_on_vertices.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@3451 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent d55841fc
2009-03-01 Edwin Carlinet <carlinet@lrde.epita.fr>
Make area_on_vertices work with new algebraic code [POST-RUSH].
* mln/morpho/attribute/count_adjacent_vertices.hh,
* mln/morpho/closing/area_on_vertices.hh,
* mln/morpho/opening/area_on_vertices.hh:
Make area_on_vertices work with new algebraic code, and
adapt count_adjacent_vertices accumulator as a morpho attribute.
* mln/morpho/closing_area_on_vertices.hh,
* mln/morpho/closing_attribute.hh,
* mln/morpho/opening_area_on_vertices.hh,
* mln/morpho/opening_attribute.hh:
Delete old implementations.
* tests/morpho/artificial_line_graph_image_wst.cc,
* tests/morpho/lena_line_graph_image_wst2.cc:
Update test files using area_on_vertices.
2009-03-01 Edwin Carlinet <carlinet@lrde.epita.fr>
 
[EXO2] Add shell script for exo2.
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of the Olena Library. This library is free
......@@ -25,112 +25,173 @@
// 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_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_
# define MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_
#ifndef MLN_MORPHO_OPENING_ATTRIBUTE_HH
# define MLN_MORPHO_OPENING_ATTRIBUTE_HH
/// \file mln/morpho/opening_attribute.hh
///
/// Morphological attribute opening.
/// \file mln/accu/count_adjacent_vertices.hh
///
/// \todo Add extension::adjust_fill.
/// Define an accumulator that counts the vertices adjacent to a
/// set of p_edges psites.
# include <mln/morpho/includes.hh>
# include <mln/canvas/morpho/algebraic_union_find.hh>
# include <mln/level/sort_psites.hh>
# include <mln/accu/internal/base.hh>
# include <mln/pw/image.hh>
# include <mln/util/pix.hh>
namespace mln
{
namespace morpho
// Forward declaration.
namespace morpho {
namespace attribute {
template <typename I>
struct count_adjacent_vertices;
}
}
// Traits.
namespace trait
{
/// Morphological attribute opening.
template <typename A,
typename I, typename N>
mln_concrete(I)
opening_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda);
template <typename I>
struct accumulator_< morpho::attribute::count_adjacent_vertices<I> >
{
typedef accumulator::has_untake::no has_untake;
typedef accumulator::has_set_value::no has_set_value;
typedef accumulator::has_stop::no has_stop;
typedef accumulator::when_pix::use_p when_pix;
};
} // end of namespace mln::trait
# ifndef MLN_INCLUDE_ONLY
namespace morpho
{
namespace impl
namespace attribute
{
template <typename I, typename A_>
struct opening_attribute_t
/// Count_Adjacent_Vertices accumulator class.
///
/// The parameter \p I is the image type on which the accumulator
/// of pixels is built.
template <typename F, typename S>
struct count_adjacent_vertices< pw::image<F, S> >
: public accu::internal::base< unsigned , count_adjacent_vertices< pw::image<F, S> > >
{
// requirements from mln::canvas::morpho::algebraic_union_find
typedef A_ A;
typedef mln_psite(I) P;
typedef p_array<P> S;
mln_result(A) lambda;
const S s;
inline
void init()
{
// FIXME: border::fill(input, mln_max(mln_value(I)));
}
inline
bool is_active(const A& attr) const
{
return attr.to_result() < lambda;
}
inline
void inactivate(A& attr)
{
attr.set_value(lambda);
}
// end of requirements
inline
opening_attribute_t(const Image<I>& input, mln_result(A) lambda)
: lambda(lambda),
s(level::sort_psites_decreasing(exact(input)))
{
}
typedef pw::image<F, S> I;
typedef mln_psite(I) argument;
count_adjacent_vertices();
/// Manipulators.
/// \{
void init();
void take(const argument& px);
void take(const count_adjacent_vertices<I>& other);
void take_as_init(const argument& px);
/// \}
/// Get the value of the accumulator.
unsigned to_result() const;
/// Check whether this accu is able to return a result.
bool is_valid() const;
protected:
/// Update the value of the counter.
void update_ ();
/// The value of the counter.
unsigned count__;
/// The set of adjacent vertices.
std::set<unsigned> vertices_;
};
} // end of namespace mln::morpho::impl
// Facade.
# ifndef MLN_INCLUDE_ONLY
template <typename A, typename I, typename N>
inline
mln_concrete(I)
opening_attribute(const Image<I>& input,
const Neighborhood<N>& nbh, mln_result(A) lambda)
{
trace::entering("morpho::opening_attribute");
template <typename F, typename S>
inline
count_adjacent_vertices< pw::image<F, S> >::count_adjacent_vertices()
{
init();
}
mln_precondition(exact(input).is_valid());
template <typename F, typename S>
inline
void
count_adjacent_vertices< pw::image<F, S> >::init()
{
vertices_.clear();
update_();
}
template <typename F, typename S>
inline
void
count_adjacent_vertices< pw::image<F,S> >::take(const argument& p)
{
vertices_.insert(p.v1());
vertices_.insert(p.v2());
update_();
}
template <typename F, typename S>
inline
void
count_adjacent_vertices< pw::image<F,S> >::take(const count_adjacent_vertices< pw::image <F,S> >& other)
{
vertices_.insert (other.vertices_.begin(), other.vertices_.end());
update_();
}
template <typename F, typename S>
inline
void
count_adjacent_vertices< pw::image<F,S> >::take_as_init(const argument& px)
{
vertices_.clear();
take(px);
}
template <typename F, typename S>
inline
unsigned
count_adjacent_vertices< pw::image<F,S> >::to_result() const
{
return count__;
}
typedef impl::opening_attribute_t<I, A> F;
F f(input, lambda);
mln_concrete(I) output = canvas::morpho::algebraic_union_find(input, nbh, f);
template <typename F, typename S>
inline
void
count_adjacent_vertices< pw::image<F,S> >::update_()
{
count__ = vertices_.size();
}
mln_postcondition(output <= input);
template <typename F, typename S>
inline
bool
count_adjacent_vertices< pw::image<F,S> >::is_valid() const
{
return true;
}
trace::exiting("morpho::opening_attribute");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho::attribute
} // end of namespace mln::morpho
} // end of namespace mln
#endif // ! MLN_MORPHO_OPENING_ATTRIBUTE_HH
#endif /* !MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH_ */
......@@ -29,15 +29,15 @@
#ifndef MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
# define MLN_MORPHO_CLOSING_AREA_ON_VERTICES_HH
/// \file mln/morpho/closing_area.hh
/// \file mln/morpho/closing/area_on_vertices.hh
///
/// Morphological area closing on a line graph image computing
/// the area in terms of adjacent vertices.
# include <mln/pw/image.hh>
# include <mln/core/site_set/p_edges.hh>
# include <mln/morpho/closing_attribute.hh>
# include <mln/accu/count_adjacent_vertices.hh>
# include <mln/morpho/closing/algebraic.hh>
# include <mln/morpho/attribute/count_adjacent_vertices.hh>
namespace mln
......@@ -46,13 +46,16 @@ namespace mln
namespace morpho
{
namespace closing
{
/// Morphological area closing on a mln::line_graph_image computing
/// the area in terms of adjacent vertices.
template <typename P2V, typename G, typename V2P, typename N>
pw::image<P2V, p_edges<G, V2P> >
closing_area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input,
const Neighborhood<N>& nbh,
unsigned lambda);
template <typename P2V, typename G, typename V2P, typename N>
pw::image<P2V, p_edges<G, V2P> >
area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input,
const Neighborhood<N>& nbh,
unsigned lambda);
# ifndef MLN_INCLUDE_ONLY
......@@ -60,24 +63,25 @@ namespace mln
template <typename P2V, typename G, typename V2P, typename N>
inline
pw::image<P2V, p_edges<G, V2P> >
closing_area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input,
const Neighborhood<N>& nbh,
unsigned lambda)
area_on_vertices(const pw::image<P2V, p_edges<G, V2P> >& input,
const Neighborhood<N>& nbh,
unsigned lambda)
{
trace::entering("morpho::closing_area_on_vertices");
trace::entering("morpho::closing::area_on_vertices");
mln_precondition(exact(input).is_valid());
typedef p_edges<G, V2P> pe_t;
typedef accu::count_adjacent_vertices<P2V, pe_t> attribute_t;
typedef attribute::count_adjacent_vertices< pw::image<P2V, pe_t> > attribute_t;
pw::image<P2V, p_edges<G, V2P> > output;
output = closing_attribute<attribute_t>(input, nbh, lambda);
output = closing::algebraic(input, nbh, attribute_t(), lambda);
trace::exiting("morpho::closing_area_on_vertices");
trace::exiting("morpho::closing::area_on_vertices");
return output;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho::closing
} // end of namespace mln::morpho
......
// Copyright (C) 2007, 2008 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_MORPHO_CLOSING_ATTRIBUTE_HH
# define MLN_MORPHO_CLOSING_ATTRIBUTE_HH
/// \file mln/morpho/closing_attribute.hh
///
/// Morphological attribute closing.
///
/// \todo How to pass dynamic data (e.g., k of accu::rank) to the routine?
///
/// \todo Add extension::adjust_fill.
///
/// \todo Re-activate the fastest version when accumulators are
/// cleaned-up.
# include <mln/morpho/includes.hh>
# include <mln/canvas/morpho/algebraic_union_find.hh>
# include <mln/level/sort_psites.hh>
# include <mln/level/sort_offsets.hh>
# include <mln/util/pix.hh>
namespace mln
{
namespace morpho
{
/// Morphological attribute closing.
template <typename A, typename I, typename N>
mln_concrete(I)
closing_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda);
# ifndef MLN_INCLUDE_ONLY
// Implementations.
namespace impl
{
// Generic version.
namespace generic
{
template <typename I, typename A_>
struct closing_attribute_functor_t
{
// requirements from mln::canvas::morpho::algebraic_union_find
typedef A_ A;
typedef mln_psite(I) P;
typedef p_array<P> S;
mln_result(A) lambda;
const S s;
void init()
{
// FIXME: border::fill(input, mln_max(mln_value(I)));
}
bool is_active(const A& attr) const
{
return attr.to_result() < lambda;
}
void inactivate(A& attr)
{
attr.set_value(lambda);
}
// end of requirements
closing_attribute_functor_t(const Image<I>& input, mln_result(A) lambda)
: lambda(lambda),
s(level::sort_psites_increasing(exact(input)))
{
}
};
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
trace::entering("morpho::impl::generic::closing_attribute");
mln_precondition(exact(input).is_valid());
typedef closing_attribute_functor_t<I, A> F;
F f(input, lambda);
mln_concrete(I) output = canvas::morpho::impl::generic::algebraic_union_find(input, nbh, f);
mln_postcondition(output >= input);
trace::exiting("morpho::impl::generic::closing_attribute");
return output;
}
} // end of namespace mln::morpho::impl::generic
// "Fastest" version.
template <typename I, typename A_>
struct closing_attribute_fastest_functor_t
{
// requirements from mln::canvas::morpho::algebraic_union_find
typedef A_ A;
typedef mln_psite(I) P;
typedef util::array<unsigned> S;
mln_result(A) lambda;
const S s;
void init()
{
// FIXME: border::fill(input, mln_max(mln_value(I)));
}
bool is_active(const A& attr) const
{
return attr.to_result() < lambda;
}
void inactivate(A& attr)
{
attr.set_value(lambda);
}
// end of requirements
closing_attribute_fastest_functor_t(const Image<I>& input, mln_result(A) lambda)
: lambda(lambda),
s(level::sort_offsets_increasing(exact(input)))
{
}
};
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute_fastest(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
trace::entering("morpho::impl::closing_attribute_fastest");
mln_precondition(exact(input).is_valid());
typedef impl::closing_attribute_fastest_functor_t<I, A> F;
F f(input, lambda);
mln_concrete(I) output = canvas::morpho::impl::algebraic_union_find_fastest(input, nbh, f);
mln_postcondition(output >= input);
trace::exiting("morpho::impl::closing_attribute_fastest");
return output;
}
} // end of namespace mln::morpho::impl
// Dispatch.
namespace internal
{
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute_dispatch(metal::false_,
const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
return impl::generic::closing_attribute<A>(input, nbh, lambda);
}
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute_dispatch(metal::true_,
const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
return impl::generic::closing_attribute<A>(input, nbh, lambda);
// return impl::closing_attribute_fastest<A>(input, nbh, lambda);
}
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute_dispatch(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
enum {
test = mlc_equal(mln_trait_image_speed(I),
trait::image::speed::fastest)::value
&&
mln_is_simple_neighborhood(N)::value
};
return closing_attribute_dispatch<A>(metal::bool_<test>(),
input, nbh, lambda);
}
} // end of namespace internal
// Facade.
template <typename A, typename I, typename N>
inline
mln_concrete(I)
closing_attribute(const Image<I>& input, const Neighborhood<N>& nbh,
mln_result(A) lambda)
{
trace::entering("morpho::closing_attribute");