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