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_MINUS_HH 00027 # define MLN_ARITH_MINUS_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::minus, Image, L, Image, R > 00047 { 00048 typedef mln_trait_op_minus(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::minus, Image, I, mln::value::Scalar, S > 00054 { 00055 typedef mln_trait_op_minus(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_minus(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_minus(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_minus(L, R) 00097 minus(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 minus(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 minus(const Image<L>& lhs, const Image<R>& rhs); 00127 00128 00130 00140 template <typename L, typename R> 00141 void 00142 minus_inplace(Image<L>& lhs, const Image<R>& rhs); 00143 00144 00146 00153 template <typename I, typename V> 00154 mln_trait_op_minus(I, V) 00155 minus_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 minus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f); 00170 00171 00173 00179 template <typename I, typename V> 00180 I& 00181 minus_cst_inplace(Image<I>& input, const V& val); 00182 00183 00184 } // end of namespace mln::arith 00185 00186 00187 00188 00189 # ifndef MLN_INCLUDE_ONLY 00190 00191 00192 template <typename L, typename R> 00193 inline 00194 mln_trait_op_minus(L,R) 00195 operator-(const Image<L>& lhs, const Image<R>& rhs) 00196 { 00197 trace::entering("operator::minus"); 00198 00199 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00200 mln_trait_op_minus(L,R) output = arith::minus(lhs, rhs); 00201 00202 trace::exiting("operator::minus"); 00203 return output; 00204 } 00205 00206 template <typename L, typename R> 00207 inline 00208 L& 00209 operator-=(Image<L>& lhs, const Image<R>& rhs) 00210 { 00211 trace::entering("operator::minus_eq"); 00212 00213 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00214 arith::minus_inplace(lhs, rhs); 00215 00216 trace::exiting("operator::minus_eq"); 00217 return exact(lhs); 00218 } 00219 00220 00221 template <typename I, typename S> 00222 inline 00223 mln_trait_op_minus(I,S) 00224 operator-(const Image<I>& ima, const value::Scalar<S>& s) 00225 { 00226 trace::entering("operator::minus"); 00227 00228 mln_precondition(exact(ima).is_valid()); 00229 mln_trait_op_minus(I,S) output = arith::minus_cst(ima, exact(s)); 00230 00231 trace::exiting("operator::minus"); 00232 return output; 00233 } 00234 00235 template <typename I, typename S> 00236 inline 00237 I& 00238 operator-=(Image<I>& ima, const value::Scalar<S>& s) 00239 { 00240 trace::entering("operator::minus_eq"); 00241 00242 mln_precondition(exact(ima).is_valid()); 00243 arith::minus_cst_inplace(ima, exact(s)); 00244 00245 trace::exiting("operator::minus_eq"); 00246 return exact(ima); 00247 } 00248 00249 00250 00251 namespace arith 00252 { 00253 00254 namespace impl 00255 { 00256 00257 template <typename L, typename R, typename O> 00258 inline 00259 void minus_(trait::image::speed::any, const L& lhs, 00260 trait::image::speed::any, const R& rhs, O& output) 00261 { 00262 mln_piter(L) p(lhs.domain()); 00263 for_all(p) 00264 output(p) = lhs(p) - rhs(p); 00265 } 00266 00267 template <typename L, typename R, typename F, typename O> 00268 inline 00269 void minus_(trait::image::speed::any, const L& lhs, 00270 trait::image::speed::any, const R& rhs, const F& f, O& output) 00271 { 00272 mln_piter(L) p(lhs.domain()); 00273 for_all(p) 00274 output(p) = f(lhs(p) - rhs(p)); 00275 } 00276 00277 template <typename L, typename R, typename O> 00278 inline 00279 void minus_(trait::image::speed::fastest, const L& lhs, 00280 trait::image::speed::fastest, const R& rhs, O& output) 00281 { 00282 mln_pixter(const L) lp(lhs); 00283 mln_pixter(const R) rp(rhs); 00284 mln_pixter(O) op(output); 00285 for_all_3(lp, rp, op) 00286 op.val() = lp.val() - rp.val(); 00287 } 00288 00289 template <typename L, typename R, typename F, typename O> 00290 inline 00291 void minus_(trait::image::speed::fastest, const L& lhs, 00292 trait::image::speed::fastest, const R& rhs, const F& f, O& output) 00293 { 00294 mln_pixter(const L) lp(lhs); 00295 mln_pixter(const R) rp(rhs); 00296 mln_pixter(O) op(output); 00297 for_all_3(lp, rp, op) 00298 op.val() = f(lp.val() - rp.val()); 00299 } 00300 00301 template <typename L, typename R> 00302 inline 00303 void minus_inplace_(trait::image::speed::any, L& lhs, 00304 trait::image::speed::any, const R& rhs) 00305 { 00306 mln_piter(L) p(lhs.domain()); 00307 for_all(p) 00308 lhs(p) -= rhs(p); 00309 } 00310 00311 template <typename L, typename R> 00312 inline 00313 void minus_inplace_(trait::image::speed::fastest, L& lhs, 00314 trait::image::speed::fastest, const R& rhs) 00315 { 00316 mln_pixter(L) lp(lhs); 00317 mln_pixter(const R) rp(rhs); 00318 for_all_2(lp, rp) 00319 lp.val() -= rp.val(); 00320 } 00321 00322 } // end of namespace mln::arith::impl 00323 00324 00325 // Facades. 00326 00327 00328 template <typename L, typename R> 00329 inline 00330 mln_trait_op_minus(L, R) 00331 minus(const Image<L>& lhs, const Image<R>& rhs) 00332 { 00333 trace::entering("arith::minus"); 00334 00335 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00336 00337 mln_trait_op_minus(L, R) output; 00338 initialize(output, lhs); 00339 impl::minus_(mln_trait_image_speed(L)(), exact(lhs), 00340 mln_trait_image_speed(R)(), exact(rhs), output); 00341 00342 trace::exiting("arith::minus"); 00343 return output; 00344 } 00345 00346 00347 template <typename L, typename R, typename F> 00348 inline 00349 mln_ch_value(L, mln_result(F)) 00350 minus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f) 00351 { 00352 trace::entering("arith::minus"); 00353 00354 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00355 00356 mln_ch_value(L, mln_result(F)) output; 00357 initialize(output, lhs); 00358 impl::minus_(mln_trait_image_speed(L)(), exact(lhs), 00359 mln_trait_image_speed(R)(), exact(rhs), exact(f), output); 00360 00361 trace::exiting("arith::minus"); 00362 return output; 00363 } 00364 00365 00366 template <typename V, typename L, typename R> 00367 inline 00368 mln_ch_value(L, V) 00369 minus(const Image<L>& lhs, const Image<R>& rhs) 00370 { 00371 trace::entering("arith::minus"); 00372 00373 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00374 00375 // Calls the previous version. 00376 mln_ch_value(L, V) output = minus(lhs, rhs, 00377 mln::fun::v2v::cast<V>()); 00378 00379 trace::exiting("arith::minus"); 00380 return output; 00381 } 00382 00383 00384 template <typename I, typename V> 00385 inline 00386 mln_trait_op_minus(I, V) 00387 minus_cst(const Image<I>& input, const V& val) 00388 { 00389 trace::entering("arith::minus_cst"); 00390 00391 mln_precondition(exact(input).is_valid()); 00392 00393 // Calls the previous version. 00394 mln_trait_op_minus(I, V) output = minus(input, 00395 pw::cst(val) | exact(input).domain()); 00396 00397 trace::exiting("arith::minus_cst"); 00398 return output; 00399 } 00400 00401 00402 template <typename I, typename V, typename F> 00403 inline 00404 mln_ch_value(I, mln_result(F)) 00405 minus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f) 00406 { 00407 trace::entering("arith::minus_cst"); 00408 00409 mln_precondition(exact(input).is_valid()); 00410 00411 // Calls the previous version. 00412 mln_ch_value(I, mln_result(F)) output = minus(input, 00413 pw::cst(val) | exact(input).domain(), 00414 f); 00415 00416 trace::exiting("arith::minus_cst"); 00417 return output; 00418 } 00419 00420 00421 template <typename L, typename R> 00422 inline 00423 void 00424 minus_inplace(Image<L>& lhs, const Image<R>& rhs) 00425 { 00426 trace::entering("arith::minus_inplace"); 00427 00428 mln_precondition(exact(rhs).domain() == exact(lhs).domain()); 00429 00430 impl::minus_inplace_(mln_trait_image_speed(L)(), exact(lhs), 00431 mln_trait_image_speed(R)(), exact(rhs)); 00432 00433 trace::exiting("arith::minus_inplace"); 00434 } 00435 00436 00437 template <typename I, typename V> 00438 inline 00439 I& 00440 minus_cst_inplace(Image<I>& input, const V& val) 00441 { 00442 trace::entering("arith::minus_cst_inplace"); 00443 00444 mln_precondition(exact(input).is_valid()); 00445 00446 // Calls the previous version. 00447 minus_inplace(input, 00448 pw::cst(val) | exact(input).domain()); 00449 00450 trace::exiting("arith::minus_cst_inplace"); 00451 return exact(input); 00452 } 00453 00454 } // end of namespace mln::arith 00455 00456 # endif // ! MLN_INCLUDE_ONLY 00457 00458 } // end of namespace mln 00459 00460 00461 #endif // ! MLN_ARITH_MINUS_HH