$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
propagate_node.hh
1 // Copyright (C) 2009, 2013 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_MORPHO_TREE_PROPAGATE_NODE_HH
27 # define MLN_MORPHO_TREE_PROPAGATE_NODE_HH
28 
29 # include <mln/core/concept/image.hh>
30 # include <mln/core/macros.hh>
31 # include <mln/morpho/tree/data.hh>
32 
36 
37 
38 namespace mln
39 {
40 
41  namespace morpho
42  {
43 
44  namespace tree
45  {
46 
57  template <typename T, typename A>
58  void
59  propagate_node_to_descendants(mln_psite(A) n,
60  const T& t,
61  Image<A>& a_,
62  const mln_value(A)& v,
63  unsigned* nb_leaves = 0);
64 
74  template <typename T, typename A>
75  inline
76  void
77  propagate_node_to_descendants(mln_psite(A)& n,
78  const T& t,
79  Image<A>& a_,
80  unsigned* nb_leaves = 0);
81 
82 
91  template <typename T, typename A>
92  void
93  propagate_node_to_ancestors(mln_psite(A) n,
94  const T& t,
95  Image<A>& a_,
96  const mln_value(A)& v);
97 
105  template <typename T, typename A>
106  inline
107  void
108  propagate_node_to_ancestors(mln_psite(A) n,
109  const T& t,
110  Image<A>& a_);
111 
112 
113 # ifndef MLN_INCLUDE_ONLY
114 
115  /* Descendants propagation */
116 
117  template <typename T, typename A>
118  inline
119  void
120  propagate_node_to_descendants(mln_psite(A) n,
121  const T& t,
122  Image<A>& a_,
123  const mln_value(A)& v,
124  unsigned* nb_leaves)
125  {
126  A& a = exact(a_);
127  mln_precondition(a.is_valid());
128  mln_precondition(a.domain() == t.f().domain());
129  mln_precondition(a.domain().has(n));
130 
131 
132  if (!t.is_a_node(n)) // Get the representant.
133  n = t.parent(n);
134  mln_assertion(t.is_a_node(n));
135 
136  typename T::depth1st_piter pp(t, n);
137 
138  pp.start(); // We don't set n to v.
139 
140  if (nb_leaves)
141  *nb_leaves += t.is_a_leaf(pp);
142 
143  for (pp.next(); pp.is_valid(); pp.next())
144  {
145  a(pp) = v;
146  if (nb_leaves && t.is_a_leaf(pp))
147  ++(*nb_leaves);
148  }
149  }
150 
151 
152  template <typename T, typename A>
153  inline
154  void
155  propagate_node_to_descendants(mln_psite(A) n,
156  const T& t,
157  Image<A>& a_,
158  unsigned* nb_leaves = 0)
159 
160  {
161  A& a = exact(a_);
162  propagate_node_to_descendants(n, t, a, a(n), nb_leaves);
163  }
164 
165 
166  /* Ancestors propagation */
167 
168  template <typename T, typename A>
169  void
170  propagate_node_to_ancestors(mln_psite(A) n,
171  const T& t,
172  Image<A>& a_,
173  const mln_value(A)& v)
174  {
175  A& a = exact(a_);
176  mln_precondition(a.is_valid());
177  mln_precondition(a.domain() == t.f().domain());
178  mln_precondition(a.domain().has(n));
179 
180  if (!t.is_a_node(n)) // Get the representant.
181  n = t.parent(n);
182  mln_assertion(t.is_a_node(n));
183 
184  if (t.is_root(n))
185  return;
186 
187  do {
188  n = t.parent(n);
189  a(n) = v;
190  } while (!t.is_root(n));
191 
192  }
193 
194  template <typename T, typename A>
195  inline
196  void
197  propagate_node_to_ancestors(mln_psite(A) n,
198  const T& t,
199  Image<A>& a_)
200  {
201  A& a = exact(a_);
202  propagate_node_to_ancestors(n, t, a, a(n));
203  }
204 
205 # endif // ! MLN_INCLUDE_ONLY
206 
207  } // end of namespace mln::morpho::tree
208 
209  } // end of namespace mln::morpho
210 
211 } // end of namespace mln
212 
213 #endif // ! MLN_MORPHO_TREE_PROPAGATE_NODE_HH