$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arith/plus.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_ARITH_PLUS_HH
27 # define MLN_ARITH_PLUS_HH
28 
34 
35 # include <mln/arith/includes.hh>
36 
37 
38 namespace mln
39 {
40 
41 
42  namespace trait
43  {
44 
45  template <typename L, typename R>
46  struct set_binary_< op::plus, Image, L, Image, R >
47  {
48  typedef mln_trait_op_plus(mln_value(L), mln_value(R)) value;
49  typedef mln_ch_value(L, value) ret;
50  };
51 
52  template <typename I, typename S>
53  struct set_binary_< op::plus, Image, I, mln::value::Scalar, S >
54  {
55  typedef mln_trait_op_plus(mln_value(I), S) value;
56  typedef mln_ch_value(I, value) ret;
57  };
58 
59  } // end of namespace mln::trait
60 
61 
62 
63  template <typename L, typename R>
64  mln_trait_op_plus(L,R)
65  operator+(const Image<L>& lhs, const Image<R>& rhs);
66 
67 
68  template <typename L, typename R>
69  L&
70  operator+=(Image<L>& lhs, const Image<R>& rhs);
71 
72 
73  template <typename I, typename S>
74  mln_trait_op_plus(I,S)
75  operator+(const Image<I>& ima, const value::Scalar<S>& s);
76 
77 
78  template <typename I, typename S>
79  I&
80  operator+=(Image<I>& ima, const value::Scalar<S>& s);
81 
82 
83 
84  namespace arith
85  {
86 
88 
95  template <typename L, typename R>
96  mln_trait_op_plus(L, R)
97  plus(const Image<L>& lhs, const Image<R>& rhs);
98 
99 
101 
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);
112 
113 
115 
124  template <typename V, typename L, typename R>
125  mln_ch_value(L, V)
126  plus(const Image<L>& lhs, const Image<R>& rhs);
127 
128 
130 
140  template <typename L, typename R>
141  void
142  plus_inplace(Image<L>& lhs, const Image<R>& rhs);
143 
144 
146 
153  template <typename I, typename V>
154  mln_trait_op_plus(I, V)
155  plus_cst(const Image<I>& input, const V& val);
156 
157 
159 
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);
170 
171 
173 
180  template <typename W, typename I, typename V>
181  mln_ch_value(I, W)
182  plus_cst(const Image<I>& input, const V& val);
183 
184 
186 
192  template <typename I, typename V>
193  I&
194  plus_cst_inplace(Image<I>& input, const V& val);
195 
196 
197  } // end of namespace mln::arith
198 
199 
200 
201 
202 # ifndef MLN_INCLUDE_ONLY
203 
204 
205  template <typename L, typename R>
206  inline
207  mln_trait_op_plus(L,R)
208  operator+(const Image<L>& lhs, const Image<R>& rhs)
209  {
210  mln_trace("operator::plus");
211 
212  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
213 
214  mln_trait_op_plus(L,R) output = arith::plus(lhs, rhs);
215 
216  return output;
217  }
218 
219  template <typename L, typename R>
220  inline
221  L&
222  operator+=(Image<L>& lhs, const Image<R>& rhs)
223  {
224  mln_trace("operator::plus_eq");
225 
226  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
227 
228  arith::plus_inplace(lhs, rhs);
229 
230  return exact(lhs);
231  }
232 
233 
234  template <typename I, typename S>
235  inline
236  mln_trait_op_plus(I,S)
237  operator+(const Image<I>& ima, const value::Scalar<S>& s)
238  {
239  mln_trace("operator::plus");
240 
241  mln_precondition(exact(ima).is_valid());
242 
243  mln_trait_op_plus(I,S) output = arith::plus_cst(ima, exact(s));
244 
245  return output;
246  }
247 
248  template <typename I, typename S>
249  inline
250  I&
251  operator+=(Image<I>& ima, const value::Scalar<S>& s)
252  {
253  mln_trace("operator::plus_eq");
254 
255  mln_precondition(exact(ima).is_valid());
256 
258 
259  return exact(ima);
260  }
261 
262 
263 
264  namespace arith
265  {
266 
267  namespace impl
268  {
269 
270  template <typename L, typename R, typename O>
271  inline
272  void plus_(trait::image::speed::any, const L& lhs,
273  trait::image::speed::any, const R& rhs, O& output)
274  {
275  mln_piter(L) p(lhs.domain());
276  for_all(p)
277  output(p) = lhs(p) + rhs(p);
278  }
279 
280  template <typename L, typename R, typename F, typename O>
281  inline
282  void plus_(trait::image::speed::any, const L& lhs,
283  trait::image::speed::any, const R& rhs, const F& f, O& output)
284  {
285  mln_piter(L) p(lhs.domain());
286  for_all(p)
287  output(p) = f(lhs(p) + rhs(p));
288  }
289 
290  template <typename L, typename R, typename O>
291  inline
292  void plus_(trait::image::speed::fastest, const L& lhs,
293  trait::image::speed::fastest, const R& rhs, O& output)
294  {
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();
300  }
301 
302  template <typename L, typename R, typename F, typename O>
303  inline
304  void plus_(trait::image::speed::fastest, const L& lhs,
305  trait::image::speed::fastest, const R& rhs, const F& f, O& output)
306  {
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());
312  }
313 
314  template <typename L, typename R>
315  inline
316  void plus_inplace_(trait::image::speed::any, L& lhs,
317  trait::image::speed::any, const R& rhs)
318  {
319  mln_piter(L) p(lhs.domain());
320  for_all(p)
321  lhs(p) += rhs(p);
322  }
323 
324  template <typename L, typename R>
325  inline
326  void plus_inplace_(trait::image::speed::fastest, L& lhs,
327  trait::image::speed::fastest, const R& rhs)
328  {
329  mln_pixter(L) lp(lhs);
330  mln_pixter(const R) rp(rhs);
331  for_all_2(lp, rp)
332  lp.val() += rp.val();
333  }
334 
335  } // end of namespace mln::arith::impl
336 
337 
338  // Facades.
339 
340 
341  template <typename L, typename R>
342  inline
343  mln_trait_op_plus(L, R)
344  plus(const Image<L>& lhs, const Image<R>& rhs)
345  {
346  mln_trace("arith::plus");
347 
348  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
349 
350  mln_trait_op_plus(L, R) output;
351  initialize(output, lhs);
352  impl::plus_(mln_trait_image_speed(L)(), exact(lhs),
353  mln_trait_image_speed(R)(), exact(rhs), output);
354 
355  return output;
356  }
357 
358 
359  template <typename L, typename R, typename F>
360  inline
361  mln_ch_value(L, mln_result(F))
362  plus(const Image<L>& lhs, const Image<R>& rhs, const Function_v2v<F>& f)
363  {
364  mln_trace("arith::plus");
365 
366  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
367 
368  mln_ch_value(L, mln_result(F)) output;
369  initialize(output, lhs);
370  impl::plus_(mln_trait_image_speed(L)(), exact(lhs),
371  mln_trait_image_speed(R)(), exact(rhs), exact(f), output);
372 
373  return output;
374  }
375 
376 
377  template <typename V, typename L, typename R>
378  inline
379  mln_ch_value(L, V)
380  plus(const Image<L>& lhs, const Image<R>& rhs)
381  {
382  mln_trace("arith::plus");
383 
384  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
385 
386  // Calls the previous version.
387  mln_ch_value(L, V) output = plus(lhs, rhs,
388  mln::fun::v2v::cast<V>());
389 
390  return output;
391  }
392 
393 
394  template <typename I, typename V>
395  inline
396  mln_trait_op_plus(I, V)
397  plus_cst(const Image<I>& input, const V& val)
398  {
399  mln_trace("arith::plus_cst");
400 
401  mln_precondition(exact(input).is_valid());
402 
403  // Calls the previous version.
404  mln_trait_op_plus(I, V) output = plus(input,
405  pw::cst(val) | exact(input).domain());
406 
407  return output;
408  }
409 
410 
411  template <typename I, typename V, typename F>
412  inline
413  mln_ch_value(I, mln_result(F))
414  plus_cst(const Image<I>& input, const V& val, const Function_v2v<F>& f)
415  {
416  mln_trace("arith::plus_cst");
417 
418  mln_precondition(exact(input).is_valid());
419 
420  // Calls the previous version.
421  mln_ch_value(I, mln_result(F)) output = plus(input,
422  pw::cst(val) | exact(input).domain(),
423  f);
424 
425  return output;
426  }
427 
428 
429  template <typename W, typename I, typename V>
430  inline
431  mln_ch_value(I, W)
432  plus_cst(const Image<I>& input, const V& val)
433  {
434  mln_trace("arith::plus_cst");
435 
436  mln_precondition(exact(input).is_valid());
437 
438  // Calls the previous version.
439  mln_ch_value(I, W) output = plus_cst(input, val,
440  mln::fun::v2v::cast<W>());
441 
442  return output;
443  }
444 
445 
446  template <typename L, typename R>
447  inline
448  void
449  plus_inplace(Image<L>& lhs, const Image<R>& rhs)
450  {
451  mln_trace("arith::plus_inplace");
452 
453  mln_precondition(exact(rhs).domain() == exact(lhs).domain());
454 
455  impl::plus_inplace_(mln_trait_image_speed(L)(), exact(lhs),
456  mln_trait_image_speed(R)(), exact(rhs));
457 
458  }
459 
460 
461  template <typename I, typename V>
462  inline
463  I&
464  plus_cst_inplace(Image<I>& input, const V& val)
465  {
466  mln_trace("arith::plus_cst_inplace");
467 
468  mln_precondition(exact(input).is_valid());
469 
470  // Calls the previous version.
471  plus_inplace(input,
472  pw::cst(val) | exact(input).domain());
473 
474  return exact(input);
475  }
476 
477  } // end of namespace mln::arith
478 
479 # endif // ! MLN_INCLUDE_ONLY
480 
481 } // end of namespace mln
482 
483 
484 #endif // ! MLN_ARITH_PLUS_HH