Milena (Olena)
User documentation 2.0a Id
|
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_ACCU_IMAGE_TAKE_N_TIMES_HH 00027 # define MLN_ACCU_IMAGE_TAKE_N_TIMES_HH 00028 00035 00036 # include <mln/core/concept/accumulator.hh> 00037 # include <mln/core/concept/image.hh> 00038 # include <mln/border/resize_equal.hh> 00039 00040 00041 namespace mln 00042 { 00043 00044 namespace accu 00045 { 00046 00047 namespace image 00048 { 00049 00050 template <typename I, typename J> 00051 void 00052 take_n_times(Image<I>& input, const Image<J>& n_times, const mln_deduce(I, value, argument)& arg); 00053 00054 template <typename I, typename J, typename K> 00055 void 00056 take_n_times(Image<I>& input, const Image<J>& n_times, const Image<K>& arg); 00057 00058 00059 00060 # ifndef MLN_INCLUDE_ONLY 00061 00062 00063 // Tests. 00064 00065 namespace internal 00066 { 00067 00068 template <typename I, typename J> 00069 inline 00070 void 00071 take_n_times_tests(Image<I>& input_, const Image<J>& n_times_) 00072 { 00073 I& input = exact(input_); 00074 const J& n_times = exact(n_times_); 00075 00076 mln_precondition(input.is_valid()); 00077 mln_precondition(n_times.is_valid()); 00078 00079 mln_precondition(n_times.domain() <= input.domain()); 00080 00081 (void) input; 00082 (void) n_times; 00083 } 00084 00085 template <typename I, typename J, typename K> 00086 inline 00087 void 00088 take_n_times_tests(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_) 00089 { 00090 I& input = exact(input_); 00091 const J& n_times = exact(n_times_); 00092 const K& arg = exact(arg_); 00093 00094 mln_precondition(input.is_valid()); 00095 mln_precondition(n_times.is_valid()); 00096 mln_precondition(arg.is_valid()); 00097 00098 mln_precondition(arg.domain() <= input.domain()); 00099 mln_precondition(arg.domain() <= n_times.domain()); 00100 00101 (void) input; 00102 (void) n_times; 00103 (void) arg; 00104 } 00105 00106 } // end of namespace mln::accu::image::internal 00107 00108 00109 // Implementations. 00110 00111 namespace impl 00112 { 00113 00114 // Generic versions. 00115 00116 namespace generic 00117 { 00118 00119 template <typename I, typename J, typename K> 00120 inline 00121 void 00122 take_n_times(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_) 00123 { 00124 trace::entering("accu::impl::image::generic::take_n_times"); 00125 00126 mlc_is_a(mln_value(I), Accumulator)::check(); 00127 mlc_converts_to(mln_value(J), unsigned)::check(); 00128 mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check(); 00129 00130 I& input = exact(input_); 00131 const J& n_times = exact(n_times_); 00132 const K& arg = exact(arg_); 00133 00134 internal::take_n_times_tests(input, n_times, arg); 00135 00136 mln_piter(J) p(arg.domain()); 00137 for_all(p) 00138 input(p).take_n_times(n_times(p), arg(p)); 00139 00140 trace::exiting("accu::impl::image::generic::take_n_times"); 00141 } 00142 00143 template <typename I, typename J> 00144 inline 00145 void 00146 take_n_times(Image<I>& input_, const Image<J>& n_times_, const mln_deduce(I, value, argument)& arg) 00147 { 00148 trace::entering("accu::impl::image::generic::take_n_times"); 00149 00150 mlc_is_a(mln_value(I), Accumulator)::check(); 00151 mlc_converts_to(mln_value(J), unsigned)::check(); 00152 00153 I& input = exact(input_); 00154 const J& n_times = exact(n_times_); 00155 00156 internal::take_n_times_tests(input, n_times); 00157 00158 mln_piter(J) p(n_times.domain()); 00159 for_all(p) 00160 input(p).take_n_times(n_times(p), arg); 00161 00162 trace::exiting("accu::impl::image::generic::take_n_times"); 00163 } 00164 00165 } // end of namespace mln::accu::image::impl::generic 00166 00167 00168 // Fastest versions. 00169 00170 template <typename I, typename J> 00171 inline 00172 void 00173 take_n_times_fastest(Image<I>& input_, const Image<J>& n_times_, const mln_deduce(I, value, argument)& arg) 00174 { 00175 trace::entering("accu::impl::image::take_n_times_fastest"); 00176 00177 mlc_is_a(mln_value(I), Accumulator)::check(); 00178 mlc_converts_to(mln_value(J), unsigned)::check(); 00179 00180 I& input = exact(input_); 00181 const J& n_times = exact(n_times_); 00182 00183 internal::take_n_times_tests(input, n_times); 00184 // Extra (stronger) test: 00185 mln_precondition(n_times.domain() == input.domain()); 00186 00187 border::resize_equal(input, n_times); 00188 00189 mln_pixter(I) p_in(input); 00190 mln_pixter(const J) p_ntm(n_times); 00191 for_all_2(p_in, p_ntm) 00192 p_in.val().take_n_times( p_ntm.val(), arg ); 00193 00194 trace::exiting("accu::impl::image::take_n_times_fastest"); 00195 } 00196 00197 template <typename I, typename J, typename K> 00198 inline 00199 void 00200 take_n_times_fastest(Image<I>& input_, const Image<J>& n_times_, const Image<K>& arg_) 00201 { 00202 trace::entering("accu::impl::image::take_n_times_fastest"); 00203 00204 mlc_is_a(mln_value(I), Accumulator)::check(); 00205 mlc_converts_to(mln_value(J), unsigned)::check(); 00206 mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check(); 00207 00208 I& input = exact(input_); 00209 const J& n_times = exact(n_times_); 00210 const K& arg = exact(arg_); 00211 00212 internal::take_n_times_tests(input, n_times, arg); 00213 00214 // Extra (stronger) tests. 00215 mln_precondition(arg.domain() == input.domain()); 00216 mln_precondition(arg.domain() == n_times.domain()); 00217 00218 border::resize(n_times, input.border()); 00219 border::resize(arg, input.border()); 00220 00221 mln_pixter(I) p_in(input); 00222 mln_pixter(const J) p_ntm(n_times); 00223 mln_pixter(const K) p_arg(arg); 00224 for_all_3(p_in, p_ntm, p_arg) 00225 p_in.val().take_n_times( p_ntm.val(), p_arg.val() ); 00226 00227 trace::exiting("accu::impl::image::take_n_times_fastest"); 00228 } 00229 00230 } // end of namespace mln::accu::image::impl 00231 00232 00233 00234 // Dispatch. 00235 00236 namespace internal 00237 { 00238 00239 // 'arg' as value. 00240 00241 template <typename I, typename J> 00242 inline 00243 void 00244 take_n_times_dispatch(trait::image::speed::any, 00245 trait::image::speed::any, 00246 Image<I>& input, const Image<J>& n_times, const mln_deduce(I, value, argument)& arg) 00247 { 00248 impl::generic::take_n_times(input, n_times, arg); 00249 } 00250 00251 template <typename I, typename J> 00252 inline 00253 void 00254 take_n_times_dispatch(trait::image::speed::fastest, 00255 trait::image::speed::fastest, 00256 Image<I>& input, const Image<J>& n_times, const mln_deduce(I, value, argument)& arg) 00257 { 00258 if (exact(n_times).domain() == exact(input).domain()) 00259 impl::take_n_times_fastest(input, n_times, arg); 00260 else 00261 impl::generic::take_n_times(input, n_times, arg); 00262 } 00263 00264 template <typename I, typename J> 00265 inline 00266 void 00267 take_n_times_dispatch(Image<I>& input, const Image<J>& n_times, const mln_deduce(I, value, argument)& arg) 00268 { 00269 take_n_times_dispatch(mln_trait_image_speed(I)(), 00270 mln_trait_image_speed(J)(), 00271 input, n_times, arg); 00272 } 00273 00274 // Triplet of images. 00275 00276 template <typename I, typename J, typename K> 00277 inline 00278 void 00279 take_n_times_dispatch(trait::image::speed::any, 00280 trait::image::speed::any, 00281 trait::image::speed::any, 00282 Image<I>& input, const Image<J>& n_times, const Image<K>& arg) 00283 { 00284 impl::generic::take_n_times(input, n_times, arg); 00285 } 00286 00287 template <typename I, typename J, typename K> 00288 inline 00289 void 00290 take_n_times_dispatch(trait::image::speed::fastest, 00291 trait::image::speed::fastest, 00292 trait::image::speed::fastest, 00293 Image<I>& input, const Image<J>& n_times, const Image<K>& arg) 00294 { 00295 if (exact(n_times).domain() == exact(input).domain() && 00296 exact(arg) .domain() == exact(input).domain()) 00297 impl::take_n_times_fastest(input, n_times, arg); 00298 else 00299 impl::generic::take_n_times(input, n_times, arg); 00300 } 00301 00302 template <typename I, typename J, typename K> 00303 inline 00304 void 00305 take_n_times_dispatch(Image<I>& input, const Image<J>& n_times, const Image<K>& arg) 00306 { 00307 take_n_times_dispatch(mln_trait_image_speed(I)(), 00308 mln_trait_image_speed(J)(), 00309 mln_trait_image_speed(K)(), 00310 input, n_times, arg); 00311 } 00312 00313 } // end of namespace mln::accu::image::internal 00314 00315 00316 // Facades. 00317 00318 template <typename I, typename J> 00319 void 00320 take_n_times(Image<I>& input, const Image<J>& n_times, const mln_deduce(I, value, argument)& arg) 00321 { 00322 trace::entering("accu::image::take_n_times"); 00323 00324 mlc_is_a(mln_value(I), Accumulator)::check(); 00325 mlc_converts_to(mln_value(J), unsigned)::check(); 00326 00327 internal::take_n_times_tests(input, n_times); 00328 internal::take_n_times_dispatch(input, n_times, arg); 00329 00330 trace::exiting("accu::image::take_n_times"); 00331 } 00332 00333 template <typename I, typename J, typename K> 00334 inline 00335 void 00336 take_n_times(Image<I>& input, const Image<J>& n_times, const Image<K>& arg) 00337 { 00338 trace::entering("accu::image::take_n_times"); 00339 00340 mlc_is_a(mln_value(I), Accumulator)::check(); 00341 mlc_converts_to(mln_value(J), unsigned)::check(); 00342 mlc_converts_to(mln_value(K), mln_deduce(I, value, argument))::check(); 00343 00344 internal::take_n_times_tests(input, n_times, arg); 00345 internal::take_n_times_dispatch(input, n_times, arg); 00346 00347 trace::exiting("accu::image::take_n_times"); 00348 } 00349 00350 # endif // ! MLN_INCLUDE_ONLY 00351 00352 } // end of namespace mln::accu::image 00353 00354 } // end of namespace mln::accu 00355 00356 } // end of namespace mln 00357 00358 00359 #endif // ! MLN_ACCU_IMAGE_TAKE_N_TIMES_HH