• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

propagate_node.hh

00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_MORPHO_TREE_PROPAGATE_NODE_HH
00027 # define MLN_MORPHO_TREE_PROPAGATE_NODE_HH
00028 
00029 # include <mln/core/concept/image.hh>
00030 # include <mln/core/macros.hh>
00031 # include <mln/morpho/tree/data.hh>
00032 
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   namespace morpho
00042   {
00043 
00044     namespace tree
00045     {
00046 
00057       template <typename T, typename A>
00058       void
00059       propagate_node_to_descendants(mln_psite(A) n,
00060                                     const T& t,
00061                                     Image<A>& a_,
00062                                     const mln_value(A)& v,
00063                                     unsigned* nb_leaves = 0);
00064 
00074       template <typename T, typename A>
00075       inline
00076       void
00077       propagate_node_to_descendants(mln_psite(A)& n,
00078                                     const T& t,
00079                                     Image<A>& a_,
00080                                     unsigned* nb_leaves = 0);
00081 
00082 
00091       template <typename T, typename A>
00092       void
00093       propagate_node_to_ancestors(mln_psite(A) n,
00094                                   const T& t,
00095                                   Image<A>& a_,
00096                                   const mln_value(A)& v);
00097 
00105       template <typename T, typename A>
00106       inline
00107       void
00108       propagate_node_to_ancestors(mln_psite(A) n,
00109                                   const T& t,
00110                                   Image<A>& a_);
00111 
00112 
00113 # ifndef MLN_INCLUDE_ONLY
00114 
00115       /* Descendants propagation */
00116 
00117       template <typename T, typename A>
00118       inline
00119       void
00120       propagate_node_to_descendants(mln_psite(A) n,
00121                                     const T& t,
00122                                     Image<A>& a_,
00123                                     const mln_value(A)& v,
00124                                     unsigned* nb_leaves = 0)
00125       {
00126         A& a = exact(a_);
00127         mln_precondition(a.is_valid());
00128         mln_precondition(a.domain() == t.f().domain());
00129         mln_precondition(a.domain().has(n));
00130 
00131 
00132         if (!t.is_a_node(n)) // Get the representant.
00133           n = t.parent(n);
00134         mln_assertion(t.is_a_node(n));
00135 
00136         typename T::depth1st_piter pp(t, n);
00137 
00138         pp.start(); // We don't set n to v.
00139 
00140         if (nb_leaves)
00141           *nb_leaves += t.is_a_leaf(pp);
00142 
00143         for (pp.next(); pp.is_valid(); pp.next())
00144           {
00145             a(pp) = v;
00146             if (nb_leaves && t.is_a_leaf(pp))
00147               ++(*nb_leaves);
00148           }
00149       }
00150 
00151 
00152       template <typename T, typename A>
00153       inline
00154       void
00155       propagate_node_to_descendants(mln_psite(A) n,
00156                                     const T& t,
00157                                     Image<A>& a_,
00158                                     unsigned* nb_leaves = 0)
00159 
00160       {
00161         A& a = exact(a_);
00162         propagate_node_to_descendants(n, t, a, a(n), nb_leaves);
00163       }
00164 
00165 
00166       /* Ancestors propagation */
00167 
00168       template <typename T, typename A>
00169       void
00170       propagate_node_to_ancestors(mln_psite(A) n,
00171                                   const T& t,
00172                                   Image<A>& a_,
00173                                   const mln_value(A)& v)
00174       {
00175         A& a = exact(a_);
00176         mln_precondition(a.is_valid());
00177         mln_precondition(a.domain() == t.f().domain());
00178         mln_precondition(a.domain().has(n));
00179 
00180         if (!t.is_a_node(n)) // Get the representant.
00181           n = t.parent(n);
00182         mln_assertion(t.is_a_node(n));
00183 
00184         if (t.is_root(n))
00185           return;
00186 
00187         do {
00188           n = t.parent(n);
00189           a(n) = v;
00190         } while (!t.is_root(n));
00191 
00192       }
00193 
00194       template <typename T, typename A>
00195       inline
00196       void
00197       propagate_node_to_ancestors(mln_psite(A) n,
00198                                   const T& t,
00199                                   Image<A>& a_)
00200       {
00201         A& a = exact(a_);
00202         propagate_node_to_ancestors(n, t, a, a(n));
00203       }
00204 
00205 # endif // ! MLN_INCLUDE_ONLY
00206 
00207     } // end of namespace mln::morpho::tree
00208 
00209   } // end of namespace mln::morpho
00210 
00211 } // end of namespace mln
00212 
00213 #endif // ! MLN_MORPHO_TREE_PROPAGATE_NODE_HH

Generated on Tue Oct 4 2011 15:24:20 for Milena (Olena) by  doxygen 1.7.1