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