https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fetch card and algebraic_union_find.hh from Edwin's sandbox.
* mln/trait/accumulator/props.hh (use_none): New.
* mln/trait/accumulators.hh
(mln_trait_accumulator_has_setvalue): Rename as...
(mln_trait_accumulator_has_set_value): ...this.
* mln/morpho/attribute: New directory.
* mln/morpho/attribute/all.hh: New.
* sandbox/edwin/card.hh: Copy to...
* mln/morpho/attribute/card.hh: ...this new file.
Update.
* mln/morpho/all.hh: Update.
* sandbox/edwin/algebraic_union_find.hh: Copy to...
* mln/canvas/morpho/algebraic_filter.hh: ...this new file.
(algebraic_union_find): Rename as...
(algebraic_filter): ...this.
Fix.
* mln/morpho/closing_algebraic.hh: New.
* mln/canvas/morpho/all.hh: Update.
* tests/morpho/attribute: New directory.
* tests/morpho/attribute/Makefile.am: New.
* tests/morpho/attribute/card.cc: New.
* tests/morpho/Makefile.am: Update.
* tests/morpho/closing_algebraic.cc: New.
mln/canvas/morpho/algebraic_filter.hh | 174 ++++++++++++------------
mln/canvas/morpho/all.hh | 5
mln/morpho/all.hh | 5
mln/morpho/attribute/all.hh | 51 +++++++
mln/morpho/attribute/card.hh | 146 +++++++++++++++-----
mln/morpho/closing_algebraic.hh | 240 ++--------------------------------
mln/trait/accumulator/props.hh | 1
mln/trait/accumulators.hh | 2
tests/morpho/Makefile.am | 3
tests/morpho/attribute/Makefile.am | 10 +
tests/morpho/attribute/card.cc | 50 +++++++
tests/morpho/closing_algebraic.cc | 29 ++--
12 files changed, 360 insertions(+), 356 deletions(-)
Index: mln/trait/accumulator/props.hh
--- mln/trait/accumulator/props.hh (revision 3331)
+++ mln/trait/accumulator/props.hh (working copy)
@@ -74,6 +74,7 @@
struct use_v : any { std::string name() const { return
"when_pix::use_v"; } };
struct use_p : any { std::string name() const { return
"when_pix::use_p"; } };
struct use_pix : any { std::string name() const { return
"when_pix::use_pix"; } };
+ struct use_none : any { std::string name() const { return
"when_pix::use_none"; } };
struct not_ok : any { std::string name() const { return
"when_pix::not_ok"; } };
};
Index: mln/trait/accumulators.hh
--- mln/trait/accumulators.hh (revision 3331)
+++ mln/trait/accumulators.hh (working copy)
@@ -40,7 +40,7 @@
# define mln_trait_accumulator_has_untake(A) typename mln::trait::accumulator_< A
>::has_untake
/// Shortcut to the accumulator property about setvalue method disponibility
-# define mln_trait_accumulator_has_setvalue(A) typename mln::trait::accumulator_< A
>::has_setvalue
+# define mln_trait_accumulator_has_set_value(A) typename mln::trait::accumulator_< A
>::has_set_value
/// Shortcut to the accumulator property about stop method disponibility
# define mln_trait_accumulator_has_stop(A) typename mln::trait::accumulator_< A
>::has_stop
Index: mln/morpho/attribute/all.hh
--- mln/morpho/attribute/all.hh (revision 0)
+++ mln/morpho/attribute/all.hh (revision 0)
@@ -0,0 +1,51 @@
+// 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_MORPHO_ATTRIBUTE_ALL_HH
+# define MLN_MORPHO_ATTRIBUTE_ALL_HH
+
+/// \file mln/morpho/attribute/all.hh
+///
+/// File that includes all attributes used in mathematical morphology.
+
+
+namespace mln
+{
+ namespace morpho
+ {
+
+ /// Namespace of attributes used in mathematical morphology.
+ namespace attribute {}
+
+ }
+}
+
+
+# include <mln/morpho/attribute/card.hh>
+
+
+#endif // ! MLN_MORPHO_ATTRIBUTE_ALL_HH
Index: mln/morpho/attribute/card.hh
--- mln/morpho/attribute/card.hh (revision 0)
+++ mln/morpho/attribute/card.hh (working copy)
@@ -1,44 +1,121 @@
-#ifndef CARD_HH_
-# define CARD_HH_
+// 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_MORPHO_ATTRIBUTE_CARD_HH
+# define MLN_MORPHO_ATTRIBUTE_CARD_HH
+
+/// \file mln/morpho/attribute/card.hh
+///
+/// Define an accumulator that computes the cardinality of a
+/// component.
+
+# include <mln/accu/internal/base.hh>
-# include <mln/accu/all.hh>
-# include <mln/util/pix.hh>
namespace mln
{
+
+
+ // Forward declaration.
+
+ namespace morpho {
+ namespace attribute {
+ template <typename I> struct card;
+ }
+ }
+
+
+ // Traits.
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct accumulator_< morpho::attribute::card<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_none when_pix;
+
+ };
+
+ } // end of namespace mln::trait
+
+
namespace morpho
{
- namespace accu
+
+ namespace attribute
{
+
+ /// Cardinality accumulator class.
+
template <typename I>
struct card : public mln::accu::internal::base< unsigned, card<I> >
{
typedef mln_psite(I) argument;
card ();
+
+ /// Manipulators.
+ /// \{
void init ();
- void take (const card<I>& accu);
+ void take(const argument& s);
+ void take(const card<I>& other);
+
+ void take(const util::pix<I>& px);
void take ();
- void take (const mln_psite(I)& elt);
- void take (const mln_value(I)& elt);
- void take (const util::pix<I>& pix);
+ void take_as_init();
+ /// \}
+ /// 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;
- private:
+ protected:
+ /// The value.
unsigned c_;
};
+
+
# ifndef MLN_INCLUDE_ONLY
+
template <typename I>
inline
- card<I>::card () :
- c_ (0)
+ card<I>::card()
{
+ init();
}
template <typename I>
@@ -52,45 +129,43 @@
template <typename I>
inline
void
- card<I>::take (const card<I>& accu)
+ card<I>::take(const argument&)
{
- c_ += accu.c_;
+ take();
}
-
template <typename I>
inline
void
- card<I>::take ()
+ card<I>::take(const card<I>& other)
{
- ++c_;
- };
+ c_ += other.c_;
+ }
template <typename I>
inline
void
- card<I>::take (const mln_psite(I)& elt)
+ card<I>::take(const util::pix<I>&)
{
- ++c_;
- };
-
+ take();
+ }
template <typename I>
inline
void
- card<I>::take (const mln_value(I)& elt)
+ card<I>::take()
{
++c_;
- };
-
+ }
template <typename I>
inline
void
- card<I>::take (const util::pix<I>& pix)
+ card<I>::take_as_init()
{
- ++c_;
- };
+ init();
+ take();
+ }
template <typename I>
inline
@@ -98,7 +173,7 @@
card<I>::to_result() const
{
return c_;
- };
+ }
template <typename I>
inline
@@ -106,14 +181,15 @@
card<I>::is_valid () const
{
return true;
- };
-# endif
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::morpho::attribute
- } // mln::morpho::accu
- } // mln::morpho
-} // mln
+ } // end of namespace mln::morpho
-#endif /* !CARD_HH_ */
+} // end of namespace mln
+#endif // ! MLN_MORPHO_ATTRIBUTE_CARD_HH
Property changes on: mln/morpho/attribute/card.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/morpho/all.hh
--- mln/morpho/all.hh (revision 3331)
+++ mln/morpho/all.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -84,6 +84,7 @@
// Sub-directories.
+# include <mln/morpho/attribute/all.hh>
# include <mln/morpho/elementary/all.hh>
# include <mln/morpho/tree/all.hh>
# include <mln/morpho/watershed/all.hh>
Index: mln/morpho/closing_algebraic.hh
--- mln/morpho/closing_algebraic.hh (revision 3330)
+++ mln/morpho/closing_algebraic.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -26,25 +26,15 @@
// 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
+#ifndef MLN_MORPHO_CLOSING_ALGEBRAIC_HH
+# define MLN_MORPHO_CLOSING_ALGEBRAIC_HH
-/// \file mln/morpho/closing_attribute.hh
+/// \file mln/morpho/closing_algebraic.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.
+/// Morphological algebraic closing.
# 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>
+# include <mln/canvas/morpho/algebraic_filter.hh>
namespace mln
@@ -53,227 +43,39 @@
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
+ /// Morphological algebraic closing.
+ template <typename I, typename N, typename A>
mln_concrete(I)
- closing_attribute(const Image<I>& input, const Neighborhood<N>&
nbh,
- mln_result(A) lambda)
- {
- trace::entering("morpho::impl::generic::closing_attribute");
+ closing_algebraic(const Image<I>& input, const Neighborhood<N>&
nbh,
+ const Accumulator<A>& accu, const mln_result(A)& lambda);
- 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
+# ifndef MLN_INCLUDE_ONLY
- // Facade.
- template <typename A, typename I, typename N>
+ template <typename I, typename N, typename A>
inline
mln_concrete(I)
- closing_attribute(const Image<I>& input, const Neighborhood<N>&
nbh,
- mln_result(A) lambda)
+ closing_algebraic(const Image<I>& input, const Neighborhood<N>&
nbh,
+ const Accumulator<A>& accu, const mln_result(A)& lambda)
{
- trace::entering("morpho::closing_attribute");
+ trace::entering("morpho::closing_algebraic");
mln_precondition(exact(input).is_valid());
- mln_concrete(I) output = internal::closing_attribute_dispatch<A>(input, nbh,
lambda);
+ mln_concrete(I) output;
+ output = canvas::morpho::algebraic_filter(input, nbh, accu, lambda,
+ /* increasing = */ true);
mln_postcondition(output >= input);
- trace::exiting("morpho::closing_attribute");
+ trace::exiting("morpho::closing_algebraic");
return output;
}
- // Facade.
-
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::morpho
@@ -281,4 +83,4 @@
} // end of namespace mln
-#endif // ! MLN_MORPHO_CLOSING_ATTRIBUTE_HH
+#endif // ! MLN_MORPHO_CLOSING_ALGEBRAIC_HH
Property changes on: mln/morpho/closing_algebraic.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: mln/canvas/morpho/all.hh
--- mln/canvas/morpho/all.hh (revision 3331)
+++ mln/canvas/morpho/all.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -46,6 +46,7 @@
}
+# include <mln/canvas/morpho/algebraic_filter.hh>
# include <mln/canvas/morpho/algebraic_union_find.hh>
Index: mln/canvas/morpho/algebraic_filter.hh
--- mln/canvas/morpho/algebraic_filter.hh (revision 3330)
+++ mln/canvas/morpho/algebraic_filter.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 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
@@ -26,27 +26,24 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CANVAS_MORPHO_ALGEBRAIC_UNION_FIND_HH
-# define MLN_CANVAS_MORPHO_ALGEBRAIC_UNION_FIND_HH
+#ifndef MLN_CANVAS_MORPHO_ALGEBRAIC_FILTER_HH
+# define MLN_CANVAS_MORPHO_ALGEBRAIC_FILTER_HH
+/// \file mln/canvas/morpho/algebraic_filter.hh
///
-///
-/// \todo: Doc!
-///
-/// \todo Re-activate the fastest version when accumulators are
-/// cleaned-up.
+/// Canvas for morphological algebraic filters.
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/concept/accumulator.hh>
-# include <mln/data/fill.hh>
-# include <mln/util/pix.hh>
+# include <mln/data/fill.hh>
+# include <mln/extension/adjust_fill.hh>
# include <mln/level/sort_psites.hh>
# include <mln/level/sort_offsets.hh>
-# include "accu_trait.hh"
+
namespace mln
{
@@ -57,6 +54,23 @@
namespace morpho
{
+
+ template <typename I, typename N, typename A>
+ mln_concrete(I)
+ algebraic_filter(const Image<I>& input,
+ const Neighborhood<N>& nbh,
+ const Accumulator<A>& accu,
+ const mln_result(A)& lambda,
+ bool increasing);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Implementations.
+
+
namespace impl
{
@@ -79,18 +93,19 @@
template <typename I, typename N, typename S, typename A>
inline
mln_concrete(I)
- algebraic_union_find(const Image<I>& input_,
+ algebraic_filter(const Image<I>& input_,
const Neighborhood<N>& nbh_,
- const Site_Set<S>& s_,
const Accumulator<A>& accu_,
- mln_result(A) lambda)
+ const mln_result(A)& lambda,
+ const Site_Set<S>& s_)
{
- trace::entering("canvas::morpho::impl::generic::algebraic_union_find");
+ trace::entering("canvas::morpho::impl::generic::algebraic_filter");
// FIXME: Tests?
const I& input = exact(input_);
const N& nbh = exact(nbh_);
+ const S& s = exact(s_);
mln_concrete(I) output;
initialize(output, input);
@@ -117,42 +132,18 @@
// First pass.
{
- mln_fwd_piter(S) p(s_);
+ mln_fwd_piter(S) p(s);
mln_niter(N) n(nbh, p);
for_all(p)
{
- // Make set.
- {
+ // Make-Set.
parent(p) = p;
- /* FIXME: What if the value_type of DATA (i.e., A) were not
- based on a accu::count<mln::pix>? Currently, nothing
- enforces this, but the code below expects this line to be
- valid:
-
- data(p).take_as_init(make::pix(f.input, p))
-
- which probably restricts the kind of input images.
-
- If we want to be more generic, the initialization should
- read something like:
-
- init_data(p);
-
- i.e., the functor for the initialization of data should
- be passed as an argument to the canvas' ctor.
-
- Of course, we might want to restrict attributes to the
- accumulator accu::count<mln::pix> (which is perfectly
- acceptable), but then this class should statically check
- the conformance of the template parameter A to this
- constraint. */
- data(p).take_as_init(p); // FIXME: algebraic so p!
- }
+ data(p).take_as_init(p);
for_all(n)
if (input.domain().has(n) && deja_vu(n))
{
- //do_union(n, p);
+ // Do-Union.
P r = find_root(parent, n);
if (r != p)
{
@@ -177,18 +168,16 @@
activity(p) = false;
}
else
- {
activity(p) = false;
}
}
- }
deja_vu(p) = true;
}
}
// Second pass.
{
- mln_bkd_piter(S) p(s_);
+ mln_bkd_piter(S) p(s);
for_all(p)
if (parent(p) == p) // p is root.
output(p) = input(p);
@@ -202,7 +191,7 @@
and add in init:
mln::data::fill(output, input);
*/
- trace::exiting("canvas::morpho::impl::generic::algebraic_union_find");
+ trace::exiting("canvas::morpho::impl::generic::algebraic_filter");
return output;
}
@@ -213,34 +202,36 @@
// Fastest version.
+
template <typename I>
inline
unsigned
find_root_fastest(I& parent, unsigned x)
{
- if (parent.element(x) == x)
+ if (parent.element(x) == 0)
return x;
else
return parent.element(x) = find_root_fastest(parent, parent.element(x));
}
-
- template <typename I, typename N, typename S, typename A>
+ template <typename I, typename N, typename A>
inline
mln_concrete(I)
- algebraic_union_find_fastest(const Image<I>& input_,
+ algebraic_filter_fastest(const Image<I>& input_,
const Neighborhood<N>& nbh_,
- const Site_Set<S>& s_,
const Accumulator<A>& accu_,
- mln_result(A) lambda)
+ const mln_result(A)& lambda,
+ const util::array<unsigned>& s)
{
- trace::entering("canvas::morpho::impl::algebraic_union_find_fastest");
+ trace::entering("canvas::morpho::impl::algebraic_filter_fastest");
// FIXME: Tests?
const I& input = exact(input_);
const N& nbh = exact(nbh_);
+ extension::adjust(input, nbh);
+
mln_concrete(I) output;
initialize(output, input);
@@ -257,6 +248,7 @@
{
initialize(deja_vu, input);
mln::data::fill(deja_vu, false);
+ extension::fill(deja_vu, false); // So that the extension is ignored.
initialize(activity, input);
mln::data::fill(activity, true);
initialize(parent, input);
@@ -267,18 +259,17 @@
util::array<int> dp = offsets_wrt(input, nbh);
const unsigned n_nbhs = dp.nelements();
- const unsigned n_points = s_.nelements();
+ const unsigned n = s.nelements();
// First pass.
{
- for (unsigned i = 0; i < n_points; ++i)
+ for (unsigned i = 0; i < n; ++i)
{
- unsigned p = s_[i]; // An offset.
+ unsigned p = s[i]; // An offset.
// Make set.
- parent.element(p) = p;
- data.element(p).take_as_init(); // FIXME: Very bad et SEULEMENT POUR CARD !!! C CON!!!
+ data.element(p).take_as_init(); // FIXME: Very bad!
for (unsigned j = 0; j < n_nbhs; ++j)
{
@@ -290,20 +281,17 @@
if (r != p)
{
if (input.element(r) == input.element(p)
- || (activity.element(r)
- && data.element(r) < lambda))
+ || (activity.element(r) && data.element(r) < lambda))
{
- data.element(p).take();
+ data.element(p).take(data.element(r));
parent.element(r) = p;
if (activity.element(r) == false)
activity.element(p) = false;
}
else
- {
activity.element(p) = false;
}
}
- }
deja_vu.element(p) = true;
}
@@ -312,16 +300,16 @@
// Second pass.
{
- for (int i = n_points - 1; i >= 0 ; --i)
+ for (int i = n - 1; i >= 0 ; --i)
{
- unsigned p = s_[i];
- if (parent.element(p) == p) // p is root.
+ unsigned p = s[i];
+ if (parent.element(p) == 0) // p is root.
output.element(p) = input.element(p);
else
output.element(p) = output.element(parent.element(p));
}
}
- trace::exiting("canvas::morpho::impl::algebraic_union_find_fastest");
+ trace::exiting("canvas::morpho::impl::algebraic_filter_fastest");
return output;
}
@@ -332,59 +320,64 @@
// Dispatch.
+
namespace internal
{
template <typename I, typename N, typename A>
inline
mln_concrete(I)
- algebraic_union_find_dispatch(metal::false_,
+ algebraic_filter_dispatch(metal::false_,
const Image<I>& input,
const Neighborhood<N>& nbh,
const Accumulator<A>& accu,
- mln_result(A) lambda,
+ const mln_result(A)& lambda,
bool increasing)
{
p_array<mln_psite(I)> s = increasing ?
level::sort_psites_increasing(input) :
level::sort_psites_decreasing(input);
- return impl::generic::algebraic_union_find(input, nbh, s, accu,
- lambda);
+ return impl::generic::algebraic_filter(input, nbh, accu, lambda,
+ s);
}
template <typename I, typename N, typename A>
inline
mln_concrete(I)
- algebraic_union_find_dispatch(metal::true_,
+ algebraic_filter_dispatch(metal::true_,
const Image<I>& input,
const Neighborhood<N>& nbh,
const Accumulator<A>& accu,
- mln_result(A) lambda,
+ const mln_result(A)& lambda,
bool increasing)
{
util::array<unsigned> s = increasing ?
level::sort_offsets_increasing(input) :
level::sort_offsets_decreasing(input);
- return impl::algebraic_union_find_fastest(input, nbh, s, accu, lambda);
+ return impl::algebraic_filter_fastest(input, nbh, accu, lambda,
+ s);
}
template <typename I, typename N, typename A>
inline
mln_concrete(I)
- algebraic_union_find_dispatch(const Image<I>& input,
+ algebraic_filter_dispatch(const Image<I>& input,
const Neighborhood<N>& nbh,
const Accumulator<A>& accu,
- mln_result(A) lambda,
+ const mln_result(A)& lambda,
bool increasing)
{
enum {
test = (mlc_equal(mln_trait_image_speed(I),
- trait::image::speed::fastest)::value &&
- mln_is_simple_neighborhood(N)::value &&
- mlc_equal(mln_trait_accu_when_pix(A),
- trait::accu::when_pix::use_whatever)::value)
+ trait::image::speed::fastest)::value
+ &&
+ mln_is_simple_neighborhood(N)::value
+ &&
+ mlc_equal(mln_trait_accumulator_when_pix(A),
+ trait::accumulator::when_pix::use_none)::value)
};
- return algebraic_union_find_dispatch(metal::bool_<test>(), input, nbh,
- accu, lambda, increasing);
+ return algebraic_filter_dispatch(metal::bool_<test>(),
+ input, nbh, accu, lambda,
+ increasing);
}
} // end of namespace mln::canvas::morpho::internal
@@ -393,20 +386,23 @@
// Facade.
+
template <typename I, typename N, typename A>
inline
mln_concrete(I)
- algebraic_union_find(const Image<I>& input,
+ algebraic_filter(const Image<I>& input,
const Neighborhood<N>& nbh,
const Accumulator<A>& accu,
- mln_result(A) lambda,
+ const mln_result(A)& lambda,
bool increasing)
{
- return internal::algebraic_union_find_dispatch(input, nbh, accu,
- lambda, increasing);
+ return internal::algebraic_filter_dispatch(input, nbh, accu, lambda,
+ increasing);
}
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln::canvas::morpho
} // end of namespace mln::canvas
@@ -414,4 +410,4 @@
} // end of namespace mln
-#endif // ! MLN_CANVAS_MORPHO_ALGEBRAIC_UNION_FIND_HH
+#endif // ! MLN_CANVAS_MORPHO_ALGEBRAIC_FILTER_HH
Property changes on: mln/canvas/morpho/algebraic_filter.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: tests/morpho/attribute/Makefile.am
--- tests/morpho/attribute/Makefile.am (revision 0)
+++ tests/morpho/attribute/Makefile.am (revision 0)
@@ -0,0 +1,10 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ card
+
+card_SOURCES = card.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/morpho/attribute/card.cc
--- tests/morpho/attribute/card.cc (revision 0)
+++ tests/morpho/attribute/card.cc (revision 0)
@@ -0,0 +1,50 @@
+// 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.
+
+/// \file tests/morpho/attribute/card.cc
+///
+/// Test on mln::morpho::attribute::card.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/morpho/attribute/card.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d<int> I;
+ I ima(3, 3);
+ point2d p(0, 0);
+ util::pix<I> px(ima, p);
+
+ morpho::attribute::card<I> c;
+ c.take();
+ c.take(p);
+ c.take(px);
+ mln_assertion(c == 3);
+}
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 3331)
+++ tests/morpho/Makefile.am (working copy)
@@ -3,12 +3,14 @@
include $(top_srcdir)/milena/tests/tests.mk
SUBDIRS = \
+ attribute \
elementary \
tree \
watershed
check_PROGRAMS = \
artificial_line_graph_image_wst \
+ closing_algebraic \
closing_area \
closing_height \
closing_volume \
@@ -45,6 +47,7 @@
erosion_SOURCES = erosion.cc
opening_area_SOURCES = opening_area.cc
+closing_algebraic_SOURCES = closing_algebraic.cc
closing_area_SOURCES = closing_area.cc
closing_height_SOURCES = closing_height.cc
opening_height_SOURCES = opening_height.cc
Index: tests/morpho/closing_algebraic.cc
--- tests/morpho/closing_algebraic.cc (revision 3330)
+++ tests/morpho/closing_algebraic.cc (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// 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
@@ -26,9 +25,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/// \file tests/morpho/closing_area.cc
+/// \file tests/morpho/closing_algebraic.cc
///
-/// Test on mln::morpho::closing_area.
+/// Test on mln::morpho::closing_algebraic.
#include <mln/core/image/image2d.hh>
#include <mln/value/int_u8.hh>
@@ -37,7 +36,9 @@
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
-#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/closing_algebraic.hh>
+#include <mln/morpho/attribute/card.hh>
+#include <mln/accu/count.hh>
#include "tests/data.hh"
@@ -48,7 +49,19 @@
using namespace mln;
using value::int_u8;
- image2d<int_u8> lena;
- io::pgm::load(lena, MLN_IMG_DIR "/lena.pgm");
- io::pgm::save(morpho::closing_area(lena, c4(), 510), "out.pgm");
+ trace::quiet = false;
+
+ typedef image2d<int_u8> I;
+ I lena;
+ io::pgm::load(lena, MLN_IMG_DIR "/tiny.pgm");//lena.pgm");
+ {
+ accu::count<point2d> a;
+ io::pgm::save(morpho::closing_algebraic(lena, c4(), a, 10),
+ "ref.pgm");
+ }
+ {
+ morpho::attribute::card<I> a;
+ io::pgm::save(morpho::closing_algebraic(lena, c4(), a, 10),
+ "out.pgm");
+ }
}
Property changes on: tests/morpho/closing_algebraic.cc
___________________________________________________________________
Added: svn:mergeinfo