Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 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_ARITH_PLUS_HH 00027 # define MLN_ARITH_PLUS_HH 00028 00034 00035 # include <mln/arith/includes.hh> 00036 00037 00038 namespace mln 00039 { 00040 00041 00042 namespace trait 00043 { 00044 00045 template <typename L, typename R> 00046 struct set_binary_< op::plus, Image, L, Image, R > 00047 { 00048 typedef mln_trait_op_plus(mln_value(L), mln_value(R)) value; 00049 typedef mln_ch_value(L, value) ret; 00050 }; 00051 00052 template <typename I, typename S> 00053 struct set_binary_< op::plus, Image, I, mln::value::Scalar, S > 00054 { 00055 typedef mln_trait_op_plus(mln_value(I), S) value; 00056 typedef mln_ch_value(I, value) ret; 00057 }; 00058 00059 } // end of namespace mln::trait 00060 00061 00062 00063 template <typename L, typename R> 00064 mln_trait_op_plus(L,R) 00065 operator+(const Image<L>& lhs, const Image<R>& rhs); 00066 00067 00068 template <typename L, typename R> 00069 L& 00070 operator+=(Image<L>& lhs, const Image<R>& rhs); 00071 00072 00073 template <typename I, typename S> 00074 mln_trait_op_plus(I,S) 00075 operator+(const Image<I>& ima, const value::Scalar<S>& s); 00076 00077 00078 template <typename I, typename S> 00079 I& 00080 operator+=(Image<I>& ima, const value::Scalar<S>& s); 00081 00082 00083 00084 namespace arith 00085 { 00086 00088 00095 template <typename L, typename R> 00096 mln_trait_op_plus(L, R) 00097 plus(const Image<L>& lhs, const Image<R>& rhs); 00098 00099 00101 00109 template <typename L, typename R, typename F> 00110 mln_ch_value(L, mln_result(F)) 00111 plus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f); 00112 00113 00115 00124 template <typename V, typename L, typename R> 00125 mln_ch_value(L, V) 00126 plus(const Image<L>& lhs, const Image<R>& rhs); 00127 00128 00130 00140 template <typename L, typename R> 00141 void 00142 plus_inplace(Image<L>& lhs, const Image<R>& rhs); 00143 00144 00146 00153 template <typename I, typename V> 00154 mln_trait_op_plus(I, V) 00155 plus_cst(const Image<I>& input, const V& val); 00156 00157 00159 00167 template <typename I, typename V, typename F> 00168 mln_ch_value(I, mln_result(F)) 00169 plus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f); 00170 00171 00173 00180 template <typename W, typename I, typename V> 00181 mln_ch_value(I, W) 00182 plus_cst(const Image<I>& input, const V& val); 00183 00184 00186 00192 template <typename I, typename V> 00193 I& 00194 plus_cst_inplace(Image<I>& input, const V& val); 00195 00196 00197 } // end of namespace mln::arith 00198 00199 00200 00201 00202 # ifndef MLN_INCLUDE_ONLY 00203 00204 00205 template <typename L, typename R> 00206 inline 00207 mln_trait_op_plus(L,R) 00208 operator+(const Image<L>& lhs, const Image<R>& rhs) 00209 { 00210 trace::entering("operator::plus"); 00211 00212 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00213 00214 mln_trait_op_plus(L,R) output = arith::plus(lhs, rhs); 00215 00216 trace::exiting("operator::plus"); 00217 return output; 00218 } 00219 00220 template <typename L, typename R> 00221 inline 00222 L& 00223 operator+=(Image<L>& lhs, const Image<R>& rhs) 00224 { 00225 trace::entering("operator::plus_eq"); 00226 00227 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00228 00229 arith::plus_inplace(lhs, rhs); 00230 00231 trace::exiting("operator::plus_eq"); 00232 return exact(lhs); 00233 } 00234 00235 00236 template <typename I, typename S> 00237 inline 00238 mln_trait_op_plus(I,S) 00239 operator+(const Image<I>& ima, const value::Scalar<S>& s) 00240 { 00241 trace::entering("operator::plus"); 00242 00243 mln_precondition(exact(ima).is_valid()); 00244 00245 mln_trait_op_plus(I,S) output = arith::plus_cst(ima, exact(s)); 00246 00247 trace::exiting("operator::plus"); 00248 return output; 00249 } 00250 00251 template <typename I, typename S> 00252 inline 00253 I& 00254 operator+=(Image<I>& ima, const value::Scalar<S>& s) 00255 { 00256 trace::entering("operator::plus_eq"); 00257 00258 mln_precondition(exact(ima).is_valid()); 00259 00260 arith::plus_cst_inplace(ima, exact(s)); 00261 00262 trace::exiting("operator::plus_eq"); 00263 return exact(ima); 00264 } 00265 00266 00267 00268 namespace arith 00269 { 00270 00271 namespace impl 00272 { 00273 00274 template <typename L, typename R, typename O> 00275 inline 00276 void plus_(trait::image::speed::any, const L& lhs, 00277 trait::image::speed::any, const R& rhs, O& output) 00278 { 00279 mln_piter(L) p(lhs.domain()); 00280 for_all(p) 00281 output(p) = lhs(p) + rhs(p); 00282 } 00283 00284 template <typename L, typename R, typename F, typename O> 00285 inline 00286 void plus_(trait::image::speed::any, const L& lhs, 00287 trait::image::speed::any, const R& rhs, const F& f, O& output) 00288 { 00289 mln_piter(L) p(lhs.domain()); 00290 for_all(p) 00291 output(p) = f(lhs(p) + rhs(p)); 00292 } 00293 00294 template <typename L, typename R, typename O> 00295 inline 00296 void plus_(trait::image::speed::fastest, const L& lhs, 00297 trait::image::speed::fastest, const R& rhs, O& output) 00298 { 00299 mln_pixter(const L) lp(lhs); 00300 mln_pixter(const R) rp(rhs); 00301 mln_pixter(O) op(output); 00302 for_all_3(lp, rp, op) 00303 op.val() = lp.val() + rp.val(); 00304 } 00305 00306 template <typename L, typename R, typename F, typename O> 00307 inline 00308 void plus_(trait::image::speed::fastest, const L& lhs, 00309 trait::image::speed::fastest, const R& rhs, const F& f, O& output) 00310 { 00311 mln_pixter(const L) lp(lhs); 00312 mln_pixter(const R) rp(rhs); 00313 mln_pixter(O) op(output); 00314 for_all_3(lp, rp, op) 00315 op.val() = f(lp.val() + rp.val()); 00316 } 00317 00318 template <typename L, typename R> 00319 inline 00320 void plus_inplace_(trait::image::speed::any, L& lhs, 00321 trait::image::speed::any, const R& rhs) 00322 { 00323 mln_piter(L) p(lhs.domain()); 00324 for_all(p) 00325 lhs(p) += rhs(p); 00326 } 00327 00328 template <typename L, typename R> 00329 inline 00330 void plus_inplace_(trait::image::speed::fastest, L& lhs, 00331 trait::image::speed::fastest, const R& rhs) 00332 { 00333 mln_pixter(L) lp(lhs); 00334 mln_pixter(const R) rp(rhs); 00335 for_all_2(lp, rp) 00336 lp.val() += rp.val(); 00337 } 00338 00339 } // end of namespace mln::arith::impl 00340 00341 00342 // Facades. 00343 00344 00345 template <typename L, typename R> 00346 inline 00347 mln_trait_op_plus(L, R) 00348 plus(const Image<L>& lhs, const Image<R>& rhs) 00349 { 00350 trace::entering("arith::plus"); 00351 00352 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00353 00354 mln_trait_op_plus(L, R) output; 00355 initialize(output, lhs); 00356 impl::plus_(mln_trait_image_speed(L)(), exact(lhs), 00357 mln_trait_image_speed(R)(), exact(rhs), output); 00358 00359 trace::exiting("arith::plus"); 00360 return output; 00361 } 00362 00363 00364 template <typename L, typename R, typename F> 00365 inline 00366 mln_ch_value(L, mln_result(F)) 00367 plus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f) 00368 { 00369 trace::entering("arith::plus"); 00370 00371 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00372 00373 mln_ch_value(L, mln_result(F)) output; 00374 initialize(output, lhs); 00375 impl::plus_(mln_trait_image_speed(L)(), exact(lhs), 00376 mln_trait_image_speed(R)(), exact(rhs), exact(f), output); 00377 00378 trace::exiting("arith::plus"); 00379 return output; 00380 } 00381 00382 00383 template <typename V, typename L, typename R> 00384 inline 00385 mln_ch_value(L, V) 00386 plus(const Image<L>& lhs, const Image<R>& rhs) 00387 { 00388 trace::entering("arith::plus"); 00389 00390 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00391 00392 // Calls the previous version. 00393 mln_ch_value(L, V) output = plus(lhs, rhs, 00394 mln::fun::v2v::cast<V>()); 00395 00396 trace::exiting("arith::plus"); 00397 return output; 00398 } 00399 00400 00401 template <typename I, typename V> 00402 inline 00403 mln_trait_op_plus(I, V) 00404 plus_cst(const Image<I>& input, const V& val) 00405 { 00406 trace::entering("arith::plus_cst"); 00407 00408 mln_precondition(exact(input).is_valid()); 00409 00410 // Calls the previous version. 00411 mln_trait_op_plus(I, V) output = plus(input, 00412 pw::cst(val) | exact(input).domain()); 00413 00414 trace::exiting("arith::plus_cst"); 00415 return output; 00416 } 00417 00418 00419 template <typename I, typename V, typename F> 00420 inline 00421 mln_ch_value(I, mln_result(F)) 00422 plus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f) 00423 { 00424 trace::entering("arith::plus_cst"); 00425 00426 mln_precondition(exact(input).is_valid()); 00427 00428 // Calls the previous version. 00429 mln_ch_value(I, mln_result(F)) output = plus(input, 00430 pw::cst(val) | exact(input).domain(), 00431 f); 00432 00433 trace::exiting("arith::plus_cst"); 00434 return output; 00435 } 00436 00437 00438 template <typename W, typename I, typename V> 00439 inline 00440 mln_ch_value(I, W) 00441 plus_cst(const Image<I>& input, const V& val) 00442 { 00443 trace::entering("arith::plus_cst"); 00444 00445 mln_precondition(exact(input).is_valid()); 00446 00447 // Calls the previous version. 00448 mln_ch_value(I, W) output = plus_cst(input, val, 00449 mln::fun::v2v::cast<W>()); 00450 00451 trace::exiting("arith::plus_cst"); 00452 return output; 00453 } 00454 00455 00456 template <typename L, typename R> 00457 inline 00458 void 00459 plus_inplace(Image<L>& lhs, const Image<R>& rhs) 00460 { 00461 trace::entering("arith::plus_inplace"); 00462 00463 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00464 00465 impl::plus_inplace_(mln_trait_image_speed(L)(), exact(lhs), 00466 mln_trait_image_speed(R)(), exact(rhs)); 00467 00468 trace::exiting("arith::plus_inplace"); 00469 } 00470 00471 00472 template <typename I, typename V> 00473 inline 00474 I& 00475 plus_cst_inplace(Image<I>& input, const V& val) 00476 { 00477 trace::entering("arith::plus_cst_inplace"); 00478 00479 mln_precondition(exact(input).is_valid()); 00480 00481 // Calls the previous version. 00482 plus_inplace(input, 00483 pw::cst(val) | exact(input).domain()); 00484 00485 trace::exiting("arith::plus_cst_inplace"); 00486 return exact(input); 00487 } 00488 00489 } // end of namespace mln::arith 00490 00491 # endif // ! MLN_INCLUDE_ONLY 00492 00493 } // end of namespace mln 00494 00495 00496 #endif // ! MLN_ARITH_PLUS_HH