00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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))
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();
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
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))
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 }
00208
00209 }
00210
00211 }
00212
00213 #endif // ! MLN_MORPHO_TREE_PROPAGATE_NODE_HH