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