URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2009-05-26 Edwin Carlinet <carlinet(a)lrde.epita.fr>
Move propagation and filtering attributes routines from sandbox.
* mln/morpho/tree/filter: New.
* mln/morpho/tree/propagate_if.hh: New.
* mln/morpho/tree/propagate_node.hh: New.
* mln/morpho/tree/propagate_representative.hh: New.
* sandbox/edwin/mln/morpho/tree/filter/all.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/direct.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/max.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/min.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter/subtractive.hh: Remove.
* sandbox/edwin/mln/morpho/tree/filter: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_if.hh: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_node.hh: Remove.
* sandbox/edwin/mln/morpho/tree/propagate_representative.hh: Remove.
---
trunk/milena/headers.mk | 10
trunk/milena/mln/morpho/tree/filter/all.hh | 66 +++
trunk/milena/mln/morpho/tree/filter/direct.hh | 91 ++++
trunk/milena/mln/morpho/tree/filter/max.hh | 110 +++++
trunk/milena/mln/morpho/tree/filter/min.hh | 100 ++++
trunk/milena/mln/morpho/tree/filter/subtractive.hh | 97 ++++
trunk/milena/mln/morpho/tree/propagate_if.hh | 326 +++++++++++++++
trunk/milena/mln/morpho/tree/propagate_node.hh | 209 +++++++++
trunk/milena/mln/morpho/tree/propagate_representative.hh | 76 +++
9 files changed, 1084 insertions(+), 1 deletion(-)
Index: trunk/milena/headers.mk
===================================================================
--- trunk/milena/headers.mk (revision 3874)
+++ trunk/milena/headers.mk (revision 3875)
@@ -261,6 +261,8 @@
mln/core/image/complex_window_piter.hh \
mln/core/image/complex_windows.hh \
mln/core/image/decorated_image.hh \
+mln/core/image/dmorph/all.hh \
+mln/core/image/dmorph/transformed_image.hh \
mln/core/image/edge_image.hh \
mln/core/image/essential.hh \
mln/core/image/extended.hh \
@@ -398,6 +400,8 @@
mln/core/site_set/p_run_piter.hh \
mln/core/site_set/p_set.hh \
mln/core/site_set/p_set_of.hh \
+mln/core/site_set/p_transformed.hh \
+mln/core/site_set/p_transformed_piter.hh \
mln/core/site_set/p_vaccess.hh \
mln/core/site_set/p_vertices.hh \
mln/core/site_set/p_vertices_psite.hh \
@@ -664,6 +668,8 @@
mln/io/pgm/all.hh \
mln/io/pgm/load.hh \
mln/io/pgm/save.hh \
+mln/io/plot/all.hh \
+mln/io/plot/load.hh \
mln/io/plot/save.hh \
mln/io/pnm/all.hh \
mln/io/pnm/load_header.hh \
@@ -677,7 +683,6 @@
mln/io/ppm/save.hh \
mln/io/tiff/all.hh \
mln/io/tiff/load.hh \
-mln/io/tiff/save.hh \
mln/io/txt/all.hh \
mln/io/txt/save.hh \
mln/labeling/all.hh \
@@ -934,6 +939,8 @@
mln/morpho/reconstruction/all.hh \
mln/morpho/reconstruction/by_dilation/all.hh \
mln/morpho/reconstruction/by_dilation/union_find.hh \
+mln/morpho/reconstruction/by_erosion/all.hh \
+mln/morpho/reconstruction/by_erosion/union_find.hh \
mln/morpho/skeleton_constrained.hh \
mln/morpho/thickening.hh \
mln/morpho/thick_miss.hh \
@@ -1245,6 +1252,7 @@
mln/value/stack.hh \
mln/value/super_value.hh \
mln/value/viter.hh \
+mln/version.hh \
mln/win/all.hh \
mln/win/backdiag2d.hh \
mln/win/ball.hh \
Index: trunk/milena/mln/morpho/tree/propagate_representative.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_representative.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_representative.hh (revision 3875)
@@ -0,0 +1,76 @@
+// 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_TREE_PROPAGATE_REPRESENTATIVE_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_
+
+/// \file mln/morpho/tree/propagate_representative.hh
+///
+/// Component tree routines.
+
+namespace mln{
+ namespace morpho {
+ namespace tree {
+
+ /**
+ ** Propagate the representative node's value to
+ ** non-representative points of the component.
+ **
+ ** @param t Component tree.
+ ** @param f_ Value image.
+ */
+ template <typename T, typename F>
+ void
+ propagate_representative(const T& t, Image<F>& f_);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F>
+ inline
+ void
+ propagate_representative(const T& t, Image<F>& f_)
+ {
+ F a = exact(f_);
+ mln_up_site_piter(T) p(t);
+ for_all(p)
+ if (! t.is_a_node(p))
+ {
+ mln_assertion(t.is_a_node(t.parent(p)));
+ a(p) = a(t.parent(p));
+ }
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ }
+ }
+}
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_REPRESENTATIVE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_representative.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/filter/min.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/min.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/min.hh (revision 3875)
@@ -0,0 +1,100 @@
+// 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_TREE_FILTER_MIN_HH_
+# define MLN_MORPHO_TREE_FILTER_MIN_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+
+/**
+** @file mln/morpho/tree/filter/min.hh
+**
+** @brief Filtering with min strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+
+ /**
+ ** Min pruning strategy. A node is removed iif its parent is
+ ** removed or if it does not verify the predicate \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ min(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::min");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)) || !pred(n))
+ {
+ f(n) = f(tree.parent(n));
+ mark(n) = true;
+ }
+
+ trace::exiting("mln::morpho::tree::filter::min");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MIN_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/max.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/max.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/max.hh (revision 3875)
@@ -0,0 +1,110 @@
+// 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_TREE_FILTER_MAX_HH_
+# define MLN_MORPHO_TREE_FILTER_MAX_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/max.hh
+**
+** @brief Filtering with max strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Max pruning strategy. A node is removed iif all of its
+ ** children are removed or if it does not verify the predicate
+ ** \p pred_.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ max(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::max");
+
+ mln_ch_value(F, bool) mark;
+ initialize(mark, f);
+ mln::data::fill(mark, true);
+
+ {
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!mark(n))
+ mark(tree.parent(n)) = false;
+ else if (pred(n))
+ {
+ mark(tree.parent(n)) = false;
+ mark(n) = false;
+ }
+ }
+
+ {
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(n))
+ f(n) = f(tree.parent(n));
+ }
+
+ trace::exiting("mln::morpho::tree::filter::max");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_MAX_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/all.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/all.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/all.hh (revision 3875)
@@ -0,0 +1,66 @@
+// 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_TREE_FILTER_ALL_HH_
+# define MLN_MORPHO_TREE_FILTER_ALL_HH_
+
+/**
+** @file mln/morpho/tree/filter.hh
+**
+** Methods to handle component tree filtering strategies with
+** non-increasing attribute. Nevertheless, it works on increasing
+** predicate as well. In this case, all strategies have the same
+** result but min filter or direct filter should be used in term
+** of performance. If a predicate test is too slow, then consider
+** the min filter that minimizes calls to predicate function.
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ /// Namespace for attribute filtering.
+ namespace filter {
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+
+// Pruning strategies.
+# include <mln/morpho/tree/filter/min.hh>
+# include <mln/morpho/tree/filter/max.hh>
+
+// Non-pruning stategies.
+# include <mln/morpho/tree/filter/direct.hh>
+# include <mln/morpho/tree/filter/subtractive.hh>
+
+
+
+#endif /* !MLN_MORPHO_TREE_FILTER_ALL_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/direct.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/direct.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/direct.hh (revision 3875)
@@ -0,0 +1,91 @@
+// 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_TREE_FILTER_DIRECT_HH_
+# define MLN_MORPHO_TREE_FILTER_DIRECT_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/morpho/tree/data.hh>
+
+/**
+** @file mln/morpho/tree/filter/direct.hh
+**
+** @brief Filtering with direct strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Direct non-pruning strategy. A node is removed if it does
+ ** not verify the predicate. The sub-components remain intact.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ direct(const T& tree, Image<F>& f_, const Function_p2b<P2B>&
pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::direct");
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::direct");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_DIRECT_HH_ */
Index: trunk/milena/mln/morpho/tree/filter/subtractive.hh
===================================================================
--- trunk/milena/mln/morpho/tree/filter/subtractive.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/filter/subtractive.hh (revision 3875)
@@ -0,0 +1,97 @@
+// 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_TREE_FILTER_SUBTRACTIVE_HH_
+# define MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_
+
+# include <mln/core/concept/function.hh>
+# include <mln/fun/ops.hh>
+
+# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_if.hh>
+
+/**
+** @file mln/morpho/tree/filter/subtractive.hh
+**
+** @brief Filtering with subtractive strategy.
+**
+**
+*/
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+ namespace filter {
+
+ /**
+ ** Subtractive pruning strategy. The node is removed if it
+ ** does not verify the predicate. The sub-components values
+ ** are set to the value of the removed component.
+ **
+ ** @param[in] tree Component tree.
+ ** @param[out] f_ Image to filter.
+ ** @param[in] pred_ Filtering criterion.
+ */
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const
Function_p2b<P2B>& pred_);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename F, typename P2B>
+ inline
+ void
+ subtractive(const T& tree, Image<F>& f_, const
Function_p2b<P2B>& pred_)
+ {
+ F& f = exact(f_);
+ const P2B& pred = exact(pred_);
+
+ trace::entering("mln::morpho::tree::filter::subtractive");
+
+ morpho::tree::propagate_if(tree, f, morpho::tree::desc_propagation (), !pred);
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (!pred(n))
+ f(n) = f(tree.parent(n));
+
+ trace::exiting("mln::morpho::tree::filter::subtractive");
+ }
+
+# endif /* !MLN_INCLUDE_ONLY */
+
+ } // end of namespace mln::morpho::tree::filter
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_FILTER_SUBTRACTIVE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/filter
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/propagate_node.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_node.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_node.hh (revision 3875)
@@ -0,0 +1,209 @@
+// 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_TREE_PROPAGATE_NODE_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_NODE_HH_
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/macros.hh>
+# include <mln/morpho/tree/data.hh>
+
+/// \file mln/morpho/tree/propagate_node.hh
+///
+/// Functions to propagate node in the tree.
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ /**
+ ** Propagate a value \p v from a node \p n to its descendants.
+ **
+ ** @param n[in] Node to propagate.
+ ** @param t[in] Component tree used for propagation.
+ ** @param a_[in] Attribute image where values are propagated.
+ ** @param v[in] Value to propagate.
+ ** @param nb_leaves[out] Optional. Store the number of leaves in
+ ** the component.
+ */
+ template <typename T, typename A>
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v,
+ unsigned* nb_leaves = 0);
+
+ /**
+ ** Propagate the node's value to its descendants.
+ **
+ ** @param n[in] Node to propagate.
+ ** @param t[in] Component tree used for propagation.
+ ** @param a_[in] Attribute image where values are propagated.
+ ** @param nb_leaves[out] Optional. Store the number of leaves in
+ ** the component.
+ */
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A)& n,
+ const T& t,
+ Image<A>& a_,
+ unsigned* nb_leaves = 0);
+
+
+ /**
+ ** Propagate a value \p v from a node \p n to its ancestors.
+ **
+ ** @param n Node to propagate.
+ ** @param t Component tree used for propagation.
+ ** @param a_ Attribute image where values are propagated.
+ ** @param v Value to propagate.
+ */
+ template <typename T, typename A>
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v);
+
+ /**
+ ** Propagate the node's value to its ancestors.
+ **
+ ** @param n Node to propagate.
+ ** @param t Component tree used for propagation.
+ ** @param a_ Attribute image where values are propagated.
+ */
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_);
+
+
+ # ifndef MLN_INCLUDE_ONLY
+
+ /* Descendants propagation */
+
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v,
+ unsigned* nb_leaves = 0)
+ {
+ A& a = exact(a_);
+ mln_precondition(a.is_valid());
+ mln_precondition(a.domain() == t.f().domain());
+ mln_precondition(a.domain().has(n));
+
+
+ if (!t.is_a_node(n)) // Get the representant.
+ n = t.parent(n);
+ mln_assertion(t.is_a_node(n));
+
+ typename T::preorder_piter pp(t, n);
+
+ pp.start(); // We don't set n to v.
+
+ if (nb_leaves)
+ *nb_leaves += t.is_a_leaf(pp);
+
+ for (pp.next(); pp.is_valid(); pp.next())
+ {
+ a(pp) = v;
+ if (nb_leaves && t.is_a_leaf(pp))
+ ++(*nb_leaves);
+ }
+ }
+
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_descendants(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ unsigned* nb_leaves = 0)
+
+ {
+ A& a = exact(a_);
+ propagate_node_to_descendants(n, t, a, a(n), nb_leaves);
+ }
+
+
+ /* Ancestors propagation */
+
+ template <typename T, typename A>
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ mln_precondition(a.is_valid());
+ mln_precondition(a.domain() == t.f().domain());
+ mln_precondition(a.domain().has(n));
+
+ if (!t.is_a_node(n)) // Get the representant.
+ n = t.parent(n);
+ mln_assertion(t.is_a_node(n));
+
+ if (t.is_root(n))
+ return;
+
+ do {
+ n = t.parent(n);
+ a(n) = v;
+ } while (!t.is_root(n));
+
+ }
+
+ template <typename T, typename A>
+ inline
+ void
+ propagate_node_to_ancestors(mln_psite(A) n,
+ const T& t,
+ Image<A>& a_)
+ {
+ A& a = exact(a_);
+ propagate_node_to_ancestors(n, t, a, a(n));
+ }
+
+ # endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_NODE_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_node.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/mln/morpho/tree/propagate_if.hh
===================================================================
--- trunk/milena/mln/morpho/tree/propagate_if.hh (revision 0)
+++ trunk/milena/mln/morpho/tree/propagate_if.hh (revision 3875)
@@ -0,0 +1,326 @@
+// 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_TREE_PROPAGATE_IF_HH_
+# define MLN_MORPHO_TREE_PROPAGATE_IF_HH_
+
+/**
+** @file mln/morpho/tree/propagate_if.hh
+**
+** @brief Routines to handle propagation with predicate.
+**
+*/
+
+# include <mln/morpho/tree/data.hh>
+# include <mln/morpho/tree/propagate_node.hh>
+
+# include <mln/data/fill.hh>
+# include <mln/pw/all.hh>
+
+namespace mln {
+ namespace morpho {
+ namespace tree {
+
+ template <typename WP>
+ struct way_of_propagation : Object< WP > { protected: way_of_propagation()
{}; };
+ struct desc_propagation : way_of_propagation <desc_propagation> {};
+ struct asc_propagation : way_of_propagation <asc_propagation> {};
+
+ /**
+ ** Propagate nodes checking the predicate \p pred in the way
+ ** defined by \p way_of_propagation.
+ **
+ ** @param tree Component tree used for propagation.
+ ** @param a_ Attributed image where values are propagated.
+ ** @param way_of_propagation Propagate node in acsendant or
+ ** descendant way.
+ ** @param pred Predicate that node must check to be propagated.
+ ** @param v Value to be propagated. (By default \p v is the value
+ ** at the node being propagated).
+ */
+ template <typename T, typename A, typename P2B, typename WP>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const Function_p2b<P2B>& pred,
+ const mln_value(A)& v);
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const desc_propagation&,
+ const Function_p2b<P2B>& pred);
+
+ /**
+ ** Propagate nodes having the value v in the way
+ ** defined by \p way_of_propagation.
+ **
+ ** @param tree Component tree used for propagation.
+ ** @param a_ Attributed image where values are propagated.
+ ** @param way_of_propagation Propagate node in acsendant or
+ ** descendant way.
+ ** @param v Value that node must have to be propagated.
+ ** @param v_prop Value to propagate (By default it is the value
+ ** at the node being propagated).
+ */
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const mln_value(A)& v,
+ const mln_value(A)& v_prop);
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>&,
+ const mln_value(A)& v);
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const asc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (pred(n) && a(t.parent(n)) != v)
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const desc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (a(n) != v && pred(t.parent(n)))
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ bool check_propagate_if(const T& t,
+ const A& a,
+ const desc_propagation& prop,
+ const P2B& pred)
+ {
+ (void) prop;
+ mln_node_piter(T) n(t);
+ for_all(n)
+ if (a(n) != a(t.parent(n)) && pred(t.parent(n)))
+ return false;
+ return true;
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const desc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)))
+ {
+ a(n) = v;
+ mark(n) = true;
+ }
+ else if (pred(n))
+ mark(n) = true;
+ mln_postcondition(check_propagate_if(tree, a, prop, pred, v));
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const desc_propagation& prop,
+ const P2B& pred)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_dn_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(tree.parent(n)))
+ {
+ a(n) = a(tree.parent(n));
+ mark(n) = true;
+ }
+ else if (pred(n))
+ mark(n) = true;
+ mln_postcondition(check_propagate_if(tree, a, prop, pred));
+ }
+
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ A& a,
+ const asc_propagation& prop,
+ const P2B& pred,
+ const mln_value(A)& v)
+ {
+ (void) prop;
+
+ mln_precondition(a.is_valid());
+ mln_precondition(tree.f().domain() == a.domain());
+
+ mln_ch_value(typename T::function, bool) mark;
+ initialize(mark, tree.f());
+ mln::data::fill(mark, false);
+
+ mln_up_node_piter(T) n(tree);
+ for_all(n)
+ if (mark(n))
+ {
+ a(n) = v;
+ mark(tree.parent(n)) = true;
+ }
+ else if (pred(n))
+ mark(tree.parent(n)) = true;
+
+ mln_postcondition(check_propagate_if(tree, a, prop, pred, v));
+ }
+
+ } // end of namespace mln::morpho::tree::internal
+
+
+ /* Facades */
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const mln_value(A)& v,
+ const mln_value(A)& v_prop)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+
+ internal::propagate_if(tree, a, prop, pw::value(a) == pw::cst(v), v_prop);
+ }
+
+
+ template <typename T, typename A, typename WP>
+ inline
+ void
+ propagate_if_value(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+
+ internal::propagate_if(tree, a, prop, pw::value(a) == pw::cst(v), v);
+ }
+
+ template <typename T, typename A, typename P2B, typename WP>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const way_of_propagation<WP>& prop_,
+ const Function_p2b<P2B>& pred_,
+ const mln_value(A)& v)
+ {
+ A& a = exact(a_);
+ const WP& prop = exact(prop_);
+ const P2B& pred = exact(pred_);
+
+ internal::propagate_if(tree, a, prop, pred, v);
+ }
+
+ template <typename T, typename A, typename P2B>
+ inline
+ void
+ propagate_if(const T& tree,
+ Image<A>& a_,
+ const desc_propagation& prop,
+ const Function_p2b<P2B>& pred_)
+ {
+ A& a = exact(a_);
+ const P2B& pred = exact(pred_);
+
+ internal::propagate_if(tree, a, prop, pred);
+ }
+
+#endif /* !MLN_INCLUDE_ONLY */
+
+
+ } // end of namespace mln::morpho::tree
+ } // end of namespace mln::morpho
+} // end of namespace mln
+
+#endif /* !MLN_MORPHO_TREE_PROPAGATE_IF_HH_ */
Property changes on: trunk/milena/mln/morpho/tree/propagate_if.hh
___________________________________________________________________
Added: svn:mergeinfo
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_representative.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_node.hh (deleted)
===================================================================
Index: trunk/milena/sandbox/edwin/mln/morpho/tree/propagate_if.hh (deleted)
===================================================================