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 mln_trace(
"operator::plus");
214 mln_trait_op_plus(L,R) output = arith::plus(lhs, rhs);
219 template <typename L, typename R>
222 operator+=(Image<L>& lhs, const Image<R>& rhs)
224 mln_trace(
"operator::plus_eq");
234 template <
typename I,
typename S>
236 mln_trait_op_plus(I,S)
237 operator+(const Image<I>& ima, const value::Scalar<S>& s)
239 mln_trace(
"operator::plus");
241 mln_precondition(
exact(ima).is_valid());
243 mln_trait_op_plus(I,S) output = arith::plus_cst(ima,
exact(s));
248 template <typename I, typename S>
251 operator+=(Image<I>& ima, const value::Scalar<S>& s)
253 mln_trace(
"operator::plus_eq");
255 mln_precondition(
exact(ima).is_valid());
270 template <
typename L,
typename R,
typename O>
272 void plus_(trait::image::speed::any,
const L& lhs,
273 trait::image::speed::any,
const R& rhs, O& output)
275 mln_piter(L)
p(lhs.domain());
277 output(
p) = lhs(
p) + rhs(
p);
280 template <typename L, typename R, typename F, typename O>
282 void plus_(trait::image::speed::any, const L& lhs,
283 trait::image::speed::any, const R& rhs, const F& f, O& output)
285 mln_piter(L) p(lhs.domain());
287 output(p) = f(lhs(p) + rhs(p));
290 template <typename L, typename R, typename O>
292 void plus_(trait::image::speed::fastest, const L& lhs,
293 trait::image::speed::fastest, const R& rhs, O& output)
295 mln_pixter(
const L) lp(lhs);
296 mln_pixter(const R) rp(rhs);
297 mln_pixter(O) op(output);
298 for_all_3(lp, rp, op)
299 op.val() = lp.val() + rp.val();
302 template <typename L, typename R, typename F, typename O>
304 void plus_(trait::image::speed::fastest, const L& lhs,
305 trait::image::speed::fastest, const R& rhs, const F& f, O& output)
307 mln_pixter(
const L) lp(lhs);
308 mln_pixter(const R) rp(rhs);
309 mln_pixter(O) op(output);
310 for_all_3(lp, rp, op)
311 op.val() = f(lp.val() + rp.val());
314 template <typename L, typename R>
316 void plus_inplace_(trait::image::speed::any, L& lhs,
317 trait::image::speed::any, const R& rhs)
319 mln_piter(L) p(lhs.domain());
324 template <typename L, typename R>
326 void plus_inplace_(trait::image::speed::fastest, L& lhs,
327 trait::image::speed::fastest, const R& rhs)
329 mln_pixter(L) lp(lhs);
330 mln_pixter(const R) rp(rhs);
332 lp.val() += rp.val();
341 template <typename L, typename R>
343 mln_trait_op_plus(L, R)
344 plus(const Image<L>& lhs, const Image<R>& rhs)
346 mln_trace(
"arith::plus");
348 mln_precondition(
exact(rhs).domain() ==
exact(lhs).domain());
350 mln_trait_op_plus(L, R) output;
352 impl::plus_(mln_trait_image_speed(L)(),
exact(lhs),
353 mln_trait_image_speed(R)(),
exact(rhs), output);
359 template <typename L, typename R, typename F>
361 mln_ch_value(L, mln_result(F))
362 plus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f)
364 mln_trace(
"arith::plus");
366 mln_precondition(
exact(rhs).domain() ==
exact(lhs).domain());
368 mln_ch_value(L, mln_result(F)) output;
370 impl::plus_(mln_trait_image_speed(L)(),
exact(lhs),
371 mln_trait_image_speed(R)(),
exact(rhs),
exact(f), output);
377 template <typename V, typename L, typename R>
380 plus(const Image<L>& lhs, const Image<R>& rhs)
382 mln_trace(
"arith::plus");
384 mln_precondition(
exact(rhs).domain() ==
exact(lhs).domain());
387 mln_ch_value(L, V) output = plus(lhs, rhs,
388 mln::fun::v2v::cast<V>());
394 template <typename I, typename V>
396 mln_trait_op_plus(I, V)
397 plus_cst(const Image<I>& input, const V& val)
399 mln_trace(
"arith::plus_cst");
401 mln_precondition(
exact(input).is_valid());
404 mln_trait_op_plus(I, V) output = plus(input,
405 pw::cst(val) |
exact(input).domain());
411 template <typename I, typename V, typename F>
413 mln_ch_value(I, mln_result(F))
414 plus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f)
416 mln_trace(
"arith::plus_cst");
418 mln_precondition(
exact(input).is_valid());
421 mln_ch_value(I, mln_result(F)) output = plus(input,
422 pw::cst(val) |
exact(input).domain(),
429 template <typename W, typename I, typename V>
432 plus_cst(const Image<I>& input, const V& val)
434 mln_trace(
"arith::plus_cst");
436 mln_precondition(
exact(input).is_valid());
439 mln_ch_value(I, W) output = plus_cst(input, val,
440 mln::fun::v2v::cast<W>());
446 template <typename L, typename R>
449 plus_inplace(Image<L>& lhs, const Image<R>& rhs)
451 mln_trace(
"arith::plus_inplace");
453 mln_precondition(
exact(rhs).domain() ==
exact(lhs).domain());
455 impl::plus_inplace_(mln_trait_image_speed(L)(),
exact(lhs),
456 mln_trait_image_speed(R)(),
exact(rhs));
461 template <
typename I,
typename V>
466 mln_trace(
"arith::plus_cst_inplace");
468 mln_precondition(
exact(input).is_valid());
479 # endif // ! MLN_INCLUDE_ONLY
484 #endif // ! MLN_ARITH_PLUS_HH