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
00027 #ifndef MLN_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH
00028 # define MLN_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH
00029
00035
00036 # include <mln/core/routine/duplicate.hh>
00037 # include <mln/core/concept/image.hh>
00038 # include <mln/morpho/tree/data.hh>
00039 # include <mln/trait/accumulators.hh>
00040 # include <mln/util/pix.hh>
00041 # include <mln/data/fill.hh>
00042
00043
00044 namespace mln
00045 {
00046
00047 namespace morpho
00048 {
00049
00050 namespace tree
00051 {
00052
00080 template <typename A, typename T>
00081 mln_ch_value(typename T::function, mln_result(A))
00082 compute_attribute_image(const Accumulator<A>& a,
00083 const T& t,
00084 mln_ch_value(typename T::function, A)* accu_image = 0);
00085
00086
00087
00098 template <typename A, typename T, typename V>
00099 mln_ch_value(typename T::function, mln_result(A))
00100 compute_attribute_image_from(const Accumulator<A>& a,
00101 const T& t,
00102 const Image<V>& values,
00103 mln_ch_value(typename T::function, A)* accu_image = 0);
00104
00105
00106
00107 # ifndef MLN_INCLUDE_ONLY
00108
00109
00110 namespace internal
00111 {
00112 template <typename A, typename I, typename P>
00113 void take_as_init (trait::accumulator::when_pix::use_none, A& accu,
00114 const I& input, const P& p)
00115 {
00116 (void)input;
00117 (void)p;
00118 accu.take_as_init();
00119 }
00120
00121 template <typename A, typename I, typename P>
00122 void take_as_init (trait::accumulator::when_pix::use_pix, A& accu,
00123 const I& input, const P& p)
00124 {
00125 accu.take_as_init(make::pix(input, p));
00126 }
00127
00128 template <typename A, typename I, typename P>
00129 void take_as_init (trait::accumulator::when_pix::use_v, A& accu,
00130 const I& input, const P& p)
00131 {
00132 accu.take_as_init(input(p));
00133 }
00134
00135 template <typename A, typename I, typename P>
00136 void take_as_init (trait::accumulator::when_pix::use_p, A& accu,
00137 const I& input, const P& p)
00138 {
00139 (void) input;
00140 accu.take_as_init(p);
00141 }
00142
00143
00144 template <typename A, typename I, typename P>
00145 void take_as_init (A& accu, const I& input, const P& p)
00146 {
00147 take_as_init (mln_trait_accumulator_when_pix(A)(), accu, input, p);
00148 }
00149
00150
00151 template <typename A, typename T, typename V>
00152 inline
00153 mln_ch_value(typename T::function, mln_result(A))
00154 compute_attribute_image(const A& a,
00155 const T& t,
00156 const V& values,
00157 mln_ch_value(typename T::function, A)* accu_image = 0)
00158 {
00159
00160 typedef typename T::function I;
00161 mln_ch_value(I, A) acc;
00162 initialize(acc, t.f());
00163
00164 {
00165
00166
00167
00168
00169 mln::data::fill(acc, a);
00170 }
00171
00172 {
00173
00174 mln_site_piter(T) p(t);
00175 for_all(p)
00176 take_as_init(acc(p), values, p);
00177 }
00178
00179 {
00180 mln_up_site_piter(T) p(t);
00181
00182 for_all(p)
00183 if (! t.is_root(p))
00184 acc(t.parent(p)).take(acc(p));
00185
00186
00187
00188
00189
00190 for_all(p)
00191 if (! t.is_a_node(p))
00192 {
00193 mln_assertion(t.is_a_node(t.parent(p)));
00194 acc(p) = acc(t.parent(p));
00195 }
00196 }
00197
00198
00199
00200 if (accu_image)
00201 *accu_image = duplicate(acc);
00202
00203 typedef typename T::function I;
00204 mln_ch_value(I, mln_result(A)) output;
00205 initialize(output, acc);
00206 mln::data::fill(output, acc);
00207
00208 return output;
00209 }
00210 }
00211
00212
00213
00214 template <typename A, typename T>
00215 inline
00216 mln_ch_value(typename T::function, mln_result(A))
00217 compute_attribute_image(const Accumulator<A>& a_,
00218 const T& t,
00219 mln_ch_value(typename T::function, A)* accu_image)
00220 {
00221 trace::entering("morpho::tree::compute_attribute_image");
00222
00223 mln_ch_value(typename T::function, mln_result(A)) output;
00224 output = internal::compute_attribute_image(exact(a_), t, t.f(),
00225 accu_image);
00226
00227 trace::exiting("morpho::tree::compute_attribute_image");
00228 return (output);
00229 }
00230
00231 template <typename A, typename T, typename V>
00232 inline
00233 mln_ch_value(typename T::function, mln_result(A))
00234 compute_attribute_image_from(const Accumulator<A>& a_,
00235 const T& t,
00236 const Image<V>& values,
00237 mln_ch_value(typename T::function, A)* accu_image)
00238 {
00239 trace::entering("morpho::tree::compute_attribute_image_from");
00240
00241
00242 mln_ch_value(typename T::function, mln_result(A)) output;
00243 output = internal::compute_attribute_image(exact(a_), t, exact(values),
00244 accu_image);
00245
00246 trace::exiting("morpho::tree::compute_attribute_image_from");
00247 return output;
00248 }
00249
00250
00251
00252
00253 # endif // ! MLN_INCLUDE_ONLY
00254
00255 }
00256
00257 }
00258
00259 }
00260
00261
00262 #endif // ! MLN_MORPHO_TREE_COMPUTE_ATTRIBUTE_IMAGE_HH