26 #ifndef MLN_ARITH_PLUS_HH
27 # define MLN_ARITH_PLUS_HH
35 # include <mln/arith/includes.hh>
45 template <
typename L,
typename R>
46 struct set_binary_< op::
plus, Image, L, Image, R >
48 typedef mln_trait_op_plus(mln_value(L), mln_value(R)) value;
49 typedef mln_ch_value(L, value) ret;
52 template <typename I, typename S>
53 struct set_binary_< op::plus, Image, I, mln::value::Scalar, S >
55 typedef mln_trait_op_plus(mln_value(I), S) value;
56 typedef mln_ch_value(I, value) ret;
63 template <typename L, typename R>
64 mln_trait_op_plus(L,R)
65 operator+(const Image<L>& lhs, const Image<R>& rhs);
68 template <typename L, typename R>
70 operator+=(Image<L>& lhs, const Image<R>& rhs);
73 template <typename I, typename S>
74 mln_trait_op_plus(I,S)
75 operator+(const Image<I>& ima, const value::Scalar<S>& s);
78 template <typename I, typename S>
80 operator+=(Image<I>& ima, const value::Scalar<S>& s);
95 template <
typename L,
typename R>
96 mln_trait_op_plus(L, R)
97 plus(const Image<L>& lhs, const Image<R>& rhs);
109 template <typename L, typename R, typename F>
110 mln_ch_value(L, mln_result(F))
111 plus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f);
124 template <typename V, typename L, typename R>
126 plus(const Image<L>& lhs, const Image<R>& rhs);
140 template <typename L, typename R>
142 plus_inplace(Image<L>& lhs, const Image<R>& rhs);
153 template <typename I, typename V>
154 mln_trait_op_plus(I, V)
155 plus_cst(const Image<I>& input, const V& val);
167 template <typename I, typename V, typename F>
168 mln_ch_value(I, mln_result(F))
169 plus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f);
180 template <typename W, typename I, typename V>
182 plus_cst(const Image<I>& input, const V& val);
192 template <typename I, typename V>
194 plus_cst_inplace(Image<I>& input, const V& val);
202 # ifndef MLN_INCLUDE_ONLY
205 template <
typename L,
typename R>
207 mln_trait_op_plus(L,R)
208 operator+(const Image<L>& lhs, const Image<R>& rhs)
210 trace::entering(
"operator::plus");
212 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
214 mln_trait_op_plus(L,R) output = arith::plus(lhs, rhs);
216 trace::exiting("operator::plus");
220 template <typename L, typename R>
223 operator+=(Image<L>& lhs, const Image<R>& rhs)
225 trace::entering(
"operator::plus_eq");
227 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
231 trace::exiting(
"operator::plus_eq");
236 template <
typename I,
typename S>
238 mln_trait_op_plus(I,S)
239 operator+(const Image<I>& ima, const value::Scalar<S>& s)
241 trace::entering(
"operator::plus");
243 mln_precondition(exact(ima).is_valid());
245 mln_trait_op_plus(I,S) output = arith::plus_cst(ima, exact(s));
247 trace::exiting("operator::plus");
251 template <typename I, typename S>
254 operator+=(Image<I>& ima, const value::Scalar<S>& s)
256 trace::entering(
"operator::plus_eq");
258 mln_precondition(exact(ima).is_valid());
262 trace::exiting(
"operator::plus_eq");
274 template <
typename L,
typename R,
typename O>
276 void plus_(trait::image::speed::any,
const L& lhs,
277 trait::image::speed::any,
const R& rhs, O& output)
279 mln_piter(L) p(lhs.domain());
281 output(p) = lhs(p) + rhs(p);
284 template <typename L, typename R, typename F, typename O>
286 void plus_(trait::image::speed::any, const L& lhs,
287 trait::image::speed::any, const R& rhs, const F& f, O& output)
289 mln_piter(L) p(lhs.domain());
291 output(p) = f(lhs(p) + rhs(p));
294 template <typename L, typename R, typename O>
296 void plus_(trait::image::speed::fastest, const L& lhs,
297 trait::image::speed::fastest, const R& rhs, O& output)
299 mln_pixter(
const L) lp(lhs);
300 mln_pixter(const R) rp(rhs);
301 mln_pixter(O) op(output);
302 for_all_3(lp, rp, op)
303 op.val() = lp.val() + rp.val();
306 template <typename L, typename R, typename F, typename O>
308 void plus_(trait::image::speed::fastest, const L& lhs,
309 trait::image::speed::fastest, const R& rhs, const F& f, O& output)
311 mln_pixter(
const L) lp(lhs);
312 mln_pixter(const R) rp(rhs);
313 mln_pixter(O) op(output);
314 for_all_3(lp, rp, op)
315 op.val() = f(lp.val() + rp.val());
318 template <typename L, typename R>
320 void plus_inplace_(trait::image::speed::any, L& lhs,
321 trait::image::speed::any, const R& rhs)
323 mln_piter(L) p(lhs.domain());
328 template <typename L, typename R>
330 void plus_inplace_(trait::image::speed::fastest, L& lhs,
331 trait::image::speed::fastest, const R& rhs)
333 mln_pixter(L) lp(lhs);
334 mln_pixter(const R) rp(rhs);
336 lp.val() += rp.val();
345 template <typename L, typename R>
347 mln_trait_op_plus(L, R)
348 plus(const Image<L>& lhs, const Image<R>& rhs)
350 trace::entering(
"arith::plus");
352 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
354 mln_trait_op_plus(L, R) output;
356 impl::plus_(mln_trait_image_speed(L)(), exact(lhs),
357 mln_trait_image_speed(R)(), exact(rhs), output);
359 trace::exiting(
"arith::plus");
364 template <
typename L,
typename R,
typename F>
366 mln_ch_value(L, mln_result(F))
367 plus(const Image<L>& lhs, const Image<R>& rhs, const
Function_v2v<F>& f)
369 trace::entering(
"arith::plus");
371 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
373 mln_ch_value(L, mln_result(F)) output;
375 impl::plus_(mln_trait_image_speed(L)(), exact(lhs),
376 mln_trait_image_speed(R)(), exact(rhs), exact(f), output);
378 trace::exiting(
"arith::plus");
383 template <
typename V,
typename L,
typename R>
386 plus(const Image<L>& lhs, const Image<R>& rhs)
388 trace::entering(
"arith::plus");
390 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
393 mln_ch_value(L, V) output = plus(lhs, rhs,
394 mln::fun::v2v::cast<V>());
396 trace::exiting(
"arith::plus");
401 template <
typename I,
typename V>
403 mln_trait_op_plus(I, V)
404 plus_cst(const Image<I>& input, const V& val)
406 trace::entering(
"arith::plus_cst");
408 mln_precondition(exact(input).is_valid());
411 mln_trait_op_plus(I, V) output = plus(input,
412 pw::cst(val) | exact(input).domain());
414 trace::exiting(
"arith::plus_cst");
419 template <
typename I,
typename V,
typename F>
421 mln_ch_value(I, mln_result(F))
422 plus_cst(const Image<I>& input, const V& val, const
Function_v2v<F>& f)
424 trace::entering(
"arith::plus_cst");
426 mln_precondition(exact(input).is_valid());
429 mln_ch_value(I, mln_result(F)) output = plus(input,
430 pw::cst(val) | exact(input).domain(),
433 trace::exiting(
"arith::plus_cst");
438 template <
typename W,
typename I,
typename V>
441 plus_cst(const Image<I>& input, const V& val)
443 trace::entering(
"arith::plus_cst");
445 mln_precondition(exact(input).is_valid());
448 mln_ch_value(I, W) output =
plus_cst(input, val,
449 mln::fun::v2v::cast<W>());
451 trace::exiting(
"arith::plus_cst");
456 template <
typename L,
typename R>
461 trace::entering(
"arith::plus_inplace");
463 mln_precondition(exact(rhs).domain() == exact(lhs).domain());
465 impl::plus_inplace_(mln_trait_image_speed(L)(), exact(lhs),
466 mln_trait_image_speed(R)(), exact(rhs));
468 trace::exiting(
"arith::plus_inplace");
472 template <
typename I,
typename V>
477 trace::entering(
"arith::plus_cst_inplace");
479 mln_precondition(exact(input).is_valid());
483 pw::cst(val) | exact(input).domain());
485 trace::exiting(
"arith::plus_cst_inplace");
491 # endif // ! MLN_INCLUDE_ONLY
496 #endif // ! MLN_ARITH_PLUS_HH