
https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@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>