https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some reference code in morpho tree.
* mln/morpho/tree/compute_parent.hh: Add doc.
* mln/morpho/tree/max.hh: New.
* mln/morpho/tree/all.hh: New.
* mln/morpho/tree/utils.hh: New.
* mln/morpho/all.hh: Update.
* tests/morpho/tree/max.cc: New.
* tests/morpho/tree/Makefile.am: Update.
mln/morpho/all.hh | 12 ++-
mln/morpho/tree/all.hh | 55 ++++++++++++++
mln/morpho/tree/compute_parent.hh | 18 ++++
mln/morpho/tree/max.hh | 91 ++++++++++++++++++++++++
mln/morpho/tree/utils.hh | 141 ++++++++++++++++++++++++++++++++++++++
tests/morpho/tree/Makefile.am | 5 -
tests/morpho/tree/max.cc | 73 +++++++++++++++++++
7 files changed, 386 insertions(+), 9 deletions(-)
Index: tests/morpho/tree/Makefile.am
--- tests/morpho/tree/Makefile.am (revision 2938)
+++ tests/morpho/tree/Makefile.am (working copy)
@@ -3,9 +3,10 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
- compute_tree
-
+ compute_tree \
+ max
compute_tree_SOURCES = compute_tree_.cc
+max_SOURCES = max_.cc
TESTS = $(check_PROGRAMS)
Index: tests/morpho/tree/max.cc
--- tests/morpho/tree/max.cc (revision 0)
+++ tests/morpho/tree/max.cc (revision 0)
@@ -0,0 +1,73 @@
+// Copyright (C) 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.
+
+/// \file tests/morpho/tree/max.cc
+///
+/// Tests on mln::morpho::tree::max.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+#include <mln/pw/image.hh>
+
+#include <mln/debug/println.hh>
+#include <mln/debug/iota.hh>
+#include <mln/morpho/elementary/dilation.hh>
+
+#include <mln/morpho/tree/utils.hh>
+#include <mln/morpho/tree/max.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d<unsigned> ima(3, 3);
+ debug::iota(ima);
+
+ ima = morpho::elementary::dilation(ima, c8());
+ debug::println(ima);
+
+ image2d<point2d> par = morpho::tree::max(ima, c4());
+ debug::println(par);
+
+
+// using morpho::tree::is_root;
+// using morpho::tree::is_a_node;
+
+// mln_piter_(box2d) p(ima.domain());
+// for_all(p)
+// if (is_root(par, p, ima))
+// std::cout << "R ";
+// else if (is_a_node(par, p, ima))
+// std::cout << "n ";
+// else
+// std::cout << ". ";
+// std::cout << std::endl;
+
+ p_array<point2d> s = level::sort_psites_increasing(ima);
+ std::cout << morpho::tree::nodes(par, ima, s) << std::endl;
+}
Index: mln/morpho/tree/compute_parent.hh
--- mln/morpho/tree/compute_parent.hh (revision 2938)
+++ mln/morpho/tree/compute_parent.hh (working copy)
@@ -49,9 +49,21 @@
namespace tree
{
- // Remember:
- // p is root iff parent(p) == p
- // p is node iff either p is root or f(parent(p)) != f(p)
+ /// Compute a tree with a parent relationship between sites.
+ ///
+ /// Warning: \p s translates the ordering related to the
+ /// "natural" childhood relationship. The parenthood is thus
+ /// inverted w.r.t. to \p s.
+ ///
+ /// It is very convenient since all processing upon the parent
+ /// tree are performed following \p s (in the default "forward"
+ /// way).
+ ///
+ /// FIXME: Put it more clearly...
+ ///
+ /// The parent result image verifies: \n
+ /// - p is root iff parent(p) == p \n
+ /// - p is a node iff either p is root or f(parent(p)) != f(p).
template <typename I, typename N, typename S>
mln_ch_value(I, mln_psite(I))
Index: mln/morpho/tree/max.hh
--- mln/morpho/tree/max.hh (revision 0)
+++ mln/morpho/tree/max.hh (revision 0)
@@ -0,0 +1,91 @@
+// Copyright (C) 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_TREE_MAX_HH
+# define MLN_MORPHO_TREE_MAX_HH
+
+/// \file mln/morpho/tree/max.hh
+///
+/// Compute a canonized (parenthood) max-tree from an image.
+
+# include <mln/morpho/tree/compute_parent.hh>
+# include <mln/level/sort_psites.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ namespace tree
+ {
+
+ // Remember:
+ // p is root iff parent(p) == p
+ // p is node iff either p is root or f(parent(p)) != f(p)
+
+ template <typename I, typename N>
+ mln_ch_value(I, mln_psite(I))
+ max(const Image<I>& f, const Neighborhood<N>& nbh);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename I, typename N>
+ inline
+ mln_ch_value(I, mln_psite(I))
+ max(const Image<I>& f_, const Neighborhood<N>& nbh_)
+ {
+ trace::entering("morpho::tree::max");
+
+ const I& f = exact(f_);
+ const N& nbh = exact(nbh_);
+
+ mln_precondition(f.has_data());
+ // mln_precondition(nbh.is_valid());
+
+ // For the max-tree, childhood maps "increasing level":
+ p_array<mln_psite(I)> s = level::sort_psites_increasing(f);
+ mln_ch_value(I, mln_psite(I)) output = compute_parent(f, nbh, s);
+
+ trace::exiting("morpho::tree::max");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho::tree
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_TREE_MAX_HH
Index: mln/morpho/tree/all.hh
--- mln/morpho/tree/all.hh (revision 0)
+++ mln/morpho/tree/all.hh (revision 0)
@@ -0,0 +1,55 @@
+// Copyright (C) 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_TREE_ALL_HH
+# define MLN_MORPHO_TREE_ALL_HH
+
+/// \file mln/morpho/tree/all.hh
+///
+/// File that includes all morphological tree-related routines.
+
+
+namespace mln
+{
+ namespace morpho
+ {
+
+ /// Namespace of morphological tree-related routines.
+ namespace tree
+ {}
+
+ }
+}
+
+
+# include <mln/morpho/tree/compute_parent.hh>
+# include <mln/morpho/tree/max.hh>
+# include <mln/morpho/tree/utils.hh>
+
+
+
+#endif // ! MLN_MORPHO_TREE_ALL_HH
Index: mln/morpho/tree/utils.hh
--- mln/morpho/tree/utils.hh (revision 0)
+++ mln/morpho/tree/utils.hh (revision 0)
@@ -0,0 +1,141 @@
+// Copyright (C) 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_TREE_UTILS_HH
+# define MLN_MORPHO_TREE_UTILS_HH
+
+/// \file mln/morpho/tree/utils.hh
+///
+/// Utilities.
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/site_set/p_array.hh>
+
+
+namespace mln
+{
+
+ namespace morpho
+ {
+
+ namespace tree
+ {
+
+ template <typename T, typename I>
+ bool
+ is_root(const Image<T>& parent, const mln_psite(T)& p,
+ const Image<I>& f);
+
+
+ template <typename T, typename I>
+ bool
+ is_a_node(const Image<T>& parent, const mln_psite(T)& p,
+ const Image<I>& f);
+
+
+
+ template <typename T, typename I, typename S>
+ p_array<mln_psite(T)>
+ nodes(const Image<T>& parent, const Image<I>& f, const Site_Set<S>& s);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename T, typename I>
+ inline
+ bool
+ is_root(const Image<T>& parent_, const mln_psite(T)& p,
+ const Image<I>& f_)
+ {
+ mlc_equal(mln_value(T), mln_psite(T))::check();
+
+ const T& parent = exact(parent_);
+ const I& f = exact(f_);
+
+ mln_precondition(parent.has_data());
+ mln_precondition(f.has_data());
+ mln_precondition(parent.domain() == f.domain());
+
+ return parent(p) == p;
+ }
+
+
+ template <typename T, typename I>
+ inline
+ bool
+ is_a_node(const Image<T>& parent_, const mln_psite(T)& p,
+ const Image<I>& f_)
+ {
+ mlc_equal(mln_value(T), mln_psite(T))::check();
+
+ const T& parent = exact(parent_);
+ const I& f = exact(f_);
+
+ mln_precondition(parent.has_data());
+ mln_precondition(f.has_data());
+ mln_precondition(parent.domain() == f.domain());
+
+ return parent(p) == p || f(parent(p)) != f(p);
+ }
+
+
+ template <typename T, typename I, typename S>
+ inline
+ p_array<mln_psite(T)>
+ nodes(const Image<T>& parent_, const Image<I>& f_, const Site_Set<S>& s_)
+ {
+ mlc_equal(mln_value(T), mln_psite(T))::check();
+
+ const T& parent = exact(parent_);
+ const I& f = exact(f_);
+ const S& s = exact(s_);
+
+ mln_precondition(parent.has_data());
+ mln_precondition(f.has_data());
+ mln_precondition(f.domain() == parent.domain());
+ mln_precondition(s == f.domain());
+
+ p_array<mln_psite(T)> arr;
+ mln_bkd_piter(S) p(exact(s));
+ for_all(p)
+ if (is_a_node(parent, p, f))
+ arr.insert(p);
+
+ return arr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho::tree
+
+ } // end of namespace mln::morpho
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MORPHO_TREE_MAX_HH
Index: mln/morpho/all.hh
--- mln/morpho/all.hh (revision 2938)
+++ mln/morpho/all.hh (working copy)
@@ -1,4 +1,5 @@
// 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
@@ -28,10 +29,9 @@
#ifndef MLN_MORPHO_ALL_HH
# define MLN_MORPHO_ALL_HH
-/*! \file mln/morpho/all.hh
- *
- * \brief File that includes all morpho-related routines.
- */
+/// \file mln/morpho/all.hh
+///
+/// File that includes all morpho-related routines.
namespace mln
@@ -82,7 +82,11 @@
# include <mln/morpho/thinning.hh>
# include <mln/morpho/top_hat.hh>
+
+// Sub-directories.
+
# include <mln/morpho/elementary/all.hh>
+# include <mln/morpho/tree/all.hh>
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add a morpho tree computation.
* mln/morpho/tree: New directory.
* mln/morpho/tree/compute_parent.hh: New; revamp of...
* sandbox/geraud/max_tree_nnodes.cc: ...this file.
* tests/morpho/tree: New directory.
* tests/morpho/tree/compute_parent.cc:
* tests/morpho/tree/Makefile.am: New.
* tests/morpho/Makefile.am: Update.
* mln/canvas/morpho/all.hh: Upgrade doc style.
mln/canvas/morpho/all.hh | 16 +-
mln/morpho/tree/compute_parent.hh | 273 +++++++++++++++++++++++-------------
tests/morpho/Makefile.am | 4
tests/morpho/tree/Makefile.am | 11 +
tests/morpho/tree/compute_parent.cc | 80 ++++++++++
5 files changed, 284 insertions(+), 100 deletions(-)
Index: tests/morpho/tree/compute_parent.cc
--- tests/morpho/tree/compute_parent.cc (revision 0)
+++ tests/morpho/tree/compute_parent.cc (revision 0)
@@ -0,0 +1,80 @@
+// Copyright (C) 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.
+
+/// \file tests/morpho/tree/compute_parent.cc
+///
+/// Tests on mln::morpho::tree::compute_parent.
+
+#include <mln/core/image/image2d.hh>
+#include <mln/core/alias/neighb2d.hh>
+
+#include <mln/debug/println.hh>
+#include <mln/debug/iota.hh>
+
+#include <mln/core/var.hh>
+#include <mln/core/image/image_if.hh>
+#include <mln/pw/value.hh>
+
+#include <mln/morpho/tree/compute_parent.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ {
+ bool vals[] = { 1, 1, 1,
+ 0, 1, 0,
+ 0, 0, 1 };
+ image2d<bool> ima = make::image2d(vals);
+ mln_VAR(sub, ima | pw::value(ima));
+ debug::println(sub);
+
+ mln_VAR(par, morpho::tree::compute_parent(sub, c4(), sub.domain()));
+ debug::println(par);
+ }
+
+/*
+ {
+ image2d<unsigned> ima(3, 3);
+ debug::iota(ima);
+ debug::println(ima);
+
+ debug::println( morpho::tree::compute_parent(ima, c4(), ima.domain()) );
+ }
+
+
+ {
+ image2d<unsigned> ima(3, 3);
+ level::fill(ima, 0);
+ debug::println(ima);
+
+ debug::println( morpho::tree::compute_parent(ima, c4(), ima.domain()) );
+ }
+*/
+
+}
Index: tests/morpho/tree/Makefile.am
--- tests/morpho/tree/Makefile.am (revision 0)
+++ tests/morpho/tree/Makefile.am (revision 0)
@@ -0,0 +1,11 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+include $(top_srcdir)/milena/tests/tests.mk
+
+check_PROGRAMS = \
+ compute_tree
+
+
+compute_tree_SOURCES = compute_tree_.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/morpho/Makefile.am
--- tests/morpho/Makefile.am (revision 2937)
+++ tests/morpho/Makefile.am (working copy)
@@ -2,7 +2,9 @@
include $(top_srcdir)/milena/tests/tests.mk
-SUBDIRS = elementary
+SUBDIRS = \
+ elementary \
+ tree
check_PROGRAMS = \
artificial_line_graph_image_wst \
Index: mln/morpho/tree/compute_parent.hh
--- mln/morpho/tree/compute_parent.hh (revision 0)
+++ mln/morpho/tree/compute_parent.hh (working copy)
@@ -1,151 +1,240 @@
+// Copyright (C) 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_TREE_COMPUTE_PARENT_HH
+# define MLN_MORPHO_TREE_COMPUTE_PARENT_HH
+
+/// \file mln/morpho/tree/compute_parent.hh
+///
+/// Compute a canonized tree from an image.
+///
+/// \todo Specialize for low quant (and try fastest).
# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/level/fill.hh>
-# include <mln/util/pix.hh>
-# include <mln/morpho/includes.hh>
-# include <mln/level/sort_psites.hh>
-
-# include <mln/core/image/image2d.hh>
-# include <mln/core/alias/neighb2d.hh>
-# include <mln/value/int_u8.hh>
-# include <mln/io/pgm/load.hh>
namespace mln
{
- template <typename I, typename N>
- struct max_tree_
+ namespace morpho
{
- typedef mln_site(I) point;
- typedef p_array<point> S;
- // in:
- const I& f;
- const N& nbh;
+ namespace tree
+ {
- // aux:
- S s;
- mln_ch_value(I, bool) deja_vu;
- mln_ch_value(I, point) parent;
- mln_ch_value(I, point) zpar;
+ // Remember:
+ // p is root iff parent(p) == p
+ // p is node iff either p is root or f(parent(p)) != f(p)
+
+ template <typename I, typename N, typename S>
+ mln_ch_value(I, mln_psite(I))
+ compute_parent(const Image<I>& f, const Neighborhood<N>& nbh,
+ const Site_Set<S>& s);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // Tests.
+
+
+ namespace internal
+ {
- max_tree_(const I& f, const N& nbh)
- : f(f),
- nbh(nbh)
+ template <typename I, typename N, typename S>
+ void
+ compute_parent_tests(const Image<I>& f_,
+ const Neighborhood<N>& nbh_,
+ const Site_Set<S>& s_)
{
- run();
+ const I& f = exact(f_);
+ const N& nbh = exact(nbh_);
+ const S& s = exact(s_);
+
+ mln_precondition(f.has_data());
+ // mln_precondition(nbh.is_valid());
+ mln_precondition(s == f.domain());
+
+ (void) f;
+ (void) nbh;
+ (void) s;
}
- void run()
+
+ } // end of namespace mln::morpho::tree::internal
+
+
+
+ // Implementations.
+
+
+ namespace impl
+ {
+
+ namespace generic
{
- // init
+
+ // Z-Find-Root.
+
+ template <typename T>
+ inline
+ mln_psite(T) zfind_root(T& zpar, const mln_psite(T)& x)
{
+ mlc_equal(mln_value(T), mln_psite(T))::check();
+ if (zpar(x) == x)
+ return x;
+ else
+ return zpar(x) = zfind_root(zpar, zpar(x));
+ }
+
+ // Compute-Parent.
+
+ template <typename I, typename N, typename S>
+ inline
+ mln_ch_value(I, mln_psite(I))
+ compute_parent(const Image<I>& f_,
+ const Neighborhood<N>& nbh_,
+ const Site_Set<S>& s_)
+ {
+ trace::entering("morpho::tree::impl::generic::compute_parent");
+
+ typedef mln_psite(I) P;
+
+ const I& f = exact(f_);
+ const N& nbh = exact(nbh_);
+ const S& s = exact(s_);
+
+ // Tests.
+ internal::compute_parent_tests(f, nbh, s);
+
+ // Auxiliary data.
+ mln_ch_value(I, bool) deja_vu;
+ mln_ch_value(I, P) parent;
+ mln_ch_value(I, P) zpar;
+
initialize(deja_vu, f);
- mln::level::fill(deja_vu, false);
initialize(parent, f);
initialize(zpar, f);
- s = level::sort_psites_decreasing(f);
- }
- // first pass
- {
- mln_fwd_piter(S) p(s);
+ // Initialization.
+ level::fill(deja_vu, false);
+
+ // Body.
+ mln_bkd_piter(S) p(s);
mln_niter(N) n(nbh, p);
for_all(p)
{
- make_set(p);
+ // Make-Set.
+ parent(p) = p;
+ zpar(p) = p;
+
for_all(n)
- if (f.has(n) && deja_vu(n))
- do_union(n, p);
- deja_vu(p) = true;
+ if (f.domain().has(n) && deja_vu(n))
+ {
+ // Do-Union.
+ P r = zfind_root(zpar, n);
+ if (r != p)
+ {
+ parent(r) = p;
+ zpar(r) = p;
}
}
+ deja_vu(p) = true;
+ }
- // second pass: canonization
+ // Canonization.
{
- mln_bkd_piter(S) p(s);
+ mln_fwd_piter(S) p(s);
for_all(p)
{
- point q = parent(p);
+ P q = parent(p);
if (f(parent(q)) == f(q))
parent(p) = parent(q);
}
}
- } // end of run()
-
- void make_set(const point& p)
- {
- parent(p) = p;
- zpar(p) = p;
+ trace::exiting("morpho::tree::impl::generic::compute_parent");
+ return parent;
}
- bool is_root(const point& p) const
- {
- return parent(p) == p;
- }
+ } // end of namespace mln::morpho::tree::impl::generic
+
+ } // end of namespace mln::morpho::tree::impl
- bool is_node(const point& p) const
- {
- return is_root(p) || f(parent(p)) != f(p);
- }
- point find_root(const point& x)
- {
- if (zpar(x) == x)
- return x;
- else
- return zpar(x) = find_root(zpar(x));
- }
- void do_union(const point& n, const point& p)
+ // Dispatch.
+
+ namespace internal
{
- point r = find_root(n);
- if (r != p)
+
+ template <typename I, typename N, typename S>
+ inline
+ mln_ch_value(I, mln_psite(I))
+ compute_parent_dispatch(const Image<I>& f,
+ const Neighborhood<N>& nbh,
+ const Site_Set<S>& s)
{
- parent(r) = p;
- zpar(r) = p;
+ return impl::generic::compute_parent(f, nbh, s);
}
- }
-
- };
+ } // end of namespace mln::morpho::tree::internal
+ // Facade.
- template <typename I, typename N>
- unsigned max_tree(const I& f, const N& nbh)
+ template <typename I, typename N, typename S>
+ inline
+ mln_ch_value(I, mln_psite(I))
+ compute_parent(const Image<I>& f, const Neighborhood<N>& nbh,
+ const Site_Set<S>& s)
{
- max_tree_<I,N> run(f, nbh);
+ trace::entering("morpho::tree::compute_parent");
- mln_piter(I) p(f.domain());
- unsigned nnodes = 0;
- for_all(p)
- if (run.is_node(p))
- ++nnodes;
- return nnodes;
- }
+ internal::compute_parent_tests(f, nbh, s);
+
+ mln_ch_value(I, mln_psite(I)) output;
+ output = internal::compute_parent_dispatch(f, nbh, s);
-} // end of mln
+ trace::exiting("morpho::tree::compute_parent");
+ return output;
+ }
+# endif // ! MLN_INCLUDE_ONLY
+ } // end of namespace mln::morpho::tree
-int main(int argc, char* argv[])
-{
- if (argc != 2)
- {
- std::cerr << "usage: " << argv[0] << " filename" << std::endl;
- return 1;
- }
+ } // end of namespace mln::morpho
- using namespace mln;
- using value::int_u8;
+} // end of namespace mln
- image2d<int_u8> f;
- io::pgm::load(f, argv[1]);
- std::cout << "n nodes = " << mln::max_tree(f, c8()) << std::endl;
-}
+#endif // ! MLN_MORPHO_TREE_COMPUTE_PARENT_HH
Index: mln/canvas/morpho/all.hh
--- mln/canvas/morpho/all.hh (revision 2937)
+++ mln/canvas/morpho/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -28,23 +29,24 @@
#ifndef MLN_CANVAS_MORPHO_ALL_HH
# define MLN_CANVAS_MORPHO_ALL_HH
-/*! \file mln/canvas/morpho/all.hh
- *
- * \brief File that includes morphological canvas-related routines.
- */
+/// \file mln/canvas/morpho/all.hh
+///
+/// File that includes morphological canvas-related routines.
namespace mln
{
-
namespace canvas
{
+
/// Namespace of morphological canvas.
namespace morpho {}
- }
}
+}
+
# include <mln/canvas/morpho/algebraic_union_find.hh>
+
#endif // ! MLN_CANVAS_MORPHO_ALL_HH
* doc/examples/mk_graph.cc: use int_u16 instead of int_u8.
* mln/debug/colorize.hh,
* mln/debug/draw_graph.hh,
* mln/level/compute.hh,
* mln/literal/zero.hh,
* mln/value/concept/symbolic.hh,
* mln/value/int_u.hh,
* mln/value/internal/value_like.hh: Cleanup comments.
* tests/core/image/graph_image.cc: Fix includes.
---
milena/ChangeLog | 17 +++++++++++++++
milena/doc/examples/mk_graph.cc | 12 +++++-----
milena/mln/debug/colorize.hh | 20 +++++++++--------
milena/mln/debug/draw_graph.hh | 7 ++---
milena/mln/level/compute.hh | 24 ++++++++++----------
milena/mln/literal/zero.hh | 14 ++++++------
milena/mln/value/concept/symbolic.hh | 12 +++++-----
milena/mln/value/int_u.hh | 35 +++++++++++++++----------------
milena/mln/value/internal/value_like.hh | 34 +++++++++++++----------------
milena/tests/core/image/graph_image.cc | 2 +-
10 files changed, 95 insertions(+), 82 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 3dfa998..7c72bd2 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,22 @@
2008-11-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Cleanup various files.
+
+ * doc/examples/mk_graph.cc: use int_u16 instead of int_u8.
+
+ * mln/debug/colorize.hh,
+ * mln/debug/draw_graph.hh,
+ * mln/level/compute.hh,
+ * mln/literal/zero.hh,
+ * mln/value/concept/symbolic.hh,
+ * mln/value/int_u.hh,
+ * mln/value/internal/value_like.hh: Cleanup comments.
+
+ * tests/core/image/graph_image.cc: Fix includes.
+
+
+2008-11-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Update unit tests.
* tests/unit_test/Makefile.am: update list of tests.
diff --git a/milena/doc/examples/mk_graph.cc b/milena/doc/examples/mk_graph.cc
index 18b7a86..eff6433 100644
--- a/milena/doc/examples/mk_graph.cc
+++ b/milena/doc/examples/mk_graph.cc
@@ -47,7 +47,7 @@
int main(int argc, char *argv[])
{
using namespace mln;
- using value::int_u8;
+ using value::int_u16;
if (argc < 2)
{
@@ -59,13 +59,13 @@ int main(int argc, char *argv[])
logical::not_inplace(ima);
// Create a label image and compute the influence zones.
- int_u8 nlabels;
- image2d<int_u8> lbl = labeling::blobs(ima, c8(), nlabels);
+ int_u16 nlabels;
+ image2d<int_u16> lbl = labeling::blobs(ima, c8(), nlabels);
io::ppm::save(debug::colorize< image2d<value::rgb8> >(lbl, nlabels),
"1_blobs.ppm");
- image2d<int_u8> iz = transform::influence_zone_geodesic(lbl,
- c8(),
- lbl.ncols());
+ image2d<int_u16> iz = transform::influence_zone_geodesic(lbl,
+ c8(),
+ lbl.ncols());
io::ppm::save(debug::colorize< image2d<value::rgb8> >(iz, nlabels),
"2_influence_zone_geodesic.ppm");
diff --git a/milena/mln/debug/colorize.hh b/milena/mln/debug/colorize.hh
index c997921..f764278 100644
--- a/milena/mln/debug/colorize.hh
+++ b/milena/mln/debug/colorize.hh
@@ -1,4 +1,5 @@
// Copyright (C) 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
@@ -28,10 +29,9 @@
#ifndef MLN_DEBUG_COLORIZE_HH
# define MLN_DEBUG_COLORIZE_HH
-/*! \file mln/debug/colorize.hh
- *
- * \brief Fill an image with successive values.
- */
+/// \file mln/debug/colorize.hh
+///
+/// Fill an image with successive values.
# include <mln/core/concept/image.hh>
# include <mln/fun/i2v/array.hh>
@@ -64,8 +64,8 @@ namespace mln
* \param[in] labeled_image A labeled image (\sa labeling::blobs).
* \param[in] nlabels Number of labels.
*/
- template <typename I, typename J>
- mln_concrete(I) colorize(const Image<J>& labeled_image, mln_value(J) nlabels);
+ template <typename I, typename L>
+ mln_concrete(I) colorize(const Image<L>& labeled_image, mln_value(L) nlabels);
# ifndef MLN_INCLUDE_ONLY
@@ -93,10 +93,10 @@ namespace mln
}
- template <typename I, typename J>
+ template <typename I, typename L>
inline
mln_concrete(I)
- colorize(const Image<J>& input, mln_value(J) nlabels)
+ colorize(const Image<L>& input, mln_value(L) nlabels)
{
trace::entering("debug::colorize");
mln_precondition(exact(input).has_data());
@@ -109,8 +109,10 @@ namespace mln
unsigned i = f.size() + diff_size;
// We want to treat comp 0 differently since it is the background.
if (i == 0)
+ {
i = 1;
- f(0) = literal::black;
+ f(0) = literal::black;
+ }
for (; i < f.size(); ++i)
f(i) = internal::random_color();
}
diff --git a/milena/mln/debug/draw_graph.hh b/milena/mln/debug/draw_graph.hh
index 159b974..a891534 100644
--- a/milena/mln/debug/draw_graph.hh
+++ b/milena/mln/debug/draw_graph.hh
@@ -29,16 +29,15 @@
#ifndef MLN_DEBUG_DRAW_GRAPH_HH
# define MLN_DEBUG_DRAW_GRAPH_HH
-/// \file mln/debug/graph.hh
+/// \file mln/debug/draw_graph.hh
///
/// \brief Draw an (classical) image from a mln::graph_image.
///
/// \todo write a version for graph images.
-# include <mln/pw/image.hh>
-# include <mln/level/fill.hh>
-# include <mln/draw/line.hh>
# include <mln/core/site_set/p_vertices.hh>
+# include <mln/draw/line.hh>
+# include <mln/level/fill.hh>
namespace mln
{
diff --git a/milena/mln/level/compute.hh b/milena/mln/level/compute.hh
index 776ee66..888120f 100644
--- a/milena/mln/level/compute.hh
+++ b/milena/mln/level/compute.hh
@@ -45,24 +45,24 @@ namespace mln
{
/// Compute an accumulator onto the pixel values of the image \p input.
- /*!
- * \param[in] a An accumulator.
- * \param[in] input The input image.
- * \return The accumulator result.
- *
- * It fully relies on level::update.
- */
+ ///
+ /// \param[in] a An accumulator.
+ /// \param[in] input The input image.
+ /// \return The accumulator result.
+ ///
+ /// It fully relies on level::update.
+ ///
template <typename A, typename I>
mln_result(A)
compute(const Accumulator<A>& a, const Image<I>& input);
/// Compute an accumulator onto the pixel values of the image \p input.
- /*!
- * \param[in] a A meta-accumulator.
- * \param[in] input The input image.
- * \return The accumulator result.
- */
+ ///
+ /// \param[in] a A meta-accumulator.
+ /// \param[in] input The input image.
+ /// \return The accumulator result.
+ ///
template <typename A, typename I>
mln_accu_with(A, mln_value(I))::result
compute(const Meta_Accumulator<A>& a, const Image<I>& input);
diff --git a/milena/mln/literal/zero.hh b/milena/mln/literal/zero.hh
index 8762ec1..b6b4e48 100644
--- a/milena/mln/literal/zero.hh
+++ b/milena/mln/literal/zero.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -28,12 +29,11 @@
#ifndef MLN_LITERAL_ZERO_HH
# define MLN_LITERAL_ZERO_HH
-/*! \file mln/literal/zero.hh
- *
- * \brief Definition of the literal of mln::zero.
- *
- * \todo Macro-ification of similar code (when no trivial conversion ops are involved).
- */
+/// \file mln/literal/zero.hh
+///
+/// Definition of the literal of mln::zero.
+///
+/// \todo Macro-ification of similar code (when no trivial conversion ops are involved).
# include <mln/core/concept/literal.hh>
# include <mln/metal/converts_to.hh>
diff --git a/milena/mln/value/concept/symbolic.hh b/milena/mln/value/concept/symbolic.hh
index ad171d9..b4d0d98 100644
--- a/milena/mln/value/concept/symbolic.hh
+++ b/milena/mln/value/concept/symbolic.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -28,10 +29,9 @@
#ifndef MLN_VALUE_CONCEPT_SYMBOLIC_HH
# define MLN_VALUE_CONCEPT_SYMBOLIC_HH
-/*! \file mln/value/concept/symbolic.hh
- *
- * \brief Define a generic class for symbolic values.
- */
+/// \file mln/value/concept/symbolic.hh
+///
+/// Define a generic class for symbolic values.
# include <mln/core/concept/value.hh>
@@ -39,7 +39,7 @@
namespace mln
{
- // Fwd decl.
+ // Forward declaration.
namespace value { template <typename E> struct Symbolic; }
diff --git a/milena/mln/value/int_u.hh b/milena/mln/value/int_u.hh
index 10d6526..e5589fe 100644
--- a/milena/mln/value/int_u.hh
+++ b/milena/mln/value/int_u.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -28,10 +29,9 @@
#ifndef MLN_VALUE_INT_U_HH
# define MLN_VALUE_INT_U_HH
-/*! \file mln/value/int_u.hh
- *
- * \brief Define a generic class for unsigned integers.
- */
+/// \file mln/value/int_u.hh
+///
+/// Define a generic class for unsigned integers.
# include <mln/trait/all.hh> // FIXME!
@@ -51,13 +51,13 @@ namespace mln
namespace value
{
- // Fwd decls.
+ // Forward declaration.
template <unsigned n> struct int_u;
}
namespace literal
{
- // Fwd decls.
+ // Forward declarations.
struct zero_t;
struct one_t;
}
@@ -104,10 +104,9 @@ namespace mln
namespace value
{
- /*! \brief Unsigned integer value class.
- *
- * The parameter is \c n the number of encoding bits.
- */
+ /// Unsigned integer value class.
+ ///
+ /// The parameter is \c n the number of encoding bits.
template <unsigned n>
struct int_u
:
@@ -154,13 +153,13 @@ namespace mln
- /*! \brief Print an unsigned integer \p i into the output stream \p ostr.
- *
- * \param[in,out] ostr An output stream.
- * \param[in] i An unsigned integer.
- *
- * \return The modified output stream \p ostr.
- */
+ /// \brief Print an unsigned integer \p i into the output stream \p ostr.
+ ///
+ /// \param[in,out] ostr An output stream.
+ /// \param[in] i An unsigned integer.
+ ///
+ /// \return The modified output stream \p ostr.
+ ///
template <unsigned n>
std::ostream& operator<<(std::ostream& ostr, const int_u<n>& i);
diff --git a/milena/mln/value/internal/value_like.hh b/milena/mln/value/internal/value_like.hh
index 7a52e80..6159ee5 100644
--- a/milena/mln/value/internal/value_like.hh
+++ b/milena/mln/value/internal/value_like.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// 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
@@ -28,12 +29,9 @@
#ifndef MLN_VALUE_INTERNAL_VALUE_LIKE_HH
# define MLN_VALUE_INTERNAL_VALUE_LIKE_HH
-/*! \file mln/value/internal/value_like.hh
- *
- * \brief Factor code for value classes defined over another type.
- *
- *
- */
+/// \file mln/value/internal/value_like.hh
+///
+/// Factor code for value classes defined over another type.
# include <mln/core/concept/value.hh>
# include <mln/core/internal/force_exact.hh>
@@ -48,10 +46,10 @@ namespace mln
namespace internal
{
- /*! Base class for value classes defined over another
- * type. Parameters are \c V the equivalent value type and
- * \c E the exact value type.
- */
+ /// Base class for value classes defined over another
+ /// type. Parameters are \c V the equivalent value type and
+ /// \c E the exact value type.
+ ///
template < typename V, // Equivalent.
typename C, // Encoding.
typename N, // Interoperation.
@@ -85,18 +83,16 @@ namespace mln
};
- /*! General definition of the "equal to" operator between
- * value-like types.
- *
- */
+ /// General definition of the "equal to" operator between
+ /// value-like types.
+ ///
template <typename V, typename C, typename N, typename E>
bool operator==(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
- /*! General definition of the "less than" operator
- * between value-like types.
- *
- */
+ /// General definition of the "less than" operator
+ /// between value-like types.
+ ///
template <typename V, typename C, typename N, typename E>
bool operator<(const value_like_<V,C,N,E>& lhs, const value_like_<V,C,N,E>& rhs);
diff --git a/milena/tests/core/image/graph_image.cc b/milena/tests/core/image/graph_image.cc
index 9fc556c..3614807 100644
--- a/milena/tests/core/image/graph_image.cc
+++ b/milena/tests/core/image/graph_image.cc
@@ -49,7 +49,7 @@
#include <mln/util/graph.hh>
-#include <mln/debug/graph.hh>
+#include <mln/debug/draw_graph.hh>
#include <mln/debug/println.hh>
#include <mln/core/concept/function.hh>
--
1.5.6.5